extended ButtonController so that only FL_OBJECT *s in a trigger_change_

vector can actually cause the Ok, Apply buttons to change state on input.
Vector created for FormCitation.

Please test!


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1514 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2001-02-14 18:56:38 +00:00
parent debcb43788
commit 99a8f84465
5 changed files with 65 additions and 10 deletions

View File

@ -11,11 +11,14 @@
#include "gettext.h" // _()
//#include "debug.h"
using std::find;
using std::vector;
ButtonController::ButtonController(ButtonPolicy * bp,
char const * cancel, char const * close)
: bp_(bp), okay_(0), apply_(0), cancel_(0), undo_all_(0),
read_only_(), cancel_label(cancel), close_label(close)
read_only_(), trigger_change_(),
cancel_label(cancel), close_label(close)
{
Assert(bp);
}
@ -143,13 +146,29 @@ void ButtonController::readWrite()
}
bool ButtonController::valid(bool v)
bool ButtonController::valid(bool v, FL_OBJECT * obj)
{
if (v) {
input(ButtonPolicy::SMI_VALID);
if (obj && !trigger_change_.empty()) {
vector<FL_OBJECT *>::const_iterator cit =
find(trigger_change_.begin(), trigger_change_.end(),
obj);
// Only trigger a change if the obj is in the list
if (cit != trigger_change_.end()) {
if (v) {
input(ButtonPolicy::SMI_VALID);
} else {
input(ButtonPolicy::SMI_INVALID);
}
}
} else {
input(ButtonPolicy::SMI_INVALID);
if (v) {
input(ButtonPolicy::SMI_VALID);
} else {
input(ButtonPolicy::SMI_INVALID);
}
}
return v;
}

View File

@ -89,6 +89,15 @@ public:
read_only_.erase(read_only_.begin(), read_only_.end());
}
///
void addTriggerChange(FL_OBJECT * obj) {
trigger_change_.push_back(obj);
}
///
void eraseTriggerChange() {
trigger_change_.clear();
}
/* Action Functions */
/// force a refresh of the buttons
void refresh();
@ -110,7 +119,7 @@ public:
///
void readWrite();
/// Passthrough function -- returns its input value
bool valid(bool v = true);
bool valid(bool v = true, FL_OBJECT * obj = 0);
///
void invalid();
private:
@ -126,6 +135,8 @@ private:
FL_OBJECT * undo_all_;
/// List of items to be deactivated when in one of the read-only states
std::list<FL_OBJECT *> read_only_;
/// List of items that will trigger a change in activation status.
std::vector<FL_OBJECT *> trigger_change_;
///
char const * cancel_label;
///

View File

@ -1,3 +1,21 @@
2001-02-14 Angus Leeming <a.leeming@ic.ac.uk>
* ButtonController.[Ch] (addTriggerChange, eraseTriggerChange):
new methods.
(valid): method can now be passed an optional FL_OBJECT *. If it is, and
the vector of FL_OBJECT *s that can trigger a change in the button state
is not empty, then a change of state will occur only if the FL_OBJECT *
is present in this vector.
* FormBase.C (RestoreCB): call bc.undoAll() before restore(). Allows
the user to deactivate specific fields within restore().
(InputCB): pass the FL_OBJECT * to bc_.valid().
* FormCitation.C (build): create a vector of FL_OBJECT *s that can
trigger a change of state in the Ok,Apply buttons.
(update): bc_.readOnly() to the start of the method. Similar reasoning
to that for FormBase::RestoreCB, above.
2001-02-14 Angus Leeming <a.leeming@ic.ac.uk>
* FormBrowser.C: used OkCancelPolicy for ButtonController rather than

View File

@ -170,7 +170,7 @@ void FormBase::InputCB(FL_OBJECT * ob, long data)
Assert(ob && ob->form);
FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
Assert(ob);
pre->bc_.valid(pre->input(ob, data));
pre->bc_.valid(pre->input(ob, data), ob);
}
@ -179,8 +179,8 @@ void FormBase::RestoreCB(FL_OBJECT * ob, long)
Assert(ob && ob->form);
FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
Assert(ob);
pre->restore();
pre->bc_.undoAll();
pre->restore();
}

View File

@ -96,11 +96,20 @@ void FormCitation::build()
bc_.addReadOnly(dialog_->downBtn);
bc_.addReadOnly(dialog_->textBefore);
bc_.addReadOnly(dialog_->textAftr);
bc_.addTriggerChange(dialog_->addBtn);
bc_.addTriggerChange(dialog_->delBtn);
bc_.addTriggerChange(dialog_->upBtn);
bc_.addTriggerChange(dialog_->downBtn);
bc_.addTriggerChange(dialog_->textBefore);
bc_.addTriggerChange(dialog_->textAftr);
}
void FormCitation::update()
{
bc_.readOnly(lv_->buffer()->isReadonly());
bibkeys.clear();
bibkeysInfo.clear();
@ -141,8 +150,6 @@ void FormCitation::update()
setSize( size, bibPresent );
fl_set_input( dialog_->textAftr, params.getOptions().c_str());
bc_.readOnly(lv_->buffer()->isReadonly());
}