From 24cc3e5be30a2503010ac09c9c904a8ee4baefca Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Mon, 26 Mar 2001 08:14:39 +0000 Subject: [PATCH] Fixed "can't create new inset" bug. Described dialogs' control loop in controllers/README. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1825 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ChangeLog | 9 +++ src/frontends/controllers/ControlCitation.C | 4 +- src/frontends/controllers/ControlCitation.h | 2 +- src/frontends/controllers/ControlCommand.C | 5 -- src/frontends/controllers/ControlInset.h | 14 ++-- src/frontends/controllers/README | 76 +++++++++++++++++++++ 6 files changed, 95 insertions(+), 15 deletions(-) diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 1d77f2f179..aac6150072 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,12 @@ +2001-03-26 Angus Leeming + + * ControlCitation.C (getBibkeyInfo): get nasty and assert the info map + contains data. + + * ControlInset.h (apply): fix bug. Can now create new insets again. + + * README: describe program flow. + 2001-03-24 Lars Gullik Bjønnes * Makefile.am (libcontrollers_la_SOURCES): add ControlDialogs.h diff --git a/src/frontends/controllers/ControlCitation.C b/src/frontends/controllers/ControlCitation.C index 57b1f2745c..b4c711a927 100644 --- a/src/frontends/controllers/ControlCitation.C +++ b/src/frontends/controllers/ControlCitation.C @@ -80,9 +80,9 @@ vector const ControlCitation::getBibkeys() string const ControlCitation::getBibkeyInfo(string const & key) { - string result; + Assert(!bibkeysInfo_.empty()); - if (bibkeysInfo_.empty()) getBibkeys(); + string result; InfoMap::const_iterator it = bibkeysInfo_.find(key); if (it != bibkeysInfo_.end()) { diff --git a/src/frontends/controllers/ControlCitation.h b/src/frontends/controllers/ControlCitation.h index 26ff36da4a..daa7aafad6 100644 --- a/src/frontends/controllers/ControlCitation.h +++ b/src/frontends/controllers/ControlCitation.h @@ -55,7 +55,7 @@ public: Empty if no info exists. */ string const getBibkeyInfo(string const &); private: - /// clean-up any daughter class-particular data on hide. + /// clean-up any daughter class-particular data on hide(). virtual void clearDaughterParams(); /// The info associated with each key InfoMap bibkeysInfo_; diff --git a/src/frontends/controllers/ControlCommand.C b/src/frontends/controllers/ControlCommand.C index fbb1388325..45806e8ee8 100644 --- a/src/frontends/controllers/ControlCommand.C +++ b/src/frontends/controllers/ControlCommand.C @@ -49,12 +49,7 @@ void ControlCommand::applyParamsToInset() void ControlCommand::applyParamsNoInset() { - std::cerr << "1" << std::endl; if (action_ == LFUN_NOACTION) return; - - std::cerr << "2" << std::endl; - lv_.getLyXFunc()->Dispatch(action_, params().getAsString()); - std::cerr << "3" << std::endl; } diff --git a/src/frontends/controllers/ControlInset.h b/src/frontends/controllers/ControlInset.h index fea95371c8..a8859839e2 100644 --- a/src/frontends/controllers/ControlInset.h +++ b/src/frontends/controllers/ControlInset.h @@ -41,19 +41,19 @@ protected: Inset * inset() const; private: - /** These 5 methods are all that the individual daughter classes + /** These methods are all that the individual daughter classes should need to instantiate. */ /// if the inset exists then do this... virtual void applyParamsToInset() = 0; /// else this... virtual void applyParamsNoInset() = 0; - /// clean-up any daughter class-particular data on hide. - virtual void clearDaughterParams() = 0; /// get the parameters from the string passed to createInset. virtual Params const getParams(string const &) = 0; /// get the parameters from the inset passed to showInset. virtual Params const getParams(Inset const &) = 0; + /// clean-up any daughter class-particular data on hide(). + virtual void clearDaughterParams() = 0; /// Instantiation of ControlBase virtual methods. @@ -164,14 +164,14 @@ void ControlInset::update() template void ControlInset::apply() { - if (lv_.buffer()->isReadonly() || !inset_) + if (lv_.buffer()->isReadonly()) return; view().apply(); - if (inset_) { - if (params() != getParams(*inset_)) applyParamsToInset(); - } else + if (inset_ && params() != getParams(*inset_)) + applyParamsToInset(); + else applyParamsNoInset(); } diff --git a/src/frontends/controllers/README b/src/frontends/controllers/README index 06f2c05c5f..fd6472dbf7 100644 --- a/src/frontends/controllers/README +++ b/src/frontends/controllers/README @@ -15,3 +15,79 @@ data that it has been created to input/modify. This concept has been instatiated for the Citation dialog only at the moment. See xforms-new/FormCitation.[Ch] for an xforms-specific View of the dialog. + +How the code works. +=================== + +I'll describe Inset-type dialogs (eg, the Citation dialog). Non-inset-type +(eg the Document dialog) have similar flow, but the important controller +functions are to be found in ControlDialogs.h, not ControlInset.h. + +Let's use the citation dialog as an example. + +The dialog is launched by : + a) clicking on an existing inset, emitting the showCitation() +(Dialogs.h) signal, connected to the showInset() slot +(controllers/ControlInset.h) in theControlCitation c-tor. + b) request a new inset (eg from the menubar), emitting a +createCitation() signal (Dialogs.h) connected to the createInset() +slot (controllers/ControlInset.h) in theControlCitation c-tor. + +The user presses the Ok, Apply, Cancel or Restore buttons. In xforms +these are connected to the button controller (xforms/FormCitation.C: +build) so: + bc().setOK(dialog_->button_ok); + bc().setApply(dialog_->button_apply); + bc().setCancel(dialog_->button_cancel); + bc().setUndoAll(dialog_->button_restore); +The button controller alters the state of the buttons (active/inactive). +xforms works by callbacks, so clicking on say the button_ok button +causes a callback event to (see FormBase.C) + +extern "C" void C_FormBaseOKCB(FL_OBJECT * ob, long) +{ + GetForm(ob)->OKButton(); +} + +GetForm() extracts the actual instance of FormCitation that caused the +event and calls OKButton() (see controllers/ViewBase.h) which in turn +calls the controller's OKButton method. (The ViewBase method exists +only because : + /** These shortcuts allow (e.g. xform's) global callback functions + access to the buttons without making the whole controller_ + public. */ + +So, ultimately, pressing button_ok on the Citation dialog calls +ControlBase::OKButton(). + +void ControlBase::OKButton() +{ + apply(); + hide(); + bc().ok(); +} + + +apply() and hide() are pure virtual methods, instantiated in +ControlInset.h because the Citation dialog is an inset dialog and all +insets are functionally identical. + +template +void ControlInset::apply() +{ + if (lv_.buffer()->isReadonly()) + return; + + view().apply(); + + if (inset_ && params() != getParams(*inset_)) + applyParamsToInset(); + else + applyParamsNoInset(); +} + +applyParamsToInset() and applyParamsNoInset(); are to be found in +FormCommand.[Ch] because the citation inset is derived from +InsetCommand and this subset of insets have identical internal +structure and so the params can be applied in the same way. + -- 2.39.5