]> git.lyx.org Git - features.git/commitdiff
Cleanup LyXFunc::dispatch() following JMarc advice.
authorAbdelrazak Younes <younes@lyx.org>
Mon, 26 Nov 2007 14:36:50 +0000 (14:36 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 26 Nov 2007 14:36:50 +0000 (14:36 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21797 a592a061-630c-0410-9148-cb99ea01b6c8

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

index 627be90f70b0d9c241a1a10baa27c8b4a247eebb..891d40b0102c47dfa729a1399f7b65739b86a462 100644 (file)
@@ -197,7 +197,7 @@ bool import(LyXView * lv, FileName const & filename,
                        : changeExtension(filename.absFilename(),
                                          formats.extension(loader_format));
                lv->view()->insertPlaintextFile(filename2, as_paragraphs);
-               lv->dispatch(FuncRequest(LFUN_MARK_OFF));
+               lv->dispatch(FuncRequest(LFUN_MARK_OFF), true);
        }
 
        // we are done
@@ -847,35 +847,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
        } 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:
-               case LFUN_BUFFER_PREVIOUS:
-               case LFUN_COMMAND_EXECUTE:
-               case LFUN_DROP_LAYOUTS_CHOICE:
-               case LFUN_MENU_OPEN:
-               case LFUN_TOOLBAR_TOGGLE:
-               case LFUN_DIALOG_UPDATE:
-               case LFUN_DIALOG_TOGGLE:
-               case LFUN_DIALOG_DISCONNECT_INSET:
-               case LFUN_DIALOG_HIDE:
-               case LFUN_DIALOG_SHOW:
-               case LFUN_INSET_APPLY:
-                       BOOST_ASSERT(lyx_view_);
-                       lyx_view_->dispatch(cmd);
-                       if (lyx_view_->view())
-                               updateFlags = lyx_view_->view()->cursor().result().update();
-                       break;
-
                case LFUN_WORD_FIND_FORWARD:
                case LFUN_WORD_FIND_BACKWARD: {
                        BOOST_ASSERT(lyx_view_ && lyx_view_->view());
@@ -1844,10 +1815,29 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                default: {
+                       BOOST_ASSERT(theApp());
+                       // Let the frontend dispatch its own actions.
+                       if (theApp()->dispatch(cmd))
+                               // Nothing more to do.
+                               return;
+
+                       // Let the current LyXView dispatch its own actions.
                        BOOST_ASSERT(lyx_view_);
+                       if (lyx_view_->dispatch(cmd, false)) {
+                               if (lyx_view_->view())
+                                       updateFlags = lyx_view_->view()->cursor().result().update();
+                               break;
+                       }
+
+                       // FIXME: Probably a good idea to inverse the Cursor and BufferView
+                       // dispatching.
+
+                       // Let the current Cursor dispatch its own actions.
+                       BOOST_ASSERT(lyx_view_->view());
                        view()->cursor().dispatch(cmd);
                        updateFlags = view()->cursor().result().update();
                        if (!view()->cursor().result().dispatched())
+                               // Let the current BufferView dispatch its own actions.
                                updateFlags = view()->dispatch(cmd);
                        break;
                }
@@ -1868,9 +1858,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                        //Do we have a selection?
                        theSelection().haveSelection(view()->cursor().selection());
-
-                       if (view()->cursor().inTexted()) {
-                       }
                }
        }
        if (!quitting && lyx_view_) {
index ab3a82557afda12379e3e14b0b3b48936ba31be0..6bcb53acfc46ddc3a2b4412a9ae9fb3f6cd02807 100644 (file)
@@ -156,7 +156,8 @@ public:
        ///
        virtual FuncStatus getStatus(FuncRequest const & cmd) = 0;
        /// dispatch command.
-       virtual void dispatch(FuncRequest const & cmd) = 0;
+       /// \return true if the \c FuncRequest has been dispatched.
+       virtual bool dispatch(FuncRequest const & cmd) = 0;
 
        ///
        virtual void resetGui() = 0;
index 37ff766e7726ec6197d042289709e93bf9e04e4b..da93d5d4d4c704f91c6ff643208f310ad8df7620 100644 (file)
@@ -75,7 +75,10 @@ public:
        ///
        virtual FuncStatus getStatus(FuncRequest const & cmd) = 0;
        /// dispatch command.
-       virtual void dispatch(FuncRequest const & cmd) = 0;
+       /// \param propagate: indicate if the dispatch should be probagated to
+       /// the main lyx::dispatch().
+       /// \return true if the \c FuncRequest has been dispatched.
+       virtual bool dispatch(FuncRequest const & cmd, bool propagate) = 0;
 
        ///
        virtual void restartCursor() = 0;
index ee1c7db1e6c614795a6dfbcb88547d4a12170b3f..148166312ac719b205bfc225c73a2a6c8ba06217 100644 (file)
@@ -237,7 +237,7 @@ FuncStatus GuiApplication::getStatus(FuncRequest const & cmd)
 }
 
        
-void GuiApplication::dispatch(FuncRequest const & cmd)
+bool GuiApplication::dispatch(FuncRequest const & cmd)
 {
        switch(cmd.action) {
 
@@ -281,8 +281,12 @@ void GuiApplication::dispatch(FuncRequest const & cmd)
        }
 
        default:
-               break;
+               // Notify the caller that the action has not been dispatched.
+               return false;
        }
+
+       // The action has been dispatched.
+       return true;
 }
 
 
index 77655cdc0475b7f739ac0aa0de85bca10a9fcec3..65fa5b76faf8baa91efc1011f716b3d4ba815e70 100644 (file)
@@ -57,7 +57,7 @@ public:
        /// Method inherited from \c Application class
        //@{
        virtual FuncStatus getStatus(FuncRequest const &);
-       virtual void dispatch(FuncRequest const &);
+       virtual bool dispatch(FuncRequest const &);
        virtual void resetGui();
        virtual Clipboard & clipboard();
        virtual Selection & selection();
index 9a5674d5b0d006ba438c14238e51501a6436d973..46c59a38047bbbf4f7d0d7692b44792efcf5f2dc 100644 (file)
@@ -1018,7 +1018,7 @@ FuncStatus GuiView::getStatus(FuncRequest const & cmd)
 }
 
 
-void GuiView::dispatch(FuncRequest const & cmd)
+bool GuiView::dispatch(FuncRequest const & cmd, bool propagate)
 {
        BufferView * bv = view();       
        // By default we won't need any update.
@@ -1161,16 +1161,19 @@ void GuiView::dispatch(FuncRequest const & cmd)
                }
 
                default:
-                       theLyXFunc().setLyXView(this);
-                       lyx::dispatch(cmd);
-                       return;
+                       if (propagate) {
+                               theLyXFunc().setLyXView(this);
+                               lyx::dispatch(cmd);
+                       }
+                       return false;
        }
 
-       if (!bv)
-               return;
-       bv->processUpdateFlags(bv->cursor().result().update());
-       // We won't need any new update.
-       bv->cursor().updateFlags(Update::None);
+       if (bv) {
+               bv->processUpdateFlags(bv->cursor().result().update());
+               // We won't need any new update.
+               bv->cursor().updateFlags(Update::None);
+       }
+       return true;
 }
 
 
index 107e07a9e85b01ba96411968853bd6ec8c85e25f..4078683878069846b776468c2d2fe0d76f0a0ebb 100644 (file)
@@ -76,7 +76,7 @@ public:
        void updateToolbars();
        QMenu * createPopupMenu();
        FuncStatus getStatus(FuncRequest const & cmd);
-       void dispatch(FuncRequest const & cmd);
+       bool dispatch(FuncRequest const & cmd, bool propagate = true);
 
        ///
        void setLayoutDialog(GuiLayoutBox *);