Hello,
Here is the window-close feature. It wise much more difficult to
implement than I initially thought. At least, I learnt a great deal
about Qt memory management in the process :-)
Bo, the geometry session stuff is now stored in GuiView::saveGeometry().
It is guaranted to be called, either in GuiView::closeEvent() or in
LyX::quit().
I reckon adding multiple view support will be simple as you have access
to the window id in GuiView thanks to the LyXView::id() method. As I
don't know how to handle the file format change, I will let you do that
if you don't mind.
Abdel.
Index: development/scons/scons_manifest.py
===================================================================
--- development/scons/scons_manifest.py (revision 15509)
+++ development/scons/scons_manifest.py (working copy)
@@ -429,9 +429,9 @@
Alert.h
Alert_pimpl.h
Application.h
- Clipboard.h
- NoGuiFontLoader.h
- NoGuiFontMetrics.h
+ Clipboard.h
+ NoGuiFontLoader.h
+ NoGuiFontMetrics.h
Dialogs.h
FileDialog.h
FontLoader.h
Property changes on: development\scons\scons_manifest.py
___________________________________________________________________
Name: svn:eol-style
+ native
Index: lib/ui/stdmenus.ui
===================================================================
--- lib/ui/stdmenus.ui (revision 15509)
+++ lib/ui/stdmenus.ui (working copy)
@@ -33,6 +33,7 @@
Menu "file"
Item "New Window|W" "window-new"
+ Item "Close Window|d" "window-close"
Item "New|N" "buffer-new"
Item "New from Template...|m" "buffer-new-template"
Item "Open...|O" "file-open"
Index: src/frontends/Application.h
===================================================================
--- src/frontends/Application.h (revision 15509)
+++ src/frontends/Application.h (working copy)
@@ -11,6 +11,7 @@
#ifndef LYX_APPLICATION_H
#define LYX_APPLICATION_H
+#include <boost/signals/trackable.hpp>
#include <boost/function.hpp>
#include <string>
@@ -37,7 +38,7 @@
\todo The work areas handling could be moved to a base virtual class
common to all frontends.
*/
-class Application
+class Application: public boost::signals::trackable
{
public:
///
@@ -113,7 +114,7 @@
/// Create the main window with given geometry settings.
LyXView & createView(unsigned int width, unsigned int height,
int posx, int posy, bool maximize);
-
+
///
void setBufferView(BufferView * buffer_view);
Index: src/frontends/Gui.h
===================================================================
--- src/frontends/Gui.h (revision 15509)
+++ src/frontends/Gui.h (working copy)
@@ -17,6 +17,7 @@
#include <boost/shared_ptr.hpp>
#include <map>
+#include <vector>
namespace lyx {
@@ -40,19 +41,20 @@
virtual int newView() = 0;
///
virtual LyXView & view(int id) = 0;
- ///
- virtual void destroyView(int id) = 0;
///
virtual int newWorkArea(unsigned int width, unsigned int height, int
view_id) = 0;
///
virtual WorkArea & workArea(int id) = 0;
+
///
- virtual void destroyWorkArea(int id) = 0;
+ std::vector<int> const & viewIds() { return view_ids_; };
protected:
/// view of a buffer. Eventually there will be several.
std::map<int, boost::shared_ptr<BufferView> > buffer_views_;
+
+ std::vector<int> view_ids_;
};
} // namespace frontend
Index: src/frontends/LyXView.C
===================================================================
--- src/frontends/LyXView.C (revision 15509)
+++ src/frontends/LyXView.C (working copy)
@@ -67,8 +67,8 @@
string current_layout;
-LyXView::LyXView()
- : work_area_(0),
+LyXView::LyXView(int id)
+ : id_(id), work_area_(0),
toolbars_(new Toolbars(*this)),
autosave_timeout_(new Timeout(5000)),
dialogs_(new Dialogs(*this)),
@@ -88,9 +88,12 @@
}
+// FIXME, there's only one WorkArea per LyXView possible for now.
void LyXView::setWorkArea(WorkArea * work_area)
{
work_area_ = work_area;
+ work_area_ids_.clear();
+ work_area_ids_.push_back(work_area_->id());
}
@@ -363,6 +366,12 @@
void LyXView::dispatch(FuncRequest const & cmd)
{
+ if (cmd.action == LFUN_WINDOW_CLOSE) {
+ close();
+ closed(id_);
+ return;
+ }
+
theLyXFunc().setLyXView(this);
lyx::dispatch(cmd);
}
Index: src/frontends/LyXView.h
===================================================================
--- src/frontends/LyXView.h (revision 15509)
+++ src/frontends/LyXView.h (working copy)
@@ -23,6 +23,8 @@
#include <boost/signals/trackable.hpp>
#include <boost/utility.hpp>
+#include <vector>
+
namespace lyx {
class Buffer;
@@ -58,12 +60,21 @@
class LyXView : public boost::signals::trackable, boost::noncopyable {
public:
- LyXView();
+ LyXView(int id);
virtual ~LyXView();
+ int const id() const { return id_; }
+
+ virtual void close() = 0;
+
+ std::vector<int> const & workAreaIds() const { return work_area_ids_; }
+
void setWorkArea(frontend::WorkArea * work_area);
+ /// This signal is emitted with the LyXView id when it is closed.
+ boost::signal<void(int)> closed;
+
/**
* This is called after the concrete view has been created.
* We have to have the toolbar and the other stuff created
@@ -71,12 +82,16 @@
*/
virtual void init() = 0;
+ ///
virtual void setGeometry(
unsigned int width,
unsigned int height,
int posx, int posy,
bool maximize) = 0;
+ /// save the geometry state in the session manager.
+ virtual void saveGeometry() = 0;
+
/// show busy cursor
virtual void busy(bool) const = 0;
@@ -243,6 +258,10 @@
CommandBufferPtr;
CommandBufferPtr const controlcommand_;
+
+private:
+ int id_;
+ std::vector<int> work_area_ids_;
};
} // namespace lyx
Index: src/frontends/qt4/GuiApplication.C
===================================================================
--- src/frontends/qt4/GuiApplication.C (revision 15509)
+++ src/frontends/qt4/GuiApplication.C (working copy)
@@ -27,7 +27,9 @@
#include "BufferView.h"
#include "Color.h"
#include "debug.h"
+#include "funcrequest.h"
#include "lyx_main.h"
+#include "lyxfunc.h"
#include "lyxrc.h"
#include <QApplication>
@@ -149,10 +151,24 @@
LoaderQueue::setPriority(10,100);
+ setQuitOnLastWindowClosed(false);
+ QObject::connect(this, SIGNAL(lastWindowClosed()),
+ this, SLOT(quitLyX()));
+
guiApp = this;
}
+void GuiApplication::quitLyX()
+{
+ theLyXFunc().setLyXView(0);
+
+ // trigger LFUN_LYX_QUIT instead of QApplication::quit() directly
+ // since LFUN_LYX_QUIT may have more cleanup stuff
+ dispatch(FuncRequest(LFUN_LYX_QUIT));
+}
+
+
Clipboard& GuiApplication::clipboard()
{
return clipboard_;
@@ -374,3 +390,5 @@
} // namespace frontend
} // namespace lyx
+
+#include "GuiApplication_moc.cpp"
Index: src/frontends/qt4/GuiApplication.h
===================================================================
--- src/frontends/qt4/GuiApplication.h (revision 15509)
+++ src/frontends/qt4/GuiApplication.h (working copy)
@@ -50,6 +50,8 @@
*/
class GuiApplication : public QApplication, public Application
{
+ Q_OBJECT
+
public:
GuiApplication(int & argc, char ** argv);
///
@@ -81,6 +83,10 @@
///
GuiFontLoader & guiFontLoader() { return font_loader_; }
+private Q_SLOTS:
+ /// request an LFUN_LYX_QUIT
+ void quitLyX();
+
private:
///
GuiImplementation gui_;
Index: src/frontends/qt4/GuiImplementation.C
===================================================================
--- src/frontends/qt4/GuiImplementation.C (revision 15509)
+++ src/frontends/qt4/GuiImplementation.C (working copy)
@@ -20,12 +20,15 @@
#include "GuiWorkArea.h"
#include "BufferView.h"
+#include "funcrequest.h"
+#include "lyxfunc.h"
using boost::shared_ptr;
namespace lyx {
namespace frontend {
+
GuiImplementation::GuiImplementation(): max_view_id_(0), max_wa_id_(0)
{
}
@@ -36,8 +39,12 @@
size_t const id = max_view_id_;
++max_view_id_;
- views_[id].reset(new GuiView());
+ views_[id] = new GuiView(id);
+ view_ids_.push_back(id);
+ QObject::connect(views_[id], SIGNAL(destroyed(QObject *)),
+ this, SLOT(cleanupViews(QObject *)));
+
return id;
}
@@ -46,31 +53,57 @@
{
BOOST_ASSERT(views_.find(id) != views_.end());
- return *views_[id].get();
+ return *views_[id];
}
-void GuiImplementation::destroyView(int id)
+void GuiImplementation::cleanupViews(QObject * qobj)
{
- views_.erase(id);
+ GuiView * view = static_cast<GuiView *>(qobj);
+ std::map<int, GuiView *>::iterator I;
+
+ for (I = views_.begin(); I != views_.end(); ++I) {
+ if (I->second == view) {
+ views_.erase(I->first);
+ break;
+ }
+ }
+
+ buildViewIds();
+
+ if (views_.empty()) {
+ theLyXFunc().setLyXView(0);
+// dispatch(FuncRequest(LFUN_LYX_QUIT));
+ return;
+ }
+ theLyXFunc().setLyXView(views_.begin()->second);
}
+void GuiImplementation::buildViewIds()
+{
+ view_ids_.clear();
+ std::map<int, GuiView *>::const_iterator I;
+ for (I = views_.begin(); I != views_.end(); ++I)
+ view_ids_.push_back(I->first);
+}
+
+
int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int view_id)
{
size_t const id = max_wa_id_;
++max_wa_id_;
- GuiView * view = views_[view_id].get();
+ GuiView * view = views_[view_id];
- work_areas_[id].reset(new GuiWorkArea(w, h, *view));
+ work_areas_[id] = new GuiWorkArea(w, h, id, *view);
// FIXME BufferView creation should be independant of WorkArea creation
buffer_views_[id].reset(new BufferView);
work_areas_[id]->setBufferView(buffer_views_[id].get());
- view->setWorkArea(work_areas_[id].get());
+ view->setWorkArea(work_areas_[id]);
- view->setCentralWidget(work_areas_[id].get());
+ view->setCentralWidget(work_areas_[id]);
return id;
}
@@ -80,14 +113,11 @@
{
BOOST_ASSERT(work_areas_.find(id) != work_areas_.end());
- return *work_areas_[id].get();
+ return *work_areas_[id];
}
-void GuiImplementation::destroyWorkArea(int id)
-{
- work_areas_.erase(id);
-}
-
} // namespace frontend
} // namespace lyx
+
+#include "GuiImplementation_moc.cpp"
Index: src/frontends/qt4/GuiImplementation.h
===================================================================
--- src/frontends/qt4/GuiImplementation.h (revision 15509)
+++ src/frontends/qt4/GuiImplementation.h (working copy)
@@ -15,7 +15,7 @@
#include "frontends/Gui.h"
-#include <boost/shared_ptr.hpp>
+#include <QObject>
#include <map>
@@ -30,26 +30,42 @@
/**
* The GuiImplementation class is the interface to all Qt4 components.
*/
-class GuiImplementation: public Gui
+class GuiImplementation: public QObject, public Gui
{
+ Q_OBJECT
+
public:
GuiImplementation();
virtual ~GuiImplementation() {}
int newView();
LyXView& view(int id);
- void destroyView(int id);
int newWorkArea(unsigned int width, unsigned int height, int view_id);
WorkArea& workArea(int id);
- void destroyWorkArea(int id);
+private Q_SLOTS:
+ ///
+ void cleanupViews(QObject * view);
private:
///
- std::map<int, boost::shared_ptr<GuiView> > views_;
+ void buildViewIds();
+
+ /// Multiple views container.
+ /**
+ * Warning: This must not be a smart pointer as the destruction of the
+ * object is handled by Qt when the view is closed
+ * \sa Qt::WA_DeleteOnClose attribute.
+ */
+ std::map<int, GuiView *> views_;
+
+ /// Multiple workareas container.
+ /**
+ * Warning: This must not be a smart pointer as the destruction of the
+ * object is handled by Qt when its parent view is closed.
+ */
+ std::map<int, GuiWorkArea *> work_areas_;
///
- std::map<int, boost::shared_ptr<GuiWorkArea> > work_areas_;
- ///
size_t max_view_id_;
///
size_t max_wa_id_;
Index: src/frontends/qt4/GuiView.C
===================================================================
--- src/frontends/qt4/GuiView.C (revision 15509)
+++ src/frontends/qt4/GuiView.C (working copy)
@@ -67,9 +67,12 @@
} // namespace anon
-GuiView::GuiView()
- : QMainWindow(), LyXView(), commandbuffer_(0)
+GuiView::GuiView(int id)
+ : QMainWindow(), LyXView(id), commandbuffer_(0)
{
+ setAttribute(Qt::WA_DeleteOnClose, true);
+ setAttribute(Qt::WA_QuitOnClose, true);
+
// setToolButtonStyle(Qt::ToolButtonIconOnly);
// setIconSize(QSize(12,12));
@@ -90,6 +93,12 @@
}
+void GuiView::close()
+{
+ QMainWindow::close();
+}
+
+
void GuiView::init()
{
menubar_.reset(new QLMenubar(this, menubackend));
@@ -110,6 +119,33 @@
}
+void GuiView::saveGeometry()
+{
+ // FIXME:
+ // change the ifdef to 'geometry = normalGeometry();' only
+ // when Trolltech has fixed the broken normalGeometry on X11:
+ //
http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
+ // Then also the moveEvent, resizeEvent, and the
+ // code for floatingGeometry_ can be removed;
+ // adjust GuiView::setGeometry()
+#ifdef Q_OS_WIN32
+ QRect geometry = normalGeometry();
+#else
+ updateFloatingGeometry();
+ QRect geometry = floatingGeometry_;
+#endif
+
+ // save windows size and position
+ Session & session = LyX::ref().session();
+ session.saveSessionInfo("WindowWidth",
convert<string>(geometry.width()));
+ session.saveSessionInfo("WindowHeight",
convert<string>(geometry.height()));
+ session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" :
"no"));
+ if (lyxrc.geometry_xysaved) {
+ session.saveSessionInfo("WindowPosX",
convert<string>(geometry.x()));
+ session.saveSessionInfo("WindowPosY",
convert<string>(geometry.y()));
+ }
+}
+
void GuiView::setGeometry(unsigned int width,
unsigned int
height,
int posx, int
posy,
@@ -230,32 +266,7 @@
void GuiView::closeEvent(QCloseEvent *)
{
- // FIXME:
- // change the ifdef to 'geometry = normalGeometry();' only
- // when Trolltech has fixed the broken normalGeometry on X11:
- //
http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
- // Then also the moveEvent, resizeEvent, and the
- // code for floatingGeometry_ can be removed;
- // adjust GuiView::setGeometry()
-#ifdef Q_OS_WIN32
- QRect geometry = normalGeometry();
-#else
- updateFloatingGeometry();
- QRect geometry = floatingGeometry_;
-#endif
-
- // save windows size and position
- Session & session = LyX::ref().session();
- session.saveSessionInfo("WindowWidth",
convert<string>(geometry.width()));
- session.saveSessionInfo("WindowHeight",
convert<string>(geometry.height()));
- session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" :
"no"));
- if (lyxrc.geometry_xysaved) {
- session.saveSessionInfo("WindowPosX",
convert<string>(geometry.x()));
- session.saveSessionInfo("WindowPosY",
convert<string>(geometry.y()));
- }
- // trigger LFUN_LYX_QUIT instead of quit directly
- // since LFUN_LYX_QUIT may have more cleanup stuff
- dispatch(FuncRequest(LFUN_LYX_QUIT));
+ saveGeometry();
}
Index: src/frontends/qt4/GuiView.h
===================================================================
--- src/frontends/qt4/GuiView.h (revision 15509)
+++ src/frontends/qt4/GuiView.h (working copy)
@@ -47,36 +47,27 @@
Q_OBJECT
public:
/// create a main window of the given dimensions
- GuiView();
+ GuiView(int id);
~GuiView();
- /// initialize the object
virtual void init();
-
- ///
+ virtual void close();
virtual void setGeometry(
unsigned int width,
unsigned int height,
int posx, int posy,
bool maximize);
-
- /// show - display the top-level window
- void show();
-
- /// show busy cursor
+ virtual void saveGeometry();
virtual void busy(bool) const;
-
Toolbars::ToolbarPtr makeToolbar(ToolbarBackend::Toolbar const & tbb);
-
- /// display a status message
+ virtual void updateStatusBar();
virtual void message(lyx::docstring const & str);
-
- /// clear status message
virtual void clearMessage();
+ virtual bool hasFocus() const;
- /// update the status bar
- virtual void updateStatusBar();
+ /// show - display the top-level window
+ void show();
/// add the command buffer
void addCommandBuffer(QToolBar * toolbar);
@@ -84,9 +75,10 @@
/// menu item has been selected
void activated(FuncRequest const &);
- /// returns true if this view has the focus.
- virtual bool hasFocus() const;
+Q_SIGNALS:
+ void closing(int);
+
public Q_SLOTS:
/// idle timeout
void update_view_state_qt();
Index: src/frontends/qt4/GuiWorkArea.C
===================================================================
--- src/frontends/qt4/GuiWorkArea.C (revision 15509)
+++ src/frontends/qt4/GuiWorkArea.C (working copy)
@@ -180,8 +180,8 @@
{}
-GuiWorkArea::GuiWorkArea(int w, int h, LyXView & lyx_view)
- : WorkArea(lyx_view)
+GuiWorkArea::GuiWorkArea(int w, int h, int id, LyXView & lyx_view)
+ : WorkArea(id, lyx_view)
{
cursor_ = new frontend::CursorWidget(this);
cursor_->hide();
Index: src/frontends/qt4/GuiWorkArea.h
===================================================================
--- src/frontends/qt4/GuiWorkArea.h (revision 15509)
+++ src/frontends/qt4/GuiWorkArea.h (working copy)
@@ -91,7 +91,7 @@
public:
///
- GuiWorkArea(int width, int height, LyXView & lyx_view);
+ GuiWorkArea(int width, int height, int id, LyXView & lyx_view);
/// return the width of the content pane
virtual int width() const { return viewport()->width(); }
Index: src/frontends/qt4/Makefile.am
===================================================================
--- src/frontends/qt4/Makefile.am (revision 15509)
+++ src/frontends/qt4/Makefile.am (working copy)
@@ -34,7 +34,6 @@
ColorCache.h ColorCache.C \
Dialogs.C \
FileDialog.C \
- GuiApplication.C GuiApplication.h \
GuiClipboard.h GuiClipboard.C \
GuiFontLoader.h GuiFontLoader.C \
GuiFontMetrics.h GuiFontMetrics.C \
Index: src/frontends/qt4/Makefile.dialogs
===================================================================
--- src/frontends/qt4/Makefile.dialogs (revision 15509)
+++ src/frontends/qt4/Makefile.dialogs (working copy)
@@ -78,6 +78,7 @@
emptytable.C emptytable.h \
FileDialog_private.C FileDialog_private.h \
FloatPlacement.C FloatPlacement.h \
+ GuiApplication.C GuiApplication.h \
GuiView.C GuiView.h \
GuiWorkArea.C GuiWorkArea.h \
iconpalette.C iconpalette.h \
Index: src/frontends/WorkArea.h
===================================================================
--- src/frontends/WorkArea.h (revision 15509)
+++ src/frontends/WorkArea.h (working copy)
@@ -54,10 +54,12 @@
*/
class WorkArea : public boost::signals::trackable {
public:
- WorkArea(LyXView & lyx_view);
+ WorkArea(int id, LyXView & lyx_view);
virtual ~WorkArea() {}
+ int const id() const { return id_; }
+
void setBufferView(BufferView * buffer_view);
///
@@ -120,6 +122,8 @@
private:
///
+ int id_;
+ ///
void displayMessage(docstring const &);
/// buffer messages signal connection
boost::signals::connection message_connection_;
Index: src/lfuns.h
===================================================================
--- src/lfuns.h (revision 15509)
+++ src/lfuns.h (working copy)
@@ -370,6 +370,7 @@
LFUN_INSET_DISSOLVE, // jspitzm 20060807
LFUN_CHANGE_NEXT,
LFUN_WINDOW_NEW, // Abdel 20061021
+ LFUN_WINDOW_CLOSE, // Abdel 22062110
LFUN_UNICODE_INSERT, // Lgb 20061022
LFUN_LASTACTION // end of the table
Index: src/lyx_main.C
===================================================================
--- src/lyx_main.C (revision 15509)
+++ src/lyx_main.C (working copy)
@@ -44,6 +44,7 @@
#include "frontends/Alert.h"
#include "frontends/Application.h"
+#include "frontends/Gui.h"
#include "frontends/LyXView.h"
#include "support/environment.h"
@@ -284,22 +285,19 @@
return *pimpl_->toplevel_keymap_.get();
}
-void LyX::addLyXView(LyXView * lyxview)
-{
- views_.push_back(lyxview);
-}
-
Buffer const * const LyX::updateInset(InsetBase const * inset) const
{
if (!inset)
return 0;
Buffer const * buffer_ptr = 0;
- ViewList::const_iterator it = views_.begin();
- ViewList::const_iterator const end = views_.end();
+ vector<int> const & view_ids = pimpl_->application_->gui().viewIds();
+ vector<int>::const_iterator it = view_ids.begin();
+ vector<int>::const_iterator const end = view_ids.end();
for (; it != end; ++it) {
- Buffer const * ptr = (*it)->updateInset(inset);
+ Buffer const * ptr =
+
pimpl_->application_->gui().view(*it).updateInset(inset);
if (ptr)
buffer_ptr = ptr;
}
@@ -403,6 +401,13 @@
if (!noask && !pimpl_->buffer_list_.quitWriteAll())
return;
+ // The LyXView Geometry settings are stored when LyXView::close
+ // is called explicitely but a straight quit() command would not
+ // guarante that. So we make sure this is done here:
+ vector<int> const & view_ids =
pimpl_->application_->gui().viewIds();
+ for (size_t i = 0; i < view_ids.size(); ++i)
+
pimpl_->application_->gui().view(view_ids[i]).saveGeometry();
+
pimpl_->session_->writeFile();
}
@@ -515,6 +520,9 @@
LyXView * LyX::newLyXView()
{
+ if (!lyx::use_gui)
+ return 0;
+
// determine windows size and position, from lyxrc and/or session
// initial geometry
unsigned int width = 690;
@@ -555,7 +563,6 @@
}
// create the main window
LyXView * view = &pimpl_->application_->createView(width, height, posx,
posy, maximize);
- ref().addLyXView(view);
return view;
}
Index: src/lyx_main.h
===================================================================
--- src/lyx_main.h (revision 15509)
+++ src/lyx_main.h (working copy)
@@ -17,7 +17,6 @@
#include <boost/scoped_ptr.hpp>
#include <boost/utility.hpp>
-#include <list>
#include <string>
#include <vector>
@@ -123,9 +122,6 @@
/// Create a View and restore GUI Session.
void restoreGuiSession(std::vector<std::string> const & files);
- ///
- void addLyXView(LyXView * lyxview);
-
/// Initialize RC font for the GUI.
void initGuiFont();
@@ -163,9 +159,6 @@
/// Use the Pimpl idiom to hide the internals.
struct Singletons;
boost::scoped_ptr<Singletons> pimpl_;
- ///
- typedef std::list<LyXView *> ViewList;
- ViewList views_;
///
bool geometryOption_;
Index: src/LyXAction.C
===================================================================
--- src/LyXAction.C (revision 15509)
+++ src/LyXAction.C (working copy)
@@ -363,8 +363,12 @@
{ LFUN_PARAGRAPH_MOVE_DOWN, "paragraph-move-down", Noop },
{ LFUN_PARAGRAPH_MOVE_UP, "paragraph-move-up", Noop },
{ LFUN_WINDOW_NEW, "window-new", NoBuffer },
+<<<<<<< .mine
+ { LFUN_WINDOW_CLOSE, "window-close", NoBuffer },
+=======
{ LFUN_UNICODE_INSERT, "unicode-insert", Noop },
+>>>>>>> .r15509
{ LFUN_NOACTION, "", Noop }
};
Index: src/lyxfunc.C
===================================================================
--- src/lyxfunc.C (revision 15509)
+++ src/lyxfunc.C (working copy)
@@ -78,6 +78,7 @@
#include "frontends/Dialogs.h"
#include "frontends/FileDialog.h"
#include "frontends/FontLoader.h"
+#include "frontends/Gui.h"
#include "frontends/LyXKeySym.h"
#include "frontends/LyXView.h"
#include "frontends/Menubar.h"
@@ -346,6 +347,13 @@
{
//lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
FuncStatus flag;
+
+ if (cmd.action == LFUN_LYX_QUIT) {
+ flag.message(from_utf8(N_("Exiting")));
+ flag.enabled(true);
+ return flag;
+ }
+
LCursor & cur = view()->cursor();
/* In LyX/Mac, when a dialog is open, the menus of the
@@ -580,7 +588,6 @@
case LFUN_BUFFER_UPDATE:
case LFUN_BUFFER_VIEW:
case LFUN_BUFFER_IMPORT:
- case LFUN_LYX_QUIT:
case LFUN_TOC_VIEW:
case LFUN_BUFFER_AUTO_SAVE:
case LFUN_RECONFIGURE:
@@ -619,6 +626,7 @@
case LFUN_BUFFER_NEXT:
case LFUN_BUFFER_PREVIOUS:
case LFUN_WINDOW_NEW:
+ case LFUN_WINDOW_CLOSE:
// these are handled in our dispatch()
break;
@@ -716,7 +724,6 @@
void LyXFunc::dispatch(FuncRequest const & cmd)
{
- BOOST_ASSERT(view());
string const argument = to_utf8(cmd.argument());
kb_action const action = cmd.action;
@@ -744,6 +751,7 @@
case LFUN_WORD_FIND_FORWARD:
case LFUN_WORD_FIND_BACKWARD: {
+ BOOST_ASSERT(lyx_view_ && lyx_view_->view());
static string last_search;
string searched_string;
@@ -765,15 +773,18 @@
}
case LFUN_COMMAND_PREFIX:
+ BOOST_ASSERT(lyx_view_);
lyx_view_->message(from_utf8(keyseq->printOptions()));
break;
case LFUN_COMMAND_EXECUTE:
+ BOOST_ASSERT(lyx_view_);
lyx_view_->getToolbars().display("minibuffer", true);
lyx_view_->focus_command_buffer();
break;
case LFUN_CANCEL:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->view());
keyseq->reset();
meta_fake_bit = key_modifier::none;
if (view()->buffer())
@@ -788,6 +799,7 @@
break;
case LFUN_BUFFER_TOGGLE_READ_ONLY:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->view() &&
lyx_view_->buffer());
if (lyx_view_->buffer()->lyxvc().inUse())
lyx_view_->buffer()->lyxvc().toggleReadOnly();
else
@@ -810,6 +822,7 @@
break;
case LFUN_BUFFER_WRITE:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
if (!lyx_view_->buffer()->isUnnamed()) {
docstring const str = bformat(_("Saving
document %1$s..."),
makeDisplayPath(lyx_view_->buffer()->fileName()));
@@ -822,11 +835,13 @@
break;
case LFUN_BUFFER_WRITE_AS:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
writeAs(lyx_view_->buffer(), argument);
updateFlags = Update::None;
break;
case LFUN_BUFFER_RELOAD: {
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
docstring const file =
makeDisplayPath(view()->buffer()->fileName(), 20);
docstring text = bformat(_("Any changes will be lost.
Are you sure "
"you want to
revert to the saved version of the document %1$s?"), file);
@@ -839,22 +854,27 @@
}
case LFUN_BUFFER_UPDATE:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
Exporter::Export(lyx_view_->buffer(), argument, true);
break;
case LFUN_BUFFER_VIEW:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
Exporter::preview(lyx_view_->buffer(), argument);
break;
case LFUN_BUILD_PROGRAM:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
Exporter::Export(lyx_view_->buffer(), "program", true);
break;
case LFUN_BUFFER_CHKTEX:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
lyx_view_->buffer()->runChktex();
break;
case LFUN_BUFFER_EXPORT:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
if (argument == "custom")
lyx_view_->getDialogs().show("sendto");
else {
@@ -863,6 +883,7 @@
break;
case LFUN_BUFFER_EXPORT_CUSTOM: {
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
string format_name;
string command = split(argument, format_name, ' ');
Format const * format = formats.getFormat(format_name);
@@ -905,6 +926,7 @@
}
case LFUN_BUFFER_PRINT: {
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
string target;
string target_name;
string command = split(split(argument, target, ' '),
@@ -1000,7 +1022,7 @@
break;
case LFUN_LYX_QUIT:
- if (view()->buffer()) {
+ if (lyx_view_ && lyx_view_->view()->buffer()) {
// save cursor Position for opened files to
.lyx/session
LyX::ref().session().saveFilePosition(lyx_view_->buffer()->fileName(),
boost::tie(view()->cursor().pit(),
view()->cursor().pos()) );
@@ -1011,6 +1033,7 @@
break;
case LFUN_TOC_VIEW: {
+ BOOST_ASSERT(lyx_view_);
InsetCommandParams p("tableofcontents");
string const data =
InsetCommandMailer::params2string("toc", p);
lyx_view_->getDialogs().show("toc", data, 0);
@@ -1026,6 +1049,7 @@
break;
case LFUN_HELP_OPEN: {
+ BOOST_ASSERT(lyx_view_);
string const arg = argument;
if (arg.empty()) {
setErrorMessage(_("Missing argument"));
@@ -1045,6 +1069,7 @@
// --- version control -------------------------------
case LFUN_VC_REGISTER:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
if (!ensureBufferClean(view()))
break;
if (!lyx_view_->buffer()->lyxvc().inUse()) {
@@ -1054,6 +1079,7 @@
break;
case LFUN_VC_CHECK_IN:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
if (!ensureBufferClean(view()))
break;
if (lyx_view_->buffer()->lyxvc().inUse()
@@ -1064,6 +1090,7 @@
break;
case LFUN_VC_CHECK_OUT:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
if (!ensureBufferClean(view()))
break;
if (lyx_view_->buffer()->lyxvc().inUse()
@@ -1074,46 +1101,56 @@
break;
case LFUN_VC_REVERT:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
lyx_view_->buffer()->lyxvc().revert();
view()->reload();
break;
case LFUN_VC_UNDO_LAST:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
lyx_view_->buffer()->lyxvc().undoLast();
view()->reload();
break;
// --- buffers ----------------------------------------
case LFUN_BUFFER_SWITCH:
+ BOOST_ASSERT(lyx_view_);
lyx_view_->setBuffer(theBufferList().getBuffer(argument));
break;
case LFUN_BUFFER_NEXT:
+ BOOST_ASSERT(lyx_view_);
lyx_view_->setBuffer(theBufferList().next(view()->buffer()));
break;
case LFUN_BUFFER_PREVIOUS:
+ BOOST_ASSERT(lyx_view_);
lyx_view_->setBuffer(theBufferList().previous(view()->buffer()));
break;
case LFUN_FILE_NEW:
+ BOOST_ASSERT(lyx_view_);
newFile(view(), argument);
break;
case LFUN_FILE_OPEN:
+ BOOST_ASSERT(lyx_view_);
open(argument);
break;
case LFUN_DROP_LAYOUTS_CHOICE:
+ BOOST_ASSERT(lyx_view_);
lyx_view_->getToolbars().openLayoutList();
break;
case LFUN_MENU_OPEN:
+ BOOST_ASSERT(lyx_view_);
lyx_view_->getMenubar().openByName(from_utf8(argument));
break;
// --- lyxserver commands ----------------------------
case LFUN_SERVER_GET_NAME:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
setMessage(from_utf8(lyx_view_->buffer()->fileName()));
lyxerr[Debug::INFO] << "FNAME["
<<
lyx_view_->buffer()->fileName()
@@ -1126,6 +1163,7 @@
break;
case LFUN_SERVER_GOTO_FILE_ROW: {
+ BOOST_ASSERT(lyx_view_);
string file_name;
int row;
istringstream is(argument);
@@ -1154,6 +1192,7 @@
}
case LFUN_DIALOG_SHOW: {
+ BOOST_ASSERT(lyx_view_);
string const name = cmd.getArg(0);
string data =
trim(to_utf8(cmd.argument()).substr(name.size()));
@@ -1184,6 +1223,7 @@
}
case LFUN_DIALOG_SHOW_NEW_INSET: {
+ BOOST_ASSERT(lyx_view_);
string const name = cmd.getArg(0);
string data =
trim(to_utf8(cmd.argument()).substr(name.size()));
if (name == "bibitem" ||
@@ -1236,6 +1276,7 @@
}
case LFUN_DIALOG_UPDATE: {
+ BOOST_ASSERT(lyx_view_);
string const & name = argument;
// Can only update a dialog connected to an existing
inset
InsetBase * inset =
lyx_view_->getDialogs().getOpenInset(name);
@@ -1255,11 +1296,13 @@
break;
case LFUN_DIALOG_DISCONNECT_INSET:
+ BOOST_ASSERT(lyx_view_);
lyx_view_->getDialogs().disconnect(argument);
break;
case LFUN_CITATION_INSERT: {
+ BOOST_ASSERT(lyx_view_);
if (!argument.empty()) {
// we can have one optional argument, delimited
by '|'
// citation-insert <key>|<text_before>
@@ -1283,6 +1326,7 @@
}
case LFUN_BUFFER_CHILD_OPEN: {
+ BOOST_ASSERT(lyx_view_);
string const filename =
makeAbsPath(argument,
lyx_view_->buffer()->filePath());
// FIXME Should use bformat
@@ -1302,22 +1346,27 @@
}
case LFUN_TOGGLE_CURSOR_FOLLOWS_SCROLLBAR:
+ BOOST_ASSERT(lyx_view_);
lyxrc.cursor_follows_scrollbar =
!lyxrc.cursor_follows_scrollbar;
break;
case LFUN_KEYMAP_OFF:
+ BOOST_ASSERT(lyx_view_);
lyx_view_->view()->getIntl().keyMapOn(false);
break;
case LFUN_KEYMAP_PRIMARY:
+ BOOST_ASSERT(lyx_view_);
lyx_view_->view()->getIntl().keyMapPrim();
break;
case LFUN_KEYMAP_SECONDARY:
+ BOOST_ASSERT(lyx_view_);
lyx_view_->view()->getIntl().keyMapSec();
break;
case LFUN_KEYMAP_TOGGLE:
+ BOOST_ASSERT(lyx_view_);
lyx_view_->view()->getIntl().toggleKeyMap();
break;
@@ -1354,6 +1403,7 @@
}
case LFUN_SCREEN_FONT_UPDATE:
+ BOOST_ASSERT(lyx_view_);
// handle the screen font changes.
lyxrc.set_font_norm_type();
theFontLoader().update();
@@ -1397,10 +1447,12 @@
}
case LFUN_MESSAGE:
+ BOOST_ASSERT(lyx_view_);
lyx_view_->message(from_utf8(argument));
break;
case LFUN_EXTERNAL_EDIT: {
+ BOOST_ASSERT(lyx_view_);
FuncRequest fr(action, argument);
InsetExternal().dispatch(view()->cursor(), fr);
break;
@@ -1413,6 +1465,7 @@
}
case LFUN_INSET_APPLY: {
+ BOOST_ASSERT(lyx_view_);
string const name = cmd.getArg(0);
InsetBase * inset =
lyx_view_->getDialogs().getOpenInset(name);
if (inset) {
@@ -1429,6 +1482,7 @@
}
case LFUN_ALL_INSETS_TOGGLE: {
+ BOOST_ASSERT(lyx_view_);
string action;
string const name = split(argument, action, ' ');
InsetBase::Code const inset_code =
@@ -1453,6 +1507,7 @@
}
case LFUN_BUFFER_LANGUAGE: {
+ BOOST_ASSERT(lyx_view_);
Buffer & buffer = *lyx_view_->buffer();
Language const * oldL = buffer.params().language;
Language const * newL = languages.getLanguage(argument);
@@ -1495,6 +1550,7 @@
}
case LFUN_BUFFER_PARAMS_APPLY: {
+ BOOST_ASSERT(lyx_view_);
biblio::CiteEngine const engine =
lyx_view_->buffer()->params().cite_engine;
@@ -1526,6 +1582,7 @@
}
case LFUN_TEXTCLASS_APPLY: {
+ BOOST_ASSERT(lyx_view_);
Buffer * buffer = lyx_view_->buffer();
textclass_type const old_class =
@@ -1583,10 +1640,18 @@
}
case LFUN_WINDOW_NEW:
- BOOST_ASSERT(theApp);
LyX::ref().newLyXView();
+ break;
+ case LFUN_WINDOW_CLOSE:
+ BOOST_ASSERT(lyx_view_);
+ BOOST_ASSERT(theApp);
+ lyx_view_->close();
+ // We return here because lyx_view does not exists
anymore.
+ return;
+
default: {
+ BOOST_ASSERT(lyx_view_);
view()->cursor().dispatch(cmd);
updateFlags = view()->cursor().result().update();
if (!view()->cursor().result().dispatched())
@@ -1596,7 +1661,7 @@
}
}
- if (view()->buffer()) {
+ if (lyx_view_ && view()->buffer()) {
// Redraw screen unless explicitly told otherwise.
// This also initializes the position cache for all
insets
// in (at least partially) visible top-level paragraphs.