From: Angus Leeming Date: Mon, 19 Mar 2001 16:37:01 +0000 (+0000) Subject: Implemented controller-view split for FormBibtex. X-Git-Tag: 1.6.10~21432 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=14c60d0aaeff364a78f77e163e6eae5fc3dab8c0;p=features.git Implemented controller-view split for FormBibtex. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1794 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 070057f613..b84d2a3dde 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,9 @@ +2001-03-19 Angus Leeming + + * ControlBibtex.[Ch]: new files; controller for an InsetBibtex popup. + + * Makefile.am: added ControlBibtex.[Ch]. + 2001-03-16 Angus Leeming * ControlBibitem.C: diff --git a/src/frontends/controllers/ControlBibtex.C b/src/frontends/controllers/ControlBibtex.C new file mode 100644 index 0000000000..8614b105bb --- /dev/null +++ b/src/frontends/controllers/ControlBibtex.C @@ -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 + */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include +#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 index 0000000000..4699427292 --- /dev/null +++ b/src/frontends/controllers/ControlBibtex.h @@ -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 + */ + +#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 GUIBibtex : public ControlBibtex { +public: + /// + GUIBibtex(LyXView &, Dialogs &); + /// + virtual ButtonControllerBase & bc() { return bc_; } + /// + virtual ViewBase & view() { return view_; } + +private: + /// + ButtonController bc_; + /// + GUIview view_; +}; + +template +GUIBibtex::GUIBibtex(LyXView & lv, Dialogs & d) + : ControlBibtex(lv, d), + view_(*this) +{} + +#endif // CONTROLBIBTEX_H diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index 50d0e811e1..53bc704593 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -18,6 +18,8 @@ libcontrollers_la_SOURCES=\ ControlBase.h \ ControlBibitem.C \ ControlBibitem.h \ + ControlBibtex.C \ + ControlBibtex.h \ ControlCitation.C \ ControlCitation.h \ ControlCommand.C \ diff --git a/src/frontends/controllers/ViewBase.h b/src/frontends/controllers/ViewBase.h index bbd6a52cd1..541bbe9335 100644 --- a/src/frontends/controllers/ViewBase.h +++ b/src/frontends/controllers/ViewBase.h @@ -60,6 +60,8 @@ class ViewBC : public ViewBase { public: /// ViewBC(ControlBase & c) : ViewBase(c) {} + +protected: /// GUIbc & bc() const { diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 33d830eb41..5b8dee4181 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,10 @@ +2001-03-19 Angus Leeming + + * FormBibtex.[Ch]: + * forms/form_bibtex.fd: implemented controller-view split. + + * Dialogs.C: associated changes. + 2001-03-19 Angus Leeming * FormBaseDeprecated.[Ch]: rename title as title_. diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 5c6a2e8ff6..b1b6b9d520 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -10,7 +10,6 @@ */ #include -#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(*lv, *this)); add(new GUIBibitem(*lv, *this)); + add(new GUIBibtex(*lv, *this)); - add(new FormBibtex(lv, this)); add(new FormCharacter(lv, this)); add(new FormCopyright(lv, this)); add(new FormCredits(lv, this)); diff --git a/src/frontends/xforms/FormBase.h b/src/frontends/xforms/FormBase.h index 6138f4a586..8668e3722f 100644 --- a/src/frontends/xforms/FormBase.h +++ b/src/frontends/xforms/FormBase.h @@ -15,12 +15,12 @@ #define FORMBASE_H #include +#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" diff --git a/src/frontends/xforms/FormBibitem.C b/src/frontends/xforms/FormBibitem.C index 2fb4ddba6b..d23831c753 100644 --- a/src/frontends/xforms/FormBibitem.C +++ b/src/frontends/xforms/FormBibitem.C @@ -14,7 +14,6 @@ #include #include "ControlBibitem.h" #include "FormBibitem.h" -#include "form_bibitem.h" #include "gettext.h" #include "xformsBC.h" #include "support/lstrings.h" // compare diff --git a/src/frontends/xforms/FormBibitem.h b/src/frontends/xforms/FormBibitem.h index 75be7c5464..f103d12e27 100644 --- a/src/frontends/xforms/FormBibitem.h +++ b/src/frontends/xforms/FormBibitem.h @@ -17,13 +17,13 @@ #include "FormBase.h" -/** - * For bibliography entry editing - */ - #include "form_bibitem.h" + class ControlBibitem; +/** + * For bibliography entry editing + */ class FormBibitem : public FormBase2 { public: /// diff --git a/src/frontends/xforms/FormBibtex.C b/src/frontends/xforms/FormBibtex.C index b062d719a1..2f32c2434b 100644 --- a/src/frontends/xforms/FormBibtex.C +++ b/src/frontends/xforms/FormBibtex.C @@ -7,48 +7,22 @@ * \author John Levon */ -#include - -#include FORMS_H_LOCATION - #ifdef __GNUG__ #pragma implementation #endif - -#include "Dialogs.h" +#include +#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(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)); } diff --git a/src/frontends/xforms/FormBibtex.h b/src/frontends/xforms/FormBibtex.h index 9c0dfdf58b..ce9ca1d378 100644 --- a/src/frontends/xforms/FormBibtex.h +++ b/src/frontends/xforms/FormBibtex.h @@ -11,50 +11,38 @@ #ifndef FORMBIBTEX_H #define FORMBIBTEX_H -#include - #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 { 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 dialog_; - /// The ButtonController - ButtonController bc_; }; - -inline -xformsBC & FormBibtex::bc() -{ - return bc_; -} #endif // FORMBIBTEX_H diff --git a/src/frontends/xforms/form_bibtex.C b/src/frontends/xforms/form_bibtex.C index f650a8098c..68c1f44ba3 100644 --- a/src/frontends/xforms/form_bibtex.C +++ b/src/frontends/xforms/form_bibtex.C @@ -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; diff --git a/src/frontends/xforms/form_bibtex.h b/src/frontends/xforms/form_bibtex.h index 3ea6ce3357..8189af6e7a 100644 --- a/src/frontends/xforms/form_bibtex.h +++ b/src/frontends/xforms/form_bibtex.h @@ -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 ****/ diff --git a/src/frontends/xforms/forms/form_bibtex.fd b/src/frontends/xforms/forms/form_bibtex.fd index ad0a54b41d..65693be144 100644 --- a/src/frontends/xforms/forms/form_bibtex.fd +++ b/src/frontends/xforms/forms/form_bibtex.fd @@ -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 ============================== diff --git a/src/frontends/xforms/xformsBC.C b/src/frontends/xforms/xformsBC.C index 216667fe26..c904cd167a 100644 --- a/src/frontends/xforms/xformsBC.C +++ b/src/frontends/xforms/xformsBC.C @@ -1,6 +1,13 @@ -#include +/** + * \file xformsBC.C + * Copyright 2001 the LyX Team + * Read the file COPYING + * + * \author Allan Rae + * \author Angus Leeming + */ -#include FORMS_H_LOCATION +#include #ifdef __GNUG__ #pragma implementation diff --git a/src/frontends/xforms/xformsBC.h b/src/frontends/xforms/xformsBC.h index d65ac7d714..614b3e9fed 100644 --- a/src/frontends/xforms/xformsBC.h +++ b/src/frontends/xforms/xformsBC.h @@ -19,13 +19,15 @@ #ifndef XFORMSBC_H #define XFORMSBC_H -#include "ButtonController.h" +#include FORMS_H_LOCATION #include #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