From a70b4ef0510c6c655f7487839098ce7ec104b8b4 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Tue, 26 Apr 2005 09:37:52 +0000 Subject: [PATCH] refine the logic for checking whether a dialog may apply its data or not git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9874 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ChangeLog | 9 +++++++ src/frontends/controllers/ControlBox.C | 2 +- src/frontends/controllers/ControlBranch.C | 2 +- src/frontends/controllers/ControlChanges.h | 2 ++ src/frontends/controllers/ControlCharacter.C | 2 +- src/frontends/controllers/ControlCharacter.h | 2 ++ src/frontends/controllers/ControlCommand.C | 2 +- src/frontends/controllers/ControlDocument.h | 2 ++ src/frontends/controllers/ControlERT.C | 2 +- src/frontends/controllers/ControlExternal.C | 2 +- src/frontends/controllers/ControlFloat.C | 2 +- src/frontends/controllers/ControlGraphics.C | 2 +- src/frontends/controllers/ControlInclude.C | 2 +- src/frontends/controllers/ControlNote.C | 2 +- src/frontends/controllers/ControlPrint.C | 2 +- src/frontends/controllers/ControlPrint.h | 2 ++ src/frontends/controllers/ControlSendto.C | 3 ++- src/frontends/controllers/ControlSendto.h | 2 ++ src/frontends/controllers/ControlTabular.C | 2 +- src/frontends/controllers/ControlTabular.h | 2 ++ .../controllers/ControlTabularCreate.C | 2 +- .../controllers/ControlTabularCreate.h | 2 ++ src/frontends/controllers/ControlVSpace.C | 2 +- src/frontends/controllers/ControlWrap.C | 2 +- src/frontends/controllers/Dialog.C | 24 ++++++++++++++++--- src/frontends/controllers/Dialog.h | 20 ++++++++++++++++ 26 files changed, 81 insertions(+), 19 deletions(-) diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index d1958482b2..2f2c4725e3 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,12 @@ +2005-04-25 Georg Baum + + * Dialog.h, ControlCharacter.h, ControlPrint.h, ControlSendto.h, + ControlTabular.h, ControlTabularCreate.h (getLfun): new, return the + lfun for applying the data + * Control*.C (dispatchParams): use getLfun where appropriate + * Dialog.[Ch], ControlChanges.h, ControlDocument.h (canApply): new, + check whether the dialog data may be applied + 2005-04-11 Jean-Marc Lasgouttes * ControlDocument.C (dispatchParams): update the counters if diff --git a/src/frontends/controllers/ControlBox.C b/src/frontends/controllers/ControlBox.C index 789224fba6..c73b173eda 100644 --- a/src/frontends/controllers/ControlBox.C +++ b/src/frontends/controllers/ControlBox.C @@ -47,7 +47,7 @@ void ControlBox::clearParams() void ControlBox::dispatchParams() { string const lfun = InsetBoxMailer::params2string(params()); - kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); + kernel().dispatch(FuncRequest(getLfun(), lfun)); } diff --git a/src/frontends/controllers/ControlBranch.C b/src/frontends/controllers/ControlBranch.C index aa7f97c58a..1b656b542c 100644 --- a/src/frontends/controllers/ControlBranch.C +++ b/src/frontends/controllers/ControlBranch.C @@ -49,7 +49,7 @@ void ControlBranch::clearParams() void ControlBranch::dispatchParams() { string const lfun = InsetBranchMailer::params2string(params()); - kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); + kernel().dispatch(FuncRequest(getLfun(), lfun)); } diff --git a/src/frontends/controllers/ControlChanges.h b/src/frontends/controllers/ControlChanges.h index cdd2622075..f146befa45 100644 --- a/src/frontends/controllers/ControlChanges.h +++ b/src/frontends/controllers/ControlChanges.h @@ -32,6 +32,8 @@ public: virtual void dispatchParams() {} /// virtual bool isBufferDependent() const { return true; } + /// always true since dispatchParams() is empty + virtual bool canApply() const { return true; } /// find the next merge chunk and highlight it bool find(); diff --git a/src/frontends/controllers/ControlCharacter.C b/src/frontends/controllers/ControlCharacter.C index b665725d83..ec47153efa 100644 --- a/src/frontends/controllers/ControlCharacter.C +++ b/src/frontends/controllers/ControlCharacter.C @@ -65,7 +65,7 @@ void ControlCharacter::dispatchParams() string data; if (font2string(*font_.get(), toggleall_, data)) { - kernel().dispatch(FuncRequest(LFUN_FREEFONT_UPDATE, data)); + kernel().dispatch(FuncRequest(getLfun(), data)); } } diff --git a/src/frontends/controllers/ControlCharacter.h b/src/frontends/controllers/ControlCharacter.h index 9740cbf8f0..5352e960ea 100644 --- a/src/frontends/controllers/ControlCharacter.h +++ b/src/frontends/controllers/ControlCharacter.h @@ -34,6 +34,8 @@ public: virtual void dispatchParams(); /// virtual bool isBufferDependent() const { return true; } + /// + virtual kb_action getLfun() const { return LFUN_TABULAR_INSERT; } /// void setFamily(LyXFont::FONT_FAMILY); diff --git a/src/frontends/controllers/ControlCommand.C b/src/frontends/controllers/ControlCommand.C index 9086ac4cab..0fa8df22f8 100644 --- a/src/frontends/controllers/ControlCommand.C +++ b/src/frontends/controllers/ControlCommand.C @@ -49,7 +49,7 @@ void ControlCommand::dispatchParams() string const lfun = InsetCommandMailer::params2string(lfun_name_, params_); - kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); + kernel().dispatch(FuncRequest(getLfun(), lfun)); } } // namespace frontend diff --git a/src/frontends/controllers/ControlDocument.h b/src/frontends/controllers/ControlDocument.h index 7197e55ec6..bde75914ff 100644 --- a/src/frontends/controllers/ControlDocument.h +++ b/src/frontends/controllers/ControlDocument.h @@ -38,6 +38,8 @@ public: virtual void dispatchParams(); /// virtual bool isBufferDependent() const { return true; } + /// always true since we don't manipulate document contents + virtual bool canApply() const { return true; } /// LyXTextClass const & textClass() const; /// diff --git a/src/frontends/controllers/ControlERT.C b/src/frontends/controllers/ControlERT.C index 3e366eaaa4..a809f7795e 100644 --- a/src/frontends/controllers/ControlERT.C +++ b/src/frontends/controllers/ControlERT.C @@ -41,7 +41,7 @@ void ControlERT::clearParams() void ControlERT::dispatchParams() { string const lfun = InsetERTMailer::params2string(status_); - kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); + kernel().dispatch(FuncRequest(getLfun(), lfun)); } } // namespace frontend diff --git a/src/frontends/controllers/ControlExternal.C b/src/frontends/controllers/ControlExternal.C index 30fee5b52c..d88151d0db 100644 --- a/src/frontends/controllers/ControlExternal.C +++ b/src/frontends/controllers/ControlExternal.C @@ -69,7 +69,7 @@ void ControlExternal::dispatchParams() string const lfun = InsetExternalMailer::params2string(params(), kernel().buffer()); - kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); + kernel().dispatch(FuncRequest(getLfun(), lfun)); } diff --git a/src/frontends/controllers/ControlFloat.C b/src/frontends/controllers/ControlFloat.C index 5214072826..7e66324dcd 100644 --- a/src/frontends/controllers/ControlFloat.C +++ b/src/frontends/controllers/ControlFloat.C @@ -43,7 +43,7 @@ void ControlFloat::clearParams() void ControlFloat::dispatchParams() { string const lfun = InsetFloatMailer::params2string(params()); - kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); + kernel().dispatch(FuncRequest(getLfun(), lfun)); } } // namespace frontend diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index 8cae4fb0b1..f409c02b0e 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -77,7 +77,7 @@ void ControlGraphics::dispatchParams() InsetGraphicsParams tmp_params(params()); string const lfun = InsetGraphicsMailer::params2string(tmp_params, kernel().buffer()); - kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); + kernel().dispatch(FuncRequest(getLfun(), lfun)); } diff --git a/src/frontends/controllers/ControlInclude.C b/src/frontends/controllers/ControlInclude.C index 7fa1a1756b..92e5e50a2d 100644 --- a/src/frontends/controllers/ControlInclude.C +++ b/src/frontends/controllers/ControlInclude.C @@ -62,7 +62,7 @@ void ControlInclude::clearParams() void ControlInclude::dispatchParams() { string const lfun = InsetIncludeMailer::params2string(params_); - kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); + kernel().dispatch(FuncRequest(getLfun(), lfun)); } diff --git a/src/frontends/controllers/ControlNote.C b/src/frontends/controllers/ControlNote.C index 8b7e48ef2e..3d2bd460be 100644 --- a/src/frontends/controllers/ControlNote.C +++ b/src/frontends/controllers/ControlNote.C @@ -44,7 +44,7 @@ void ControlNote::clearParams() void ControlNote::dispatchParams() { string const lfun = InsetNoteMailer::params2string(params()); - kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); + kernel().dispatch(FuncRequest(getLfun(), lfun)); } } // namespace frontend diff --git a/src/frontends/controllers/ControlPrint.C b/src/frontends/controllers/ControlPrint.C index c9755e2242..a78e5531fc 100644 --- a/src/frontends/controllers/ControlPrint.C +++ b/src/frontends/controllers/ControlPrint.C @@ -139,7 +139,7 @@ void ControlPrint::dispatchParams() pp.file_name; string const data = target + " " + target_name + " " + command; - kernel().dispatch(FuncRequest(LFUN_PRINT, data)); + kernel().dispatch(FuncRequest(getLfun(), data)); } } // namespace frontend diff --git a/src/frontends/controllers/ControlPrint.h b/src/frontends/controllers/ControlPrint.h index 224a57f13c..35c8cc32c6 100644 --- a/src/frontends/controllers/ControlPrint.h +++ b/src/frontends/controllers/ControlPrint.h @@ -35,6 +35,8 @@ public: virtual void dispatchParams(); /// virtual bool isBufferDependent() const { return true; } + /// + virtual kb_action getLfun() const { return LFUN_PRINT; } /// Browse for a file std::string const browse(std::string const &) const; diff --git a/src/frontends/controllers/ControlSendto.C b/src/frontends/controllers/ControlSendto.C index fb35d3102a..c58eb7dd45 100644 --- a/src/frontends/controllers/ControlSendto.C +++ b/src/frontends/controllers/ControlSendto.C @@ -11,6 +11,7 @@ #include #include "ControlSendto.h" + #include "buffer.h" #include "converter.h" #include "format.h" @@ -50,7 +51,7 @@ void ControlSendto::dispatchParams() return; string const data = format_->name() + " " + command_; - kernel().dispatch(FuncRequest(LFUN_EXPORT_CUSTOM, data)); + kernel().dispatch(FuncRequest(getLfun(), data)); } diff --git a/src/frontends/controllers/ControlSendto.h b/src/frontends/controllers/ControlSendto.h index d10a440f19..55c38ceae5 100644 --- a/src/frontends/controllers/ControlSendto.h +++ b/src/frontends/controllers/ControlSendto.h @@ -34,6 +34,8 @@ public: virtual void dispatchParams(); /// virtual bool isBufferDependent() const { return true; } + /// + virtual kb_action getLfun() const { return LFUN_EXPORT_CUSTOM; } /// Return a vector of those formats that can be exported from "lyx". std::vector const allFormats() const; diff --git a/src/frontends/controllers/ControlTabular.C b/src/frontends/controllers/ControlTabular.C index cbeec65e8d..aaac6a3704 100644 --- a/src/frontends/controllers/ControlTabular.C +++ b/src/frontends/controllers/ControlTabular.C @@ -73,7 +73,7 @@ LyXTabular const & ControlTabular::tabular() const void ControlTabular::set(LyXTabular::Feature f, string const & arg) { string const data = featureAsString(f) + ' ' + arg; - kernel().dispatch(FuncRequest(LFUN_TABULAR_FEATURE, data)); + kernel().dispatch(FuncRequest(getLfun(), data)); } diff --git a/src/frontends/controllers/ControlTabular.h b/src/frontends/controllers/ControlTabular.h index acd260139f..fcdc2bb062 100644 --- a/src/frontends/controllers/ControlTabular.h +++ b/src/frontends/controllers/ControlTabular.h @@ -34,6 +34,8 @@ public: virtual void dispatchParams() {}; /// virtual bool isBufferDependent() const { return true; } + /// + virtual kb_action getLfun() const { return LFUN_TABULAR_FEATURE; } /// LyXTabular::idx_type getActiveCell() const; diff --git a/src/frontends/controllers/ControlTabularCreate.C b/src/frontends/controllers/ControlTabularCreate.C index e13f491895..e7bd1e430b 100644 --- a/src/frontends/controllers/ControlTabularCreate.C +++ b/src/frontends/controllers/ControlTabularCreate.C @@ -44,7 +44,7 @@ void ControlTabularCreate::clearParams() void ControlTabularCreate::dispatchParams() { string const data = convert(params().first) + ' ' + convert(params().second); - kernel().dispatch(FuncRequest(LFUN_TABULAR_INSERT, data)); + kernel().dispatch(FuncRequest(getLfun(), data)); } } // namespace frontend diff --git a/src/frontends/controllers/ControlTabularCreate.h b/src/frontends/controllers/ControlTabularCreate.h index 815cb26bd3..c1da77bf16 100644 --- a/src/frontends/controllers/ControlTabularCreate.h +++ b/src/frontends/controllers/ControlTabularCreate.h @@ -32,6 +32,8 @@ public: virtual void dispatchParams(); /// virtual bool isBufferDependent() const { return true; } + /// + virtual kb_action getLfun() const { return LFUN_TABULAR_INSERT; } /// typedef std::pair rowsCols; diff --git a/src/frontends/controllers/ControlVSpace.C b/src/frontends/controllers/ControlVSpace.C index d1b8b86992..4d5c643c0b 100644 --- a/src/frontends/controllers/ControlVSpace.C +++ b/src/frontends/controllers/ControlVSpace.C @@ -49,7 +49,7 @@ void ControlVSpace::clearParams() void ControlVSpace::dispatchParams() { string const str = InsetVSpaceMailer::params2string(params_); - kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, str)); + kernel().dispatch(FuncRequest(getLfun(), str)); } diff --git a/src/frontends/controllers/ControlWrap.C b/src/frontends/controllers/ControlWrap.C index f572e76491..fd3f1309ff 100644 --- a/src/frontends/controllers/ControlWrap.C +++ b/src/frontends/controllers/ControlWrap.C @@ -43,7 +43,7 @@ void ControlWrap::clearParams() void ControlWrap::dispatchParams() { string const lfun = InsetWrapMailer::params2string(params()); - kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); + kernel().dispatch(FuncRequest(getLfun(), lfun)); } } // namespace frontend diff --git a/src/frontends/controllers/Dialog.C b/src/frontends/controllers/Dialog.C index 21b327ae89..039c1c4f16 100644 --- a/src/frontends/controllers/Dialog.C +++ b/src/frontends/controllers/Dialog.C @@ -175,9 +175,19 @@ 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()) + // buffer independant dialogs are always active. + // This check allows us leave canApply unimplemented for some dialogs. + if (!controller().isBufferDependent()) + return; + + // deactivate the dialog if we have no buffer + if (!kernel().isBufferAvailable()) { + bc().readOnly(true); + return; + } + + // check whether this dialog may be active + if (controller().canApply()) bc().readOnly(kernel().isBufferReadonly()); else bc().readOnly(true); @@ -189,6 +199,14 @@ Dialog::Controller::Controller(Dialog & parent) {} +bool Dialog::Controller::canApply() const +{ + FuncRequest const fr(getLfun(), dialog().name()); + FuncStatus const fs(kernel().lyxview().getLyXFunc().getStatus(fr)); + return fs.enabled(); +} + + Dialog::Controller & Dialog::controller() const { BOOST_ASSERT(controller_ptr_.get()); diff --git a/src/frontends/controllers/Dialog.h b/src/frontends/controllers/Dialog.h index 34452b607d..9408ab3166 100644 --- a/src/frontends/controllers/Dialog.h +++ b/src/frontends/controllers/Dialog.h @@ -13,6 +13,7 @@ #define DIALOG_H #include "Kernel.h" +#include "lfuns.h" #include #include @@ -158,6 +159,25 @@ public: */ virtual bool isBufferDependent() const = 0; + /** The lfun that is sent for applying the data. + * + * This method is used by the default implementation of canApply() + * for buffer dependant dialogs that send one lfun when applying the + * data. + * It should be used in dispatchParams(), too for consistency reasons. + * \returns the lfun that is sent for applying the data. + */ + virtual kb_action getLfun() const { return LFUN_INSET_APPLY; } + + /** Check whether we may apply our data. + * + * The default implementation works for all dialogs that send one + * lfun when applying the data. Dialogs that send none or more than + * one lfun need to reimplement it. + * \returns whether the data can be applied or not. + */ + virtual bool canApply() const; + /** \return true if the kernel should disconnect the dialog from * a particular inset after the data has been applied to it. * Clearly this makes sense only for dialogs modifying the contents -- 2.39.2