Am Montag, 21. März 2005 12:14 schrieb Jean-Marc Lasgouttes: > >>>>> "Angus" == Angus Leeming <[EMAIL PROTECTED]> writes: > > Angus> The point being that the core would explicitly tell individual > Angus> (named) dialogs when it was illegal to Apply their contents. > > Angus> Your suggesting (if I understand correctly) that each and every > Angus> open dialog should recieve notification that it should call > Angus> getStatus to ascertain whether the Button Controller should be > Angus> (de-)activated. > > Yes, the idea is that the code that knows what is permitted and what > is not already exists, and it is in getStatus.
I tried to implement this and ran into the following problem: Notifying an open dialog that it should call getStatus is easy. But what argument to getStatus would the dialog use? This is different for each dialog, so that would mean we would need a new member function checkStatus() for each dialog that calls getStatus with the correct argument, or we would need to store this argument in the base class. In any case this would mean to update every dialog, which I did not like. Therefore I took the idea a bit further and came up with the attached patch. checkStatus() is implemented in the base class and calls getStatus with LFUN_INSET_APPLY. This is handled in InsetBase::getStatus() and only accepted if it comes from this insets's dialog. This prevents that open dialogs are applied in the wrong insets. If that is not correct for some inset (as e.g. in InsetText) it needs to be overriden in that inset. The patch seems to work, but I would like to get some feedback, and I need to check wether LFUN_INSET_APPLY is short-circuited in other insets than InsetERT, too. Georg PS to Jean-Marc: my compiler tells me that you forgot to handle LyXRC::RC_TEX_ALLOWS_SPACES: in actOnUpdatedPrefs() in lyxfunc.C. Does it need special treatment, or should it simply be added at the end of the switch?
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/ChangeLog lyx-1.4-cvs/src/ChangeLog --- lyx-1.4-clean/src/ChangeLog 2005-03-27 17:59:46.000000000 +0200 +++ lyx-1.4-cvs/src/ChangeLog 2005-03-28 17:33:20.000000000 +0200 @@ -1,3 +1,7 @@ +2005-03-28 Georg Baum <[EMAIL PROTECTED]> + + * text3.C (getStatus): handle LFUN_INSET_APPLY + 2005-03-27 Martin Vermeer <[EMAIL PROTECTED]> * buffer.[Ch]: diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/text3.C lyx-1.4-cvs/src/text3.C --- lyx-1.4-clean/src/text3.C 2005-03-10 20:51:19.000000000 +0100 +++ lyx-1.4-cvs/src/text3.C 2005-03-28 16:15:49.000000000 +0200 @@ -1728,6 +1729,24 @@ bool LyXText::getStatus(LCursor & cur, F case LFUN_INSET_DIALOG_SHOW: break; + case LFUN_INSET_APPLY: { + string const name = cmd.getArg(0); + InsetBase * inset = cur.bv().owner()->getDialogs().getOpenInset(name); + if (inset) { + FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument); + FuncStatus fs; + if (inset->getStatus(cur, fr, fs)) { + flag |= fs; + return true; + } else + return false; + } else { + FuncRequest fr(LFUN_INSET_INSERT, cmd.argument); + return getStatus(cur, fr, flag); + } + break; + } + case LFUN_EMPH: flag.setOnOff(font.emph() == LyXFont::ON); break; @@ -1789,7 +1808,6 @@ bool LyXText::getStatus(LCursor & cur, F case LFUN_BREAKPARAGRAPHKEEPLAYOUT: case LFUN_BREAKPARAGRAPH_SKIP: case LFUN_PARAGRAPH_SPACING: - case LFUN_INSET_APPLY: case LFUN_INSET_INSERT: case LFUN_NEXT_INSET_TOGGLE: case LFUN_UPCASE_WORD: diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/ChangeLog lyx-1.4-cvs/src/frontends/ChangeLog --- lyx-1.4-clean/src/frontends/ChangeLog 2005-03-06 12:46:00.000000000 +0100 +++ lyx-1.4-cvs/src/frontends/ChangeLog 2005-03-28 17:15:29.000000000 +0200 @@ -1,3 +1,8 @@ +2005-03-28 Georg Baum <[EMAIL PROTECTED]> + + * Dialogs.[Ch] (checkStatus): new + * Toolbars.C (update): call Dialogs::checkStatus + 2005-03-06 Lars Gullik Bjonnes <[EMAIL PROTECTED]> * Makefile.am (DIST_SUBDIRS): remove gnome diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/Dialogs.C lyx-1.4-cvs/src/frontends/Dialogs.C --- lyx-1.4-clean/src/frontends/Dialogs.C 2005-02-22 20:44:19.000000000 +0100 +++ lyx-1.4-cvs/src/frontends/Dialogs.C 2005-03-28 17:08:12.000000000 +0200 @@ -231,3 +240,16 @@ void Dialogs::redraw() const it->second->redraw(); } } + + +void Dialogs::checkStatus() +{ + std::map<string, DialogPtr>::const_iterator it = dialogs_.begin(); + std::map<string, DialogPtr>::const_iterator end = dialogs_.end(); + + for(; it != end; ++it) { + Dialog * const dialog = it->second.get(); + if (dialog->isVisible()) + dialog->checkStatus(); + } +} diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/Dialogs.h lyx-1.4-cvs/src/frontends/Dialogs.h --- lyx-1.4-clean/src/frontends/Dialogs.h 2005-02-22 20:44:19.000000000 +0100 +++ lyx-1.4-cvs/src/frontends/Dialogs.h 2005-03-28 15:18:26.000000000 +0200 @@ -42,6 +42,15 @@ public: */ static boost::signal<void()> & redrawGUI(); + /** Check the status of all visible dialogs and disable or reenable + * them as appropriate. + * + * Disabling is needed for example when a dialog is open and the + * cursor moves to a position where the corresponding inset is not + * allowed. + */ + void checkStatus(); + /// Toggle tooltips on/off in all dialogs. static void toggleTooltips(); diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/Toolbars.C lyx-1.4-cvs/src/frontends/Toolbars.C --- lyx-1.4-clean/src/frontends/Toolbars.C 2004-11-26 17:57:34.000000000 +0100 +++ lyx-1.4-cvs/src/frontends/Toolbars.C 2005-03-28 10:46:55.000000000 +0200 @@ -16,6 +16,7 @@ #include "buffer.h" #include "bufferparams.h" #include "debug.h" +#include "Dialogs.h" #include "funcrequest.h" #include "FuncStatus.h" #include "gettext.h" @@ -148,6 +149,7 @@ void Toolbars::update() ToolbarsMap::const_iterator const end = toolbars_.end(); for (; it != end; ++it) it->second->update(); + owner_.getDialogs().checkStatus(); bool const enable = owner_.getLyXFunc(). getStatus(FuncRequest(LFUN_LAYOUT)).enabled(); diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/controllers/ChangeLog lyx-1.4-cvs/src/frontends/controllers/ChangeLog --- lyx-1.4-clean/src/frontends/controllers/ChangeLog 2005-03-27 18:00:18.000000000 +0200 +++ lyx-1.4-cvs/src/frontends/controllers/ChangeLog 2005-03-28 17:11:42.000000000 +0200 @@ -1,3 +1,7 @@ +2005-03-28 Georg Baum <[EMAIL PROTECTED]> + + * Dialog.[Ch] (checkStatus): new + 2005-03-27 MArtin Vermeer <[EMAIL PROTECTED]> * ControlDocument.C (dispatch_bufferparams): fix bug 1843 diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/controllers/Dialog.C lyx-1.4-cvs/src/frontends/controllers/Dialog.C --- lyx-1.4-clean/src/frontends/controllers/Dialog.C 2004-05-21 08:55:40.000000000 +0200 +++ lyx-1.4-cvs/src/frontends/controllers/Dialog.C 2005-03-28 17:08:07.000000000 +0200 @@ -15,6 +15,13 @@ #include "ButtonController.h" #include "BCView.h" +#include "frontends/Dialogs.h" +#include "frontends/LyXView.h" + +#include "funcrequest.h" +#include "FuncStatus.h" +#include "lyxfunc.h" + using std::string; @@ -167,6 +177,17 @@ void Dialog::setView(View * v) } +void Dialog::checkStatus() +{ + FuncRequest const fr(LFUN_INSET_APPLY, name()); + FuncStatus const fs(kernel().lyxview().getLyXFunc().getStatus(fr)); + if (fs.enabled()) + bc().readOnly(kernel().isBufferReadonly()); + else + bc().readOnly(true); +} + + Dialog::Controller::Controller(Dialog & parent) : parent_(parent) {} diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/controllers/Dialog.h lyx-1.4-cvs/src/frontends/controllers/Dialog.h --- lyx-1.4-clean/src/frontends/controllers/Dialog.h 2004-05-21 08:55:40.000000000 +0200 +++ lyx-1.4-cvs/src/frontends/controllers/Dialog.h 2005-03-28 15:29:18.000000000 +0200 @@ -70,6 +75,12 @@ public: void redraw(); //@} + /** Check wether we may apply our data. + * + * The buttons are disabled if not and (re-)enabled if yes. + */ + void checkStatus(); + /** When applying, it's useful to know whether the dialog is about * to close or not (no point refreshing the display for example). */ diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ChangeLog lyx-1.4-cvs/src/insets/ChangeLog --- lyx-1.4-clean/src/insets/ChangeLog 2005-03-22 20:52:56.000000000 +0100 +++ lyx-1.4-cvs/src/insets/ChangeLog 2005-03-28 17:22:37.000000000 +0200 @@ -1,3 +1,6 @@ +2005-03-28 Georg Baum <[EMAIL PROTECTED]> + + * insetbase.C, insetert.C (getStatus): handle LFUN_INSET_APPLY 2005-03-21 Alfredo Braunstein <[EMAIL PROTECTED]> diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/insetbase.C lyx-1.4-cvs/src/insets/insetbase.C --- lyx-1.4-clean/src/insets/insetbase.C 2005-02-01 20:15:55.000000000 +0100 +++ lyx-1.4-cvs/src/insets/insetbase.C 2005-03-28 17:18:24.000000000 +0200 @@ -20,6 +20,8 @@ #include "debug.h" #include "dimension.h" #include "dispatchresult.h" +#include "funcrequest.h" +#include "FuncStatus.h" #include "gettext.h" #include "lyxtext.h" #include "metricsinfo.h" @@ -136,9 +139,18 @@ void InsetBase::doDispatch(LCursor & cur } -bool InsetBase::getStatus(LCursor &, FuncRequest const &, FuncStatus &) const +bool InsetBase::getStatus(LCursor &, FuncRequest const & cmd, + FuncStatus & flag) const { - return false; + switch (cmd.action) { + case LFUN_INSET_APPLY: + if (lyxCode() == translate(cmd.argument)) { + flag.enabled(true); + return true; + } + default: + return false; + } } diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/insetert.C lyx-1.4-cvs/src/insets/insetert.C --- lyx-1.4-clean/src/insets/insetert.C 2005-02-03 20:13:19.000000000 +0100 +++ lyx-1.4-cvs/src/insets/insetert.C 2005-03-28 17:02:58.000000000 +0200 @@ -351,6 +351,10 @@ bool InsetERT::getStatus(LCursor & cur, return getStatus(cur, func, status); } + case LFUN_INSET_APPLY: + status.enabled(translate(cmd.argument) == ERT_CODE); + return true; + default: return InsetCollapsable::getStatus(cur, cmd, status); }