On Tuesday 01 October 2002 11:41 am, Rob Lahaye wrote: > Andre Poenitz wrote: > > On Tue, Oct 01, 2002 at 10:06:26AM +0100, Angus Leeming wrote: > >>In english: > >>If the logfile is from a Literate programming build > >> set the title of the dialog appropriately > >> load the data into the browser. > >> if this loading fails > >> inform the viewer > >> return > > > > Could be added as a comment ther... > > Don't worry, I'll modify Angus' explanation into a few comment > lines. I'll add it in my big-big patch to Xforms, which > hopefully will make it into CVS sometime. > > Thanks for the explanations.
My pleasure. Incidentally, you remember your request about removing the text_warning area and instead setting the widget label to red if the input is invalid? Well attached is a proper patch that does just this for LyXGlueLengths and which I have implemented for the Space Above field in the paragraph dialog. It has the added benefit that the Ok and Apply buttons will now not activate if the input of any such widget is invalid, not just the last widget changed. Perhaps you might like to try it out and incorporate it in your mega patch if it does as you desire. Angus
Index: src/frontends/controllers/ButtonController.tmpl =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ButtonController.tmpl,v retrieving revision 1.5 diff -u -p -r1.5 ButtonController.tmpl --- src/frontends/controllers/ButtonController.tmpl 5 Sep 2002 15:14:20 -0000 1.5 +++ src/frontends/controllers/ButtonController.tmpl 1 Oct 2002 11:39:33 -0000 @@ -29,21 +29,27 @@ template <class Button, class Widget> void GuiBC<Button, Widget>::refresh() { lyxerr[Debug::GUI] << "Calling BC refresh()" << std::endl; - + + bool const all_valid = checkWidgets(); + if (okay_) { - bool const enabled = bp().buttonStatus(ButtonPolicy::OKAY); + bool const enabled = + all_valid && bp().buttonStatus(ButtonPolicy::OKAY); setButtonEnabled(okay_, enabled); } if (apply_) { - bool const enabled = bp().buttonStatus(ButtonPolicy::APPLY); + bool const enabled = + all_valid && bp().buttonStatus(ButtonPolicy::APPLY); setButtonEnabled(apply_, enabled); } if (restore_) { - bool const enabled = bp().buttonStatus(ButtonPolicy::RESTORE); + bool const enabled = + all_valid && bp().buttonStatus(ButtonPolicy::RESTORE); setButtonEnabled(restore_, enabled); } if (cancel_) { - bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL); + bool const enabled = + all_valid && bp().buttonStatus(ButtonPolicy::CANCEL); if (enabled) setButtonLabel(cancel_, cancel_label_); else Index: src/frontends/controllers/ButtonControllerBase.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ButtonControllerBase.C,v retrieving revision 1.9 diff -u -p -r1.9 ButtonControllerBase.C --- src/frontends/controllers/ButtonControllerBase.C 5 Sep 2002 15:14:20 -0000 1.9 +++ src/frontends/controllers/ButtonControllerBase.C 1 Oct 2002 11:39:33 -0000 @@ -18,6 +18,10 @@ #include "debug.h" +CheckedWidget::~CheckedWidget() +{} + + ButtonControllerBase::ButtonControllerBase(string const & cancel, string const & close) : cancel_label_(cancel), close_label_(close) @@ -97,3 +101,30 @@ void ButtonControllerBase::readWrite() { readOnly(false); } + + +void ButtonControllerBase::addCheckedWidget(CheckedWidget * ptr) +{ + if (!ptr) + return; + checked_widgets.push_back(checked_widget_ptr(ptr)); +} + + +bool ButtonControllerBase::checkWidgets() +{ + bool all_valid = true; + + checked_widget_list::const_iterator it = checked_widgets.begin(); + checked_widget_list::const_iterator end = checked_widgets.end(); + + for (; it != end; ++it) { + bool const valid = (*it)->isValid(); + (*it)->setState(valid); + if (!valid) + all_valid = false; + } + + return all_valid; +} + Index: src/frontends/controllers/ButtonControllerBase.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ButtonControllerBase.h,v retrieving revision 1.9 diff -u -p -r1.9 ButtonControllerBase.h --- src/frontends/controllers/ButtonControllerBase.h 5 Sep 2002 15:14:20 -0000 1.9 +++ src/frontends/controllers/ButtonControllerBase.h 1 Oct 2002 11:39:33 -0000 @@ -19,6 +19,19 @@ #include "ButtonPolicies.h" #include "LString.h" +#include <boost/shared_ptr.hpp> +#include <list> + +struct CheckedWidget { + /// + virtual ~CheckedWidget(); + /// + virtual bool isValid() const = 0; + /// + virtual void setState(bool valid) = 0; +}; + + /** Abstract base class for a ButtonController * Controls the activation of the OK, Apply and Cancel buttons. @@ -70,12 +83,23 @@ public: void valid(bool = true); /// void invalid(); + /// + void addCheckedWidget(CheckedWidget * ptr); protected: /// string cancel_label_; /// string close_label_; + /// + bool checkWidgets(); + +private: + /// + typedef boost::shared_ptr<CheckedWidget> checked_widget_ptr; + typedef std::list<checked_widget_ptr> checked_widget_list; + /// + checked_widget_list checked_widgets; }; #endif // BUTTONCONTROLLERBASE_H Index: src/frontends/xforms/FormParagraph.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormParagraph.C,v retrieving revision 1.80 diff -u -p -r1.80 FormParagraph.C --- src/frontends/xforms/FormParagraph.C 5 Sep 2002 15:14:22 -0000 1.80 +++ src/frontends/xforms/FormParagraph.C 1 Oct 2002 11:39:39 -0000 @@ -23,6 +23,7 @@ #include "xforms_helpers.h" #include "lyxrc.h" // to set the deafult length values #include "input_validators.h" +#include "checkedwidgets.h" #include "helper_funcs.h" #include "gettext.h" #include "xformsBC.h" @@ -92,6 +93,11 @@ void FormParagraph::build() bc().setApply(dialog_->button_apply); bc().setCancel(dialog_->button_close); bc().setRestore(dialog_->button_restore); + + bc().addCheckedWidget( + new CheckedGlueLength(dialog_->input_space_above, + dialog_->choice_value_space_above, + dialog_->choice_space_above)); bc().addReadOnly(dialog_->radio_align_right); bc().addReadOnly(dialog_->radio_align_left); Index: src/frontends/xforms/Makefile.am =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/Makefile.am,v retrieving revision 1.82 diff -u -p -r1.82 Makefile.am --- src/frontends/xforms/Makefile.am 24 Sep 2002 18:20:25 -0000 1.82 +++ src/frontends/xforms/Makefile.am 1 Oct 2002 11:39:39 -0000 @@ -23,6 +23,8 @@ libxforms_la_SOURCES = \ forms_gettext.h \ bmtable.c \ bmtable.h \ + checkedwidgets.C \ + checkedwidgets.h \ combox.C \ combox.h \ input_validators.C \ Index: src/frontends/xforms/checkedwidgets.C =================================================================== RCS file: src/frontends/xforms/checkedwidgets.C diff -N src/frontends/xforms/checkedwidgets.C --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/frontends/xforms/checkedwidgets.C 1 Oct 2002 11:39:39 -0000 @@ -0,0 +1,57 @@ +/** + * \file checkedwidgets.C + * 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 <config.h> + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "checkedwidgets.h" +#include "xforms_helpers.h" +#include "lyxgluelength.h" +#include "support/LAssert.h" +#include "support/lstrings.h" +#include FORMS_H_LOCATION +#include "LString.h" + + +CheckedGlueLength::CheckedGlueLength(FL_OBJECT * input, + FL_OBJECT * choice, + FL_OBJECT * label) + : input_(input), choice_(choice), label_(label) +{ + lyx::Assert(input && input->objclass == FL_INPUT && + choice && choice->objclass == FL_CHOICE && + label); +} + + +bool CheckedGlueLength::isValid() const +{ + if (!input_->active) + return true; + + string const str = getString(input_); + + if (str.empty() || isStrDbl(str) || isValidGlueLength(str)) + return true; + return false; +} + + +void CheckedGlueLength::setState(bool valid) +{ + FL_COLOR const lcol = valid ? FL_BLACK : FL_RED; + if (lcol != label_->lcol) { + fl_set_object_lcol(label_, lcol); + fl_redraw_object(label_); + } +} Index: src/frontends/xforms/checkedwidgets.h =================================================================== RCS file: src/frontends/xforms/checkedwidgets.h diff -N src/frontends/xforms/checkedwidgets.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/frontends/xforms/checkedwidgets.h 1 Oct 2002 11:39:39 -0000 @@ -0,0 +1,45 @@ +// -*- C++ -*- +/** + * \file checkedwidgets.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 CHECKEDWIDGETS_H +#define CHECKEDWIDGETS_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "ButtonControllerBase.h" +#include "forms_fwd.h" + +class CheckedGlueLength : public CheckedWidget { +public: + /** The label widget's label will be turned red if input and choice + do not make a valid LyXGlueLength. + label may be one of input or choice or may be something else. + It should not be 0! + */ + CheckedGlueLength(FL_OBJECT * input, + FL_OBJECT * choice, + FL_OBJECT * label); + +private: + /// + virtual bool isValid() const; + /// + virtual void setState(bool valid); + + /// + FL_OBJECT * input_; + FL_OBJECT * choice_; + FL_OBJECT * label_; +}; + +#endif // CHECKEDWIDGETS_H