From 9705be9f1b8441175048b4e2065795051adafdc6 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Fri, 23 Mar 2001 17:09:34 +0000 Subject: [PATCH] Implemented controller-view split for FormError and FormInclude. Cleaned up code in controllers in the process; I think that the interface is stabilising now. Cleaned up code in InsetInclude a little. Mental note (to me?!): the Bibitem, Bibtex and Include insets create an inset when the appropriate menu item is selected. This is incorrect; the inset should only be created when "Ok" is pressed, as with the majority of insets. CREATE_XXX flags and associated code are needed. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1817 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 5 +- src/ChangeLog | 3 + src/frontends/controllers/ChangeLog | 22 ++ src/frontends/controllers/ControlBibitem.C | 31 +-- src/frontends/controllers/ControlBibitem.h | 10 +- src/frontends/controllers/ControlBibtex.C | 31 ++- src/frontends/controllers/ControlBibtex.h | 10 +- src/frontends/controllers/ControlCharacter.h | 5 +- src/frontends/controllers/ControlCitation.C | 2 +- src/frontends/controllers/ControlCitation.h | 4 +- src/frontends/controllers/ControlCommand.C | 83 +----- src/frontends/controllers/ControlCommand.h | 43 +-- .../controllers/ControlConnections.h | 10 +- src/frontends/controllers/ControlDialogs.h | 113 +------- src/frontends/controllers/ControlError.C | 38 +++ src/frontends/controllers/ControlError.h | 47 ++++ src/frontends/controllers/ControlInclude.C | 40 +++ src/frontends/controllers/ControlInclude.h | 47 ++++ src/frontends/controllers/ControlInset.h | 241 +++++++++++++++++ src/frontends/controllers/ControlLog.h | 3 +- src/frontends/controllers/ControlVCLog.h | 3 +- src/frontends/controllers/GUI.h | 28 ++ src/frontends/controllers/Makefile.am | 7 +- src/frontends/xforms/ChangeLog | 18 ++ src/frontends/xforms/Dialogs.C | 12 +- src/frontends/xforms/FormBibitem.h | 5 +- src/frontends/xforms/FormBibtex.h | 5 +- src/frontends/xforms/FormCitation.h | 19 +- src/frontends/xforms/FormError.C | 78 ++---- src/frontends/xforms/FormError.h | 55 ++-- src/frontends/xforms/FormInclude.C | 244 +++++++----------- src/frontends/xforms/FormInclude.h | 72 +----- src/frontends/xforms/form_error.C | 2 +- src/frontends/xforms/form_error.h | 2 +- src/frontends/xforms/form_include.C | 14 +- src/frontends/xforms/form_include.h | 6 +- src/frontends/xforms/forms/form_error.fd | 2 +- src/frontends/xforms/forms/form_include.fd | 28 +- src/insets/ChangeLog | 6 + src/insets/insetinclude.C | 90 ++++--- src/insets/insetinclude.h | 35 ++- 41 files changed, 853 insertions(+), 666 deletions(-) create mode 100644 src/frontends/controllers/ControlError.C create mode 100644 src/frontends/controllers/ControlError.h create mode 100644 src/frontends/controllers/ControlInclude.C create mode 100644 src/frontends/controllers/ControlInclude.h create mode 100644 src/frontends/controllers/ControlInset.h diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index d6a3df7345..9f114f463c 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -2928,13 +2928,14 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) if (!bv_->insertInset(inset, "Standard", true)) delete inset; } + break; case LFUN_CHILD_INSERT: { - InsetInclude::InsetIncludeParams p; + InsetInclude::Params p; p.cparams.setFromString(argument); - p.buffer = buffer_; + p.masterFilename_ = buffer_->fileName(); InsetInclude * inset = new InsetInclude(p); if (!bv_->insertInset(inset)) diff --git a/src/ChangeLog b/src/ChangeLog index 99b6fcee47..9403b0b79b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -2,6 +2,9 @@ * LString.h: removed "using std::getline"! + * BufferView_pimpl.C (Dispatch): changes due to changes in + InsetInclude::Params. + * buffer.C (tag_name): removed redundant break statements as they were producing lots of warnings with my compiler. diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 118fabaa34..84638ba95d 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,25 @@ +2001-03-23 Angus Leeming + + * ControlDialogs.h: moved class ControlInset into its own file. + + * ControlInset.h: new file. class ControlInset has been expanded to take + two template parameters, Inset and Params. Believe that all inset + controllers can be derived from this with the minimum of effort. + + * ControlBibitem.[Ch]: + * ControlBibtex.[Ch]: + * ControlCitation.[Ch]: + * ControlCommand.[Ch]: moved most code into ControlInset. + + * lots of files. Moved protected stuff into private where possible. + + * ControlError.[Ch]: + * ControlInclude.[Ch]: new files; controllers for the LaTeX error and + Include popups, respectively. + + * GUI.h: + * Makefile.am: associated changes. + 2001-03-23 Angus Leeming * ControlCredits.[Ch] (getCredits): returns a stringstream not a diff --git a/src/frontends/controllers/ControlBibitem.C b/src/frontends/controllers/ControlBibitem.C index 3ca711a592..3e27790510 100644 --- a/src/frontends/controllers/ControlBibitem.C +++ b/src/frontends/controllers/ControlBibitem.C @@ -23,7 +23,7 @@ #include "ControlBibitem.h" #include "Dialogs.h" #include "LyXView.h" -#include "BufferView.h" +#include "buffer.h" using SigC::slot; @@ -33,24 +33,19 @@ ControlBibitem::ControlBibitem(LyXView & lv, Dialogs & d) d_.showBibitem.connect(slot(this, &ControlBibitem::showInset)); } -void ControlBibitem::apply() +void ControlBibitem::applyParamsToInset() { - view().apply(); + // FIXME: + // confirm, is this only necessary for FormBibTeX ??? + if (params().getContents() != inset()->params().getContents()) + lv_.view()->ChangeCitationsIfUnique(inset()->params().getContents(), + params().getContents()); - if (inset_ && params() != inset_->params()) { - // FIXME: - // confirm, is this only necessary for FormBibTeX ??? - if (params().getContents() != inset_->params().getContents()) - lv_.view()->ChangeCitationsIfUnique( - inset_->params().getContents(), - params().getContents()); + inset()->setParams(params()); + lv_.view()->updateInset(inset(), true); - 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()); - } + // 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/ControlBibitem.h b/src/frontends/controllers/ControlBibitem.h index 27263b2425..6a852cbe09 100644 --- a/src/frontends/controllers/ControlBibitem.h +++ b/src/frontends/controllers/ControlBibitem.h @@ -30,9 +30,13 @@ public: /// ControlBibitem(LyXView &, Dialogs &); -protected: - /// Get changed parameters and Dispatch them to the kernel. - virtual void apply(); +private: + /// Dispatch the changed parameters to the kernel. + virtual void applyParamsToInset(); + /// not needed. + virtual void applyParamsNoInset() {} + /// not needed. + virtual void clearDaughterParams() {} }; #endif // CONTROLBIBITEM_H diff --git a/src/frontends/controllers/ControlBibtex.C b/src/frontends/controllers/ControlBibtex.C index 0692d60982..560b20e32d 100644 --- a/src/frontends/controllers/ControlBibtex.C +++ b/src/frontends/controllers/ControlBibtex.C @@ -23,7 +23,7 @@ #include "ControlBibtex.h" #include "Dialogs.h" #include "LyXView.h" -#include "BufferView.h" +#include "buffer.h" using SigC::slot; @@ -33,22 +33,21 @@ ControlBibtex::ControlBibtex(LyXView & lv, Dialogs & d) d_.showBibtex.connect(slot(this, &ControlBibtex::showInset)); } -void ControlBibtex::apply() +void ControlBibtex::applyParamsToInset() { - view().apply(); + if (params().getContents() != inset()->params().getContents()) + lv_.view()->ChangeCitationsIfUnique(inset()->params().getContents(), + params().getContents()); - 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); - 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()); - } + // We need to do a redraw because the maximum + // InsetBibKey width could have changed + lv_.view()->redraw(); + lv_.view()->fitCursor(lv_.view()->getLyXText()); } + + +void ControlBibtex::applyParamsNoInset() +{} diff --git a/src/frontends/controllers/ControlBibtex.h b/src/frontends/controllers/ControlBibtex.h index 2be3c6c241..392540aaf0 100644 --- a/src/frontends/controllers/ControlBibtex.h +++ b/src/frontends/controllers/ControlBibtex.h @@ -30,9 +30,13 @@ public: /// ControlBibtex(LyXView &, Dialogs &); -protected: - /// Get changed parameters and Dispatch them to the kernel. - virtual void apply(); +private: + /// Dispatch the changed parameters to the kernel. + virtual void applyParamsToInset(); + /// + virtual void applyParamsNoInset(); + /// not needed. + virtual void clearDaughterParams() {} }; #endif // CONTROLBIBTEX_H diff --git a/src/frontends/controllers/ControlCharacter.h b/src/frontends/controllers/ControlCharacter.h index 4eb44ca0b6..b593c83c52 100644 --- a/src/frontends/controllers/ControlCharacter.h +++ b/src/frontends/controllers/ControlCharacter.h @@ -71,7 +71,7 @@ public: /// void setToggleAll(bool); -protected: +private: /// Get changed parameters and Dispatch them to the kernel. virtual void apply(); /// set the params before show or update. @@ -79,8 +79,9 @@ protected: /// clean-up on hide. virtual void clearParams(); -private: + /// LyXFont * font_; + /// bool toggleall_; }; diff --git a/src/frontends/controllers/ControlCitation.C b/src/frontends/controllers/ControlCitation.C index 7a882f7f17..57b1f2745c 100644 --- a/src/frontends/controllers/ControlCitation.C +++ b/src/frontends/controllers/ControlCitation.C @@ -45,7 +45,7 @@ ControlCitation::ControlCitation(LyXView & lv, Dialogs & d) } -void ControlCitation::clearParams() +void ControlCitation::clearDaughterParams() { bibkeysInfo_.clear(); } diff --git a/src/frontends/controllers/ControlCitation.h b/src/frontends/controllers/ControlCitation.h index 166264ec5e..26ff36da4a 100644 --- a/src/frontends/controllers/ControlCitation.h +++ b/src/frontends/controllers/ControlCitation.h @@ -55,8 +55,8 @@ public: Empty if no info exists. */ string const getBibkeyInfo(string const &); private: - /// Clean up, then hide dialog. - virtual void clearParams(); + /// clean-up any daughter class-particular data on hide. + virtual void clearDaughterParams(); /// The info associated with each key InfoMap bibkeysInfo_; }; diff --git a/src/frontends/controllers/ControlCommand.C b/src/frontends/controllers/ControlCommand.C index 1ed0c12fa6..d95c53bf2e 100644 --- a/src/frontends/controllers/ControlCommand.C +++ b/src/frontends/controllers/ControlCommand.C @@ -1,4 +1,3 @@ -// -*- C++ -*- /* This file is part of * ====================================================== * @@ -19,95 +18,39 @@ #include #include "ControlCommand.h" -#include "BufferView.h" +#include "buffer.h" #include "Dialogs.h" #include "lyxfunc.h" #include "LyXView.h" -#include "support/LAssert.h" ControlCommand::ControlCommand(LyXView & lv, Dialogs & d, kb_action ac) - : ControlInset(lv, d), - params_(0), action_(ac) + : ControlInset(lv, d), + action_(ac) {} -void ControlCommand::showInset(InsetCommand * inset) +InsetCommandParams const ControlCommand::getParams(string const & arg) { - if (inset == 0) return; // maybe we should Assert this? - - connectInset(inset); - show(inset->params()); -} - - -void ControlCommand::createInset(string const & arg) -{ - connectInset(); - - if ( !arg.empty() ) - bc().valid(); // so that the user can press Ok - InsetCommandParams params; params.setFromString(arg); - show(params); + return params; } - -void ControlCommand::update() +InsetCommandParams const ControlCommand::getParams(InsetCommand const & inset) { - if (params_) delete params_; - - if (inset_) - params_ = new InsetCommandParams(inset_->params()); - else - params_ = new InsetCommandParams; - - bc().readOnly(isReadonly()); - view().update(); + return inset.params(); } - -void ControlCommand::show(InsetCommandParams const & params) +void ControlCommand::applyParamsToInset() { - if (params_) delete params_; - params_ = new InsetCommandParams(params); - - bc().readOnly(isReadonly()); - view().show(); + inset()->setParams(params()); + lv_.view()->updateInset(inset(), true); } - -void ControlCommand::hide() +void ControlCommand::applyParamsNoInset() { - if (params_) { - delete params_; - params_ = 0; - } + if (action_ == LFUN_NOACTION) return; - clearParams(); - - disconnect(); - view().hide(); + lv_.getLyXFunc()->Dispatch(action_, params().getAsString()); } -InsetCommandParams & ControlCommand::params() const -{ - Assert(params_); - return *params_; -} - - -void ControlCommand::apply() -{ - view().apply(); - - if (inset_) { - // Only update if contents have changed - if (params() != inset_->params()) { - inset_->setParams(params()); - lv_.view()->updateInset(inset_, true); - } - } else if (action_ != LFUN_NOACTION){ - lv_.getLyXFunc()->Dispatch(action_, params().getAsString()); - } -} diff --git a/src/frontends/controllers/ControlCommand.h b/src/frontends/controllers/ControlCommand.h index 996a84d326..cd7ea20783 100644 --- a/src/frontends/controllers/ControlCommand.h +++ b/src/frontends/controllers/ControlCommand.h @@ -1,4 +1,3 @@ -// -*- C++ -*- /* This file is part of * ====================================================== * @@ -27,49 +26,29 @@ #pragma interface #endif -#include "ControlDialogs.h" +#include "ControlInset.h" #include "insets/insetcommand.h" #include "commandtags.h" // kb_action /** The Inset dialog controller. Connects/disconnects signals, launches GUI-dependent View and returns the output from this View to the kernel. */ -class ControlCommand : public ControlInset +class ControlCommand : public ControlInset { public: /// ControlCommand(LyXView &, Dialogs &, kb_action=LFUN_NOACTION); - /// Allow the View access to the local copy. - InsetCommandParams & 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(InsetCommand *); - - /// Connect signals and launch View. - void show(InsetCommandParams const &); - - /// Instantiation of private ControlBase virtual methods. - /// Get changed parameters and Dispatch them to the kernel. - virtual void apply(); - /// Disconnect signals and hide View. - virtual void hide(); - /// Update dialog before showing it. - virtual void update(); - - /// clean-up on hide. - virtual void clearParams() {} - - private: - /** A local copy of the inset's params. - Memory is allocated only whilst the dialog is visible. - */ - InsetCommandParams * params_; + /// Dispatch the changed parameters to the kernel. + virtual void applyParamsToInset(); + /// + virtual void applyParamsNoInset(); + /// get the parameters from the string passed to createInset. + virtual InsetCommandParams const getParams(string const &); + /// get the parameters from the inset passed to showInset. + virtual InsetCommandParams const getParams(InsetCommand const &); + /// Controls what is done in LyXFunc::Dispatch() kb_action const action_; }; diff --git a/src/frontends/controllers/ControlConnections.h b/src/frontends/controllers/ControlConnections.h index 7a295c9610..ff8a805a09 100644 --- a/src/frontends/controllers/ControlConnections.h +++ b/src/frontends/controllers/ControlConnections.h @@ -108,17 +108,17 @@ public: protected: /// virtual bool isBufferDependent() const { return true; } - /** Slot connected to update signal. - Bool indicates if a buffer switch took place. - Default behaviour is to ignore this and simply update(). - */ - virtual void updateSlot(bool) { update(); } /// Connect signals virtual void connect(); /// Disconnect signals virtual void disconnect(); private: + /** Slot connected to update signal. + Bool indicates if a buffer switch took place. + Default behaviour is to ignore this and simply update(). + */ + virtual void updateSlot(bool) { update(); } /// Update connection. SigC::Connection u_; }; diff --git a/src/frontends/controllers/ControlDialogs.h b/src/frontends/controllers/ControlDialogs.h index 4026d20daa..0bfea6048b 100644 --- a/src/frontends/controllers/ControlDialogs.h +++ b/src/frontends/controllers/ControlDialogs.h @@ -10,33 +10,16 @@ * \file ControlDialogs.h * \author Angus Leeming * - * ControlDialogs.h contains the definition of two template controller classes, - * ControlDialog and ControlInset, rather clumsy names for classes that - * control the showing, updating and hiding of popups. - * - * ControlInset is to be used as a parent class for popups that display and - * can perhaps modify the contents of an individual inset. An example being the - * ubiquitous Citation popup. - * * ControlDialog is to be used as a parent class for popups that are not * Inset-popups. (An ugly description I know, but I hope the meaning is clear! * Can anyone do any better?) Examples would be the Document and Paragraph * popups. - * - * At the moment, ControlDialog is reaching a state of maturity as several - * controllers are now derived from it and its required functionality - * becaomes clear. - * - * ControlInset is still in a state of flux as currently only InsetCommand-type - * insets have a controller. - * */ -#ifndef CONTROLCONNECTIONS2_H -#define CONTROLCONNECTIONS2_H +#ifndef CONTROLDIALOGS_H +#define CONTROLDIALOGS_H #include "ControlConnections.h" -#include "LyXView.h" /** Base class to control connection/disconnection of signals with the LyX kernel for dialogs NOT used with insets. @@ -57,46 +40,14 @@ protected: /// Update the dialog. virtual void update(); - /// set the params before show or update - virtual void setParams() {} /// clean-up on hide. virtual void clearParams() {} + /// set the params before show or update + virtual void setParams() {} }; -/** Base class to control connection/disconnection of signals with the LyX - kernel for Inset dialogs. - */ -class Inset; - -template -class ControlInset : public ControlConnectBD -{ -public: - /// - ControlInset(LyXView &, Dialogs &); - -protected: - /// Slot connected to update signal. - virtual void updateSlot(bool); - /// Connect signals - void connectInset(Inset * = 0); - /// Disconnect signals - virtual void disconnect(); - /// - void disconnectInset(); - -protected: - /// pointer to the inset passed through connectInset - Inset * inset_; - -private: - /// inset::hide connection. - SigC::Connection ih_; -}; - - - +#include "LyXView.h" template @@ -138,56 +89,4 @@ void ControlDialog::hide() view().hide(); } - -template -ControlInset::ControlInset(LyXView & lv, Dialogs & d) - : ControlConnectBD(lv, d), - inset_(0), ih_(0) -{} - - -template -void ControlInset::updateSlot(bool switched) -{ - if (switched) - hide(); - else - update(); -} - - -template -void ControlInset::disconnect() -{ - inset_ = 0; - ih_.disconnect(); - ControlConnectBD::disconnect(); -} - - -template -void ControlInset::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(); -} - - -template -void ControlInset::disconnectInset() -{ - ih_.disconnect(); -} - - -#endif // CONTROLCONNECTIONS2_H +#endif // CONTROLDIALOGS_H diff --git a/src/frontends/controllers/ControlError.C b/src/frontends/controllers/ControlError.C new file mode 100644 index 0000000000..4a178607d9 --- /dev/null +++ b/src/frontends/controllers/ControlError.C @@ -0,0 +1,38 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 2001 The LyX Team. + * + * ====================================================== + * + * \file ControlError.C + * \author Angus Leeming + */ + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include + +#include "ControlError.h" +#include "Dialogs.h" +#include "LyXView.h" +#include "buffer.h" +#include "insets/inseterror.h" + +using SigC::slot; + +ControlError::ControlError(LyXView & lv, Dialogs & d) + : ControlInset(lv, d) +{ + d_.showError.connect(slot(this, &ControlError::showInset)); +} + +string const ControlError::getParams(InsetError const & inset) +{ + return inset.getContents(); +} + diff --git a/src/frontends/controllers/ControlError.h b/src/frontends/controllers/ControlError.h new file mode 100644 index 0000000000..e296b54a16 --- /dev/null +++ b/src/frontends/controllers/ControlError.h @@ -0,0 +1,47 @@ +/* + * \file ControlError.h + * This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 2000-2001 The LyX Team. + * + * ====================================================== + * + * \author Angus Leeming, a.leeming@.ac.uk + */ + +#ifndef CONTROLERROR_H +#define CONTROLERROR_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "ControlInset.h" + +class InsetError; + +/** A controller for LaTeX Error dialogs. + */ +class ControlError : public ControlInset +{ +public: + /// + ControlError(LyXView &, Dialogs &); + +private: + /// not needed. + virtual void applyParamsToInset() {} + /// + virtual void applyParamsNoInset() {} + /// + virtual void clearDaughterParams() {} + /// get the parameters from the string passed to createInset. + virtual string const getParams(string const &) { return string(); } + /// get the parameters from the inset passed to showInset. + virtual string const getParams(InsetError const &); +}; + +#endif // CONTROLERROR_H diff --git a/src/frontends/controllers/ControlInclude.C b/src/frontends/controllers/ControlInclude.C new file mode 100644 index 0000000000..04416f2f66 --- /dev/null +++ b/src/frontends/controllers/ControlInclude.C @@ -0,0 +1,40 @@ +/** + * \file ControlInclude.C + * Copyright 2001 the LyX Team + * Read the file COPYING + * + * \author Alejandro Aguilar Sierra + * \author John Levon, moz@compsoc.man.ac.uk + * \author Angus Leeming, a.leeming@.ac.uk + */ + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include +#include "ControlInclude.h" +#include "buffer.h" +#include "Dialogs.h" +#include "lyxfunc.h" +#include "LyXView.h" + +using SigC::slot; + +ControlInclude::ControlInclude(LyXView & lv, Dialogs & d) + : ControlInset(lv, d) +{ + d_.showInclude.connect(slot(this, &ControlInclude::showInset)); +} + +LyXView * ControlInclude::lv() const +{ + return &lv_; +} + + +void ControlInclude::applyParamsToInset() +{ + inset()->set(params()); + lv_.view()->updateInset(inset(), true); +} diff --git a/src/frontends/controllers/ControlInclude.h b/src/frontends/controllers/ControlInclude.h new file mode 100644 index 0000000000..06bb86eb42 --- /dev/null +++ b/src/frontends/controllers/ControlInclude.h @@ -0,0 +1,47 @@ +/** + * \file ControlInclude.h + * Copyright 2001 the LyX Team + * See the file COPYING + * + * \author Alejandro Aguilar Sierra + * \author John Levon, moz@compsoc.man.ac.uk + * \author Angus Leeming, a.leeming@.ac.uk + */ + +#ifndef CONTROLINCLUDE_H +#define CONTROLINCLUDE_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "ControlInset.h" +#include "insets/insetinclude.h" // InsetIncludeParams + +/** A controller for the Include file dialog. + */ +class ControlInclude + : public ControlInset +{ +public: + /// + ControlInclude(LyXView &, Dialogs &); + + /// The file dialog popup requires a LyXView * ??? + LyXView * lv() const; + +private: + /// Dispatch the changed parameters to the kernel. + virtual void applyParamsToInset(); + /// Should be used but currently isn't + virtual void applyParamsNoInset() {} + /// not needed. + virtual void clearDaughterParams() {} + /// get the parameters from the string passed to createInset. + virtual InsetInclude::Params const getParams(string const &) + { return InsetInclude::Params(); } + /// get the parameters from the inset passed to showInset. + virtual InsetInclude::Params const getParams(InsetInclude const & inset) + { return inset.params(); } +}; +#endif // CONTROLINCLUDE_H diff --git a/src/frontends/controllers/ControlInset.h b/src/frontends/controllers/ControlInset.h new file mode 100644 index 0000000000..7ca3a902f6 --- /dev/null +++ b/src/frontends/controllers/ControlInset.h @@ -0,0 +1,241 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 2001 The LyX Team. + * + * ====================================================== + * + * \file ControlInsets.h + * \author Angus Leeming + * + * ControlInset is to be used as a parent class for popups that display and + * can perhaps modify the contents of an individual inset. An example being the + * ubiquitous Citation popup. + */ + +#ifndef CONTROLINSET_H +#define CONTROLINSET_H + +#include "ControlConnections.h" + +class Inset; + +template +class ControlInset : public ControlConnectBD +{ +public: + /// + ControlInset(LyXView &, Dialogs &); + /// Allow the View access to the local copy. + Params & 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); + /// Allow the daughter methods to access the inset. + Inset * inset() const; + +private: + /** These 5 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. + + /// Get changed parameters and Dispatch them to the kernel. + virtual void apply(); + /// Disconnect signals and hide View. + virtual void hide(); + /// Update the dialog. + virtual void update(); + + /** Instantiation of ControlConnectBD private virtual method. + Slot connected to update signal. */ + virtual void updateSlot(bool); + + /// Show the dialog. + 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_; + /// inset::hide connection. + SigC::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 +ControlInset::ControlInset(LyXView & lv, Dialogs & d) + : ControlConnectBD(lv, d), + inset_(0), ih_(0), params_(0) +{} + + +template +void ControlInset::showInset(Inset * inset) +{ + if (inset == 0) return; // maybe we should Assert this? + + connectInset(inset); + show(getParams(*inset)); +} + + +template +void ControlInset::createInset(string const & arg) +{ + connectInset(); + + if ( !arg.empty() ) + bc().valid(); // so that the user can press Ok + + show(getParams(arg)); +} + + +template +void ControlInset::show(Params const & params) +{ + if (params_) delete params_; + params_ = new Params(params); + + bc().readOnly(isReadonly()); + view().show(); +} + + +template +void ControlInset::hide() +{ + if (params_) { + delete params_; + params_ = 0; + } + + clearDaughterParams(); + + disconnect(); + view().hide(); +} + + +template +void ControlInset::update() +{ + if (params_) delete params_; + + if (inset_) + params_ = new Params(getParams(*inset_)); + else + params_ = new Params(); + + bc().readOnly(isReadonly()); + view().update(); +} + + +template +void ControlInset::apply() +{ + if (lv_.buffer()->isReadonly() || !inset_) + return; + + view().apply(); + + if (inset_ && params() != getParams(*inset_)) + applyParamsToInset(); + else if (!inset_) + applyParamsNoInset(); +} + + +template +Params & ControlInset::params() const +{ + Assert(params_); + return *params_; +} + + +template +Inset * ControlInset::inset() const +{ + Assert(inset_); + return inset_; +} + + +template +void ControlInset::updateSlot(bool switched) +{ + if (switched) + hide(); + else + update(); +} + + +template +void ControlInset::disconnect() +{ + inset_ = 0; + ih_.disconnect(); + ControlConnectBD::disconnect(); +} + + +template +void ControlInset::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(); +} + + +template +void ControlInset::disconnectInset() +{ + ih_.disconnect(); +} + + +#endif // CONTROLINSET_H diff --git a/src/frontends/controllers/ControlLog.h b/src/frontends/controllers/ControlLog.h index 22f0270740..894671fd04 100644 --- a/src/frontends/controllers/ControlLog.h +++ b/src/frontends/controllers/ControlLog.h @@ -36,7 +36,7 @@ public: std::pair const & logfile() { return logfile_; } -protected: +private: /// virtual void apply() {} /// set the params before show or update @@ -44,7 +44,6 @@ protected: /// clean-up on hide. virtual void clearParams(); -private: std::pair logfile_; }; diff --git a/src/frontends/controllers/ControlVCLog.h b/src/frontends/controllers/ControlVCLog.h index 9644225dc5..790d4418a7 100644 --- a/src/frontends/controllers/ControlVCLog.h +++ b/src/frontends/controllers/ControlVCLog.h @@ -34,7 +34,7 @@ public: /// string const & logfile() { return logfile_; } -protected: +private: /// virtual void apply() {} /// set the params before show or update @@ -42,7 +42,6 @@ protected: /// clean-up on hide. virtual void clearParams(); -private: string logfile_; }; diff --git a/src/frontends/controllers/GUI.h b/src/frontends/controllers/GUI.h index 8d934df7c7..cfa4bc5c87 100644 --- a/src/frontends/controllers/GUI.h +++ b/src/frontends/controllers/GUI.h @@ -109,6 +109,34 @@ public: }; +/** Specialization for Error dialog + */ +class ControlError; + +template +class GUIError : + public GUI { +public: + /// + GUIError(LyXView & lv, Dialogs & d) + : GUI(lv, d) {} +}; + + +/** Specialization for Include dialog + */ +class ControlInclude; + +template +class GUIInclude : + public GUI { +public: + /// + GUIInclude(LyXView & lv, Dialogs & d) + : GUI(lv, d) {} +}; + + /** Specialization for Log dialog */ class ControlLog; diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index 704b535f4a..fb219a4424 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -29,9 +29,14 @@ libcontrollers_la_SOURCES=\ ControlConnections.C \ ControlConnections.h \ ControlCopyright.C \ + ControlCopyright.h \ ControlCredits.h \ ControlCredits.C \ - ControlCopyright.h \ + ControlError.h \ + ControlError.C \ + ControlInclude.C \ + ControlInclude.h \ + ControlInset.h \ ControlLog.C \ ControlLog.h \ ControlVCLog.C \ diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 8890cc9f71..095baae307 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,21 @@ +2001-03-23 Angus Leeming + + * FormError.[Ch]: + * form_error.fd: + * FormInclude.[Ch]: + * form_include.fd: implemented controller-view split. + + * Dialogs.C: associated changes. + + * FormBibitem.h: + * FormBibtex.h: + * FormCitation.h: moved methods from protected to private. + +2001-03-23 Angus Leeming + + * FormCredits.C (build): changes associated with + ControlCredits::getCredits returning a stringstream not a vector + 2001-03-22 Angus Leeming * FormCopyright.[Ch]: diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index a9461eb573..c34f73c976 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -25,6 +25,8 @@ #include "ControlCitation.h" #include "ControlCopyright.h" #include "ControlCredits.h" +#include "ControlError.h" +#include "ControlInclude.h" #include "ControlLog.h" #include "ControlVCLog.h" @@ -38,6 +40,8 @@ #include "form_citation.h" #include "form_copyright.h" #include "form_credits.h" +#include "form_error.h" +#include "form_include.h" #include "FormBibitem.h" #include "FormBibtex.h" @@ -45,14 +49,14 @@ #include "FormCitation.h" #include "FormCopyright.h" #include "FormCredits.h" +#include "FormError.h" +#include "FormInclude.h" #include "FormLog.h" #include "FormVCLog.h" #include "FormDocument.h" -#include "FormError.h" #include "FormExternal.h" #include "FormGraphics.h" -#include "FormInclude.h" #include "FormIndex.h" #include "FormMathsPanel.h" #include "FormParagraph.h" @@ -82,14 +86,14 @@ Dialogs::Dialogs(LyXView * lv) add(new GUICitation(*lv, *this)); add(new GUICopyright(*lv, *this)); add(new GUICredits(*lv, *this)); + add(new GUIError(*lv, *this)); + add(new GUIInclude(*lv, *this)); add(new GUILog(*lv, *this)); add(new GUIVCLog(*lv, *this)); add(new FormDocument(lv, this)); - add(new FormError(lv, this)); add(new FormExternal(lv, this)); add(new FormGraphics(lv, this)); - add(new FormInclude(lv, this)); add(new FormIndex(lv, this)); add(new FormMathsPanel(lv, this)); add(new FormParagraph(lv, this)); diff --git a/src/frontends/xforms/FormBibitem.h b/src/frontends/xforms/FormBibitem.h index 3016ab6aaf..82e1326d79 100644 --- a/src/frontends/xforms/FormBibitem.h +++ b/src/frontends/xforms/FormBibitem.h @@ -28,16 +28,13 @@ public: /// FormBibitem(ControlBibitem &); - // Functions accessible to the Controller. - +private: /// Set the Params variable for the Controller. virtual void apply(); /// Build the dialog. virtual void build(); /// Update dialog before/whilst showing it. virtual void update(); - -private: /// Filter the inputs on callback from xforms virtual ButtonPolicy::SMInput input(FL_OBJECT *, long); diff --git a/src/frontends/xforms/FormBibtex.h b/src/frontends/xforms/FormBibtex.h index 452cab7d59..6b19448f10 100644 --- a/src/frontends/xforms/FormBibtex.h +++ b/src/frontends/xforms/FormBibtex.h @@ -28,16 +28,13 @@ public: /// FormBibtex(ControlBibtex &); - // Functions accessible to the Controller. - +private: /// Set the Params variable for the Controller. virtual void apply(); /// Build the dialog. virtual void build(); /// Update dialog before/whilst showing it. virtual void update(); - -private: /// Filter the inputs on callback from xforms virtual ButtonPolicy::SMInput input(FL_OBJECT *, long); /// diff --git a/src/frontends/xforms/FormCitation.h b/src/frontends/xforms/FormCitation.h index d35c256a15..541470f2d2 100644 --- a/src/frontends/xforms/FormCitation.h +++ b/src/frontends/xforms/FormCitation.h @@ -30,17 +30,6 @@ public: /// FormCitation(ControlCitation &); - // Functions accessible to the Controller. - - /// Set the Params variable for the Controller. - virtual void apply(); - /// Build the dialog. - virtual void build(); - /// Hide the dialog. - virtual void hide(); - /// Update dialog before/whilst showing it. - virtual void update(); - private: /// enum State { @@ -50,6 +39,14 @@ private: OFF }; + /// Set the Params variable for the Controller. + virtual void apply(); + /// Build the dialog. + virtual void build(); + /// Hide the dialog. + virtual void hide(); + /// Update dialog before/whilst showing it. + virtual void update(); /// Filter the inputs on callback from xforms virtual ButtonPolicy::SMInput input(FL_OBJECT *, long); diff --git a/src/frontends/xforms/FormError.C b/src/frontends/xforms/FormError.C index 0a6b5b2d1a..a475649a00 100644 --- a/src/frontends/xforms/FormError.C +++ b/src/frontends/xforms/FormError.C @@ -1,74 +1,34 @@ -// -*- C++ -*- -/* This file is part of +/* + * \file FormError.C + * This file is part of * ====================================================== * * LyX, The Document Processor * - * Copyright 2000 The LyX Team. + * Copyright 2000-2001 The LyX Team. * * ====================================================== + * + * \author Angus Leeming, a.leeming@.ac.uk */ -#include - #ifdef __GNUG__ #pragma implementation #endif -#include "Dialogs.h" +#include + +#include "xformsBC.h" +#include "ControlError.h" #include "FormError.h" #include "form_error.h" -#include "insets/inseterror.h" -#include "support/LAssert.h" +#include "xforms_helpers.h" // formatted -using SigC::slot; +typedef FormCB > base_class; -FormError::FormError(LyXView * lv, Dialogs * d) - : FormInset( lv, d, _("LaTeX Error")), - inset_(0) -{ - Assert(lv && d); - // let the dialog be shown - // This is a permanent connection so we won't bother - // storing a copy because we won't be disconnecting. - d->showError.connect(slot(this, &FormError::showInset)); -} - - -FL_FORM * FormError::form() const -{ - if (dialog_.get()) return dialog_->form; - return 0; -} - - -void FormError::disconnect() -{ - inset_ = 0; - message_.erase(); - FormInset::disconnect(); -} - - -void FormError::showInset(InsetError * inset) -{ - if (inset == 0) return; // Is this _really_ allowed? (Lgb) - - // If connected to another inset, disconnect from it. - if (inset_) - ih_.disconnect(); - - inset_ = inset; - message_ = inset->getContents(); - ih_ = inset->hideDialog.connect(slot(this, &FormError::hide)); - show(); -} - - -void FormError::update() -{ - fl_set_object_label(dialog_->message, message_.c_str()); -} +FormError::FormError(ControlError & c) + : base_class(c, _("LaTeX Error")) +{} void FormError::build() @@ -79,3 +39,11 @@ void FormError::build() bc().setCancel(dialog_->button_cancel); bc().refresh(); } + + +void FormError::update() +{ + string const txt = formatted(controller().params(), + dialog_->message->w-10); + fl_set_object_label(dialog_->message, txt.c_str()); +} diff --git a/src/frontends/xforms/FormError.h b/src/frontends/xforms/FormError.h index 50331bb941..08342a8963 100644 --- a/src/frontends/xforms/FormError.h +++ b/src/frontends/xforms/FormError.h @@ -1,65 +1,46 @@ -// -*- C++ -*- -/* This file is part of +/* + * \file FormError.h + * This file is part of * ====================================================== * * LyX, The Document Processor * - * Copyright 2000 The LyX Team. + * Copyright 2000-2001 The LyX Team. * * ====================================================== + * + * \author Angus Leeming, a.leeming@.ac.uk */ #ifndef FORMERROR_H #define FORMERROR_H -#include - #ifdef __GNUG__ #pragma interface #endif -#include "FormInset.h" +#include "FormBase.h" -class InsetError; +class ControlError; struct FD_form_error; -/** This class provides an XForms implementation of the FormError Dialog. +/** This class provides an XForms implementation of the Error Dialog. */ -class FormError : public FormInset { +class FormError : public FormCB > { public: /// Constructor - FormError(LyXView *, Dialogs *); -private: - /// Pointer to the actual instantiation of the ButtonController. - virtual xformsBC & bc(); - /// Disconnect signals. Also perform any necessary housekeeping. - virtual void disconnect(); + FormError(ControlError &); - /// Slot launching dialog to an existing inset - void showInset(InsetError *); - /// Update dialog before showing it - virtual void update(); +private: + /// not needed. + virtual void apply() {} /// Build the dialog virtual void build(); - /// Pointer to the actual instantiation of the xforms form - virtual FL_FORM * form() const; + /// Update dialog before showing it + virtual void update(); + /// Fdesign generated method FD_form_error * build_error(); - - /// Real GUI implementation. - boost::scoped_ptr dialog_; - /// pointer to the inset passed through showInset - InsetError * inset_; - /// the error message - string message_; - /// The ButtonController - ButtonController bc_; }; - -inline -xformsBC & FormError::bc() -{ - return bc_; -} -#endif +#endif // FORMERROR_H diff --git a/src/frontends/xforms/FormInclude.C b/src/frontends/xforms/FormInclude.C index 30bf53255f..66efb6d087 100644 --- a/src/frontends/xforms/FormInclude.C +++ b/src/frontends/xforms/FormInclude.C @@ -4,9 +4,10 @@ * Read the file COPYING * * \author Alejandro Aguilar Sierra - * \author John Levon + * \author John Levon, moz@compsoc.man.ac.uk + * \author Angus Leeming, a.leeming@.ac.uk */ -#include + #include #include @@ -14,65 +15,30 @@ #pragma implementation #endif -#include "Dialogs.h" +#include +#include "xformsBC.h" +#include "ControlInclude.h" #include "FormInclude.h" +#include "form_include.h" #include "insets/insetinclude.h" + #include "frontends/FileDialog.h" -#include "support/filetools.h" -#include "support/lstrings.h" #include "LyXView.h" #include "buffer.h" -#include "lyxrc.h" -#include "lyxfunc.h" -#include "xforms_helpers.h" -#include "form_include.h" +#include "xforms_helpers.h" // setEnabled +#include "support/filetools.h" +#include "support/lstrings.h" +#include "lyxrc.h" using std::make_pair; using std::pair; -using SigC::slot; -FormInclude::FormInclude(LyXView * lv, Dialogs * d) - : FormBaseBD(lv, d, _("Include file")), - ih_(0), inset_(0) -{ - d->showInclude.connect(slot(this, &FormInclude::showInclude)); -} +typedef FormCB > base_class; - -FL_FORM * FormInclude::form() const -{ - if (dialog_.get()) - return dialog_->form; - return 0; -} - - -void FormInclude::connect() -{ - u_ = d_->updateBufferDependent. - connect(slot(this, &FormInclude::updateSlot)); - h_ = d_->hideBufferDependent. - connect(slot(this, &FormInclude::hide)); - FormBaseDeprecated::connect(); -} - - -void FormInclude::disconnect() -{ - ih_.disconnect(); - FormBaseBD::disconnect(); - inset_ = 0; -} - - -void FormInclude::updateSlot(bool switched) -{ - if (switched) - hide(); - else - update(); -} +FormInclude::FormInclude(ControlInclude & c) + : base_class(c, _("Include file")) +{} void FormInclude::build() @@ -80,36 +46,21 @@ void FormInclude::build() dialog_.reset(build_include()); // Manage the ok and cancel buttons - bc_.setOK(dialog_->button_ok); - bc_.setCancel(dialog_->button_cancel); - bc_.refresh(); + bc().setOK(dialog_->button_ok); + bc().setCancel(dialog_->button_cancel); + bc().refresh(); - bc_.addReadOnly(dialog_->button_browse); - bc_.addReadOnly(dialog_->check_verbatim); - bc_.addReadOnly(dialog_->check_typeset); - bc_.addReadOnly(dialog_->check_useinput); - bc_.addReadOnly(dialog_->check_useinclude); -} - - -void FormInclude::showInclude(InsetInclude * inset) -{ - // If connected to another inset, disconnect from it. - if (inset_) - ih_.disconnect(); - - inset_ = inset; - params = inset->params(); - ih_ = inset->hideDialog.connect(slot(this, &FormInclude::hide)); - show(); + bc().addReadOnly(dialog_->button_browse); + bc().addReadOnly(dialog_->check_verbatim); + bc().addReadOnly(dialog_->check_typeset); + bc().addReadOnly(dialog_->check_useinput); + bc().addReadOnly(dialog_->check_useinclude); } void FormInclude::update() { - bc().readOnly(lv_->buffer()->isReadonly()); - - if (!inset_) { + if (controller().params().noload) { fl_set_input(dialog_->input_filename, ""); fl_set_button(dialog_->check_typeset, 0); fl_set_button(dialog_->check_useinput, 0); @@ -121,11 +72,13 @@ void FormInclude::update() return; } - fl_set_input(dialog_->input_filename, params.cparams.getContents().c_str()); + fl_set_input(dialog_->input_filename, + controller().params().cparams.getContents().c_str()); - string const cmdname = params.cparams.getCmdName(); + string const cmdname = controller().params().cparams.getCmdName(); - fl_set_button(dialog_->check_typeset, int(params.noload)); + fl_set_button(dialog_->check_typeset, + int(controller().params().noload)); fl_set_button(dialog_->check_useinput, cmdname == "input"); fl_set_button(dialog_->check_useinclude, cmdname == "include"); @@ -145,86 +98,85 @@ void FormInclude::update() void FormInclude::apply() { - if (lv_->buffer()->isReadonly()) - return; + controller().params().noload = fl_get_button(dialog_->check_typeset); - params.noload = fl_get_button(dialog_->check_typeset); - - params.cparams.setContents(fl_get_input(dialog_->input_filename)); + controller().params().cparams. + setContents(fl_get_input(dialog_->input_filename)); if (fl_get_button(dialog_->check_useinput)) - params.flag = InsetInclude::INPUT; + controller().params().flag = InsetInclude::INPUT; else if (fl_get_button(dialog_->check_useinclude)) - params.flag = InsetInclude::INCLUDE; + controller().params().flag = InsetInclude::INCLUDE; else if (fl_get_button(dialog_->check_verbatim)) { if (fl_get_button(dialog_->check_visiblespace)) - params.flag = InsetInclude::VERBAST; + controller().params().flag = InsetInclude::VERBAST; else - params.flag = InsetInclude::VERB; + controller().params().flag = InsetInclude::VERB; } - - inset_->setFromParams(params); - lv_->view()->updateInset(inset_, true); } -#ifdef WITH_WARNINGS -#warning convert this to use the buttoncontroller -#endif -bool FormInclude::input(FL_OBJECT *, long data) + +ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long) { - State state = static_cast(data); + if (ob == dialog_->button_browse) + return inputBrowse(); - switch (state) { - case BROWSE: { - // Should browsing too be disabled in RO-mode? - FileDialog fileDlg(lv_, _("Select document to include"), - LFUN_SELECT_FILE_SYNC, - make_pair(string(_("Documents")), string(lyxrc.document_path))); - - string ext; - - /* input TeX, verbatim, or LyX file ? */ - if (fl_get_button(dialog_->check_useinput)) - ext = _("*.tex| LaTeX Documents (*.tex)"); - else if (fl_get_button(dialog_->check_verbatim)) - ext = _("*| All files "); - else - ext = _("*.lyx| LyX Documents (*.lyx)"); - - string mpath; - - mpath = OnlyPath(params.buffer->fileName()); - - FileDialog::Result result = fileDlg.Select(mpath, ext, fl_get_input(dialog_->input_filename)); - - // check selected filename - if (result.second.empty()) - break; - - string const filename2 = MakeRelPath(result.second, mpath); - - if (prefixIs(filename2, "..")) - fl_set_input(dialog_->input_filename, result.second.c_str()); - else - fl_set_input(dialog_->input_filename, filename2.c_str()); - - } break; - - case LOAD: - if (compare(fl_get_input(dialog_->input_filename),"")) { - apply(); - lv_->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, params.cparams.getContents()); - } - break; - - case VERBATIM: - setEnabled(dialog_->check_visiblespace, true); - break; - - case INPUTINCLUDE: - fl_set_button(dialog_->check_visiblespace, 0); - setEnabled(dialog_->check_visiblespace, false); - break; + if (ob == dialog_->button_load) { + if (compare(fl_get_input(dialog_->input_filename),"")) { + ApplyButton(); + return ButtonPolicy::SMI_NOOP; + } } - return true; + + if (ob == dialog_->check_verbatim) { + setEnabled(dialog_->check_visiblespace, true); + + } else if (ob == dialog_->check_useinclude || + ob == dialog_->check_useinput) { + fl_set_button(dialog_->check_visiblespace, 0); + setEnabled(dialog_->check_visiblespace, false); + } + + return ButtonPolicy::SMI_VALID; +} + + +ButtonPolicy::SMInput FormInclude::inputBrowse() +{ + // Should browsing too be disabled in RO-mode? + FileDialog fileDlg(controller().lv(), + _("Select document to include"), + LFUN_SELECT_FILE_SYNC, + make_pair(string(_("Documents")), + string(lyxrc.document_path))); + + string ext; + + // input TeX, verbatim, or LyX file ? + if (fl_get_button(dialog_->check_useinput)) + ext = _("*.tex| LaTeX Documents (*.tex)"); + else if (fl_get_button(dialog_->check_verbatim)) + ext = _("*| All files "); + else + ext = _("*.lyx| LyX Documents (*.lyx)"); + + string const mpath = + OnlyPath(controller().params().masterFilename_); + + FileDialog::Result const result = + fileDlg.Select(mpath, ext, + fl_get_input(dialog_->input_filename)); + + // check selected filename + if (result.second.empty()) + return ButtonPolicy::SMI_NOOP; + + string const filename2 = MakeRelPath(result.second, mpath); + + if (prefixIs(filename2, "..")) + fl_set_input(dialog_->input_filename, result.second.c_str()); + else + fl_set_input(dialog_->input_filename, filename2.c_str()); + + return ButtonPolicy::SMI_VALID; } diff --git a/src/frontends/xforms/FormInclude.h b/src/frontends/xforms/FormInclude.h index c97ef293de..e2f9a7b457 100644 --- a/src/frontends/xforms/FormInclude.h +++ b/src/frontends/xforms/FormInclude.h @@ -5,86 +5,42 @@ * See the file COPYING * * \author Alejandro Aguilar Sierra - * \author John Levon + * \author John Levon, moz@compsoc.man.ac.uk + * \author Angus Leeming */ #ifndef FORMINCLUDE_H #define FORMINCLUDE_H -#include - #ifdef __GNUG__ #pragma interface #endif -#include "FormBaseDeprecated.h" -#include "insets/insetinclude.h" +#include "FormBase.h" +class ControlInclude; struct FD_form_include; -/** This class provides an XForms implementation of the FormInclude Dialog. +/** This class provides an XForms implementation of the Include Dialog. */ -class FormInclude : public FormBaseBD { +class FormInclude : public FormCB > { public: /// - FormInclude(LyXView *, Dialogs *); + FormInclude(ControlInclude &); + private: - /// - enum State { - /// the browse button - BROWSE = 0, - /// the load file button - LOAD = 5, - /// the verbatim radio choice - VERBATIM = 10, - /// the input and include radio choices - INPUTINCLUDE = 11 - }; - - /// Pointer to the actual instantiation of the ButtonController. - virtual xformsBC & bc(); - /// Slot launching dialog to an existing inset - void showInclude(InsetInclude *); - - /// Connect signals. Also perform any necessary initialisation. - virtual void connect(); - /// Disconnect signals. Also perform any necessary housekeeping. - virtual void disconnect(); - + /// Set the Params variable for the Controller. + virtual void apply(); /// Build the dialog virtual void build(); - /// Filter the inputs - virtual bool input( FL_OBJECT *, long ); /// Update dialog before showing it virtual void update(); - /// Apply from dialog (modify or create inset) - virtual void apply(); - /// Pointer to the actual instantiation of the xforms form - virtual FL_FORM * form() const; - /// bool indicates if a buffer switch took place - virtual void updateSlot(bool); - + /// Filter the inputs on callback from xforms + virtual ButtonPolicy::SMInput input(FL_OBJECT *, long); + /// + ButtonPolicy::SMInput inputBrowse(); /// Type definition from the fdesign produced header file. FD_form_include * build_include(); - - /// Real GUI implementation. - boost::scoped_ptr dialog_; - /// The ButtonController - ButtonController bc_; - - /// inset::hide connection. - SigC::Connection ih_; - - /// pointer to the inset passed through showInset - InsetInclude * inset_; - /// the nitty-gritty. What is modified and passed back - InsetInclude::InsetIncludeParams params; }; - -inline -xformsBC & FormInclude::bc() -{ - return bc_; -} #endif diff --git a/src/frontends/xforms/form_error.C b/src/frontends/xforms/form_error.C index c29073aa34..591fa980fd 100644 --- a/src/frontends/xforms/form_error.C +++ b/src/frontends/xforms/form_error.C @@ -34,7 +34,7 @@ FD_form_error * FormError::build_error() } fl_set_object_gravity(obj, FL_South, FL_South); fl_set_object_resize(obj, FL_RESIZE_NONE); - fl_set_object_callback(obj, C_FormBaseDeprecatedCancelCB, 0); + fl_set_object_callback(obj, C_FormBaseCancelCB, 0); fl_end_form(); fdui->form->fdui = fdui; diff --git a/src/frontends/xforms/form_error.h b/src/frontends/xforms/form_error.h index 63521193ef..c87a7e2dd5 100644 --- a/src/frontends/xforms/form_error.h +++ b/src/frontends/xforms/form_error.h @@ -5,7 +5,7 @@ #define FD_form_error_h_ /** Callbacks, globals and object handlers **/ -extern "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT *, long); +extern "C" void C_FormBaseCancelCB(FL_OBJECT *, long); /**** Forms and Objects ****/ diff --git a/src/frontends/xforms/form_include.C b/src/frontends/xforms/form_include.C index de4d092878..8e602c31e6 100644 --- a/src/frontends/xforms/form_include.C +++ b/src/frontends/xforms/form_include.C @@ -32,7 +32,7 @@ FD_form_include * FormInclude::build_include() 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); { char const * const dummy = N_("Don't typeset|#D"); fdui->check_typeset = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 180, 70, 150, 30, idex(_(dummy))); @@ -41,21 +41,21 @@ FD_form_include * FormInclude::build_include() fl_set_object_lsize(obj, FL_NORMAL_SIZE); fdui->button_ok = obj = fl_add_button(FL_RETURN_BUTTON, 120, 170, 100, 30, _("OK")); fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_callback(obj, C_FormBaseDeprecatedOKCB, 1); + fl_set_object_callback(obj, C_FormBaseOKCB, 0); { char const * const dummy = N_("Cancel|^["); fdui->button_cancel = obj = fl_add_button(FL_NORMAL_BUTTON, 230, 170, 100, 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, 0); { char const * const dummy = N_("Load|#L"); fdui->button_load = obj = fl_add_button(FL_NORMAL_BUTTON, 230, 130, 100, 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, 5); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); { char const * const dummy = N_("File name:|#F"); fdui->input_filename = obj = fl_add_input(FL_NORMAL_INPUT, 10, 30, 210, 30, idex(_(dummy))); @@ -77,21 +77,21 @@ FD_form_include * FormInclude::build_include() fl_set_button_shortcut(obj, scex(_(dummy)), 1); } fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 10); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); { char const * const dummy = N_("Use input|#i"); fdui->check_useinput = obj = fl_add_checkbutton(FL_RADIO_BUTTON, 10, 100, 160, 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, 11); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); { char const * const dummy = N_("Use include|#U"); fdui->check_useinclude = obj = fl_add_checkbutton(FL_RADIO_BUTTON, 10, 70, 160, 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, 11); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); fl_end_group(); fl_end_form(); diff --git a/src/frontends/xforms/form_include.h b/src/frontends/xforms/form_include.h index f72e5b2fbe..f7585b4adf 100644 --- a/src/frontends/xforms/form_include.h +++ b/src/frontends/xforms/form_include.h @@ -5,9 +5,9 @@ #define FD_form_include_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_error.fd b/src/frontends/xforms/forms/form_error.fd index b0af973d9e..e60d43106e 100644 --- a/src/frontends/xforms/forms/form_error.fd +++ b/src/frontends/xforms/forms/form_error.fd @@ -63,7 +63,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_South FL_South name: button_cancel -callback: C_FormBaseDeprecatedCancelCB +callback: C_FormBaseCancelCB argument: 0 ============================== diff --git a/src/frontends/xforms/forms/form_include.fd b/src/frontends/xforms/forms/form_include.fd index 2d2f7ddff4..8a69831e98 100644 --- a/src/frontends/xforms/forms/form_include.fd +++ b/src/frontends/xforms/forms/form_include.fd @@ -63,8 +63,8 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: button_browse -callback: C_FormBaseDeprecatedInputCB -argument: 0 +callback: C_FormBaseInputCB +argument: -------------------- class: FL_CHECKBUTTON @@ -99,8 +99,8 @@ shortcut: ^M resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: button_ok -callback: C_FormBaseDeprecatedOKCB -argument: 1 +callback: C_FormBaseOKCB +argument: -------------------- class: FL_BUTTON @@ -117,8 +117,8 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: button_cancel -callback: C_FormBaseDeprecatedCancelCB -argument: 2 +callback: C_FormBaseCancelCB +argument: -------------------- class: FL_BUTTON @@ -135,8 +135,8 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: button_load -callback: C_FormBaseDeprecatedInputCB -argument: 5 +callback: C_FormBaseInputCB +argument: -------------------- class: FL_INPUT @@ -207,8 +207,8 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: check_verbatim -callback: C_FormBaseDeprecatedInputCB -argument: 10 +callback: C_FormBaseInputCB +argument: -------------------- class: FL_CHECKBUTTON @@ -225,8 +225,8 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: check_useinput -callback: C_FormBaseDeprecatedInputCB -argument: 11 +callback: C_FormBaseInputCB +argument: -------------------- class: FL_CHECKBUTTON @@ -243,8 +243,8 @@ shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity name: check_useinclude -callback: C_FormBaseDeprecatedInputCB -argument: 11 +callback: C_FormBaseInputCB +argument: -------------------- class: FL_END_GROUP diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 4a01622a01..0ef55349de 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,9 @@ +2001-03-23 Angus Leeming + + * insetinclude.[Ch]: rename InsetInclude::InsetIncludeParams as + InsetInclude::Params. Don't store a buffer * in Params. Store the + master file name instead. + 2001-03-23 Juergen Vigna * insetcollapsable.C (InsetMotionNotify): diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 42dfa7bd8d..52fbee7f33 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -31,8 +31,8 @@ extern BufferList bufferlist; namespace { -inline -string const unique_id() { +string const unique_id() +{ static unsigned int seed = 1000; std::ostringstream ost; @@ -45,19 +45,16 @@ string const unique_id() { } // namespace anon -InsetInclude::InsetInclude(InsetIncludeParams const & p) -{ - include_label = unique_id(); - setFromParams(p); - params_.buffer = p.buffer; -} +InsetInclude::InsetInclude(Params const & p) + : params_(p), include_label(unique_id()) +{} InsetInclude::InsetInclude(InsetCommandParams const & p, Buffer const & b) { + params_.cparams = p; + params_.masterFilename_ = b.fileName(); include_label = unique_id(); - params_.buffer = &b; - setFromParams(p); } @@ -67,48 +64,60 @@ InsetInclude::~InsetInclude() } -InsetInclude::InsetIncludeParams const & InsetInclude::params() const +InsetInclude::Params const & InsetInclude::params() const { return params_; } -void InsetInclude::setFromParams(InsetIncludeParams const & p) +bool InsetInclude::Params::operator==(Params const & o) const { - params_.cparams.setContents(p.cparams.getContents()); - params_.noload = p.noload; - if (params_.flag == p.flag) - return; + if (cparams == o.cparams && flag == o.flag && + noload == o.noload && masterFilename_ == o.masterFilename_) + return true; + + return false; +} - params_.flag = p.flag; +bool InsetInclude::Params::operator!=(Params const & o) const +{ + return !(*this == o); +} + + +void InsetInclude::set(Params const & p) +{ + params_ = p; + + // Just to be safe... string command; - + switch (params_.flag) { - case INCLUDE: - command="include"; - break; - case VERB: - command="verbatiminput"; - break; - case INPUT: - command="input"; - break; - case VERBAST: - command="verbatiminput*"; - break; + case INCLUDE: + command="include"; + break; + case VERB: + command="verbatiminput"; + break; + case INPUT: + command="input"; + break; + case VERBAST: + command="verbatiminput*"; + break; } - + params_.cparams.setCmdName(command); } Inset * InsetInclude::Clone(Buffer const & buffer) const { - InsetIncludeParams p(params_); - p.buffer = &buffer; + Params p(params_); + p.masterFilename_ = buffer.fileName(); - return new InsetInclude (p); + return new InsetInclude(p); } @@ -184,7 +193,7 @@ string const InsetInclude::getFileName() const string const InsetInclude::getMasterFilename() const { - return params_.buffer->fileName(); + return params_.masterFilename_; } @@ -367,11 +376,11 @@ void InsetInclude::Validate(LaTeXFeatures & features) const string incfile(params_.cparams.getContents()); string writefile; - Buffer const & b = *params_.buffer; + Buffer const * const b = bufferlist.getBuffer(getMasterFilename()); - if (!b.tmppath.empty() && b.niceFile) { + if (b && !b->tmppath.empty() && b->niceFile) { incfile = subst(incfile, '/','@'); - writefile = AddName(b.tmppath, incfile); + writefile = AddName(b->tmppath, incfile); } else writefile = getFileName(); @@ -388,8 +397,9 @@ void InsetInclude::Validate(LaTeXFeatures & features) const // to be loaded: if (loadIfNeeded()) { // a file got loaded - Buffer * tmp = bufferlist.getBuffer(getFileName()); - tmp->validate(features); + Buffer const * const tmp = bufferlist.getBuffer(getFileName()); + if (tmp) + tmp->validate(features); } } diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index f4a0ef2a39..e57afeb0c7 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -27,9 +27,9 @@ struct LaTeXFeatures; class InsetInclude: public InsetButton, public boost::noncopyable { public: /// the type of inclusion - enum IncludeFlags { + enum Flags { /// - INCLUDE= 0, + INCLUDE = 0, /// VERB = 1, /// @@ -38,30 +38,37 @@ public: VERBAST = 3 }; - struct InsetIncludeParams { - InsetIncludeParams(InsetCommandParams const & cp = InsetCommandParams(), - IncludeFlags f = INCLUDE, bool nl = false, Buffer const * b = 0) - : cparams(cp), flag(f), noload(nl), buffer(b) {} + struct Params { + Params(InsetCommandParams const & cp = InsetCommandParams(), + Flags f = INCLUDE, + bool nl = false, + string const & name = string()) + : cparams(cp), flag(f), noload(nl), + masterFilename_(name) {} InsetCommandParams cparams; - IncludeFlags flag; + Flags flag; bool noload; - Buffer const * buffer; + string masterFilename_; + + /// + bool operator==(Params const &) const; + /// + bool operator!=(Params const &) const; }; /// - InsetInclude(InsetIncludeParams const &); + InsetInclude(Params const &); /// InsetInclude(InsetCommandParams const &, Buffer const &); /// ~InsetInclude(); /// get the parameters - InsetIncludeParams const & params(void) const; - + Params const & params(void) const; /// set the parameters - void setFromParams(InsetIncludeParams const & params); + void set(Params const & params); - /// + /// Inset * Clone(Buffer const &) const; /// Inset::Code LyxCode() const { return Inset::INCLUDE_CODE; } @@ -118,7 +125,7 @@ private: string const getFileName() const; /// the parameters - InsetIncludeParams params_; + Params params_; /// string include_label; };