Cleanup LyXFunc::dispatch() following JMarc advice.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21797 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-11-26 14:36:50 +00:00
parent 27442f7c9e
commit 1133419a59
7 changed files with 46 additions and 48 deletions

View File

@ -197,7 +197,7 @@ bool import(LyXView * lv, FileName const & filename,
: changeExtension(filename.absFilename(), : changeExtension(filename.absFilename(),
formats.extension(loader_format)); formats.extension(loader_format));
lv->view()->insertPlaintextFile(filename2, as_paragraphs); lv->view()->insertPlaintextFile(filename2, as_paragraphs);
lv->dispatch(FuncRequest(LFUN_MARK_OFF)); lv->dispatch(FuncRequest(LFUN_MARK_OFF), true);
} }
// we are done // we are done
@ -847,35 +847,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
} else { } else {
switch (action) { 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_FORWARD:
case LFUN_WORD_FIND_BACKWARD: { case LFUN_WORD_FIND_BACKWARD: {
BOOST_ASSERT(lyx_view_ && lyx_view_->view()); BOOST_ASSERT(lyx_view_ && lyx_view_->view());
@ -1844,10 +1815,29 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break; break;
default: { 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_); 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); view()->cursor().dispatch(cmd);
updateFlags = view()->cursor().result().update(); updateFlags = view()->cursor().result().update();
if (!view()->cursor().result().dispatched()) if (!view()->cursor().result().dispatched())
// Let the current BufferView dispatch its own actions.
updateFlags = view()->dispatch(cmd); updateFlags = view()->dispatch(cmd);
break; break;
} }
@ -1868,9 +1858,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
//Do we have a selection? //Do we have a selection?
theSelection().haveSelection(view()->cursor().selection()); theSelection().haveSelection(view()->cursor().selection());
if (view()->cursor().inTexted()) {
}
} }
} }
if (!quitting && lyx_view_) { if (!quitting && lyx_view_) {

View File

@ -156,7 +156,8 @@ public:
/// ///
virtual FuncStatus getStatus(FuncRequest const & cmd) = 0; virtual FuncStatus getStatus(FuncRequest const & cmd) = 0;
/// dispatch command. /// 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; virtual void resetGui() = 0;

View File

@ -75,7 +75,10 @@ public:
/// ///
virtual FuncStatus getStatus(FuncRequest const & cmd) = 0; virtual FuncStatus getStatus(FuncRequest const & cmd) = 0;
/// dispatch command. /// 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; virtual void restartCursor() = 0;

View 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) { switch(cmd.action) {
@ -281,8 +281,12 @@ void GuiApplication::dispatch(FuncRequest const & cmd)
} }
default: default:
break; // Notify the caller that the action has not been dispatched.
return false;
} }
// The action has been dispatched.
return true;
} }

View File

@ -57,7 +57,7 @@ public:
/// Method inherited from \c Application class /// Method inherited from \c Application class
//@{ //@{
virtual FuncStatus getStatus(FuncRequest const &); virtual FuncStatus getStatus(FuncRequest const &);
virtual void dispatch(FuncRequest const &); virtual bool dispatch(FuncRequest const &);
virtual void resetGui(); virtual void resetGui();
virtual Clipboard & clipboard(); virtual Clipboard & clipboard();
virtual Selection & selection(); virtual Selection & selection();

View 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(); BufferView * bv = view();
// By default we won't need any update. // By default we won't need any update.
@ -1161,16 +1161,19 @@ void GuiView::dispatch(FuncRequest const & cmd)
} }
default: default:
theLyXFunc().setLyXView(this); if (propagate) {
lyx::dispatch(cmd); theLyXFunc().setLyXView(this);
return; lyx::dispatch(cmd);
}
return false;
} }
if (!bv) if (bv) {
return; bv->processUpdateFlags(bv->cursor().result().update());
bv->processUpdateFlags(bv->cursor().result().update()); // We won't need any new update.
// We won't need any new update. bv->cursor().updateFlags(Update::None);
bv->cursor().updateFlags(Update::None); }
return true;
} }

View File

@ -76,7 +76,7 @@ public:
void updateToolbars(); void updateToolbars();
QMenu * createPopupMenu(); QMenu * createPopupMenu();
FuncStatus getStatus(FuncRequest const & cmd); FuncStatus getStatus(FuncRequest const & cmd);
void dispatch(FuncRequest const & cmd); bool dispatch(FuncRequest const & cmd, bool propagate = true);
/// ///
void setLayoutDialog(GuiLayoutBox *); void setLayoutDialog(GuiLayoutBox *);