+// -*- C++ -*-
/* This file is part of
* ======================================================
*
* \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 "support/LAssert.h"
+#include "debug.h"
#include "ControlConnections.h"
class Inset;
///
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 * inset);
+ void showInset(Inset *);
/// Allow the daughter methods to access the inset.
Inset * inset() const;
private:
- /** These 5 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...
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;
- /// Instantiation of ControlBase virtual methods.
+ /** Most derived classes won't need these two, so they default to empty.
+ */
+
+ /// set any daughter class-particular data on show().
+ virtual void setDaughterParams() {}
+ /// 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 ControlButtons virtual methods.
/// Get changed parameters and Dispatch them to the kernel.
virtual void apply();
void show(Params const &);
/// Connect signals
void connectInset(Inset * = 0);
- /// Disconnect signals
- virtual void disconnect();
- ///
- void disconnectInset();
/// pointer to the inset passed through connectInset
Inset * inset_;
Memory is allocated only whilst the dialog is visible.
*/
Params * params_;
-};
-
-
-#include "LyXView.h"
-#include "support/LAssert.h"
+ /// is the dialog built ?
+ bool dialog_built_;
+
+};
template <class Inset, class Params>
ControlInset<Inset, Params>::ControlInset(LyXView & lv, Dialogs & d)
: ControlConnectBD(lv, d),
- inset_(0), ih_(0), params_(0)
+ inset_(0), ih_(0), params_(0), dialog_built_(false)
{}
{
connectInset();
- if ( !arg.empty() )
+ if (!arg.empty())
bc().valid(); // so that the user can press Ok
show(getParams(arg));
if (params_) delete params_;
params_ = new Params(params);
+ setDaughterParams();
+
+ if (!dialog_built_) {
+ view().build();
+ dialog_built_ = true;
+ }
+
bc().readOnly(isReadonly());
view().show();
}
delete params_;
params_ = 0;
}
+ inset_ = 0;
clearDaughterParams();
+ ih_.disconnect();
disconnect();
view().hide();
}
template <class Inset, class Params>
void ControlInset<Inset, Params>::apply()
{
- if (lv_.buffer()->isReadonly() || !inset_)
+ if (lv_.buffer()->isReadonly())
return;
view().apply();
if (inset_ && params() != getParams(*inset_))
applyParamsToInset();
- else if (!inset_)
+ else
applyParamsNoInset();
+
+ if (disconnectOnApply() && !isClosing()) {
+ *params_ = getParams(string());
+ inset_ = 0;
+ ih_.disconnect();
+
+ view().update();
+ }
}
template <class Inset, class Params>
-Params & ControlInset<Inset, Params>::params() const
+Params & ControlInset<Inset, Params>::params()
{
- Assert(params_);
+ lyx::Assert(params_);
+ return *params_;
+}
+
+
+template <class Inset, class Params>
+Params const & ControlInset<Inset, Params>::params() const
+{
+ lyx::Assert(params_);
return *params_;
}
template <class Inset, class Params>
Inset * ControlInset<Inset, Params>::inset() const
{
- Assert(inset_);
+ lyx::Assert(inset_);
return inset_;
}
}
-template <class Inset, class Params>
-void ControlInset<Inset, Params>::disconnect()
-{
- inset_ = 0;
- ih_.disconnect();
- ControlConnectBD::disconnect();
-}
-
-
template <class Inset, class Params>
void ControlInset<Inset, Params>::connectInset(Inset * inset)
{
}
connect();
}
-
-
-template <class Inset, class Params>
-void ControlInset<Inset, Params>::disconnectInset()
-{
- ih_.disconnect();
-}
-
-
#endif // CONTROLINSET_H