From: Angus Leeming Date: Fri, 14 Mar 2003 00:20:42 +0000 (+0000) Subject: * Give Dialog::Controller::initialiseParams a bool return type. X-Git-Tag: 1.6.10~17236 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=0de182f2571c1ab327843cc281bc1f5302058e26;p=features.git * Give Dialog::Controller::initialiseParams a bool return type. * Constify many ButtonController/View methods. * Try and document the code ;-) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6495 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/controllers/BCView.C b/src/frontends/controllers/BCView.C index 29a8b7006a..a8957483af 100644 --- a/src/frontends/controllers/BCView.C +++ b/src/frontends/controllers/BCView.C @@ -36,7 +36,7 @@ void BCView::addCheckedWidget(CheckedWidget * ptr) } -bool BCView::checkWidgets() +bool BCView::checkWidgets() const { bool valid = true; diff --git a/src/frontends/controllers/BCView.h b/src/frontends/controllers/BCView.h index f4d66bb73b..b21baf1fe5 100644 --- a/src/frontends/controllers/BCView.h +++ b/src/frontends/controllers/BCView.h @@ -14,13 +14,26 @@ #ifndef BCVIEW_H #define BCVIEW_H + #include "LString.h" #include #include + class ButtonController; class ButtonPolicy; + +/** \class CheckedWidget is an abstract base class that can be stored + * in the button controller's view and can be interrogated by it + * when the activation state of the Ok, Apply buttons is refreshed. + * Ideally, the user will be prevented from returning invalid data + * to the LyX kernel. + * + * Many widgets can be grouped together in the derived class if they + * make a logical whole. E.g., an input and a choice widget that together + * are used to set a LyXLength can be interrogated together. + */ struct CheckedWidget { /// virtual ~CheckedWidget(); @@ -33,30 +46,40 @@ struct CheckedWidget { }; +/** \class BCView is the View to ButtonController's Controller. It + * stores the individual GUI widgets and sets their activation state + * upon receipt of instructions from the controller. + * + * It is a base class. The true, GUI, instantiations derive from it. + */ class BCView { public: BCView(ButtonController const &); - /// virtual ~BCView() {} - /// - virtual void refresh() = 0; - /// - virtual void refreshReadOnly() = 0; - /// + + //@{ + /// Refresh the status of the Ok, Apply, Restore, Cancel buttons. + virtual void refresh() const = 0; + /// Refresh the status of any widgets in the read_only list + virtual void refreshReadOnly() const = 0; + //@} + + /// A shortcut to the BP of the BC. ButtonPolicy & bp() const; - /// + + /** Add a widget to the list of all widgets whose validity should + * be checked explicitly when the buttons are refreshed. + */ void addCheckedWidget(CheckedWidget * ptr); + protected: - /// - bool checkWidgets(); + /// \return true if all CheckedWidgets are in a valid state. + bool checkWidgets() const; private: - /// typedef boost::shared_ptr checked_widget_ptr; typedef std::list checked_widget_list; - /// checked_widget_list checked_widgets; - /// ButtonController const & parent; }; @@ -71,33 +94,37 @@ public: GuiBC(ButtonController const & parent, string const & cancel, string const & close); - /// + //@{ + /** Store pointers to these widgets. The pointers are _not_ + * owned by GuiBC. + */ void setOK(Button * obj) { okay_ = obj; } - /// void setApply(Button * obj) { apply_ = obj; } - /// void setCancel(Button * obj) { cancel_ = obj; } - /// void setRestore(Button * obj) { restore_ = obj; } - /// + //@} + + /** Add a pointer to the list of widgets whose activation + * state is dependent upon the read-only status of the + * underlying buffer. + */ void addReadOnly(Widget * obj) { read_only_.push_back(obj); } - /// - void eraseReadOnly() { read_only_.clear(); } /// Refresh the status of the Ok, Apply, Restore, Cancel buttons. - void refresh(); + virtual void refresh() const; /// Refresh the status of any widgets in the read_only list - void refreshReadOnly(); + virtual void refreshReadOnly() const; + private: /// Enable/Disable a widget - virtual void setWidgetEnabled(Widget * obj, bool enable) = 0; + virtual void setWidgetEnabled(Widget * obj, bool enable) const = 0; /// Enable/Disable a button - virtual void setButtonEnabled(Button * obj, bool enable) = 0; + virtual void setButtonEnabled(Button * obj, bool enable) const = 0; /// Set the Label on the button - virtual void setButtonLabel(Button * obj, string const & label) = 0; + virtual void setButtonLabel(Button * obj, string const & label) const = 0; - string cancel_label_; - string close_label_; + string const cancel_label_; + string const close_label_; Button * okay_; Button * apply_; diff --git a/src/frontends/controllers/BCView.tmpl b/src/frontends/controllers/BCView.tmpl index e97a1d2f92..4869473a58 100644 --- a/src/frontends/controllers/BCView.tmpl +++ b/src/frontends/controllers/BCView.tmpl @@ -29,7 +29,7 @@ GuiBC::GuiBC(ButtonController const & parent, template -void GuiBC::refresh() +void GuiBC::refresh() const { lyxerr[Debug::GUI] << "Calling BC refresh()" << std::endl; @@ -61,7 +61,7 @@ void GuiBC::refresh() template -void GuiBC::refreshReadOnly() +void GuiBC::refreshReadOnly() const { if (read_only_.empty()) return; diff --git a/src/frontends/controllers/ButtonController.C b/src/frontends/controllers/ButtonController.C index ea9c96d7db..8d63bd3cb9 100644 --- a/src/frontends/controllers/ButtonController.C +++ b/src/frontends/controllers/ButtonController.C @@ -16,10 +16,6 @@ #include "debug.h" -ButtonController::~ButtonController() -{} - - BCView & ButtonController::view() const { lyx::Assert(view_.get()); @@ -44,25 +40,25 @@ void ButtonController::bp(ButtonPolicy * bp) } -void ButtonController::refresh() +void ButtonController::refresh() const { view().refresh(); } - -void ButtonController::refreshReadOnly() + +void ButtonController::refreshReadOnly() const { view().refreshReadOnly(); } -void ButtonController::ok() +void ButtonController::ok() const { input(ButtonPolicy::SMI_OKAY); } -void ButtonController::input(ButtonPolicy::SMInput in) +void ButtonController::input(ButtonPolicy::SMInput in) const { if (ButtonPolicy::SMI_NOOP == in) return; @@ -71,31 +67,31 @@ void ButtonController::input(ButtonPolicy::SMInput in) } -void ButtonController::apply() +void ButtonController::apply() const { input(ButtonPolicy::SMI_APPLY); } -void ButtonController::cancel() +void ButtonController::cancel() const { input(ButtonPolicy::SMI_CANCEL); } -void ButtonController::restore() +void ButtonController::restore() const { input(ButtonPolicy::SMI_RESTORE); } -void ButtonController::hide() +void ButtonController::hide() const { input(ButtonPolicy::SMI_HIDE); } -void ButtonController::valid(bool v) +void ButtonController::valid(bool v) const { if (v) { input(ButtonPolicy::SMI_VALID); @@ -105,13 +101,7 @@ void ButtonController::valid(bool v) } -void ButtonController::invalid() -{ - input(ButtonPolicy::SMI_INVALID); -} - - -bool ButtonController::readOnly(bool ro) +bool ButtonController::readOnly(bool ro) const { lyxerr[Debug::GUI] << "Setting controller ro: " << ro << std::endl; @@ -124,9 +114,3 @@ bool ButtonController::readOnly(bool ro) view().refresh(); return ro; } - - -void ButtonController::readWrite() -{ - readOnly(false); -} diff --git a/src/frontends/controllers/ButtonController.h b/src/frontends/controllers/ButtonController.h index 6fc1f967d9..a5d44adc75 100644 --- a/src/frontends/controllers/ButtonController.h +++ b/src/frontends/controllers/ButtonController.h @@ -19,64 +19,73 @@ #include -/** Controls the activation of the OK, Apply and Cancel buttons. +class BCView; + + +/** \class ButtonController 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 + * It actually supports 4 buttons in all and it's up to the user to decide on * the activation policy and which buttons correspond to which output of the * state machine. - * Author: Allan Rae . - * This class stripped of xforms-specific code by - * Angus Leeming */ -class BCView; class ButtonController : boost::noncopyable { public: - /// - ~ButtonController(); - - /// + //@{ + /** Methods to set and get the GUI view (containing the actual + * button widgets. + * \param ptr is owned by the ButtonController. + */ + void view(BCView * ptr); BCView & view() const; - /// - void view(BCView *); + //@} - /// + //@{ + /** Methods to set and get the ButtonPolicy. + * \param ptr is owned by the ButtonController. + */ + void bp(ButtonPolicy * ptr); ButtonPolicy & bp() const; - /// - void bp(ButtonPolicy *); + //@} /// - void input(ButtonPolicy::SMInput); - /// - void ok(); - /// - void apply(); - /// - void cancel(); - /// - void restore(); - /// - void hide(); + void input(ButtonPolicy::SMInput) const; - /// - void refresh(); - /// - void refreshReadOnly(); + //@{ + /// Tell the BC that a particular button has been pressed. + void ok() const; + void apply() const; + void cancel() const; + void restore() const; + //@} - /// Passthrough function -- returns its input value - bool readOnly(bool = true); - /// - void readWrite(); + /// Tell the BC that the dialog is being hidden + void hide() const; - /// - void valid(bool = true); - /// - void invalid(); + /**Refresh the activation state of the Ok, Apply, Close and + * Restore buttons. + */ + void refresh() const; + + /** Refresh the activation state of all the widgets under the control + * of the BC to reflect the read-only status of the underlying buffer. + */ + void refreshReadOnly() const; + //@} + + /** Passthrough function -- returns its input value + * Tell the BC about the read-only status of the underlying buffer. + */ + bool readOnly(bool = true) const; + + /** \param validity Tell the BC that the data is, or is not, valid. + * Sets the activation state of the buttons immediately. + */ + void valid(bool = true) const; private: - /// boost::scoped_ptr bp_; - /// boost::scoped_ptr view_; }; diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 12aadb5414..1921d7cd56 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,18 @@ +2003-03-13 Angus Leeming + + * ButtonController.h: + +2003-03-13 Angus Leeming + + * Dialog.h (initialiseParams): return a bool to indicate successful + translation of the string. + + * Dialog.h: + * Kernel.h + * ControlAbout.h: a serious attempt at documenting the code. + + * ButtonController.[Ch] (readWrite): it wasn't used, so remove it. + 2003-03-13 Angus Leeming * ControlParagraph.[Ch]: rewrite to use the Dialog-based scheme and diff --git a/src/frontends/controllers/ControlAboutlyx.h b/src/frontends/controllers/ControlAboutlyx.h index ef6a998cee..acb7dc1b93 100644 --- a/src/frontends/controllers/ControlAboutlyx.h +++ b/src/frontends/controllers/ControlAboutlyx.h @@ -16,31 +16,28 @@ #include "Dialog.h" #include -/** A controller for the About LyX dialogs. +/** \class ControlAboutlyx is a controller for the "About LyX" dialogs. */ class ControlAboutlyx : public Dialog::Controller { public: - /// - ControlAboutlyx(Dialog &); - /// - virtual void initialiseParams(string const &) {} - /// + ControlAboutlyx(Dialog & parent); + + //@{ + /// Instantiate Dialog::Controller methods. + virtual bool initialiseParams(string const &) { return true; } virtual void clearParams() {} - /// virtual void dispatchParams() {} - /// virtual bool isBufferDependent() const { return false; } + //@} - /// + //@{ + /// Provide the View with specific pieces of information. void getCredits(std::ostream &) const; - /// string const getCopyright() const; - /// string const getLicense() const; - /// string const getDisclaimer() const; - /// string const getVersion() const; + //@} }; #endif // CONTROLABOUTLYX_H diff --git a/src/frontends/controllers/ControlChanges.h b/src/frontends/controllers/ControlChanges.h index d4fd3cc27f..8384e7af3a 100644 --- a/src/frontends/controllers/ControlChanges.h +++ b/src/frontends/controllers/ControlChanges.h @@ -22,7 +22,7 @@ public: /// ControlChanges(Dialog &); /// - virtual void initialiseParams(string const &) {} + virtual bool initialiseParams(string const &) { return true; } /// virtual void clearParams() {} /// diff --git a/src/frontends/controllers/ControlCharacter.C b/src/frontends/controllers/ControlCharacter.C index aaf48c846d..afafd939bb 100644 --- a/src/frontends/controllers/ControlCharacter.C +++ b/src/frontends/controllers/ControlCharacter.C @@ -26,7 +26,7 @@ ControlCharacter::ControlCharacter(Dialog & parent) {} -void ControlCharacter::initialiseParams(string const &) +bool ControlCharacter::initialiseParams(string const &) { // Do this the first time only. if (!font_.get()) @@ -41,6 +41,8 @@ void ControlCharacter::initialiseParams(string const &) getColor() != LColor::ignore || font_->language() != ignore_language) dialog().bc().valid(); + + return true; } diff --git a/src/frontends/controllers/ControlCharacter.h b/src/frontends/controllers/ControlCharacter.h index ca8062b76d..598d2e1e06 100644 --- a/src/frontends/controllers/ControlCharacter.h +++ b/src/frontends/controllers/ControlCharacter.h @@ -22,7 +22,7 @@ public: /// ControlCharacter(Dialog &); /// - virtual void initialiseParams(string const &); + virtual bool initialiseParams(string const & data); /// virtual void clearParams(); /// diff --git a/src/frontends/controllers/ControlCitation.C b/src/frontends/controllers/ControlCitation.C index 50c301b388..1ddddecbf4 100644 --- a/src/frontends/controllers/ControlCitation.C +++ b/src/frontends/controllers/ControlCitation.C @@ -27,7 +27,7 @@ ControlCitation::ControlCitation(Dialog & d) {} -void ControlCitation::initialiseParams(string const & data) +bool ControlCitation::initialiseParams(string const & data) { ControlCommand::initialiseParams(data); @@ -49,6 +49,8 @@ void ControlCitation::initialiseParams(string const & data) (!usingNatbib() && citeStyles_.size() != 1)) citeStyles_ = biblio::getCiteStyles(usingNatbib()); } + + return true; } diff --git a/src/frontends/controllers/ControlCitation.h b/src/frontends/controllers/ControlCitation.h index ac51a7fbe4..2d30c54a70 100644 --- a/src/frontends/controllers/ControlCitation.h +++ b/src/frontends/controllers/ControlCitation.h @@ -24,7 +24,7 @@ public: ControlCitation(Dialog &); /// - virtual void initialiseParams(string const & data); + virtual bool initialiseParams(string const & data); /// clean-up on hide. virtual void clearParams(); diff --git a/src/frontends/controllers/ControlCommand.C b/src/frontends/controllers/ControlCommand.C index 2b93e47c20..7fbdf294be 100644 --- a/src/frontends/controllers/ControlCommand.C +++ b/src/frontends/controllers/ControlCommand.C @@ -23,9 +23,10 @@ ControlCommand::ControlCommand(Dialog & dialog, string const & lfun_name) {} -void ControlCommand::initialiseParams(string const & data) +bool ControlCommand::initialiseParams(string const & data) { InsetCommandMailer::string2params(data, params_); + return true; } diff --git a/src/frontends/controllers/ControlCommand.h b/src/frontends/controllers/ControlCommand.h index 4a87e10685..6763520d11 100644 --- a/src/frontends/controllers/ControlCommand.h +++ b/src/frontends/controllers/ControlCommand.h @@ -32,7 +32,7 @@ public: /// InsetCommandParams const & params() const { return params_; } /// - virtual void initialiseParams(string const & data); + virtual bool initialiseParams(string const & data); /// clean-up on hide. virtual void clearParams(); /// clean-up on hide. diff --git a/src/frontends/controllers/ControlERT.C b/src/frontends/controllers/ControlERT.C index 64ec796d1f..20981ce91b 100644 --- a/src/frontends/controllers/ControlERT.C +++ b/src/frontends/controllers/ControlERT.C @@ -20,9 +20,10 @@ ControlERT::ControlERT(Dialog & parent) {} -void ControlERT::initialiseParams(string const & data) +bool ControlERT::initialiseParams(string const & data) { InsetERTMailer::string2params(data, status_); + return true; } diff --git a/src/frontends/controllers/ControlERT.h b/src/frontends/controllers/ControlERT.h index 575db4ef38..1cb8bb8c10 100644 --- a/src/frontends/controllers/ControlERT.h +++ b/src/frontends/controllers/ControlERT.h @@ -27,7 +27,7 @@ public: /// void setStatus(InsetERT::ERTStatus status) { status_ = status; } /// - virtual void initialiseParams(string const & data); + virtual bool initialiseParams(string const & data); /// clean-up on hide. virtual void clearParams(); /// clean-up on hide. diff --git a/src/frontends/controllers/ControlError.C b/src/frontends/controllers/ControlError.C index 375317e9db..fc9075e117 100644 --- a/src/frontends/controllers/ControlError.C +++ b/src/frontends/controllers/ControlError.C @@ -18,7 +18,7 @@ ControlError::ControlError(Dialog & parent) {} -void ControlError::initialiseParams(string const & data) +bool ControlError::initialiseParams(string const & data) { params_ = data; } diff --git a/src/frontends/controllers/ControlError.h b/src/frontends/controllers/ControlError.h index 3c9435685f..3a05a319dc 100644 --- a/src/frontends/controllers/ControlError.h +++ b/src/frontends/controllers/ControlError.h @@ -21,7 +21,7 @@ public: /// ControlError(Dialog &); /// - virtual void initialiseParams(string const &); + virtual bool initialiseParams(string const & data); /// virtual void clearParams(); /// diff --git a/src/frontends/controllers/ControlExternal.C b/src/frontends/controllers/ControlExternal.C index 6006044938..7dbba5fe14 100644 --- a/src/frontends/controllers/ControlExternal.C +++ b/src/frontends/controllers/ControlExternal.C @@ -28,13 +28,14 @@ ControlExternal::ControlExternal(Dialog & parent) {} -void ControlExternal::initialiseParams(string const & data) +bool ControlExternal::initialiseParams(string const & data) { inset_.reset(new InsetExternal); InsetExternal::Params params; InsetExternalMailer::string2params(data, params); inset_->setFromParams(params); inset_->setView(kernel().bufferview()); + return true; } diff --git a/src/frontends/controllers/ControlExternal.h b/src/frontends/controllers/ControlExternal.h index ff4d189c9d..5e21d9d538 100644 --- a/src/frontends/controllers/ControlExternal.h +++ b/src/frontends/controllers/ControlExternal.h @@ -25,7 +25,7 @@ public: /// ControlExternal(Dialog &); /// - virtual void initialiseParams(string const & data); + virtual bool initialiseParams(string const & data); /// clean-up on hide. virtual void clearParams(); /// clean-up on hide. diff --git a/src/frontends/controllers/ControlFloat.C b/src/frontends/controllers/ControlFloat.C index 3817f7f888..bd7ac6fd7e 100644 --- a/src/frontends/controllers/ControlFloat.C +++ b/src/frontends/controllers/ControlFloat.C @@ -20,11 +20,12 @@ ControlFloat::ControlFloat(Dialog & parent) {} -void ControlFloat::initialiseParams(string const & data) +bool ControlFloat::initialiseParams(string const & data) { InsetFloatParams params; InsetFloatMailer::string2params(data, params); params_.reset(new InsetFloatParams(params)); + return true; } diff --git a/src/frontends/controllers/ControlFloat.h b/src/frontends/controllers/ControlFloat.h index 7aad1e9aef..4f3c785abd 100644 --- a/src/frontends/controllers/ControlFloat.h +++ b/src/frontends/controllers/ControlFloat.h @@ -21,7 +21,7 @@ public: /// ControlFloat(Dialog &); /// - virtual void initialiseParams(string const & data); + virtual bool initialiseParams(string const & data); /// clean-up on hide. virtual void clearParams(); /// clean-up on hide. diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index e87b57479d..390703bc33 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -47,11 +47,12 @@ ControlGraphics::ControlGraphics(Dialog & parent) {} -void ControlGraphics::initialiseParams(string const & data) +bool ControlGraphics::initialiseParams(string const & data) { InsetGraphicsParams params; InsetGraphicsMailer::string2params(data, params); params_.reset(new InsetGraphicsParams(params)); + return true; } diff --git a/src/frontends/controllers/ControlGraphics.h b/src/frontends/controllers/ControlGraphics.h index 4f632fa91f..a7a1fa7bf2 100644 --- a/src/frontends/controllers/ControlGraphics.h +++ b/src/frontends/controllers/ControlGraphics.h @@ -31,7 +31,7 @@ public: /// ControlGraphics(Dialog &); /// - virtual void initialiseParams(string const & data); + virtual bool initialiseParams(string const & data); /// clean-up on hide. virtual void clearParams(); /// clean-up on hide. diff --git a/src/frontends/controllers/ControlInclude.C b/src/frontends/controllers/ControlInclude.C index 24fc60b552..98a8819b55 100644 --- a/src/frontends/controllers/ControlInclude.C +++ b/src/frontends/controllers/ControlInclude.C @@ -31,11 +31,12 @@ ControlInclude::ControlInclude(Dialog & parent) {} -void ControlInclude::initialiseParams(string const & data) +bool ControlInclude::initialiseParams(string const & data) { InsetInclude::Params params; InsetIncludeMailer::string2params(data, params); inset_.reset(new InsetInclude(params)); + return true; } diff --git a/src/frontends/controllers/ControlInclude.h b/src/frontends/controllers/ControlInclude.h index 06f7056006..f5bd7cde80 100644 --- a/src/frontends/controllers/ControlInclude.h +++ b/src/frontends/controllers/ControlInclude.h @@ -36,7 +36,7 @@ public: ControlInclude(Dialog &); /// - virtual void initialiseParams(string const & data); + virtual bool initialiseParams(string const & data); /// clean-up on hide. virtual void clearParams(); /// clean-up on hide. @@ -45,7 +45,7 @@ public: virtual bool isBufferDependent() const { return true; } /// - InsetInclude::Params const & params() const + InsetInclude::Params const & params() const { return inset_->params(); } /// void setParams(InsetInclude::Params const &); diff --git a/src/frontends/controllers/ControlMinipage.C b/src/frontends/controllers/ControlMinipage.C index 49d305ce6d..49674e6abd 100644 --- a/src/frontends/controllers/ControlMinipage.C +++ b/src/frontends/controllers/ControlMinipage.C @@ -20,11 +20,12 @@ ControlMinipage::ControlMinipage(Dialog & parent) {} -void ControlMinipage::initialiseParams(string const & data) +bool ControlMinipage::initialiseParams(string const & data) { InsetMinipage::Params params; InsetMinipageMailer::string2params(data, params); params_.reset(new InsetMinipage::Params(params)); + return true; } diff --git a/src/frontends/controllers/ControlMinipage.h b/src/frontends/controllers/ControlMinipage.h index dd938db0ad..7161e63b69 100644 --- a/src/frontends/controllers/ControlMinipage.h +++ b/src/frontends/controllers/ControlMinipage.h @@ -21,7 +21,7 @@ public: /// ControlMinipage(Dialog &); /// - virtual void initialiseParams(string const & data); + virtual bool initialiseParams(string const & data); /// clean-up on hide. virtual void clearParams(); /// clean-up on hide. diff --git a/src/frontends/controllers/ControlParagraph.C b/src/frontends/controllers/ControlParagraph.C index dc0ea89dea..05e9f3cadd 100644 --- a/src/frontends/controllers/ControlParagraph.C +++ b/src/frontends/controllers/ControlParagraph.C @@ -26,7 +26,7 @@ ControlParagraph::ControlParagraph(Dialog & parent) {} -void ControlParagraph::initialiseParams(string const & data) +bool ControlParagraph::initialiseParams(string const & data) { istringstream is(data); LyXLex lex(0,0); @@ -37,7 +37,7 @@ void ControlParagraph::initialiseParams(string const & data) // action == 1: update dialog, accept changes // action == 2: update dialog, do not accept changes int action = 0; - + if (lex.isOK()) { lex.next(); string const token = lex.getString(); @@ -50,7 +50,7 @@ void ControlParagraph::initialiseParams(string const & data) action = accept ? 1 : 2; } else { // Unrecognised token - lyx::Assert(0); + return false; } } @@ -79,9 +79,9 @@ void ControlParagraph::initialiseParams(string const & data) Int = lex.getInteger(); } else { // Unrecognised token - break; + return false; } - + ++nset; if (token == "\\alignpossible") { @@ -92,13 +92,15 @@ void ControlParagraph::initialiseParams(string const & data) ininset_ = Int; } } - lyx::Assert(nset == 3); + if (nset != 3) + return false; // If "update", then set the activation status of the button controller if (action > 0) { bool const accept = action == 1; dialog().bc().valid(accept); } + return true; } diff --git a/src/frontends/controllers/ControlParagraph.h b/src/frontends/controllers/ControlParagraph.h index 659f047e31..58f0caf82b 100644 --- a/src/frontends/controllers/ControlParagraph.h +++ b/src/frontends/controllers/ControlParagraph.h @@ -22,7 +22,7 @@ public: /// ControlParagraph(Dialog &); /// - virtual void initialiseParams(string const & data); + virtual bool initialiseParams(string const & data); /// clean-up on hide. virtual void clearParams(); /// clean-up on hide. diff --git a/src/frontends/controllers/ControlTabular.C b/src/frontends/controllers/ControlTabular.C index 9986113b93..6aa6f9c18a 100644 --- a/src/frontends/controllers/ControlTabular.C +++ b/src/frontends/controllers/ControlTabular.C @@ -23,11 +23,11 @@ ControlTabular::ControlTabular(Dialog & parent) {} -void ControlTabular::initialiseParams(string const & data) +bool ControlTabular::initialiseParams(string const & data) { Buffer * buffer = kernel().buffer(); if (!buffer) - return; + return false; InsetTabular tmp(*buffer); int cell = InsetTabularMailer::string2params(data, tmp); @@ -35,6 +35,7 @@ void ControlTabular::initialiseParams(string const & data) params_.reset(new LyXTabular(*tmp.tabular.get())); active_cell_ = cell; } + return true; } diff --git a/src/frontends/controllers/ControlTabular.h b/src/frontends/controllers/ControlTabular.h index 2301133b74..37b8c136cf 100644 --- a/src/frontends/controllers/ControlTabular.h +++ b/src/frontends/controllers/ControlTabular.h @@ -25,7 +25,7 @@ public: ControlTabular(Dialog &); /// - virtual void initialiseParams(string const & data); + virtual bool initialiseParams(string const & data); /// clean-up on hide. virtual void clearParams(); /// We use set() instead. diff --git a/src/frontends/controllers/ControlTabularCreate.C b/src/frontends/controllers/ControlTabularCreate.C index 970f5ffe6c..192f4e909f 100644 --- a/src/frontends/controllers/ControlTabularCreate.C +++ b/src/frontends/controllers/ControlTabularCreate.C @@ -20,9 +20,10 @@ ControlTabularCreate::ControlTabularCreate(Dialog & parent) {} -void ControlTabularCreate::initialiseParams(string const &) +bool ControlTabularCreate::initialiseParams(string const &) { params_.first = params_.second = 5; + return true; } diff --git a/src/frontends/controllers/ControlTabularCreate.h b/src/frontends/controllers/ControlTabularCreate.h index 819526fd4c..ad15d77c92 100644 --- a/src/frontends/controllers/ControlTabularCreate.h +++ b/src/frontends/controllers/ControlTabularCreate.h @@ -22,7 +22,7 @@ public: /// ControlTabularCreate(Dialog &); /// - virtual void initialiseParams(string const &); + virtual bool initialiseParams(string const & data); /// clean-up on hide. virtual void clearParams(); /// diff --git a/src/frontends/controllers/ControlWrap.C b/src/frontends/controllers/ControlWrap.C index 1d5ce0e333..2d39e36ce3 100644 --- a/src/frontends/controllers/ControlWrap.C +++ b/src/frontends/controllers/ControlWrap.C @@ -21,11 +21,12 @@ ControlWrap::ControlWrap(Dialog & parent) {} -void ControlWrap::initialiseParams(string const & data) +bool ControlWrap::initialiseParams(string const & data) { InsetWrapParams params; InsetWrapMailer::string2params(data, params); params_.reset(new InsetWrapParams(params)); + return true; } diff --git a/src/frontends/controllers/ControlWrap.h b/src/frontends/controllers/ControlWrap.h index bacfed18a7..7d9f1ef75d 100644 --- a/src/frontends/controllers/ControlWrap.h +++ b/src/frontends/controllers/ControlWrap.h @@ -21,7 +21,7 @@ public: /// ControlWrap(Dialog &); /// - virtual void initialiseParams(string const & data); + virtual bool initialiseParams(string const & data); /// clean-up on hide. virtual void clearParams(); /// clean-up on hide. diff --git a/src/frontends/controllers/Dialog.C b/src/frontends/controllers/Dialog.C index 29a4a141c7..708c3c0862 100644 --- a/src/frontends/controllers/Dialog.C +++ b/src/frontends/controllers/Dialog.C @@ -15,6 +15,7 @@ #include "ButtonController.h" #include "BCView.h" +#include "debug.h" #include "support/LAssert.h" @@ -67,7 +68,13 @@ void Dialog::show(string const & data) if (controller().isBufferDependent() && !kernel().isBufferAvailable()) return; - controller().initialiseParams(data); + if (!controller().initialiseParams(data)) { + lyxerr << "Dialog \"" << name_ + << "\" failed to translate the data " + "string passed to show()" << std::endl; + return; + } + bc().readOnly(kernel().isBufferReadonly()); view().show(); @@ -81,7 +88,12 @@ void Dialog::update(string const & data) if (controller().isBufferDependent() && !kernel().isBufferAvailable()) return; - controller().initialiseParams(data); + if (!controller().initialiseParams(data)) { + lyxerr << "Dialog \"" << name_ + << "\" failed to translate the data " + "string passed to update()" << std::endl; + return; + } bc().readOnly(kernel().isBufferReadonly()); view().update(); diff --git a/src/frontends/controllers/Dialog.h b/src/frontends/controllers/Dialog.h index e9200e4104..88e6719d0e 100644 --- a/src/frontends/controllers/Dialog.h +++ b/src/frontends/controllers/Dialog.h @@ -7,9 +7,6 @@ * \author Angus Leeming * * Full author contact details are available in file CREDITS - * - * The dialogs use a Model-Controller-View split, instantiated here - * by class Dialog. */ #ifndef DIALOG_H @@ -26,182 +23,220 @@ class LyXView; class ButtonController; +/** \class Dialog collects the different parts of a Model-Controller-View + * split of a generic dialog together. + */ class Dialog : boost::noncopyable { public: - /** the Dialog's "name" is the means with which a dialog identifies - * itself to the kernel. + /** \param name is the identifier given to the dialog by its parent + * container. */ Dialog(LyXView &, string const & name); - /// ~Dialog(); - /// + /** the Dialog's name is the means by which a dialog identifies + * itself to the kernel. + */ string const & name() const { return name_; } - /** These methods are publicly accessible because they are invoked - by the View. - */ //@{ - /// + /** These methods are publicly accessible because they are invoked + * by the View when the user presses... guess what ;-) + */ void ApplyButton(); - /// void OKButton(); - /// void CancelButton(); - /// void RestoreButton(); //@} + //@{ /** These methods are publicly accessible because they are invoked - * by the Dialogs class. + * by the parent container acting on commands from the kernel. */ - //@{ - /** Some dialogs, eg the Tabular or Preferences dialog, can extract - the information they require from the kernel. These dialogs will - probably be passed an empty string by the calling Dialogs class. - The inset dialogs, however, require information specific to - an individual inset. This information will be encoded in "data" - and must be translated into a set of parameters that can be - updated from the dialog. - */ - void show(string const & data = string()); - /// - void update(string const & data = string()); - /// + /** \param data The dialog is passed a string encoding the data + * that it is to display. This string is passed to the Controller + * which translates it into a useable form. + */ + void show(string const & data); + /// \param data \see show(). + void update(string const & data); + void hide(); - /// bool isVisible() const; - /// (Eg, the GUI colours have been changed.) + + /** This function is called, for example, if the GUI colours + * have been changed. + */ void redraw(); //@} - /** When Applying it's useful to know whether the dialog is about + /** When applying, it's useful to know whether the dialog is about * to close or not (no point refreshing the display for example). */ bool isClosing() const { return is_closing_; } - /// The LyX kernel is made available through this. + /** The LyX kernel is made available through this wrapper class. + * In an ideal world, it will shrink as more info is passed to the + * show() and update() methods. + */ Kernel & kernel() { return kernel_; } - /** Different dialogs will have different - Controllers, Views and ButtonControllers. - */ //@{ - /// + /** Different dialogs will have different Controllers and Views. + * deriving from these base classes. + */ class Controller; - /// class View; + //@} - /// - void setController(Controller *); - /// - void setView(View *); + //@{ + /** Methods to set the Controller and View and so specialise + * to a particular dialog. + * \param ptr is stored here. + */ + void setController(Controller * ptr); + void setView(View * ptr); + //@} - /// + //@{ + /// Get methods for the various components making up a dialog. Controller & controller() const; - /// ButtonController & bc() const; - /// View & view() const; //@} private: - /// + /// Invoked by both OKButton() and ApplyButton(). void apply(); - /// bool is_closing_; - /// Kernel kernel_; - /// string name_; - /// boost::scoped_ptr bc_ptr_; - /// boost::scoped_ptr controller_ptr_; - /// boost::scoped_ptr view_ptr_; }; +/** \class Dialog::Controller is an abstract base class for the Controller + * of a Model-Controller-View split of a generic dialog. + */ class Dialog::Controller : boost::noncopyable { public: - /// Controller(Dialog & parent) : parent_(parent) {} - /// virtual ~Controller() {} - /// - virtual void initialiseParams(string const & data) = 0; - /// + + //@{ + /** These few methods are all that a generic dialog needs of a + * controller. + */ + /** \param data The controller is passed a string encoding of the + * parameters that the dialog is to display. + * \return true if the translation was successful. + */ + virtual bool initialiseParams(string const & data) = 0; + /** Invoked by Dialog::hide, allowing the controller to + * clean up its data structures. + */ virtual void clearParams() = 0; - /// + /** Invoked by Dialog::apply, enabling the Controller to + * dispatch its data back to the LyX kernel. + */ virtual void dispatchParams() = 0; - /// + /** \return true if the dialog should be shown only when + * a buffer is open + */ virtual bool isBufferDependent() const = 0; - /// + /** \return true if the kernel should disconnect the dialog from + * a particular inset after the data has been applied to it. + * Clearly this makes sense only for dialogs modifying the contents + * of an inset :-) + * In practise, only a very few dialogs (e.g. the citation dialog) + * return true. + */ virtual bool disconnectOnApply() const { return false; } - /// + //@} + +protected: + //@{ + /** Enable the derived classes to access the other parts of the + * whole. + */ Dialog & dialog() { return parent_; } - /// Dialog const & dialog() const { return parent_; } - /// + Kernel & kernel() { return parent_.kernel(); } - /// Kernel const & kernel() const { return parent_.kernel(); } + //@} private: - /// Dialog & parent_; }; +/** \class Dialog::View is an abstract base class to the View + * of a Model-Controller-View split of a generic dialog. + */ class Dialog::View : boost::noncopyable { public: - /// View(Dialog & parent) : p_(parent) {} - /// virtual ~View() {} - /// Apply changes to LyX data from dialog. + //@{ + /** These few methods are all that a generic dialog needs of a + * view. + */ + /** A request to modify the data structures stored by the + * accompanying Controller in preparation for their dispatch to + * the LyX kernel. + * Invoked by Dialog::apply. + */ virtual void apply() = 0; - /// Hide the dialog. + /** Hide the dialog from sight + * Invoked by Dialog::hide. + */ virtual void hide() = 0; - /// Redraw the dialog (e.g. if the colors have been remapped). + /** Redraw the dialog (e.g. if the colors have been remapped). + * Invoked by Dialog::redraw. + */ virtual void redraw() {} - /// Create the dialog if necessary, update it and display it. + /** Create the dialog if necessary, update it and display it. + * Invoked by Dialog::show. + */ virtual void show() = 0; - /// Update dialog before/whilst showing it. + /** Update the display of the dialog whilst it is still visible. + * Invoked by Dialog::update. + */ virtual void update() = 0; - /// + /// \return true if the dialog is visible. virtual bool isVisible() const = 0; + //@} - /** Defaults to nothing. Can be used by the controller, however, to - * indicate to the view that something has changed and that the + /** Defaults to nothing. Can be used by the Controller, however, to + * indicate to the View that something has changed and that the * dialog therefore needs updating. */ virtual void partialUpdate(int) {} - /// + //@{ + /** Enable the derived classes to access the other parts of the + * whole. + */ Dialog & dialog() { return p_; } - /// Dialog const & dialog() const { return p_; } - /// +protected: Kernel & kernel() { return p_.kernel(); } - /// Kernel const & kernel() const { return p_.kernel(); } - /// Controller & getController() { return p_.controller(); } - /// Controller const & getController() const { return p_.controller(); } - /// ButtonController & bc() { return p_.bc(); } - /// ButtonController const & bc() const { return p_.bc(); } + //@} -protected: +private: /// Dialog & p_; }; diff --git a/src/frontends/controllers/Kernel.C b/src/frontends/controllers/Kernel.C index 99a1b81f97..ac4f4e51b1 100644 --- a/src/frontends/controllers/Kernel.C +++ b/src/frontends/controllers/Kernel.C @@ -1,3 +1,15 @@ +/** + * \file Kernel.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Angus Leeming + * + * Full author contact details are available in file CREDITS + */ + +#include + #include "Kernel.h" #include "buffer.h" @@ -60,6 +72,7 @@ Kernel::DocTypes Kernel::docType() const return DOCBOOK; } + BufferView * Kernel::bufferview() { return lyxview_.view().get(); diff --git a/src/frontends/controllers/Kernel.h b/src/frontends/controllers/Kernel.h index 1d7d1436b8..60d7cfc47f 100644 --- a/src/frontends/controllers/Kernel.h +++ b/src/frontends/controllers/Kernel.h @@ -1,4 +1,13 @@ // -*- C++ -*- +/** + * \file Kernel.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Angus Leeming + * + * Full author contact details are available in file CREDITS + */ #ifndef KERNEL_H #define KERNEL_H @@ -13,49 +22,76 @@ class FuncRequest; class LyXView; +/** \class Kernel is a wrapper making the LyX kernel available to the dialog. + * (Ie, it provides an interface to the Model part of the Model-Controller- + * View split. + * In an ideal world, it will shrink as more info is passed to the + * Dialog::show() and update() methods. + */ class Kernel { public: - /// + /// \param lv is the access point for the dialog to the LyX kernel. + Kernel(LyXView & lv); + + /** This method is the primary prupose of the class. It provides + the "gateway" by which the dialog can send a request (of a + change in the data, for more information) to the kernel, + encoded as \param fr. + \param verbose Set to true if the completed action should + be displayed in the minibuffer. + */ + void dispatch(FuncRequest const & fr, bool verbose = false) const; + + /** The dialog has received a request from the user + (who pressed the "Restore" buuton) to update contents. + It must, therefore, ask the kernel to provide this information. + \param name is used as an identifier by the kernel + when the information is posted. + */ + void updateDialog(string const & name) const; + + /** A request from the Controller that future changes to the data + * stored by the dialog are not applied to the inset currently + * connected to the dialog. Instead, they will be used to generate + * a new inset at the cursor position. + */ + void disconnect(string const & name) const; + + //@{ + /// Simple wrapper functions to Buffer methods. + bool isBufferAvailable() const; + bool isBufferReadonly() const; + //@} + + //@{ + /** \enum DocTypes is used to flag the different kinds of buffer + * without making the kernel header files available to the + * dialog's Controller or View. + */ enum DocTypes { - /// LATEX, - /// LITERATE, - /// LINUXDOC, - /// DOCBOOK }; + /// The type of the current buffer. + DocTypes docType() const; + //@} - /// - Kernel(LyXView &); - /// - void dispatch(FuncRequest const &, bool verbose = false) const; - /** The Dialog has received a request from the user to update - its contents. It must, therefore, ask the kernel to provide - this information to Dialog 'name'. + + //@{ + /** Unpleasantly public internals of the LyX kernel. + * We should aim to reduce/remove these from the interface. */ - void updateDialog(string const & name) const; - /// - void disconnect(string const & name) const; - /// - bool isBufferAvailable() const; - /// - bool isBufferReadonly() const; - /// - DocTypes docType() const; - /// LyXView & lyxview() { return lyxview_; } - /// LyXView const & lyxview() const { return lyxview_; } - /// + Buffer * buffer(); - /// Buffer const * buffer() const; - /// + BufferView * bufferview(); - /// BufferView const * bufferview() const; + //@} private: LyXView & lyxview_; diff --git a/src/frontends/qt2/QDialogView.C b/src/frontends/qt2/QDialogView.C index d2fee7a643..cbb3e117b2 100644 --- a/src/frontends/qt2/QDialogView.C +++ b/src/frontends/qt2/QDialogView.C @@ -81,11 +81,7 @@ void QDialogView::changed() { if (updating_) return; - - if (isValid()) - bc().valid(); - else - bc().invalid(); + bc().valid(isValid()); } diff --git a/src/frontends/qt2/Qt2BC.C b/src/frontends/qt2/Qt2BC.C index a9e5a700fc..32fd02e334 100644 --- a/src/frontends/qt2/Qt2BC.C +++ b/src/frontends/qt2/Qt2BC.C @@ -25,13 +25,13 @@ Qt2BC::Qt2BC(ButtonController const & parent, {} -void Qt2BC::setButtonEnabled(QButton * obj, bool enabled) +void Qt2BC::setButtonEnabled(QButton * obj, bool enabled) const { obj->setEnabled(enabled); } -void Qt2BC::setWidgetEnabled(QWidget * obj, bool enabled) +void Qt2BC::setWidgetEnabled(QWidget * obj, bool enabled) const { // yuck, rtti, but the user comes first if (obj->inherits("QLineEdit")) { @@ -47,7 +47,7 @@ void Qt2BC::setWidgetEnabled(QWidget * obj, bool enabled) } -void Qt2BC::setButtonLabel(QButton * obj, string const & label) +void Qt2BC::setButtonLabel(QButton * obj, string const & label) const { obj->setText(toqstr(label)); } diff --git a/src/frontends/qt2/Qt2BC.h b/src/frontends/qt2/Qt2BC.h index 683c4dacf8..638fdedbe2 100644 --- a/src/frontends/qt2/Qt2BC.h +++ b/src/frontends/qt2/Qt2BC.h @@ -34,13 +34,13 @@ public: string const & = _("Cancel"), string const & = _("Close")); private: /// Updates the button sensitivity (enabled/disabled) - void setButtonEnabled(QButton *, bool enabled); + void setButtonEnabled(QButton *, bool enabled) const; /// Updates the widget sensitivity (enabled/disabled) - void setWidgetEnabled(QWidget *, bool enabled); + void setWidgetEnabled(QWidget *, bool enabled) const; /// Set the label on the button - void setButtonLabel(QButton *, string const & label); + void setButtonLabel(QButton *, string const & label) const; }; #endif // QT2BC_H diff --git a/src/frontends/qt2/Qt2Base.C b/src/frontends/qt2/Qt2Base.C index 27ca0953b8..25aadf019e 100644 --- a/src/frontends/qt2/Qt2Base.C +++ b/src/frontends/qt2/Qt2Base.C @@ -76,11 +76,7 @@ void Qt2Base::changed() { if (updating_) return; - - if (isValid()) - bc().valid(); - else - bc().invalid(); + bc().valid(isValid()); } diff --git a/src/frontends/qt2/qscreen.h b/src/frontends/qt2/qscreen.h index 141692d0c2..22e8ee3160 100644 --- a/src/frontends/qt2/qscreen.h +++ b/src/frontends/qt2/qscreen.h @@ -70,7 +70,7 @@ private: /// the mini-pixmap used for backing store for the blinking cursor boost::scoped_ptr nocursor_pixmap_; - //{@ the cursor pixmap position/size + //@{ the cursor pixmap position/size int cursor_x_; int cursor_y_; int cursor_w_; diff --git a/src/frontends/qt2/qsetborder.C b/src/frontends/qt2/qsetborder.C index 8d3d6f6fda..60b38a3156 100644 --- a/src/frontends/qt2/qsetborder.C +++ b/src/frontends/qt2/qsetborder.C @@ -1,5 +1,5 @@ /** - * \file QSetBorder.C + * \file qsetborder.C * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * diff --git a/src/frontends/qt2/qsetborder.h b/src/frontends/qt2/qsetborder.h index a2336bd6f9..89a01dc773 100644 --- a/src/frontends/qt2/qsetborder.h +++ b/src/frontends/qt2/qsetborder.h @@ -1,6 +1,6 @@ // -*- C++ -*- /** - * \file QSetBorder.h + * \file qsetborder.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * diff --git a/src/frontends/xforms/FormForks.C b/src/frontends/xforms/FormForks.C index 960dc31a9f..467b141c54 100644 --- a/src/frontends/xforms/FormForks.C +++ b/src/frontends/xforms/FormForks.C @@ -49,7 +49,7 @@ void FormForks::build() { bcview().setOK(dialog_->button_ok); bcview().setApply(dialog_->button_apply); bcview().setCancel(dialog_->button_close); - bc().invalid(); + bc().valid(false); // Set up the tooltip mechanism string str = _("All currently running child processes forked by LyX."); diff --git a/src/frontends/xforms/xformsBC.C b/src/frontends/xforms/xformsBC.C index cb27c64c23..92745c762b 100644 --- a/src/frontends/xforms/xformsBC.C +++ b/src/frontends/xforms/xformsBC.C @@ -24,19 +24,19 @@ xformsBC::xformsBC(ButtonController const & parent, {} -void xformsBC::setButtonEnabled(FL_OBJECT * obj, bool enabled) +void xformsBC::setButtonEnabled(FL_OBJECT * obj, bool enabled) const { setEnabled(obj, enabled); } -void xformsBC::setWidgetEnabled(FL_OBJECT * obj, bool enabled) +void xformsBC::setWidgetEnabled(FL_OBJECT * obj, bool enabled) const { setEnabled(obj, enabled); } -void xformsBC::setButtonLabel(FL_OBJECT * obj, string const & label) +void xformsBC::setButtonLabel(FL_OBJECT * obj, string const & label) const { fl_set_object_label(obj, label.c_str()); } diff --git a/src/frontends/xforms/xformsBC.h b/src/frontends/xforms/xformsBC.h index 22a4d39157..e7bbceee5b 100644 --- a/src/frontends/xforms/xformsBC.h +++ b/src/frontends/xforms/xformsBC.h @@ -27,13 +27,13 @@ public: private: /// Updates the button sensitivity (enabled/disabled) - void setButtonEnabled(FL_OBJECT *, bool enabled); + void setButtonEnabled(FL_OBJECT *, bool enabled) const; /// Updates the widget sensitivity (enabled/disabled) - void setWidgetEnabled(FL_OBJECT *, bool enabled); + void setWidgetEnabled(FL_OBJECT *, bool enabled) const; /// Set the label on the button - void setButtonLabel(FL_OBJECT *, string const & label); + void setButtonLabel(FL_OBJECT *, string const & label) const; }; #endif // XFORMSBC_H