From f410f29244e01a83105423d7d25954675f7c8846 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Thu, 27 Sep 2007 12:33:10 +0000 Subject: [PATCH] fixing undo problems with LPE widgets. Not completely fixed yet. CheckButtons still crash, and some changes are not recorded in the history (try the random parameters of curve stitching) --- src/ui/widget/combo-enums.h | 7 +++- src/ui/widget/point.cpp | 15 +++++-- src/ui/widget/point.h | 5 ++- src/ui/widget/registered-enums.h | 5 +++ src/ui/widget/registered-widget.cpp | 61 +++++++++++++++++++++++------ src/ui/widget/registered-widget.h | 9 ++++- 6 files changed, 83 insertions(+), 19 deletions(-) diff --git a/src/ui/widget/combo-enums.h b/src/ui/widget/combo-enums.h index 555069b4a..405e82e04 100644 --- a/src/ui/widget/combo-enums.h +++ b/src/ui/widget/combo-enums.h @@ -27,7 +27,7 @@ template class ComboBoxEnum : public Gtk::ComboBox, public AttrWidge { public: ComboBoxEnum(const Util::EnumDataConverter& c, const SPAttributeEnum a = SP_ATTR_INVALID) - : AttrWidget(a), _converter(c) + : AttrWidget(a), setProgrammatically(false), _converter(c) { signal_changed().connect(signal_attr_changed().make_slot()); @@ -54,6 +54,7 @@ public: virtual void set_from_attribute(SPObject* o) { + setProgrammatically = true; const gchar* val = attribute_value(o); if(val) set_active(_converter.get_id_from_key(val)); @@ -77,6 +78,7 @@ public: } void set_active_by_id(E id) { + setProgrammatically = true; for(Gtk::TreeModel::iterator i = _model->children().begin(); i != _model->children().end(); ++i) { @@ -89,9 +91,12 @@ public: }; void set_active_by_key(const Glib::ustring& key) { + setProgrammatically = true; set_active_by_id( _converter.get_id_from_key(key) ); }; + bool setProgrammatically; + private: class Columns : public Gtk::TreeModel::ColumnRecord { diff --git a/src/ui/widget/point.cpp b/src/ui/widget/point.cpp index cfaa4303d..ae7197c29 100644 --- a/src/ui/widget/point.cpp +++ b/src/ui/widget/point.cpp @@ -43,7 +43,6 @@ Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &icon, bool mnemonic) : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic), - setProgrammatically(false), xwidget("X:",""), ywidget("Y:","") { @@ -69,7 +68,6 @@ Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &icon, bool mnemonic) : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic), - setProgrammatically(false), xwidget("X:","", digits), ywidget("Y:","", digits) { @@ -97,7 +95,6 @@ Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &icon, bool mnemonic) : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic), - setProgrammatically(false), xwidget("X:","", adjust, digits), ywidget("Y:","", adjust, digits) { @@ -194,7 +191,6 @@ Point::setRange(double min, double max) void Point::setValue(double xvalue, double yvalue) { - setProgrammatically = true; // callback is supposed to reset back, if it cares xwidget.setValue(xvalue); ywidget.setValue(yvalue); } @@ -206,6 +202,17 @@ Point::update() { ywidget.update(); } +/** Check 'setProgrammatically' of both scalar widgets. False if value is changed by user by clicking the widget. */ +bool +Point::setProgrammatically() { + return (xwidget.setProgrammatically || ywidget.setProgrammatically); +} + +void +Point::clearProgrammatically() { + xwidget.setProgrammatically = false; + ywidget.setProgrammatically = false; +} /** Signal raised when the spin button's value changes */ diff --git a/src/ui/widget/point.h b/src/ui/widget/point.h index 291ae131e..7653ceaa4 100644 --- a/src/ui/widget/point.h +++ b/src/ui/widget/point.h @@ -70,8 +70,9 @@ public: Glib::SignalProxy0 signal_x_value_changed(); Glib::SignalProxy0 signal_y_value_changed(); - bool setProgrammatically; // true if the value was set by setValue, not changed by the user; - // if a callback checks it, it must reset it back to false + bool setProgrammatically(); // true if the value was set by setValue, not changed by the user; + // if a callback checks it, it must reset it back to false + void clearProgrammatically(); protected: Scalar xwidget, ywidget; diff --git a/src/ui/widget/registered-enums.h b/src/ui/widget/registered-enums.h index bfa866e29..41b404978 100644 --- a/src/ui/widget/registered-enums.h +++ b/src/ui/widget/registered-enums.h @@ -79,6 +79,11 @@ public: protected: void on_changed() { + if (combobox()->setProgrammatically) { + combobox()->setProgrammatically = false; + return; + } + if (_wr->isUpdating()) return; _wr->setUpdating (true); diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index 5f59eff8f..46532d358 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -82,7 +82,8 @@ RegisteredWidget::write_to_xml(const char * svgstr) //==================================================== RegisteredCheckButton::RegisteredCheckButton() -: _button(0) +: _button(0), + setProgrammatically(false) { } @@ -109,16 +110,23 @@ RegisteredCheckButton::init (const Glib::ustring& label, const Glib::ustring& ti void RegisteredCheckButton::setActive (bool b) { +// FIXME: for some reason, this function is also called when user clicks. then setProgrammatically should not be set! + setProgrammatically = true; _button->set_active (b); - //The slave button is greyed out if the master button is unchecked - for (std::list::const_iterator i = _slavebuttons.begin(); i != _slavebuttons.end(); i++) { - (*i)->set_sensitive(b); - } + //The slave button is greyed out if the master button is unchecked + for (std::list::const_iterator i = _slavebuttons.begin(); i != _slavebuttons.end(); i++) { + (*i)->set_sensitive(b); + } } void RegisteredCheckButton::on_toggled() { + if (setProgrammatically) { + setProgrammatically = false; + return; + } + if (_wr->isUpdating()) return; @@ -215,12 +223,16 @@ void RegisteredScalarUnit::setValue (double val) { _widget->setValue (val); - on_value_changed(); } void RegisteredScalarUnit::on_value_changed() { + if (_widget->setProgrammatically) { + _widget->setProgrammatically = false; + return; + } + if (_wr->isUpdating()) return; @@ -274,12 +286,16 @@ void RegisteredScalar::setValue (double val) { _widget->setValue (val); - on_value_changed(); } void RegisteredScalar::on_value_changed() { + if (_widget->setProgrammatically) { + _widget->setProgrammatically = false; + return; + } + if (_wr->isUpdating()) { return; } @@ -370,7 +386,9 @@ RegisteredColorPicker::on_changed (guint32 rgba) } RegisteredSuffixedInteger::RegisteredSuffixedInteger() -: _label(0), _sb(0), +: _label(0), + setProgrammatically(false), + _sb(0), _adj(0.0,0.0,100.0,1.0,1.0,1.0), _suffix(0) { @@ -404,12 +422,18 @@ RegisteredSuffixedInteger::init (const Glib::ustring& label, const Glib::ustring void RegisteredSuffixedInteger::setValue (int i) { + setProgrammatically = true; _adj.set_value (i); } void RegisteredSuffixedInteger::on_value_changed() { + if (setProgrammatically) { + setProgrammatically = false; + return; + } + if (_wr->isUpdating()) return; @@ -425,7 +449,8 @@ RegisteredSuffixedInteger::on_value_changed() } RegisteredRadioButtonPair::RegisteredRadioButtonPair() -: _hbox(0) +: _hbox(0), + setProgrammatically(false) { } @@ -458,6 +483,7 @@ const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument void RegisteredRadioButtonPair::setValue (bool second) { + setProgrammatically = true; if (second) _rb2->set_active(); else _rb1->set_active(); } @@ -465,6 +491,11 @@ RegisteredRadioButtonPair::setValue (bool second) void RegisteredRadioButtonPair::on_value_changed() { + if (setProgrammatically) { + setProgrammatically = false; + return; + } + if (_wr->isUpdating()) return; @@ -519,12 +550,16 @@ void RegisteredPoint::setValue (double xval, double yval) { _widget->setValue(xval, yval); - on_value_changed(); } void RegisteredPoint::on_value_changed() { + if (_widget->setProgrammatically()) { + _widget->clearProgrammatically(); + return; + } + if (_wr->isUpdating()) return; @@ -582,12 +617,16 @@ RegisteredRandom::setValue (double val, long startseed) { _widget->setValue (val); _widget->setStartSeed(startseed); - on_value_changed(); } void RegisteredRandom::on_value_changed() { + if (_widget->setProgrammatically) { + _widget->setProgrammatically = false; + return; + } + if (_wr->isUpdating()) return; _wr->setUpdating (true); diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 3d4dd851b..33d7c29cd 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -100,7 +100,10 @@ public: void setSlaveButton(std::list btns) { _slavebuttons = btns; } - + + bool setProgrammatically; // true if the value was set by setValue, not changed by the user; + // if a callback checks it, it must reset it back to false + protected: Gtk::Tooltips _tt; @@ -235,6 +238,8 @@ public: void setValue (int); Gtk::Label *_label; Gtk::HBox _hbox; + bool setProgrammatically; // true if the value was set by setValue, not changed by the user; + // if a callback checks it, it must reset it back to false protected: Gtk::SpinButton *_sb; @@ -269,6 +274,8 @@ public: void setValue (bool second); Gtk::HBox *_hbox; + bool setProgrammatically; // true if the value was set by setValue, not changed by the user; + // if a callback checks it, it must reset it back to false protected: Gtk::RadioButton *_rb1, *_rb2; Gtk::Tooltips _tt; -- 2.30.2