bool enable = true;
switch (cmd.action) {
+ case LFUN_WINDOW_CLOSE:
+ if (theApp())
+ return theApp()->getStatus(cmd);
+ enable = false;
+ break;
+
case LFUN_DIALOG_TOGGLE:
case LFUN_DIALOG_SHOW:
case LFUN_DIALOG_UPDATE:
enable = LyX::ref().session().bookmarks().size() > 0;
break;
- case LFUN_WINDOW_CLOSE:
- enable = theApp()->viewCount() > 0;
- break;
-
// this one is difficult to get right. As a half-baked
// solution, we consider only the first action of the sequence
case LFUN_COMMAND_SEQUENCE: {
setErrorMessage(flag.message());
} else {
switch (action) {
+
+ // Let the frontend dispatch its own actions.
+ case LFUN_WINDOW_NEW:
+ case LFUN_WINDOW_CLOSE:
+ case LFUN_LYX_QUIT:
+ BOOST_ASSERT(theApp());
+ theApp()->dispatch(cmd);
+ // Nothing more to do.
+ return;
+
// Let lyx_view_ dispatch its own actions.
case LFUN_BUFFER_SWITCH:
case LFUN_BUFFER_NEXT:
doImport(argument);
break;
- case LFUN_LYX_QUIT:
- // quitting is triggered by the gui code
- // (leaving the event loop).
- lyx_view_->message(from_utf8(N_("Exiting.")));
- if (theBufferList().quitWriteAll())
- theApp()->closeAllViews();
- break;
-
case LFUN_BUFFER_AUTO_SAVE:
lyx_view_->buffer()->autoSave();
break;
break;
}
- case LFUN_SCREEN_FONT_UPDATE:
- BOOST_ASSERT(lyx_view_);
- // handle the screen font changes.
- theFontLoader().update();
- /// FIXME: only the current view will be updated. the Gui
- /// class is able to furnish the list of views.
- updateFlags = Update::Force;
- break;
-
case LFUN_SET_COLOR: {
string lyx_name;
string const x11_name = split(argument, lyx_name, ' ');
break;
}
- case LFUN_WINDOW_NEW:
- theApp()->createView();
- break;
-
- case LFUN_WINDOW_CLOSE:
- BOOST_ASSERT(lyx_view_);
- BOOST_ASSERT(theApp());
- // update bookmark pit of the current buffer before window close
- for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
- gotoBookmark(i+1, false, false);
- // ask the user for saving changes or cancel quit
- if (!theBufferList().quitWriteAll())
- break;
- lyx_view_->close();
- return;
-
case LFUN_BOOKMARK_GOTO:
// go to bookmark, open unopened file and switch to buffer if necessary
gotoBookmark(convert<unsigned int>(to_utf8(cmd.argument())), true, true);
namespace lyx {
class BufferView;
-struct RGBColor;
class Buffer;
+class FuncRequest;
+class FuncStatus;
class Inset;
+struct RGBColor;
namespace frontend {
///
virtual ~Application() {}
+ ///
+ virtual FuncStatus getStatus(FuncRequest const & cmd) = 0;
+ /// dispatch command.
+ virtual void dispatch(FuncRequest const & cmd) = 0;
+
///
virtual void resetGui() = 0;
///
virtual bool closeAllViews() = 0;
///
- virtual size_t viewCount() const = 0;
- ///
virtual void hideDialogs(std::string const & name, Inset * inset) const = 0;
///
virtual Buffer const * updateInset(Inset const * inset) const = 0;
#include "support/os.h"
#include "support/Package.h"
+#include "Buffer.h"
#include "BufferList.h"
#include "BufferView.h"
#include "debug.h"
#include "Font.h"
#include "FuncRequest.h"
+#include "FuncStatus.h"
#include "gettext.h"
#include "LyX.h"
#include "LyXFunc.h"
#include "LyXRC.h"
+#include "Session.h"
#include "version.h"
#include <QApplication>
}
+FuncStatus GuiApplication::getStatus(FuncRequest const & cmd)
+{
+ FuncStatus flag;
+ bool enable = true;
+
+ switch(cmd.action) {
+
+ case LFUN_WINDOW_CLOSE:
+ enable = view_ids_.size() > 0;
+ break;
+
+ default:
+ if (!current_view_) {
+ enable = false;
+ break;
+ }
+ }
+
+ if (!enable)
+ flag.enabled(false);
+
+ return flag;
+}
+
+
+void GuiApplication::dispatch(FuncRequest const & cmd)
+{
+ switch(cmd.action) {
+
+ case LFUN_WINDOW_NEW:
+ createView();
+ break;
+
+ case LFUN_WINDOW_CLOSE:
+ // update bookmark pit of the current buffer before window close
+ for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
+ theLyXFunc().gotoBookmark(i+1, false, false);
+ // ask the user for saving changes or cancel quit
+ if (!theBufferList().quitWriteAll())
+ break;
+ current_view_->close();
+ break;
+
+ case LFUN_LYX_QUIT:
+ // quitting is triggered by the gui code
+ // (leaving the event loop).
+ current_view_->message(from_utf8(N_("Exiting.")));
+ if (theBufferList().quitWriteAll())
+ closeAllViews();
+ break;
+
+ case LFUN_SCREEN_FONT_UPDATE: {
+ // handle the screen font changes.
+ font_loader_.update();
+ // Backup current_view_
+ GuiView * view = current_view_;
+ // Set current_view_ to zero to forbid GuiWorkArea::redraw()
+ // to skip the refresh.
+ current_view_ = 0;
+ BufferList::iterator it = theBufferList().begin();
+ BufferList::iterator const end = theBufferList().end();
+ for (; it != end; ++it)
+ (*it)->changed();
+ // Restore current_view_
+ current_view_ = view;
+ break;
+ }
+
+ default:
+ break;
+ }
+}
+
+
void GuiApplication::resetGui()
{
map<int, GuiView *>::iterator it;
for (it = views_.begin(); it != views_.end(); ++it)
it->second->resetDialogs();
+
+ dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
}
/// Method inherited from \c Application class
//@{
+ virtual FuncStatus getStatus(FuncRequest const &);
+ virtual void dispatch(FuncRequest const &);
virtual void resetGui();
virtual Clipboard & clipboard();
virtual Selection & selection();