add a dispatchresult parameter to lyxview::dispatch

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33258 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2010-01-29 10:42:39 +00:00
parent 818aeeddc6
commit 00338d3747
5 changed files with 27 additions and 24 deletions

View File

@ -530,13 +530,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd, DispatchResult & dr)
break; break;
// Let the current LyXView dispatch its own actions. // Let the current LyXView dispatch its own actions.
//FIXME: pass dr to LyXView::dispatch lv->dispatch(cmd, dr);
if (lv->dispatch(cmd)) {
BufferView * bv = lv->currentBufferView();
if (bv)
dr = bv->cursor().result();
break;
}
BufferView * bv = lv->currentBufferView(); BufferView * bv = lv->currentBufferView();
LASSERT(bv, /**/); LASSERT(bv, /**/);

View File

@ -22,6 +22,7 @@ namespace support { class FileName; }
class Buffer; class Buffer;
class BufferView; class BufferView;
class Cursor; class Cursor;
class DispatchResult;
class FuncStatus; class FuncStatus;
class FuncRequest; class FuncRequest;
class Inset; class Inset;
@ -64,7 +65,7 @@ public:
virtual bool getStatus(FuncRequest const & cmd, FuncStatus & flag) = 0; virtual bool getStatus(FuncRequest const & cmd, FuncStatus & flag) = 0;
/// dispatch command. /// dispatch command.
/// \return true if the \c FuncRequest has been dispatched. /// \return true if the \c FuncRequest has been dispatched.
virtual bool dispatch(FuncRequest const & cmd) = 0; virtual void dispatch(FuncRequest const & cmd, DispatchResult & dr) = 0;
/// ///
virtual void restartCursor() = 0; virtual void restartCursor() = 0;

View File

@ -16,6 +16,7 @@
#include "GuiView.h" #include "GuiView.h"
#include "Dialog.h" #include "Dialog.h"
#include "DispatchResult.h"
#include "FileDialog.h" #include "FileDialog.h"
#include "FontLoader.h" #include "FontLoader.h"
#include "GuiApplication.h" #include "GuiApplication.h"
@ -2452,6 +2453,7 @@ void GuiView::checkExternallyModifiedBuffers()
} }
//FIXME use a DispatchResult object to transmit messages
void GuiView::dispatchVC(FuncRequest const & cmd) void GuiView::dispatchVC(FuncRequest const & cmd)
{ {
// message for statusbar // message for statusbar
@ -2688,22 +2690,22 @@ static docstring previewAndDestroy(Buffer * buffer, string const & format)
#endif #endif
bool GuiView::dispatch(FuncRequest const & cmd) void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
{ {
BufferView * bv = currentBufferView(); BufferView * bv = currentBufferView();
// By default we won't need any update. // By default we won't need any update.
if (bv) dr.update(Update::None);
bv->cursor().updateFlags(Update::None); // assume cmd will be dispatched
dr.dispatched(true);
Buffer * doc_buffer = documentBufferView() Buffer * doc_buffer = documentBufferView()
? &(documentBufferView()->buffer()) : 0; ? &(documentBufferView()->buffer()) : 0;
bool dispatched = true;
if (cmd.origin == FuncRequest::TOC) { if (cmd.origin == FuncRequest::TOC) {
GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false)); GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
// FIXME: do we need to pass a DispatchResult object here?
toc->doDispatch(bv->cursor(), cmd); toc->doDispatch(bv->cursor(), cmd);
return true; return;
} }
string const argument = to_utf8(cmd.argument()); string const argument = to_utf8(cmd.argument());
@ -2721,11 +2723,13 @@ bool GuiView::dispatch(FuncRequest const & cmd)
if (!doc_buffer) if (!doc_buffer)
break; break;
if (cmd.argument() == "custom") { if (cmd.argument() == "custom") {
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto")); dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"),
dr);
break; break;
} }
if (doc_buffer->doExport(argument, false)) { if (doc_buffer->doExport(argument, false)) {
message(bformat(_("Error exporting to format: %1$s."), dr.setError(true);
dr.setMessage(bformat(_("Error exporting to format: %1$s."),
cmd.argument())); cmd.argument()));
} }
break; break;
@ -2810,8 +2814,10 @@ bool GuiView::dispatch(FuncRequest const & cmd)
theBufferList().getBuffer(FileName(to_utf8(cmd.argument()))); theBufferList().getBuffer(FileName(to_utf8(cmd.argument())));
if (buffer) if (buffer)
setBuffer(buffer); setBuffer(buffer);
else else {
message(_("Document not loaded")); dr.setError(true);
dr.setMessage(_("Document not loaded"));
}
} }
break; break;
@ -2922,6 +2928,7 @@ bool GuiView::dispatch(FuncRequest const & cmd)
// FIXME: get rid of this indirection; GuiView ask the inset // FIXME: get rid of this indirection; GuiView ask the inset
// if he is kind enough to update itself... // if he is kind enough to update itself...
FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument()); FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument());
//FIXME: pass DispatchResult here?
inset->dispatch(currentBufferView()->cursor(), fr); inset->dispatch(currentBufferView()->cursor(), fr);
} else if (name == "paragraph") { } else if (name == "paragraph") {
lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
@ -2933,9 +2940,9 @@ bool GuiView::dispatch(FuncRequest const & cmd)
case LFUN_DIALOG_TOGGLE: { case LFUN_DIALOG_TOGGLE: {
if (isDialogVisible(cmd.getArg(0))) if (isDialogVisible(cmd.getArg(0)))
dispatch(FuncRequest(LFUN_DIALOG_HIDE, cmd.argument())); dispatch(FuncRequest(LFUN_DIALOG_HIDE, cmd.argument()), dr);
else else
dispatch(FuncRequest(LFUN_DIALOG_SHOW, cmd.argument())); dispatch(FuncRequest(LFUN_DIALOG_SHOW, cmd.argument()), dr);
break; break;
} }
@ -3088,7 +3095,7 @@ bool GuiView::dispatch(FuncRequest const & cmd)
break; break;
default: default:
dispatched = false; dr.dispatched(false);
break; break;
} }
@ -3100,7 +3107,7 @@ bool GuiView::dispatch(FuncRequest const & cmd)
statusBar()->hide(); statusBar()->hide();
} }
return dispatched; return;
} }

View File

@ -79,7 +79,7 @@ public:
void updateMessage(QString const & str); void updateMessage(QString const & str);
bool getStatus(FuncRequest const & cmd, FuncStatus & flag); bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
bool dispatch(FuncRequest const & cmd); void dispatch(FuncRequest const & cmd, DispatchResult & dr);
void restartCursor(); void restartCursor();
void updateCompletion(Cursor & cur, bool start, bool keep); void updateCompletion(Cursor & cur, bool start, bool keep);
void setFocus(); void setFocus();

View File

@ -466,7 +466,8 @@ void GuiWorkArea::dispatch(FuncRequest const & cmd0, KeyModifier mod)
{ {
// Handle drag&drop // Handle drag&drop
if (cmd0.action == LFUN_FILE_OPEN) { if (cmd0.action == LFUN_FILE_OPEN) {
lyx_view_->dispatch(cmd0); DispatchResult dr;
lyx_view_->dispatch(cmd0, dr);
return; return;
} }