]> git.lyx.org Git - features.git/commitdiff
Fixed "can't create new inset" bug. Described dialogs' control loop in
authorAngus Leeming <leeming@lyx.org>
Mon, 26 Mar 2001 08:14:39 +0000 (08:14 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 26 Mar 2001 08:14:39 +0000 (08:14 +0000)
controllers/README.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1825 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlCitation.C
src/frontends/controllers/ControlCitation.h
src/frontends/controllers/ControlCommand.C
src/frontends/controllers/ControlInset.h
src/frontends/controllers/README

index 1d77f2f179b69149ed48a2baef6938b694e8e491..aac6150072eb13c2c6150a42631aef8be5e99d73 100644 (file)
@@ -1,3 +1,12 @@
+2001-03-26  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * 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  <larsbj@trylle.birdstep.com>
 
        * Makefile.am (libcontrollers_la_SOURCES): add ControlDialogs.h
index 57b1f2745c4e5186e3b0235c1b138d15ee5744f4..b4c711a9273982adf58715df422f2bc978cbe754 100644 (file)
@@ -80,9 +80,9 @@ vector<string> 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()) {
index 26ff36da4aaaa15c01ee69e458c5f7b63425d0f7..daa7aafad6cffb05dbb23f4d679ba73f8a53f4d5 100644 (file)
@@ -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_;
index fbb13883252fd38d133b5da740b8544c6fa87053..45806e8ee85496862003cbf61aabc940d4134425 100644 (file)
@@ -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;
 }
 
index fea95371c8399391d4b88a561b15a6f9f62f26aa..a8859839e2f34881f1d656b2f7d64e446a953b6b 100644 (file)
@@ -41,19 +41,19 @@ protected:
        Inset * inset() const;
 
 private:
-       /** These 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<Inset, Params>::update()
 template <class Inset, class Params>
 void ControlInset<Inset, Params>::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();
 }
 
index 06f2c05c5f8469eabf2b655173f7ad92289637a7..fd6472dbf7fa3811e4aef93187ee1c7a77bd5306 100644 (file)
@@ -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 <class Inset, class Params>
+void ControlInset<Inset, Params>::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. 
+