]> git.lyx.org Git - lyx.git/commitdiff
Implemented controller-view split for FormBibtex.
authorAngus Leeming <leeming@lyx.org>
Mon, 19 Mar 2001 16:37:01 +0000 (16:37 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 19 Mar 2001 16:37:01 +0000 (16:37 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1794 a592a061-630c-0410-9148-cb99ea01b6c8

17 files changed:
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlBibtex.C [new file with mode: 0644]
src/frontends/controllers/ControlBibtex.h [new file with mode: 0644]
src/frontends/controllers/Makefile.am
src/frontends/controllers/ViewBase.h
src/frontends/xforms/ChangeLog
src/frontends/xforms/Dialogs.C
src/frontends/xforms/FormBase.h
src/frontends/xforms/FormBibitem.C
src/frontends/xforms/FormBibitem.h
src/frontends/xforms/FormBibtex.C
src/frontends/xforms/FormBibtex.h
src/frontends/xforms/form_bibtex.C
src/frontends/xforms/form_bibtex.h
src/frontends/xforms/forms/form_bibtex.fd
src/frontends/xforms/xformsBC.C
src/frontends/xforms/xformsBC.h

index 070057f613ea7e9dd49d6a9c722601d4f591a7b4..b84d2a3dde574fa447ebb040e40cc47f1386563c 100644 (file)
@@ -1,3 +1,9 @@
+2001-03-19  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * ControlBibtex.[Ch]: new files; controller for an InsetBibtex popup.
+
+       * Makefile.am: added ControlBibtex.[Ch].
+
 2001-03-16  Angus Leeming  <a.leeming@ic.ac.uk>
 
        * ControlBibitem.C:
diff --git a/src/frontends/controllers/ControlBibtex.C b/src/frontends/controllers/ControlBibtex.C
new file mode 100644 (file)
index 0000000..8614b10
--- /dev/null
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+/* This file is part of
+ * ====================================================== 
+ *
+ *           LyX, The Document Processor
+ *
+ *           Copyright 2000 The LyX Team.
+ *
+ * ======================================================
+ *
+ * \file ControlBibtex.C
+ * \author Angus Leeming <a.leeming@ic.ac.uk>
+ */
+
+#include <algorithm>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include <config.h>
+#include "ControlBibtex.h"
+#include "Dialogs.h"
+#include "LyXView.h"
+#include "BufferView.h"
+
+using SigC::slot;
+
+ControlBibtex::ControlBibtex(LyXView & lv, Dialogs & d)
+       : ControlCommand(lv, d)
+{
+       d_.showBibtex.connect(slot(this, &ControlBibtex::showInset));
+}
+
+void ControlBibtex::apply()
+{
+       view().apply();
+
+       if (inset_ && params() != inset_->params()) {
+               if (params().getContents() != inset_->params().getContents())
+                       lv_.view()->ChangeCitationsIfUnique(
+                               inset_->params().getContents(),
+                               params().getContents());
+
+               inset_->setParams(params());
+               lv_.view()->updateInset(inset_, true);
+
+               // We need to do a redraw because the maximum
+               // InsetBibKey width could have changed
+               lv_.view()->redraw();
+               lv_.view()->fitCursor(lv_.view()->getLyXText());
+       }
+}
diff --git a/src/frontends/controllers/ControlBibtex.h b/src/frontends/controllers/ControlBibtex.h
new file mode 100644 (file)
index 0000000..4699427
--- /dev/null
@@ -0,0 +1,65 @@
+// -*- C++ -*-
+/* This file is part of
+ * ====================================================== 
+ *
+ *           LyX, The Document Processor
+ *
+ *           Copyright 2000 The LyX Team.
+ *
+ * ======================================================
+ *
+ * \file ControlBibtex.h
+ * \author Angus Leeming <a.leeming@ic.ac.uk>
+ */
+
+#ifndef CONTROLBIBTEX_H
+#define CONTROLBIBTEX_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "ControlCommand.h"
+#include "ButtonController.h"
+#include "ViewBase.h"
+
+/** A controller for Bibtex dialogs.
+ */
+class ControlBibtex : public ControlCommand
+{
+public:
+       ///
+       ControlBibtex(LyXView &, Dialogs &);
+
+protected:
+       /// Get changed parameters and Dispatch them to the kernel.
+       virtual void apply();
+};
+
+/** This class instantiates and makes available the GUI-specific
+    ButtonController and View.
+ */
+template <class GUIview, class GUIbc>
+class GUIBibtex : public ControlBibtex {
+public:
+       ///
+       GUIBibtex(LyXView &, Dialogs &);
+       ///
+       virtual ButtonControllerBase & bc() { return bc_; }
+       ///
+       virtual ViewBase & view() { return view_; }
+
+private:
+       ///
+       ButtonController<OkCancelReadOnlyPolicy, GUIbc> bc_;
+       ///
+       GUIview view_;
+};
+
+template <class GUIview, class GUIbc>
+GUIBibtex<GUIview, GUIbc>::GUIBibtex(LyXView & lv, Dialogs & d)
+       : ControlBibtex(lv, d),
+         view_(*this)
+{}
+
+#endif // CONTROLBIBTEX_H
index 50d0e811e1cf64533caf1ba0668bdcbd100caa6f..53bc704593519dd213f543739d7dfa4caa1ec651 100644 (file)
@@ -18,6 +18,8 @@ libcontrollers_la_SOURCES=\
        ControlBase.h \
        ControlBibitem.C \
        ControlBibitem.h \
+       ControlBibtex.C \
+       ControlBibtex.h \
        ControlCitation.C \
        ControlCitation.h \
        ControlCommand.C \
index bbd6a52cd1c11511a943e669b35c52a10cf397a5..541bbe933579ed22d802a08b52edd5fb097e0612 100644 (file)
@@ -60,6 +60,8 @@ class ViewBC : public ViewBase {
 public:
        ///
        ViewBC(ControlBase & c) : ViewBase(c) {}
+
+protected:
        ///
        GUIbc & bc() const
        {
index 33d830eb41c2f3f27698f38c9284d9ad79d88019..5b8dee4181bad1e04392b120310767116375edf9 100644 (file)
@@ -1,3 +1,10 @@
+2001-03-19  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * FormBibtex.[Ch]:
+       * forms/form_bibtex.fd: implemented controller-view split.
+
+       * Dialogs.C: associated changes.
+
 2001-03-19  Angus Leeming  <a.leeming@ic.ac.uk>
 
        * FormBaseDeprecated.[Ch]: rename title as title_.
index 5c6a2e8ff684057213d975b9b5ce892e75f139f1..b1b6b9d520772c3f78c8406346e7e27b870ca57b 100644 (file)
@@ -10,7 +10,6 @@
  */
 
 #include <config.h>
-#include FORMS_H_LOCATION
 
 #ifdef __GNUG__
 #pragma implementation
@@ -19,6 +18,7 @@
 #include "Dialogs.h"
 
 #include "ControlBibitem.h"
+#include "ControlBibtex.h"
 #include "ControlCitation.h"
 #include "xformsBC.h"
 
@@ -60,8 +60,8 @@ Dialogs::Dialogs(LyXView * lv)
 
        add(new GUICitation<FormCitation, xformsBC>(*lv, *this));
        add(new GUIBibitem<FormBibitem, xformsBC>(*lv, *this));
+       add(new GUIBibtex<FormBibtex, xformsBC>(*lv, *this));
 
-       add(new FormBibtex(lv, this));
        add(new FormCharacter(lv, this));
        add(new FormCopyright(lv, this));
        add(new FormCredits(lv, this));
index 6138f4a586c7fe2fce6ad03a7165ac6e63d881fa..8668e3722f92c5f7fa4ae54ba78b152ae0fb3942 100644 (file)
 #define FORMBASE_H
 
 #include <boost/smart_ptr.hpp>
+#include FORMS_H_LOCATION // Can't forward-declare FL_FORM
 
 #ifdef __GNUG__
 #pragma interface
 #endif
 
-#include FORMS_H_LOCATION // Can't forward-declare FL_FORM
 #include "ViewBase.h"
 #include "LString.h"
 #include "ButtonPolicies.h"
index 2fb4ddba6b64bc090690c94a42a53b9bfef6d8f8..d23831c7536c46197c375b8f58baf83da0f22611 100644 (file)
@@ -14,7 +14,6 @@
 #include <config.h>
 #include "ControlBibitem.h"
 #include "FormBibitem.h"
-#include "form_bibitem.h"
 #include "gettext.h"
 #include "xformsBC.h"
 #include "support/lstrings.h" // compare
index 75be7c5464528967886844f2d4e2965bfbc5e267..f103d12e27fc7e5eea4e44ab3ef0d882ca7dde7a 100644 (file)
 
 #include "FormBase.h"
 
-/**
- * For bibliography entry editing
- */
-
 #include "form_bibitem.h"
+
 class ControlBibitem;
 
+/**
+ * For bibliography entry editing
+ */
 class FormBibitem : public FormBase2<ControlBibitem, FD_form_bibitem> {
 public:
        ///
index b062d719a12bd0868b97f9f48214b1b52da48ed6..2f32c2434bc37f27c36f03256d26818d5cef7a28 100644 (file)
@@ -7,48 +7,22 @@
  * \author John Levon
  */
 
-#include <config.h>
-
-#include FORMS_H_LOCATION
-
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
-
-#include "Dialogs.h"
+#include <config.h>
+#include "ControlBibtex.h"
 #include "FormBibtex.h"
-#include "LyXView.h"
-#include "buffer.h"
-#include "form_bibtex.h"
-#include "lyxfunc.h"
+#include "gettext.h"
+#include "xformsBC.h"
 #include "debug.h"
 
-using std::endl;
-using SigC::slot;
-
-FormBibtex::FormBibtex(LyXView * lv, Dialogs * d)
-       : FormCommand(lv, d, _("BibTeX Database"))
-{
-       d->showBibtex.connect(slot(this, &FormBibtex::showInset));
-}
+FormBibtex::FormBibtex(ControlBibtex & c)
+       : FormBase2<ControlBibtex, FD_form_bibtex>(c, _("BibTeX Database"))
+{}
 
 
-FL_FORM * FormBibtex::form() const
-{
-       if (dialog_.get())
-               return dialog_->form;
-       return 0;
-}
-
-
-void FormBibtex::connect()
-{
-       fl_set_form_maxsize(form(), 2 * minw_, minh_);
-       FormCommand::connect();
-}
-       
-
 void FormBibtex::build()
 {
        dialog_.reset(build_bibtex());
@@ -66,50 +40,27 @@ void FormBibtex::build()
 }
 
 
-bool FormBibtex::input(FL_OBJECT *, long)
+ButtonPolicy::SMInput FormBibtex::input(FL_OBJECT *, long)
 {
        // minimal validation 
        if (!compare(fl_get_input(dialog_->database),""))
-               return false;
+               return ButtonPolicy::SMI_NOOP;
 
-       return true;
+       return ButtonPolicy::SMI_VALID;
 }
 
 
 void FormBibtex::update()
 {
-       fl_set_input(dialog_->database, params.getContents().c_str());
-       fl_set_input(dialog_->style, params.getOptions().c_str());
-       // Surely, this should reset the buttons to their original state?
-       // It doesn't. Instead "Restore" becomes a "Close"
-       //bc().refresh();
-       bc().readOnly(lv_->buffer()->isReadonly());
+       fl_set_input(dialog_->database,
+                    controller().params().getContents().c_str());
+       fl_set_input(dialog_->style,
+                    controller().params().getOptions().c_str());
 }
 
 
 void FormBibtex::apply()
 {
-       if (lv_->buffer()->isReadonly())
-               return;
-
-       params.setContents(fl_get_input(dialog_->database));
-       params.setOptions(fl_get_input(dialog_->style));
-
-       if (inset_ != 0) {
-               // Only update if contents have changed
-               if (params != inset_->params()) {
-                       if (params.getContents() != inset_->params().getContents())
-                               lv_->view()->ChangeCitationsIfUnique(
-                                       inset_->params().getContents(), params.getContents());
-
-               inset_->setParams(params);
-               lv_->view()->updateInset(inset_, true);
-
-               // We need to do a redraw because the maximum
-               // InsetBibKey width could have changed
-               lv_->view()->redraw();
-               lv_->view()->fitCursor(lv_->view()->getLyXText());
-               }
-       } else
-               lyxerr[Debug::GUI] << "Editing non-existent bibtex inset !" << endl;
+       controller().params().setContents(fl_get_input(dialog_->database));
+       controller().params().setOptions(fl_get_input(dialog_->style));
 }
index 9c0dfdf58bd3819e74fd5186c3b3230e44f7a943..ce9ca1d3787a5f5fd6f10bb293190f44171e9276 100644 (file)
 #ifndef FORMBIBTEX_H
 #define FORMBIBTEX_H
 
-#include <boost/smart_ptr.hpp>
-
 #ifdef __GNUG__
 #pragma interface
 #endif
 
-#include "FormInset.h"
+#include "FormBase.h"
+
+#include "form_bibtex.h"
 
-struct FD_form_bibtex;
+class ControlBibtex;
 
 /**
  * For bibtex database setting
  */
-class FormBibtex : public FormCommand {
+class FormBibtex : public FormBase2<ControlBibtex, FD_form_bibtex> {
 public:
        ///
-       FormBibtex(LyXView *, Dialogs *);
-private:
-       /// Pointer to the actual instantiation of the ButtonController.
-       virtual xformsBC & bc();
-       /// Connect signals etc. Set form's max size.
-       virtual void connect();
-       /// Build the dialog
+       FormBibtex(ControlBibtex &);
+
+       // Functions accessible to the Controller.
+
+       /// Set the Params variable for the Controller.
+       virtual void apply();
+       /// Build the dialog.
        virtual void build();
-       /// Update dialog before showing it
+       /// Update dialog before/whilst showing it.
        virtual void update();
-       /// input handler
-       virtual bool input(FL_OBJECT *, long);
-       /// Apply from dialog (modify or create inset)
-       virtual void apply();
-       /// Pointer to the actual instantiation of the xforms form
-       virtual FL_FORM * form() const;
+       
+private:
+       /// Filter the inputs on callback from xforms
+       virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
        ///
        FD_form_bibtex * build_bibtex();
-       /// Real GUI implementation.
-       boost::scoped_ptr<FD_form_bibtex> dialog_;
-       /// The ButtonController
-       ButtonController<OkCancelReadOnlyPolicy, xformsBC> bc_;
 };
 
-
-inline
-xformsBC & FormBibtex::bc()
-{
-  return bc_;
-}
 #endif // FORMBIBTEX_H
index f650a8098c222ca69ea2f24dd83aad474fe14504..68c1f44ba3ecf3c45d566e99c92f22df180e0ff6 100644 (file)
@@ -31,24 +31,24 @@ FD_form_bibtex * FormBibtex::build_bibtex()
     fl_set_button_shortcut(obj, scex(_(dummy)), 1);
   }
     fl_set_object_lsize(obj, FL_NORMAL_SIZE);
-    fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 0);
+    fl_set_object_callback(obj, C_FormBaseInputCB, 0);
   fdui->button_ok = obj = fl_add_button(FL_RETURN_BUTTON, 20, 90, 90, 30, _("OK"));
     fl_set_object_lsize(obj, FL_NORMAL_SIZE);
-    fl_set_object_callback(obj, C_FormBaseDeprecatedOKCB, 3);
+    fl_set_object_callback(obj, C_FormBaseOKCB, 3);
   {
     char const * const dummy = N_("Cancel|^[");
     fdui->button_cancel = obj = fl_add_button(FL_NORMAL_BUTTON, 120, 90, 90, 30, idex(_(dummy)));
     fl_set_button_shortcut(obj, scex(_(dummy)), 1);
   }
     fl_set_object_lsize(obj, FL_NORMAL_SIZE);
-    fl_set_object_callback(obj, C_FormBaseDeprecatedCancelCB, 2);
+    fl_set_object_callback(obj, C_FormBaseCancelCB, 2);
   {
     char const * const dummy = N_("Style:|#S");
     fdui->style = obj = fl_add_input(FL_NORMAL_INPUT, 80, 50, 130, 30, idex(_(dummy)));
     fl_set_button_shortcut(obj, scex(_(dummy)), 1);
   }
     fl_set_object_lsize(obj, FL_NORMAL_SIZE);
-    fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 0);
+    fl_set_object_callback(obj, C_FormBaseInputCB, 0);
   fl_end_form();
 
   fdui->form->fdui = fdui;
index 3ea6ce3357fdb21c4bd4375ada18c5b193afb758..8189af6e7a38b30abf7e929f40d1a2dc2faf03e9 100644 (file)
@@ -5,9 +5,9 @@
 #define FD_form_bibtex_h_
 
 /** Callbacks, globals and object handlers **/
-extern  "C" void C_FormBaseDeprecatedInputCB(FL_OBJECT *, long);
-extern  "C" void C_FormBaseDeprecatedOKCB(FL_OBJECT *, long);
-extern  "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT *, long);
+extern  "C" void C_FormBaseInputCB(FL_OBJECT *, long);
+extern  "C" void C_FormBaseOKCB(FL_OBJECT *, long);
+extern  "C" void C_FormBaseCancelCB(FL_OBJECT *, long);
 
 
 /**** Forms and Objects ****/
index ad0a54b41d8f4dba88c9053d962e697dcd13f3e8..65693be14487cba0173675ac8c75c02142b0d3b2 100644 (file)
@@ -45,7 +45,7 @@ shortcut:
 resize: FL_RESIZE_ALL
 gravity: FL_NoGravity FL_NoGravity
 name: database
-callback: C_FormBaseDeprecatedInputCB
+callback: C_FormBaseInputCB
 argument: 0
 
 --------------------
@@ -63,7 +63,7 @@ shortcut: ^M
 resize: FL_RESIZE_ALL
 gravity: FL_NoGravity FL_NoGravity
 name: button_ok
-callback: C_FormBaseDeprecatedOKCB
+callback: C_FormBaseOKCB
 argument: 3
 
 --------------------
@@ -81,7 +81,7 @@ shortcut:
 resize: FL_RESIZE_ALL
 gravity: FL_NoGravity FL_NoGravity
 name: button_cancel
-callback: C_FormBaseDeprecatedCancelCB
+callback: C_FormBaseCancelCB
 argument: 2
 
 --------------------
@@ -99,7 +99,7 @@ shortcut:
 resize: FL_RESIZE_ALL
 gravity: FL_NoGravity FL_NoGravity
 name: style
-callback: C_FormBaseDeprecatedInputCB
+callback: C_FormBaseInputCB
 argument: 0
 
 ==============================
index 216667fe26778b24b7dc3e74eb5bf451229358a4..c904cd167ad6178184e5e3fb4c34d15b4b533378 100644 (file)
@@ -1,6 +1,13 @@
-#include <config.h>
+/**
+ * \file xformsBC.C
+ * Copyright 2001 the LyX Team
+ * Read the file COPYING
+ *
+ * \author Allan Rae <rae@lyx.org>
+ * \author Angus Leeming <a.leeming@ic.ac.uk>
+ */
 
-#include FORMS_H_LOCATION
+#include <config.h>
 
 #ifdef __GNUG__
 #pragma implementation
index d65ac7d714b9bf671cd5e9c88fde802202116a1f..614b3e9fed4aa9172562b640e7a493d0007a0650 100644 (file)
 #ifndef XFORMSBC_H
 #define XFORMSBC_H
 
-#include "ButtonController.h"
+#include FORMS_H_LOCATION
 #include <list>
 
 #ifdef __GNUG__
 #pragma interface
 #endif
 
+#include "ButtonController.h"
+
 /** General purpose button controller for up to four buttons.
     Controls the activation of the OK, Apply and Cancel buttons.
     Actually supports 4 buttons in all and it's up to the user to decide on