}
-bool BufferView::dispatch(FuncRequest const & cmd)
+void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
{
//lyxerr << [ cmd = " << cmd << "]" << endl;
// 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;
// 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;
}
buffer_.params().clearLayoutModules();
buffer_.params().makeDocumentClass();
updateLayout(oldClass);
- processUpdateFlags(Update::Force | Update::FitCursor);
+ dr.update(Update::Force | Update::FitCursor);
break;
}
buffer_.params().addLayoutModule(argument);
buffer_.params().makeDocumentClass();
updateLayout(oldClass);
- processUpdateFlags(Update::Force | Update::FitCursor);
+ dr.update(Update::Force | Update::FitCursor);
break;
}
buffer_.params().setBaseClass(argument);
buffer_.params().makeDocumentClass();
updateLayout(oldDocClass);
- processUpdateFlags(Update::Force | Update::FitCursor);
+ dr.update(Update::Force | Update::FitCursor);
break;
}
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:
// 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(
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;
// 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:
// 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:
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;
// It did not work too; no action needed.
break;
cur.clearSelection();
- processUpdateFlags(Update::SinglePar | Update::FitCursor);
+ dr.update(Update::SinglePar | Update::FitCursor);
break;
}
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;
}
y = getPos(cur, cur.boundary()).y_;
cur.finishUndo();
- processUpdateFlags(Update::SinglePar | Update::FitCursor);
+ dr.update(Update::SinglePar | Update::FitCursor);
break;
}
y = getPos(cur, cur.boundary()).y_;
cur.finishUndo();
- processUpdateFlags(Update::SinglePar | Update::FitCursor);
+ dr.update(Update::SinglePar | Update::FitCursor);
break;
}
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;
}
it->dispatch(tmpcur, fr);
}
}
- processUpdateFlags(Update::Force | Update::FitCursor);
+ dr.update(Update::Force | Update::FitCursor);
break;
}
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;
}
}
buffer_.undo().endUndoGroup();
- return dispatched;
+ dr.dispatched(dispatched);
+ return;
}
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;
}
}
class Change;
class CoordCache;
class Cursor;
+class DispatchResult;
class DocIterator;
class DocumentClass;
class FuncRequest;
/// \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.
}
+void dispatch(FuncRequest const & action, DispatchResult & dr)
+{
+ LASSERT(singleton_, /**/);
+ singleton_->pimpl_->lyxfunc_.dispatch(action, dr);
+}
+
+
BufferList & theBufferList()
{
LASSERT(singleton_, /**/);
class BufferList;
class CmdDef;
class Converters;
+class DispatchResult;
class ErrorItem;
class FuncRequest;
class FuncStatus;
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();
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;
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);
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) {
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:
break;
default:
- DispatchResult dr;
-
LASSERT(theApp(), /**/);
// Let the frontend dispatch its own actions.
theApp()->dispatch(cmd, dr);
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;
}
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.
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
&& !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 _()
class Buffer;
class BufferView;
+class DispatchResult;
class DocumentClass;
class FuncRequest;
class FuncStatus;
///
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 &);
///
/// 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
#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"
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) {