]> git.lyx.org Git - features.git/commitdiff
Add DispatchResult argument to BufferView::dispatch, and remove explicit updates...
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 25 Jan 2010 15:14:41 +0000 (15:14 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 25 Jan 2010 15:14:41 +0000 (15:14 +0000)
Split LyXFunc::dispatch into a wrapper that does the actual screen updates and
a worker method that updates a DispatchResult object.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33226 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp
src/BufferView.h
src/LyX.cpp
src/LyX.h
src/LyXFunc.cpp
src/LyXFunc.h
src/mathed/InsetMathRef.cpp

index 330daa786fadc0a7697dbd509f97d856b0c09ff9..64f3065898ac4d92f04a05d3cc8526373891f30e 100644 (file)
@@ -1148,7 +1148,7 @@ void BufferView::editInset(string const & name, Inset * inset)
 }
 
 
-bool BufferView::dispatch(FuncRequest const & cmd)
+void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 {
        //lyxerr << [ cmd = " << cmd << "]" << endl;
 
@@ -1165,7 +1165,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
        // Don't dispatch function that does not apply to internal buffers.
        if (buffer_.isInternal() 
            && lyxaction.funcHasFlag(cmd.action, LyXAction::NoInternal))
-               return false;
+               return;
 
        // We'll set this back to false if need be.
        bool dispatched = true;
@@ -1190,7 +1190,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                // We are most certainly here because of a change in the document
                // It is then better to make sure that all dialogs are in sync with
                // current document settings.
-               processUpdateFlags(Update::Force | Update::FitCursor);
+               dr.update(Update::Force | Update::FitCursor);
                break;
        }
                
@@ -1201,7 +1201,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                buffer_.params().clearLayoutModules();
                buffer_.params().makeDocumentClass();
                updateLayout(oldClass);
-               processUpdateFlags(Update::Force | Update::FitCursor);
+               dr.update(Update::Force | Update::FitCursor);
                break;
        }
 
@@ -1218,7 +1218,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                buffer_.params().addLayoutModule(argument);
                buffer_.params().makeDocumentClass();
                updateLayout(oldClass);
-               processUpdateFlags(Update::Force | Update::FitCursor);
+               dr.update(Update::Force | Update::FitCursor);
                break;
        }
 
@@ -1241,7 +1241,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                buffer_.params().setBaseClass(argument);
                buffer_.params().makeDocumentClass();
                updateLayout(oldDocClass);
-               processUpdateFlags(Update::Force | Update::FitCursor);
+               dr.update(Update::Force | Update::FitCursor);
                break;
        }
 
@@ -1257,30 +1257,30 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                buffer_.params().setBaseClass(bc);
                buffer_.params().makeDocumentClass();
                updateLayout(oldClass);
-               processUpdateFlags(Update::Force | Update::FitCursor);
+               dr.update(Update::Force | Update::FitCursor);
                break;
        }
 
        case LFUN_UNDO:
-               cur.message(_("Undo"));
+               dr.setMessage(_("Undo"));
                cur.clearSelection();
                if (!cur.textUndo())
-                       cur.message(_("No further undo information"));
+                       dr.setMessage(_("No further undo information"));
                else
-                       processUpdateFlags(Update::Force | Update::FitCursor);
+                       dr.update(Update::Force | Update::FitCursor);
                break;
 
        case LFUN_REDO:
-               cur.message(_("Redo"));
+               dr.setMessage(_("Redo"));
                cur.clearSelection();
                if (!cur.textRedo())
-                       cur.message(_("No further redo information"));
+                       dr.setMessage(_("No further redo information"));
                else
-                       processUpdateFlags(Update::Force | Update::FitCursor);
+                       dr.update(Update::Force | Update::FitCursor);
                break;
 
        case LFUN_FONT_STATE:
-               cur.message(cur.currentState());
+               dr.setMessage(cur.currentState());
                break;
 
        case LFUN_BOOKMARK_SAVE:
@@ -1343,7 +1343,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                                // Set the cursor
                                dit.pos() = pos;
                                setCursor(dit);
-                               processUpdateFlags(Update::Force | Update::FitCursor);
+                               dr.update(Update::Force | Update::FitCursor);
                        } else {
                                // Switch to other buffer view and resend cmd
                                theLyXFunc().dispatch(FuncRequest(
@@ -1397,18 +1397,18 @@ bool BufferView::dispatch(FuncRequest const & cmd)
        case LFUN_CHANGE_NEXT:
                findNextChange(this);
                // FIXME: Move this LFUN to Buffer so that we don't have to do this:
-               processUpdateFlags(Update::Force | Update::FitCursor);
+               dr.update(Update::Force | Update::FitCursor);
                break;
        
        case LFUN_CHANGE_PREVIOUS:
                findPreviousChange(this);
                // FIXME: Move this LFUN to Buffer so that we don't have to do this:
-               processUpdateFlags(Update::Force | Update::FitCursor);
+               dr.update(Update::Force | Update::FitCursor);
                break;
 
        case LFUN_CHANGES_MERGE:
                if (findNextChange(this) || findPreviousChange(this)) {
-                       processUpdateFlags(Update::Force | Update::FitCursor);
+                       dr.update(Update::Force | Update::FitCursor);
                        showDialog("changes");
                }
                break;
@@ -1421,7 +1421,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                // accept everything in a single step to support atomic undo
                buffer_.text().acceptOrRejectChanges(cur, Text::ACCEPT);
                // FIXME: Move this LFUN to Buffer so that we don't have to do this:
-               processUpdateFlags(Update::Force | Update::FitCursor);
+               dr.update(Update::Force | Update::FitCursor);
                break;
 
        case LFUN_ALL_CHANGES_REJECT:
@@ -1433,7 +1433,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                // Note: reject does not work recursively; the user may have to repeat the operation
                buffer_.text().acceptOrRejectChanges(cur, Text::REJECT);
                // FIXME: Move this LFUN to Buffer so that we don't have to do this:
-               processUpdateFlags(Update::Force | Update::FitCursor);
+               dr.update(Update::Force | Update::FitCursor);
                break;
 
        case LFUN_WORD_FIND_FORWARD:
@@ -1504,23 +1504,23 @@ bool BufferView::dispatch(FuncRequest const & cmd)
 
        case LFUN_MARK_OFF:
                cur.clearSelection();
-               cur.message(from_utf8(N_("Mark off")));
+               dr.setMessage(from_utf8(N_("Mark off")));
                break;
 
        case LFUN_MARK_ON:
                cur.clearSelection();
                cur.setMark(true);
-               cur.message(from_utf8(N_("Mark on")));
+               dr.setMessage(from_utf8(N_("Mark on")));
                break;
 
        case LFUN_MARK_TOGGLE:
                cur.setSelection(false);
                if (cur.mark()) {
                        cur.setMark(false);
-                       cur.message(from_utf8(N_("Mark removed")));
+                       dr.setMessage(from_utf8(N_("Mark removed")));
                } else {
                        cur.setMark(true);
-                       cur.message(from_utf8(N_("Mark set")));
+                       dr.setMessage(from_utf8(N_("Mark set")));
                }
                cur.resetAnchor();
                break;
@@ -1614,7 +1614,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                        // It did not work too; no action needed.
                        break;
                cur.clearSelection();
-               processUpdateFlags(Update::SinglePar | Update::FitCursor);
+               dr.update(Update::SinglePar | Update::FitCursor);
                break;
        }
 
@@ -1644,7 +1644,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                bool update = in_texted && cur.bv().checkDepm(cur, old);
                cur.finishUndo();
                if (update)
-                       processUpdateFlags(Update::Force | Update::FitCursor);
+                       dr.update(Update::Force | Update::FitCursor);
                break;
        }
 
@@ -1665,7 +1665,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                        y = getPos(cur, cur.boundary()).y_;
 
                cur.finishUndo();
-               processUpdateFlags(Update::SinglePar | Update::FitCursor);
+               dr.update(Update::SinglePar | Update::FitCursor);
                break;
        }
 
@@ -1682,7 +1682,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                        y = getPos(cur, cur.boundary()).y_;
 
                cur.finishUndo();
-               processUpdateFlags(Update::SinglePar | Update::FitCursor);
+               dr.update(Update::SinglePar | Update::FitCursor);
                break;
        }
 
@@ -1725,12 +1725,13 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                cur.endUndoGroup();
                cur = savecur;
                cur.fixIfBroken();
-               processUpdateFlags(Update::Force);
+               dr.update(Update::Force);
 
-               if (iterations >= max_iter)
-                       cur.errorMessage(bformat(_("`inset-forall' interrupted because number of actions is larger than %1$d"), max_iter));
-               else
-                       cur.message(bformat(_("Applied \"%1$s\" to %2$d insets"), from_utf8(commandstr), iterations));
+               if (iterations >= max_iter) {
+                       dr.setError(true);
+                       dr.setMessage(bformat(_("`inset-forall' interrupted because number of actions is larger than %1$d"), max_iter));
+               } else
+                       dr.setMessage(bformat(_("Applied \"%1$s\" to %2$d insets"), from_utf8(commandstr), iterations));
                break;
        }
 
@@ -1754,7 +1755,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                                it->dispatch(tmpcur, fr);
                        }
                }
-               processUpdateFlags(Update::Force | Update::FitCursor);
+               dr.update(Update::Force | Update::FitCursor);
                break;
        }
 
@@ -1842,7 +1843,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                cur.recordUndo();
                FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
                inset->dispatch(cur, fr);
-               processUpdateFlags(Update::SinglePar | Update::FitCursor);
+               dr.update(Update::SinglePar | Update::FitCursor);
                break;
        }
 
@@ -1852,7 +1853,8 @@ bool BufferView::dispatch(FuncRequest const & cmd)
        }
 
        buffer_.undo().endUndoGroup();
-       return dispatched;
+       dr.dispatched(dispatched);
+       return;
 }
 
 
@@ -2163,7 +2165,7 @@ void BufferView::gotoLabel(docstring const & label)
                TocIterator end = toc.end();
                for (; toc_it != end; ++toc_it) {
                        if (label == toc_it->str()) {
-                               dispatch(toc_it->action());
+                               lyx::dispatch(toc_it->action());
                                return;
                        }
                }
index 5b277c4edc8e7dab79584040e114f90cfb3ecdc7..6a01ed0fc4ceebe17cded45591482c34cbab4886 100644 (file)
@@ -31,6 +31,7 @@ class Buffer;
 class Change;
 class CoordCache;
 class Cursor;
+class DispatchResult;
 class DocIterator;
 class DocumentClass;
 class FuncRequest;
@@ -199,8 +200,7 @@ public:
        /// \return true if we've made a decision
        bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
        /// execute the given function.
-       /// \return true if the function has been processed.
-       bool dispatch(FuncRequest const & argument);
+       void dispatch(FuncRequest const & cmd, DispatchResult & dr);
 
        /// request an X11 selection.
        /// \return the selected string.
index 02759cad546c9f4ebe9ba8258caa286332f1ccd2..510bef47e4c2fc250ae55dddf61b007e3b89cd04 100644 (file)
@@ -1158,6 +1158,13 @@ void dispatch(FuncRequest const & action)
 }
 
 
+void dispatch(FuncRequest const & action, DispatchResult & dr)
+{
+       LASSERT(singleton_, /**/);
+       singleton_->pimpl_->lyxfunc_.dispatch(action, dr);
+}
+
+
 BufferList & theBufferList()
 {
        LASSERT(singleton_, /**/);
index 6c6db63c0e0b464d6043b7ce1f73011c69c0fa56..8c1fe648a22a8412b5b0352589ca07bb676c008a 100644 (file)
--- a/src/LyX.h
+++ b/src/LyX.h
@@ -21,6 +21,7 @@ namespace lyx {
 class BufferList;
 class CmdDef;
 class Converters;
+class DispatchResult;
 class ErrorItem;
 class FuncRequest;
 class FuncStatus;
@@ -121,6 +122,7 @@ private:
 
        friend FuncStatus getStatus(FuncRequest const & action);
        friend void dispatch(FuncRequest const & action);
+       friend void dispatch(FuncRequest const & action, DispatchResult & dr);
        friend BufferList & theBufferList();
        friend LyXFunc & theLyXFunc();
        friend Server & theServer();
index 6a619200e28f9ad6a9f5acd461eae7a59eac991e..9eab7f85edb78a957e4f4c2b9ba597d370a75c27 100644 (file)
@@ -339,6 +339,32 @@ static docstring sendDispatchMessage(docstring const & msg, FuncRequest const &
 
 
 void LyXFunc::dispatch(FuncRequest const & cmd)
+{
+       DispatchResult dr;
+       // redraw the screen at the end (first of the two drawing steps).
+       //This is done unless explicitely requested otherwise
+       dr.update(Update::FitCursor);
+       dispatch(cmd, dr);
+
+       LyXView * lv = theApp()->currentWindow();
+       if (lv && lv->currentBufferView()) {
+               // BufferView::update() updates the ViewMetricsInfo and
+               // also initializes the position cache for all insets in
+               // (at least partially) visible top-level paragraphs.
+               // We will redraw the screen only if needed.
+               lv->currentBufferView()->processUpdateFlags(dr.update());
+               
+               // Do we have a selection?
+               theSelection().haveSelection(
+                       lv->currentBufferView()->cursor().selection());
+               
+               // update gui
+                       lv->restartCursor();
+       }
+}
+
+
+void LyXFunc::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 {
        string const argument = to_utf8(cmd.argument());
        FuncCode const action = cmd.action;
@@ -350,10 +376,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
        errorstat = false;
        dispatch_buffer.erase();
 
-       // redraw the screen at the end (first of the two drawing steps).
-       //This is done unless explicitely requested otherwise
-       Update::flags updateFlags = Update::FitCursor;
-
        LyXView * lv = theApp()->currentWindow();
 
        FuncStatus const flag = getStatus(cmd);
@@ -362,9 +384,12 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                LYXERR(Debug::ACTION, "LyXFunc::dispatch: "
                       << lyxaction.getActionName(action)
                       << " [" << action << "] is disabled at this location");
+               //FIXME: pass this using the DispatchResult object
                setErrorMessage(flag.message());
                if (lv)
                        lv->restartCursor();
+               dr.dispatched(false);
+               dr.update(Update::None);
        } else {
                switch (action) {
 
@@ -481,7 +506,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                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);
-                       updateFlags = Update::FitCursor;
+                       dr.update(Update::FitCursor);
                        break;
 
                case LFUN_BOOKMARK_CLEAR:
@@ -493,8 +518,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                default:
-                       DispatchResult dr;
-
                        LASSERT(theApp(), /**/);
                        // Let the frontend dispatch its own actions.
                        theApp()->dispatch(cmd, dr);
@@ -507,10 +530,11 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                break;
 
                        // Let the current LyXView dispatch its own actions.
+                       //FIXME: pass dr to LyXView::dispatch
                        if (lv->dispatch(cmd)) {
                                BufferView * bv = lv->currentBufferView();
                                if (bv)
-                                       updateFlags = bv->cursor().result().update();
+                                       dr = bv->cursor().result();
                                break;
                        }
 
@@ -518,32 +542,28 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        LASSERT(bv, /**/);
 
                        // Let the current BufferView dispatch its own actions.
-                       if (bv->dispatch(cmd)) {
-                               // The BufferView took care of its own updates if needed.
-                               updateFlags = Update::None;
+                       bv->dispatch(cmd, dr);
+                       if (dr.dispatched())
                                break;
-                       }
 
                        BufferView * doc_bv = lv->documentBufferView();
                        // Try with the document BufferView dispatch if any.
-                       if (doc_bv && doc_bv->dispatch(cmd)) {
-                               updateFlags = Update::None;
-                               break;
+                       if (doc_bv) {
+                               doc_bv->dispatch(cmd, dr);
+                               if (dr.dispatched())
+                                       break;
                        }
 
                        // OK, so try the current Buffer itself...
                        bv->buffer().dispatch(cmd, dr);
-                       if (dr.dispatched()) {
-                               updateFlags = dr.update();
+                       if (dr.dispatched())
                                break;
-                       }
+
                        // and with the document Buffer.
                        if (doc_bv) {
                                doc_bv->buffer().dispatch(cmd, dr);
-                               if (dr.dispatched()) {
-                                       updateFlags = dr.update();
+                               if (dr.dispatched())
                                        break;
-                               }
                        }
 
                        // Let the current Cursor dispatch its own actions.
@@ -573,7 +593,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                        lv->updateCompletion(bv->cursor(), false, false);
                        }
 
-                       updateFlags = bv->cursor().result().update();
+                       dr = bv->cursor().result();
                }
 
                // if we executed a mutating lfun, mark the buffer as dirty
@@ -584,21 +604,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                    && !lyxaction.funcHasFlag(action, LyXAction::NoBuffer)
                    && !lyxaction.funcHasFlag(action, LyXAction::ReadOnly))
                        lv->currentBufferView()->buffer().markDirty();                  
-
-               if (lv && lv->currentBufferView()) {
-                       // BufferView::update() updates the ViewMetricsInfo and
-                       // also initializes the position cache for all insets in
-                       // (at least partially) visible top-level paragraphs.
-                       // We will redraw the screen only if needed.
-                       lv->currentBufferView()->processUpdateFlags(updateFlags);
-
-                       // Do we have a selection?
-                       theSelection().haveSelection(
-                               lv->currentBufferView()->cursor().selection());
-                       
-                       // update gui
-                       lv->restartCursor();
-               }
        }
        if (lv) {
                // Some messages may already be translated, so we cannot use _()
index 9b8fe7ffbd89a5a87b53b498156a6d8b420920fa..a7950da2312ba1d22de94d869d4c391845c0c3b4 100644 (file)
@@ -24,6 +24,7 @@ namespace lyx {
 
 class Buffer;
 class BufferView;
+class DispatchResult;
 class DocumentClass;
 class FuncRequest;
 class FuncStatus;
@@ -46,7 +47,11 @@ public:
        ///
        explicit LyXFunc();
 
-       /// LyX dispatcher, executes lyx actions.
+       /// LyX dispatcher: executes lyx actions and returns result.
+       void dispatch(FuncRequest const &, DispatchResult &);
+
+       /// LyX dispatcher: executes lyx actions and does necessary
+       /// screen updates depending on results.
        void dispatch(FuncRequest const &);
 
        ///
@@ -94,6 +99,9 @@ extern FuncStatus getStatus(FuncRequest const & action);
 /// Implementation is in LyX.cpp
 extern void dispatch(FuncRequest const & action);
 
+/// Implementation is in LyX.cpp
+extern void dispatch(FuncRequest const & action, DispatchResult & dr);
+
 } // namespace lyx
 
 #endif
index 4fda1197cf97ddec254f106b9223fee7c8096a5a..9df6eaa04dd1fa9ba437593bed1094ed12e2815c 100644 (file)
 #include "InsetMathRef.h"
 
 #include "BufferView.h"
-#include "LaTeXFeatures.h"
 #include "Buffer.h"
 #include "Cursor.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
+#include "LaTeXFeatures.h"
+#include "LyXFunc.h"
 #include "MathData.h"
 #include "MathFactory.h"
 #include "MathSupport.h"
@@ -80,7 +81,8 @@ void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MOUSE_RELEASE:
                if (cmd.button() == mouse_button::button3) {
                        LYXERR0("trying to goto ref '" << to_utf8(asString(cell(0))) << "'");
-                       cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
+                       //FIXME: use DispatchResult argument
+                       lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
                        break;
                }
                if (cmd.button() == mouse_button::button1) {