From 9b7b1a17fc8ae34e68f1ba5fc855f366c6725c32 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Sat, 2 Jun 2001 14:53:35 +0000 Subject: [PATCH] Modification to ButtonController, so that read-only list of widgets is not refreshed every time Restore,Apply,Ok,Cancel are pressed. Has the real advantage that the GUI's can control the widgets more accurately, since the ButtonController cannot. Demonstrated with some small change to the Paragraph dialog: enabling the align buttons is now dependent on the AlignPossible entry in the Layout. Also apply a small bug fix to getVectorFromString in helper_funcs.C git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2087 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ButtonController.h | 25 +++++++++++-------- .../controllers/ButtonControllerBase.C | 5 ++-- .../controllers/ButtonControllerBase.h | 2 ++ src/frontends/controllers/ChangeLog | 13 ++++++++++ src/frontends/controllers/biblio.C | 10 ++------ src/frontends/controllers/helper_funcs.C | 8 +++--- src/frontends/xforms/ChangeLog | 5 ++++ src/frontends/xforms/FormParagraph.C | 16 +++++++++--- 8 files changed, 57 insertions(+), 27 deletions(-) diff --git a/src/frontends/controllers/ButtonController.h b/src/frontends/controllers/ButtonController.h index b0337d3fd8..8b4725976c 100644 --- a/src/frontends/controllers/ButtonController.h +++ b/src/frontends/controllers/ButtonController.h @@ -39,8 +39,10 @@ public: /// void eraseReadOnly() { read_only_.clear(); } - /// Refresh the widgets status. + /// Refresh the status of the Ok, Apply, Restore, Cancel buttons. void refresh(); + /// Refresh the status of any widgets in the read_only list + void refreshReadOnly(); private: /// Enable/Disable a widget @@ -89,18 +91,21 @@ void GuiBC::refresh() else setButtonLabel(cancel_, close_label_); } +} - // Enable/Disable read-only handled widgets. - if (!read_only_.empty()) { - bool const enable = !bp().isReadOnly(); - Widgets::const_iterator end = read_only_.end(); - Widgets::const_iterator iter = read_only_.begin(); - for (; iter != end; ++iter) { - setWidgetEnabled(*iter, enable); - } - } +template +void GuiBC::refreshReadOnly() +{ + if (read_only_.empty()) return; + + bool const enable = !bp().isReadOnly(); + Widgets::const_iterator end = read_only_.end(); + Widgets::const_iterator iter = read_only_.begin(); + for (; iter != end; ++iter) { + setWidgetEnabled(*iter, enable); + } } diff --git a/src/frontends/controllers/ButtonControllerBase.C b/src/frontends/controllers/ButtonControllerBase.C index ecd9f2dd7d..3529710ef6 100644 --- a/src/frontends/controllers/ButtonControllerBase.C +++ b/src/frontends/controllers/ButtonControllerBase.C @@ -84,10 +84,11 @@ void ButtonControllerBase::invalid() bool ButtonControllerBase::readOnly(bool ro) { if (ro) { - input(ButtonPolicy::SMI_READ_ONLY); + bp().input(ButtonPolicy::SMI_READ_ONLY); } else { - input(ButtonPolicy::SMI_READ_WRITE); + bp().input(ButtonPolicy::SMI_READ_WRITE); } + refreshReadOnly(); return ro; } diff --git a/src/frontends/controllers/ButtonControllerBase.h b/src/frontends/controllers/ButtonControllerBase.h index 5114fb483b..5d4b876413 100644 --- a/src/frontends/controllers/ButtonControllerBase.h +++ b/src/frontends/controllers/ButtonControllerBase.h @@ -62,6 +62,8 @@ public: void hide(); /// virtual void refresh() = 0; + /// + virtual void refreshReadOnly() = 0; /// Passthrough function -- returns its input value bool readOnly(bool = true); diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index bf920d2a48..fb09eee6a0 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,16 @@ +2001-06-01 Angus Leeming + + * helper_funcs.C (getVectorFromString): bug fix. + +2001-05-30 Angus Leeming + + * ButtonController.h + * ButtonControllerBase.[Ch] (refreshReadOnly): new method, called direct + from ButtonControllerBase::readOnly. Updates the state of the widgets + in the read-only list only when the read-only status of the document + changes. + (refresh): moved this stuff into refreshReadOnly. + 2001-05-18 Angus Leeming * ControlPrint.C (c-tor): diff --git a/src/frontends/controllers/biblio.C b/src/frontends/controllers/biblio.C index febb0f94c5..f363c8107f 100644 --- a/src/frontends/controllers/biblio.C +++ b/src/frontends/controllers/biblio.C @@ -11,6 +11,8 @@ * \author Angus Leeming */ +#include + #include #include @@ -18,13 +20,6 @@ #pragma implementation #endif -#include - -/* -#include "buffer.h" -#include "Dialogs.h" -#include "LyXView.h" -*/ #include "LString.h" #include "biblio.h" #include "helper_funcs.h" @@ -34,7 +29,6 @@ using std::find; using std::min; -using std::pair; using std::vector; using std::sort; diff --git a/src/frontends/controllers/helper_funcs.C b/src/frontends/controllers/helper_funcs.C index 3b0cc86d24..147fef18ea 100644 --- a/src/frontends/controllers/helper_funcs.C +++ b/src/frontends/controllers/helper_funcs.C @@ -54,7 +54,10 @@ vector const getVectorFromString(string const & str, for(;;) { string::size_type const idx = keys.find(delim); - if (idx == string::npos) break; + if (idx == string::npos) { + vec.push_back(keys); + break; + } string const key = keys.substr(0, idx); if (!key.empty()) @@ -64,9 +67,6 @@ vector const getVectorFromString(string const & str, keys = keys.substr(start); } - if (vec.empty()) // unable to separate - vec.push_back(str); - return vec; } diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 569e573cd9..94d3e8ca23 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2001-05-30 Angus Leeming + + * FormParagraph.C (update, general_update): enabling the align buttons + is now dependent on the AlignPossible entry in the Layout. + 2001-06-01 Jean-Marc Lasgouttes * MathsSymbols.C: diff --git a/src/frontends/xforms/FormParagraph.C b/src/frontends/xforms/FormParagraph.C index 2c299281d5..ef51c02e27 100644 --- a/src/frontends/xforms/FormParagraph.C +++ b/src/frontends/xforms/FormParagraph.C @@ -126,9 +126,10 @@ void FormParagraph::update() if (!dialog_.get()) return; - general_update(); - + // Do this first; some objects may be de/activated subsequently. bc_.readOnly(lv_->buffer()->isReadonly()); + + general_update(); } @@ -257,7 +258,7 @@ void FormParagraph::general_update() if (align == LYX_ALIGN_LAYOUT) align = textclasslist.Style(buf->params.textclass, text->cursor.par()->GetLayout()).align; - + switch (align) { case LYX_ALIGN_RIGHT: fl_set_button(general_->radio_align_right, 1); @@ -273,6 +274,15 @@ void FormParagraph::general_update() break; } + LyXAlignment alignpos = + textclasslist.Style(buf->params.textclass, + text->cursor.par()->GetLayout()).alignpossible; + + setEnabled(general_->radio_align_block, bool(alignpos & LYX_ALIGN_BLOCK)); + setEnabled(general_->radio_align_center, bool(alignpos & LYX_ALIGN_CENTER)); + setEnabled(general_->radio_align_left, bool(alignpos & LYX_ALIGN_LEFT)); + setEnabled(general_->radio_align_right, bool(alignpos & LYX_ALIGN_RIGHT)); + fl_set_button(general_->check_lines_top, text->cursor.par()->params.lineTop()); fl_set_button(general_->check_lines_bottom, -- 2.39.2