]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlInset.h
ws fixes, formatting and some other small changes
[lyx.git] / src / frontends / controllers / ControlInset.h
index d7798e4d48e0c765b4d86a74919936fa255aa421..99236cdc84321118cfa7b6a74d938cd4e77a61a3 100644 (file)
@@ -1,47 +1,48 @@
-/* This file is part of
- * ====================================================== 
+// -*- C++ -*-
+/**
+ * \file ControlInset.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Angus Leeming
  *
- *           Copyright 2001 The LyX Team.
+ * Full author contact details are available in file CREDITS
  *
- * ======================================================
- *
- * \file ControlInsets.h
- * \author Angus Leeming <a.leeming@ic.ac.uk>
- *
- * ControlInset is to be used as a parent class for popups that display and
+ * ControlInset is to be used as a parent class for dialogs that display and
  * can perhaps modify the contents of an individual inset. An example being the
- * ubiquitous Citation popup.
+ * ubiquitous Citation dialog.
  */
 
 #ifndef CONTROLINSET_H
 #define CONTROLINSET_H
 
 #include "ControlConnections.h"
+#include "LString.h"
+
+#include <boost/signals/connection.hpp>
 
 class Inset;
 
 template <class Inset, class Params>
-class ControlInset : public ControlConnectBD
-{
+class ControlInset : public ControlConnectBD {
 public:
        ///
        ControlInset(LyXView &, Dialogs &);
        /// Allow the View access to the local copy.
-       Params & params() const;
+       Params & params();
+       ///
+       Params const & params() const;
 
-protected:
        /// Slots connected in the daughter classes c-tor.
        /// Slot launching dialog to (possibly) create a new inset.
        void createInset(string const &);
        /// Slot launching dialog to an existing inset.
        void showInset(Inset *);
+protected:
        /// Allow the daughter methods to access the inset.
        Inset * inset() const;
-
 private:
-       /** These 6 methods are all that the individual daughter classes
+       /** These 7 methods are all that the individual daughter classes
            should need to instantiate. */
 
        /// if the inset exists then do this...
@@ -62,10 +63,12 @@ private:
        /// clean-up any daughter class-particular data on hide().
        virtual void clearDaughterParams() {}
 
+       /** Some dialogs may find it beneficial to disconnect from the inset
+        when the Apply button is pressed. E.g., doing this with the citation
+        dialog allows multiple citiations to be inserted easily. */
+       virtual bool disconnectOnApply() { return false; }
 
-
-       
-       /// Instantiation of ControlBase virtual methods.
+       /// Instantiation of ControlButtons virtual methods.
 
        /// Get changed parameters and Dispatch them to the kernel.
        virtual void apply();
@@ -84,150 +87,18 @@ private:
        void connectInset(Inset * = 0);
 
        /// pointer to the inset passed through connectInset
-       Inset * inset_; 
+       Inset * inset_;
        /// inset::hide connection.
-       SigC::Connection ih_;
+       boost::signals::connection ih_;
        /** A local copy of the inset's params.
            Memory is allocated only whilst the dialog is visible.
        */
        Params * params_;
-};
-
-
-#include "LyXView.h"
-#include "support/LAssert.h"
-
-
-
-template <class Inset, class Params>
-ControlInset<Inset, Params>::ControlInset(LyXView & lv, Dialogs & d)
-       : ControlConnectBD(lv, d),
-         inset_(0), ih_(0), params_(0)
-{}
-
-
-template <class Inset, class Params>
-void ControlInset<Inset, Params>::showInset(Inset * inset)
-{
-       if (inset == 0) return;  // maybe we should Assert this?
-
-       connectInset(inset);
-       show(getParams(*inset));
-}
-
-
-template <class Inset, class Params>
-void ControlInset<Inset, Params>::createInset(string const & arg)
-{
-       connectInset();
-
-       if ( !arg.empty() )
-               bc().valid(); // so that the user can press Ok
-
-       show(getParams(arg));
-}
-
-
-template <class Inset, class Params>
-void ControlInset<Inset, Params>::show(Params const & params)
-{
-       if (params_) delete params_;
-       params_ = new Params(params);
 
-       setDaughterParams();
-
-       bc().readOnly(isReadonly());
-       view().show();
-}
-
-
-template <class Inset, class Params>
-void ControlInset<Inset, Params>::hide()
-{
-       if (params_) {
-               delete params_;
-               params_ = 0;
-       }
-       inset_ = 0;
-
-       clearDaughterParams();
-
-       ih_.disconnect();
-       disconnect();
-       view().hide();
-}
-
-
-template <class Inset, class Params>
-void ControlInset<Inset, Params>::update()
-{
-       if (params_) delete params_;
-
-       if (inset_)
-               params_ = new Params(getParams(*inset_));
-       else
-               params_ = new Params();
-
-       bc().readOnly(isReadonly());
-       view().update();
-}
-
-
-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();
-}
-
-
-template <class Inset, class Params>
-Params & ControlInset<Inset, Params>::params() const
-{
-       Assert(params_);
-       return *params_;
-}
-
-
-template <class Inset, class Params>
-Inset * ControlInset<Inset, Params>::inset() const
-{
-       Assert(inset_);
-       return inset_;
-}
-
-
-template <class Inset, class Params>
-void ControlInset<Inset, Params>::updateSlot(bool switched)
-{
-       if (switched)
-               hide();
-       else
-               update();
-}
+       /// is the dialog built ?
+       bool dialog_built_;
+};
 
+#include "ControlInset.tmpl"
 
-template <class Inset, class Params>
-void ControlInset<Inset, Params>::connectInset(Inset * inset)
-{
-       // If connected to another inset, disconnect from it.
-       if (inset_) {
-               ih_.disconnect();
-               inset_ = 0;
-       }
-
-       if (inset) {
-               inset_ = inset;
-               ih_ = inset->hideDialog.connect(
-                       SigC::slot(this, &ControlInset::hide));
-       }
-       connect();
-}
 #endif // CONTROLINSET_H