From b518346bbd37c3a9d6c3380855c3a0a3ecd00a66 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Wed, 31 Mar 2004 20:55:59 +0000 Subject: [PATCH] Convert the preamble dialog to the Dialog-based scheme. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8576 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 5 +++ src/frontends/ChangeLog | 9 +++++ src/frontends/Dialogs.C | 2 +- src/frontends/Dialogs.h | 13 ++---- src/frontends/controllers/ChangeLog | 4 ++ src/frontends/controllers/ControlPreamble.C | 44 +++++++++------------ src/frontends/controllers/ControlPreamble.h | 23 ++++++----- src/frontends/gtk/ChangeLog | 4 ++ src/frontends/gtk/Dialogs.C | 18 ++++++--- src/frontends/guiapi.C | 5 --- src/frontends/guiapi.h | 4 -- src/frontends/qt2/ChangeLog | 5 +++ src/frontends/qt2/Dialogs.C | 36 ++++++++++++----- src/frontends/qt2/Dialogs2.C | 25 +----------- src/frontends/xforms/ChangeLog | 8 ++++ src/frontends/xforms/Dialogs.C | 19 ++++++--- src/frontends/xforms/Dialogs2.C | 28 +------------ src/frontends/xforms/FormPreamble.C | 9 +++-- src/frontends/xforms/FormPreamble.h | 8 ++-- src/frontends/xforms/forms/form_preamble.fd | 8 ++-- src/lyxfunc.C | 2 - 21 files changed, 134 insertions(+), 145 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b3ff5e756e..f48a725643 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2004-03-31 Angus Leeming + + * lyxfunc.C (dispatch): Fall through to the generic + Dialogs::show("preamble"). + 2004-03-31 Angus Leeming * lyxfunc.C (dispatch): Fall through to the generic diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 0602df73fb..2fbd3642cc 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,12 @@ +2004-03-31 Angus Leeming + + * Dialogs.h (showPreamble): + * guiapi.[Ch] (gui_Preamble): removed. + + * Dialogs.[Ch] (build): return a boost::shared_ptr rather than + a raw Dialog*. Nicer, but also enables the Qt frontend to + re-use the document dialog. + 2004-03-31 Angus Leeming * Dialogs.h (showSpellchecker): diff --git a/src/frontends/Dialogs.C b/src/frontends/Dialogs.C index 9990de1f41..82996df58b 100644 --- a/src/frontends/Dialogs.C +++ b/src/frontends/Dialogs.C @@ -89,7 +89,7 @@ Dialog * Dialogs::find_or_build(string const & name) if (it != dialogs_.end()) return it->second.get(); - dialogs_[name] = DialogPtr(build(name)); + dialogs_[name] = build(name); return dialogs_[name].get(); } diff --git a/src/frontends/Dialogs.h b/src/frontends/Dialogs.h index 26479c02c1..f839869094 100644 --- a/src/frontends/Dialogs.h +++ b/src/frontends/Dialogs.h @@ -62,13 +62,6 @@ public: */ void updateBufferDependent(bool) const ; - /**@name Dialog Access Signals. - Put into some sort of alphabetical order */ - //@{ - /// - void showPreamble(); - //@} - /** \param name == "about" etc; an identifier used to launch a particular dialog. \param data is a string encoding of the data used to populate @@ -117,15 +110,15 @@ private: /// Dialog * find_or_build(std::string const & name); /// - Dialog * build(std::string const & name); + typedef boost::shared_ptr DialogPtr; + /// + DialogPtr build(std::string const & name); /// LyXView & lyxview_; /// std::map open_insets_; - /// - typedef boost::shared_ptr DialogPtr; /// std::map dialogs_; diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 39400f2b15..d222973918 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,7 @@ +2004-03-31 Angus Leeming + + * ControlPreamble.[Ch]: converted to the dialog-based scheme. + 2004-03-31 Angus Leeming * ControlSpellchecker.C: converted to the dialog-based scheme. diff --git a/src/frontends/controllers/ControlPreamble.C b/src/frontends/controllers/ControlPreamble.C index a6eb00dff8..c63377d994 100644 --- a/src/frontends/controllers/ControlPreamble.C +++ b/src/frontends/controllers/ControlPreamble.C @@ -10,58 +10,50 @@ #include - #include "ControlPreamble.h" -#include "ViewBase.h" - #include "buffer.h" #include "bufferparams.h" -#include "gettext.h" - -#include "frontends/LyXView.h" - using std::string; -ControlPreamble::ControlPreamble(LyXView & lv, Dialogs & d) - : ControlDialogBD(lv, d) +ControlPreamble::ControlPreamble(Dialog & parent) + : Dialog::Controller(parent) {} -void ControlPreamble::apply() +bool ControlPreamble::initialiseParams(std::string const &) { - if (!bufferIsAvailable()) - return; - - view().apply(); - - buffer()->params().preamble = params(); - buffer()->markDirty(); - lv_.message(_("LaTeX preamble set")); + params_ = kernel().buffer().params().preamble; + return true; } -string const & ControlPreamble::params() const +void ControlPreamble::clearParams() { - return params_; + params_.erase(); } -void ControlPreamble::params(string const & newparams) +void ControlPreamble::dispatchParams() { - params_ = newparams; + // This can stay because we're going to throw the class away + // as soon as xforms 1.1 is released. + // Ie, there's no need to define LFUN_BUFFERPREAMBLE_APPLY. + Buffer & buffer = kernel().buffer(); + buffer.params().preamble = params(); + buffer.markDirty(); } -void ControlPreamble::setParams() +string const & ControlPreamble::params() const { - params_ = buffer()->params().preamble; + return params_; } -void ControlPreamble::clearParams() +void ControlPreamble::params(string const & newparams) { - params_.erase(); + params_ = newparams; } diff --git a/src/frontends/controllers/ControlPreamble.h b/src/frontends/controllers/ControlPreamble.h index f6aaa22d4f..931da035da 100644 --- a/src/frontends/controllers/ControlPreamble.h +++ b/src/frontends/controllers/ControlPreamble.h @@ -12,29 +12,28 @@ #ifndef CONTROLPREAMBLE_H #define CONTROLPREAMBLE_H - -#include "ControlDialog_impl.h" - +#include "Dialog.h" /** A controller for Preamble dialogs. */ -class ControlPreamble : public ControlDialogBD { +class ControlPreamble : public Dialog::Controller { public: /// - ControlPreamble(LyXView &, Dialogs &); + ControlPreamble(Dialog &); + /// + virtual bool initialiseParams(std::string const &); + /// + virtual void clearParams(); + /// + virtual void dispatchParams(); + /// + virtual bool isBufferDependent() const { return true; } /// std::string const & params() const; /// void params(std::string const & newparams); private: - /// Get changed parameters and Dispatch them to the kernel. - virtual void apply(); - /// set the params before show or update. - virtual void setParams(); - /// clean-up on hide. - virtual void clearParams(); - /// std::string params_; }; diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index 5c5420ed67..6fb69ded21 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,3 +1,7 @@ +2004-03-31 Angus Leeming + + * Dialogs.C (build): added preamble dialog. + 2004-03-31 Angus Leeming * Dialogs.C (build): added spellchecker dialog. diff --git a/src/frontends/gtk/Dialogs.C b/src/frontends/gtk/Dialogs.C index 2a7b030d0c..493dbf9bf8 100644 --- a/src/frontends/gtk/Dialogs.C +++ b/src/frontends/gtk/Dialogs.C @@ -34,6 +34,7 @@ #include "ControlMath.h" #include "ControlNote.h" #include "ControlParagraph.h" +#include "ControlPreamble.h" #include "ControlPrefs.h" #include "ControlPrint.h" #include "ControlRef.h" @@ -73,6 +74,7 @@ #include "FormMathsStyle.h" #include "FormNote.h" #include "FormParagraph.h" +#include "FormPreamble.h" #include "FormPreferences.h" #include "FormPrint.h" #include "FormRef.h" @@ -111,6 +113,7 @@ #include "ams_nrel.xbm" #include "ams_ops.xbm" +#include #include using std::string; @@ -134,8 +137,8 @@ char const * const dialognames[] = { "mathgreek", "mathmisc", "mathdots", "mathbigoperators", "mathamsmisc", "mathamsarrows", "mathamsrelations", "mathamsnegatedrelations", "mathamsoperators", "mathdelimiter", "mathmatrix", "mathspace", "mathstyle", -"note", "paragraph", "prefs", "print", "ref", "sendto", "spellchecker", -"tabular", "tabularcreate", "texinfo", +"note", "paragraph", "preamble", "prefs", "print", "ref", "sendto", +"spellchecker", "tabular", "tabularcreate", "texinfo", #ifdef HAVE_LIBAIKSAURUS "thesaurus", @@ -165,12 +168,11 @@ bool Dialogs::isValidName(string const & name) const } -Dialog * Dialogs::build(string const & name) +Dialogs::DialogPtr Dialogs::build(string const & name) { - if (!isValidName(name)) - return 0; + BOOST_ASSERT(isValidName(name)); - Dialog * dialog = new Dialog(lyxview_, name); + DialogPtr dialog(new Dialog(lyxview_, name)); dialog->bc().view(new xformsBC(dialog->bc())); if (name == "aboutlyx") { @@ -450,6 +452,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlParagraph(*dialog)); dialog->setView(new FormParagraph(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); + } else if (name == "preamble") { + dialog->setController(new ControlPreamble(*dialog)); + dialog->setView(new FormPreamble(*dialog)); + dialog->bc().bp(new OkApplyCancelPolicy); } else if (name == "prefs") { dialog->setController(new ControlPrefs(*dialog)); dialog->setView(new FormPreferences(*dialog)); diff --git a/src/frontends/guiapi.C b/src/frontends/guiapi.C index 6b9abb108d..e186de9deb 100644 --- a/src/frontends/guiapi.C +++ b/src/frontends/guiapi.C @@ -22,9 +22,4 @@ void gui_show_dialog(Dialogs * d, char const * name, char const * data) d->show(name, data, 0); } -void gui_ShowPreamble(Dialogs & d) -{ - d.showPreamble(); -} - } // extern "C" diff --git a/src/frontends/guiapi.h b/src/frontends/guiapi.h index adfd97d9c2..0855154262 100644 --- a/src/frontends/guiapi.h +++ b/src/frontends/guiapi.h @@ -12,16 +12,12 @@ #ifndef GUIAPI_H #define GUIAPI_H - - class Dialogs; extern "C" { void gui_show_dialog(Dialogs *, char const * name, char const * data); -void gui_ShowPreamble(Dialogs &); - } // extern "C" #endif // GUIAPI_H diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index d42806daca..2e7be60ae0 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,8 @@ +2004-03-31 Angus Leeming + + * Dialogs.C (build): added "preamble" as a symonym for "document". + * Dialogs2.C (showPreamble): removed. + 2004-03-31 Angus Leeming * Dialogs.C (build): added spellchecker dialog. diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index ea168b867e..7d652bb99a 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -91,6 +91,8 @@ #include "qt_helpers.h" +#include + using std::string; @@ -100,8 +102,8 @@ char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character", "citation", "document", "error", "errorlist", "ert", "external", "file", "findreplace", "float", "graphics", "include", "index", "label", "log", -"mathpanel", "mathdelimiter", "mathmatrix", "note", "paragraph", "prefs", -"print", "ref", "sendto", "spellchecker","tabular", "tabularcreate", +"mathpanel", "mathdelimiter", "mathmatrix", "note", "paragraph", "preamble", +"prefs", "print", "ref", "sendto", "spellchecker","tabular", "tabularcreate", #ifdef HAVE_LIBAIKSAURUS "thesaurus", @@ -132,12 +134,11 @@ bool Dialogs::isValidName(string const & name) const } -Dialog * Dialogs::build(string const & name) +Dialogs::DialogPtr Dialogs::build(string const & name) { - if (!isValidName(name)) - return 0; + BOOST_ASSERT(isValidName(name)); - Dialog * dialog = new Dialog(lyxview_, name); + DialogPtr dialog(new Dialog(lyxview_, name)); dialog->bc().view(new Qt2BC(dialog->bc())); if (name == "aboutlyx") { @@ -172,10 +173,25 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlCitation(*dialog)); dialog->setView(new QCitation(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); - } else if (name == "document") { - dialog->setController(new ControlDocument(*dialog)); - dialog->setView(new QDocument(*dialog)); - dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); + } else if (name == "document" || name == "preamble") { + + // This nastiness will exist only as long as xforms + // has a separate preamble dialog. + + string const other = (name == "document") ? + "preamble" : "document"; + + std::map::iterator it = + dialogs_.find(other); + + if (it != dialogs_.end()) + dialog = it->second; + else { + dialog->setController(new ControlDocument(*dialog)); + dialog->setView(new QDocument(*dialog)); + dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); + } + } else if (name == "errorlist") { dialog->setController(new ControlErrorList(*dialog)); dialog->setView(new QErrorList(*dialog)); diff --git a/src/frontends/qt2/Dialogs2.C b/src/frontends/qt2/Dialogs2.C index 21d18500d2..41603d6e58 100644 --- a/src/frontends/qt2/Dialogs2.C +++ b/src/frontends/qt2/Dialogs2.C @@ -12,28 +12,13 @@ #include -#include "debug.h" #include "Dialogs.h" -#include "controllers/GUI.h" -#include "ButtonController.h" - -#include "Qt2BC.h" - -// Here would be an appropriate point to lecture on the evils -// of the Qt headers, those most fucked up of disgusting ratholes. -// But I won't. -#undef signals - struct Dialogs::Impl { - Impl(LyXView & lv, Dialogs & d); + Impl(LyXView &, Dialogs &) {} }; -Dialogs::Impl::Impl(LyXView &, Dialogs &) -{} - - void Dialogs::init_pimpl() { pimpl_ = new Impl(lyxview_, *this); @@ -44,11 +29,3 @@ Dialogs::~Dialogs() { delete pimpl_; } - - -void Dialogs::showPreamble() -{ - show("document"); - // Oh Angus, won't you help a poor child ? - //pimpl_->document.view()->showPreamble(); -} diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 88fd766b94..21e7551808 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,11 @@ +2004-03-31 Angus Leeming + + * Dialogs.C (build): added preamble dialog. + * Dialogs2.C (showPreamble): removed. + + * FormPreamble.[Ch]: + * forms/form_preamble.fd: converted to the Dialog-based scheme. + 2004-03-31 Angus Leeming * Dialogs.C (build): added spellchecker dialog. diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 202af2b8b7..1c0b78b1c6 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -31,6 +31,7 @@ #include "ControlMath.h" #include "ControlNote.h" #include "ControlParagraph.h" +#include "ControlPreamble.h" #include "ControlPrefs.h" #include "ControlPrint.h" #include "ControlRef.h" @@ -68,6 +69,7 @@ #include "FormMathsStyle.h" #include "FormNote.h" #include "FormParagraph.h" +#include "FormPreamble.h" #include "FormPreferences.h" #include "FormPrint.h" #include "FormRef.h" @@ -107,6 +109,8 @@ #include "ams_nrel.xbm" #include "ams_ops.xbm" +#include + using std::string; @@ -129,8 +133,8 @@ char const * const dialognames[] = { "mathgreek", "mathmisc", "mathdots", "mathbigoperators", "mathamsmisc", "mathamsarrows", "mathamsrelations", "mathamsnegatedrelations", "mathamsoperators", "mathdelimiter", "mathmatrix", "mathspace", "mathstyle", -"note", "paragraph", "prefs", "print", "ref", "sendto", "spellchecker", -"tabular", "tabularcreate", "texinfo", +"note", "paragraph", "preamble", "prefs", "print", "ref", "sendto", +"spellchecker", "tabular", "tabularcreate", "texinfo", #ifdef HAVE_LIBAIKSAURUS "thesaurus", @@ -160,12 +164,11 @@ bool Dialogs::isValidName(string const & name) const } -Dialog * Dialogs::build(string const & name) +Dialogs::DialogPtr Dialogs::build(string const & name) { - if (!isValidName(name)) - return 0; + BOOST_ASSERT(isValidName(name)); - Dialog * dialog = new Dialog(lyxview_, name); + DialogPtr dialog(new Dialog(lyxview_, name)); dialog->bc().view(new xformsBC(dialog->bc())); if (name == "aboutlyx") { @@ -440,6 +443,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlParagraph(*dialog)); dialog->setView(new FormParagraph(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); + } else if (name == "preamble") { + dialog->setController(new ControlPreamble(*dialog)); + dialog->setView(new FormPreamble(*dialog)); + dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); } else if (name == "prefs") { dialog->setController(new ControlPrefs(*dialog)); dialog->setView(new FormPreferences(*dialog)); diff --git a/src/frontends/xforms/Dialogs2.C b/src/frontends/xforms/Dialogs2.C index adf60ee062..ef5f46fe45 100644 --- a/src/frontends/xforms/Dialogs2.C +++ b/src/frontends/xforms/Dialogs2.C @@ -12,32 +12,12 @@ #include #include "Dialogs.h" -#include "controllers/GUI.h" -#include "ButtonController.h" - -#include "xformsBC.h" -#include "xforms_helpers.h" - -#include "ControlPreamble.h" -#include "FormPreamble.h" -#include "forms/form_preamble.h" - -typedef GUI -PreambleDialog; - struct Dialogs::Impl { - Impl(LyXView & lv, Dialogs & d); - - PreambleDialog preamble; + Impl(LyXView &, Dialogs &) {} }; -Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) - : preamble(lv, d) -{} - - void Dialogs::init_pimpl() { pimpl_ = new Impl(lyxview_, *this); @@ -48,9 +28,3 @@ Dialogs::~Dialogs() { delete pimpl_; } - - -void Dialogs::showPreamble() -{ - pimpl_->preamble.controller().show(); -} diff --git a/src/frontends/xforms/FormPreamble.C b/src/frontends/xforms/FormPreamble.C index ff1fb401f5..ed0c7d7690 100644 --- a/src/frontends/xforms/FormPreamble.C +++ b/src/frontends/xforms/FormPreamble.C @@ -11,19 +11,20 @@ #include #include "FormPreamble.h" -#include "ControlPreamble.h" #include "forms/form_preamble.h" +#include "controllers/ControlPreamble.h" + #include "xforms_helpers.h" #include "xformsBC.h" #include "lyx_forms.h" -typedef FormCB > base_class; +typedef FormController > base_class; -FormPreamble::FormPreamble() - : base_class(_("LaTeX Preamble")) +FormPreamble::FormPreamble(Dialog & parent) + : base_class(parent, _("LaTeX Preamble")) {} diff --git a/src/frontends/xforms/FormPreamble.h b/src/frontends/xforms/FormPreamble.h index 1fe89805fb..2abcfc7a92 100644 --- a/src/frontends/xforms/FormPreamble.h +++ b/src/frontends/xforms/FormPreamble.h @@ -12,18 +12,18 @@ #ifndef FORMPREAMBLE_H #define FORMPREAMBLE_H - -#include "FormBase.h" +#include "FormDialogView.h" class ControlPreamble; struct FD_preamble; /** This class provides an XForms implementation of the Preamble Dialog. */ -class FormPreamble : public FormCB > { +class FormPreamble + : public FormController > { public: /// - FormPreamble(); + FormPreamble(Dialog &); private: /// Apply from dialog virtual void apply(); diff --git a/src/frontends/xforms/forms/form_preamble.fd b/src/frontends/xforms/forms/form_preamble.fd index 3177cf4cf2..b34487577f 100644 --- a/src/frontends/xforms/forms/form_preamble.fd +++ b/src/frontends/xforms/forms/form_preamble.fd @@ -46,7 +46,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_ok -callback: C_FormBaseOKCB +callback: C_FormDialogView_OKCB argument: 0 -------------------- @@ -64,7 +64,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_apply -callback: C_FormBaseApplyCB +callback: C_FormDialogView_ApplyCB argument: 0 -------------------- @@ -82,7 +82,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_close -callback: C_FormBaseCancelCB +callback: C_FormDialogView_CancelCB argument: 0 -------------------- @@ -100,7 +100,7 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NorthWest FL_SouthEast name: input_preamble -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 ============================== diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 7a99816e91..2bfa6f3e68 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1049,8 +1049,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose) if (!data.empty()) owner->getDialogs().show("character", data); } - else if (name == "preamble") - owner->getDialogs().showPreamble(); else if (name == "latexlog") { pair const logfile = -- 2.39.2