Introducing Application::getStatus() and Application::dispatch(). Transferring some LFUNs to those.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21759 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-11-24 07:58:12 +00:00
parent c201e0dde7
commit 662b5dba03
4 changed files with 105 additions and 40 deletions

View File

@ -535,6 +535,12 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
bool enable = true; bool enable = true;
switch (cmd.action) { switch (cmd.action) {
case LFUN_WINDOW_CLOSE:
if (theApp())
return theApp()->getStatus(cmd);
enable = false;
break;
case LFUN_DIALOG_TOGGLE: case LFUN_DIALOG_TOGGLE:
case LFUN_DIALOG_SHOW: case LFUN_DIALOG_SHOW:
case LFUN_DIALOG_UPDATE: case LFUN_DIALOG_UPDATE:
@ -632,10 +638,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
enable = LyX::ref().session().bookmarks().size() > 0; enable = LyX::ref().session().bookmarks().size() > 0;
break; break;
case LFUN_WINDOW_CLOSE:
enable = theApp()->viewCount() > 0;
break;
// this one is difficult to get right. As a half-baked // this one is difficult to get right. As a half-baked
// solution, we consider only the first action of the sequence // solution, we consider only the first action of the sequence
case LFUN_COMMAND_SEQUENCE: { case LFUN_COMMAND_SEQUENCE: {
@ -844,6 +846,16 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
setErrorMessage(flag.message()); setErrorMessage(flag.message());
} 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. // Let lyx_view_ dispatch its own actions.
case LFUN_BUFFER_SWITCH: case LFUN_BUFFER_SWITCH:
case LFUN_BUFFER_NEXT: case LFUN_BUFFER_NEXT:
@ -1181,14 +1193,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
doImport(argument); doImport(argument);
break; break;
case LFUN_LYX_QUIT:
// quitting is triggered by the gui code
// (leaving the event loop).
lyx_view_->message(from_utf8(N_("Exiting.")));
if (theBufferList().quitWriteAll())
theApp()->closeAllViews();
break;
case LFUN_BUFFER_AUTO_SAVE: case LFUN_BUFFER_AUTO_SAVE:
lyx_view_->buffer()->autoSave(); lyx_view_->buffer()->autoSave();
break; break;
@ -1578,15 +1582,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break; break;
} }
case LFUN_SCREEN_FONT_UPDATE:
BOOST_ASSERT(lyx_view_);
// handle the screen font changes.
theFontLoader().update();
/// FIXME: only the current view will be updated. the Gui
/// class is able to furnish the list of views.
updateFlags = Update::Force;
break;
case LFUN_SET_COLOR: { case LFUN_SET_COLOR: {
string lyx_name; string lyx_name;
string const x11_name = split(argument, lyx_name, ' '); string const x11_name = split(argument, lyx_name, ' ');
@ -1839,22 +1834,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break; break;
} }
case LFUN_WINDOW_NEW:
theApp()->createView();
break;
case LFUN_WINDOW_CLOSE:
BOOST_ASSERT(lyx_view_);
BOOST_ASSERT(theApp());
// update bookmark pit of the current buffer before window close
for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
gotoBookmark(i+1, false, false);
// ask the user for saving changes or cancel quit
if (!theBufferList().quitWriteAll())
break;
lyx_view_->close();
return;
case LFUN_BOOKMARK_GOTO: case LFUN_BOOKMARK_GOTO:
// go to bookmark, open unopened file and switch to buffer if necessary // go to bookmark, open unopened file and switch to buffer if necessary
gotoBookmark(convert<unsigned int>(to_utf8(cmd.argument())), true, true); gotoBookmark(convert<unsigned int>(to_utf8(cmd.argument())), true, true);

View File

@ -21,9 +21,11 @@
namespace lyx { namespace lyx {
class BufferView; class BufferView;
struct RGBColor;
class Buffer; class Buffer;
class FuncRequest;
class FuncStatus;
class Inset; class Inset;
struct RGBColor;
namespace frontend { namespace frontend {
@ -151,14 +153,17 @@ public:
/// ///
virtual ~Application() {} virtual ~Application() {}
///
virtual FuncStatus getStatus(FuncRequest const & cmd) = 0;
/// dispatch command.
virtual void dispatch(FuncRequest const & cmd) = 0;
/// ///
virtual void resetGui() = 0; virtual void resetGui() = 0;
/// ///
virtual bool closeAllViews() = 0; virtual bool closeAllViews() = 0;
/// ///
virtual size_t viewCount() const = 0;
///
virtual void hideDialogs(std::string const & name, Inset * inset) const = 0; virtual void hideDialogs(std::string const & name, Inset * inset) const = 0;
/// ///
virtual Buffer const * updateInset(Inset const * inset) const = 0; virtual Buffer const * updateInset(Inset const * inset) const = 0;

View File

@ -31,15 +31,18 @@
#include "support/os.h" #include "support/os.h"
#include "support/Package.h" #include "support/Package.h"
#include "Buffer.h"
#include "BufferList.h" #include "BufferList.h"
#include "BufferView.h" #include "BufferView.h"
#include "debug.h" #include "debug.h"
#include "Font.h" #include "Font.h"
#include "FuncRequest.h" #include "FuncRequest.h"
#include "FuncStatus.h"
#include "gettext.h" #include "gettext.h"
#include "LyX.h" #include "LyX.h"
#include "LyXFunc.h" #include "LyXFunc.h"
#include "LyXRC.h" #include "LyXRC.h"
#include "Session.h"
#include "version.h" #include "version.h"
#include <QApplication> #include <QApplication>
@ -209,11 +212,87 @@ GuiApplication::~GuiApplication()
} }
FuncStatus GuiApplication::getStatus(FuncRequest const & cmd)
{
FuncStatus flag;
bool enable = true;
switch(cmd.action) {
case LFUN_WINDOW_CLOSE:
enable = view_ids_.size() > 0;
break;
default:
if (!current_view_) {
enable = false;
break;
}
}
if (!enable)
flag.enabled(false);
return flag;
}
void GuiApplication::dispatch(FuncRequest const & cmd)
{
switch(cmd.action) {
case LFUN_WINDOW_NEW:
createView();
break;
case LFUN_WINDOW_CLOSE:
// update bookmark pit of the current buffer before window close
for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
theLyXFunc().gotoBookmark(i+1, false, false);
// ask the user for saving changes or cancel quit
if (!theBufferList().quitWriteAll())
break;
current_view_->close();
break;
case LFUN_LYX_QUIT:
// quitting is triggered by the gui code
// (leaving the event loop).
current_view_->message(from_utf8(N_("Exiting.")));
if (theBufferList().quitWriteAll())
closeAllViews();
break;
case LFUN_SCREEN_FONT_UPDATE: {
// handle the screen font changes.
font_loader_.update();
// Backup current_view_
GuiView * view = current_view_;
// Set current_view_ to zero to forbid GuiWorkArea::redraw()
// to skip the refresh.
current_view_ = 0;
BufferList::iterator it = theBufferList().begin();
BufferList::iterator const end = theBufferList().end();
for (; it != end; ++it)
(*it)->changed();
// Restore current_view_
current_view_ = view;
break;
}
default:
break;
}
}
void GuiApplication::resetGui() void GuiApplication::resetGui()
{ {
map<int, GuiView *>::iterator it; map<int, GuiView *>::iterator it;
for (it = views_.begin(); it != views_.end(); ++it) for (it = views_.begin(); it != views_.end(); ++it)
it->second->resetDialogs(); it->second->resetDialogs();
dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
} }

View File

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