]> git.lyx.org Git - features.git/commitdiff
Introducing Application::getStatus() and Application::dispatch(). Transferring some...
authorAbdelrazak Younes <younes@lyx.org>
Sat, 24 Nov 2007 07:58:12 +0000 (07:58 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sat, 24 Nov 2007 07:58:12 +0000 (07:58 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21759 a592a061-630c-0410-9148-cb99ea01b6c8

src/LyXFunc.cpp
src/frontends/Application.h
src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiApplication.h

index 7fc98ff30bc0317c6318ef8d59da0f8ee0a88423..99d30be41a67b9b9b0091f57f7086cd4b2dee180 100644 (file)
@@ -535,6 +535,12 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        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:
@@ -632,10 +638,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                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: {
@@ -844,6 +846,16 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                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:
@@ -1181,14 +1193,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        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;
@@ -1578,15 +1582,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        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, ' ');
@@ -1839,22 +1834,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        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);
index 89c999318c5699b432aa3a8e3fba6ccdf6dbab85..c6d254d68e0d0793f3a6c09461631b7819b53156 100644 (file)
 namespace lyx {
 
 class BufferView;
-struct RGBColor;
 class Buffer;
+class FuncRequest;
+class FuncStatus;
 class Inset;
+struct RGBColor;
 
 namespace frontend {
 
@@ -151,14 +153,17 @@ public:
        ///
        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;
index ab19035881ca304822972e8bc4567df57a82fa43..96ba02433d811d7aa4a029ce0bdfd8d638e76021 100644 (file)
 #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>
@@ -209,11 +212,87 @@ GuiApplication::~GuiApplication()
 }
 
 
+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));
 }
 
 
index a97878796af7b9c88d5976f6c7024a5bb5838ae0..99bc12b175b347a28638f040a2a4c56bb0ea1d38 100644 (file)
@@ -56,6 +56,8 @@ public:
 
        /// 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();