Skip to content

Commit 483b5ed

Browse files
authored
fix: color/gradient dialog edits the parameter that opened itself (#3373)
fix: color/gradient dialog edits the parameter that opened itself
2 parents 4e4d8b9 + b80368f commit 483b5ed

7 files changed

Lines changed: 105 additions & 1 deletion

File tree

‎synfig-studio/src/gui/cellrenderer/cellrenderer_value.cpp‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,15 @@ bool get_paragraph(synfig::String& text)
252252
return App::dialog_paragraph(_("Text Paragraph"), _("Enter text here:"), text);
253253
}
254254

255+
static bool
256+
is_layer_deleted(const synfig::Layer::ConstHandle& layer)
257+
{
258+
if (Canvas::LooseHandle layer_canvas = layer->get_canvas())
259+
return std::find(layer_canvas->begin(), layer_canvas->end(), layer) == layer_canvas->end();
260+
261+
return true;
262+
}
263+
255264
/* === M E T H O D S ======================================================= */
256265

257266
CellRenderer_ValueBase::CellRenderer_ValueBase():
@@ -286,6 +295,12 @@ CellRenderer_ValueBase::~CellRenderer_ValueBase()
286295
"CellRenderer_ValueBase::~CellRenderer_ValueBase(): Deleted");
287296
}
288297

298+
void
299+
CellRenderer_ValueBase::set_canvas_interface(const etl::loose_handle<synfigapp::CanvasInterface>& x)
300+
{
301+
canvas_interface = x;
302+
}
303+
289304
void
290305
CellRenderer_ValueBase::string_edited_(const Glib::ustring& path, const Glib::ustring& str)
291306
{
@@ -558,6 +573,26 @@ CellRenderer_ValueBase::activate_vfunc( GdkEvent* event,
558573
void
559574
CellRenderer_ValueBase::gradient_edited(synfig::Gradient gradient, Glib::ustring path)
560575
{
576+
synfigapp::ValueDesc vd = App::dialog_gradient->get_value_desc();
577+
if (vd.is_valid()) {
578+
if (vd.parent_is_layer()) {
579+
if (is_layer_deleted(vd.get_layer()))
580+
return;
581+
}
582+
// do not emit signal_edited_ : gradient dialog may be opened by other cell
583+
// and would try to update the parameter related to current one
584+
// as it just remembered its parameter tree path
585+
// Example:
586+
// 1. Create a region layer
587+
// 2. Create a gradient layer
588+
// 3. Click on gradient parameter to edit it
589+
// 4. Without closing gradient dialog, select the region layer instead
590+
// 5. Try to edit the gradient
591+
// 6. Error Message appears
592+
canvas_interface->change_value(vd, gradient);
593+
return;
594+
}
595+
561596
ValueBase old_value(property_value_.get_value());
562597
ValueBase value(gradient);
563598
if (old_value != value)
@@ -567,6 +602,26 @@ CellRenderer_ValueBase::gradient_edited(synfig::Gradient gradient, Glib::ustring
567602
void
568603
CellRenderer_ValueBase::color_edited(synfig::Color color, Glib::ustring path)
569604
{
605+
synfigapp::ValueDesc vd = App::dialog_color->get_value_desc();
606+
if (vd.is_valid()) {
607+
if (vd.parent_is_layer()) {
608+
if (is_layer_deleted(vd.get_layer()))
609+
return;
610+
}
611+
// do not emit signal_edited_ : color dialog may be opened by other cell
612+
// and would try to update the parameter related to current one
613+
// as it just remembered its parameter tree path
614+
// Example:
615+
// 1. Create a region layer
616+
// 2. Create an outline layer
617+
// 3. Click on color parameter to edit it
618+
// 4. Without closing color dialog, select the region layer instead
619+
// 5. Try to edit the color
620+
// 6. Error Message appears
621+
canvas_interface->change_value(vd, color);
622+
return;
623+
}
624+
570625
ValueBase old_value(property_value_.get_value());
571626
ValueBase value(color);
572627
if (old_value != value)
@@ -608,6 +663,7 @@ CellRenderer_ValueBase::start_editing_vfunc(
608663
{
609664
App::dialog_gradient->reset();
610665
App::dialog_gradient->set_gradient( data.get(Gradient()) );
666+
App::dialog_gradient->set_value_desc(get_value_desc());
611667
App::dialog_gradient->signal_edited().connect(
612668
sigc::bind(
613669
sigc::mem_fun(*this, &studio::CellRenderer_ValueBase::gradient_edited),
@@ -623,6 +679,7 @@ CellRenderer_ValueBase::start_editing_vfunc(
623679
{
624680
App::dialog_color->reset();
625681
App::dialog_color->set_color( data.get(Color()) );
682+
App::dialog_color->set_value_desc(get_value_desc());
626683
App::dialog_color->signal_edited().connect(
627684
sigc::bind(
628685
sigc::mem_fun(*this, &studio::CellRenderer_ValueBase::color_edited),

‎synfig-studio/src/gui/cellrenderer/cellrenderer_value.h‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#include <synfig/paramdesc.h>
3838
#include <synfig/value.h>
39+
40+
#include <synfigapp/canvasinterface.h>
3941
#include <synfigapp/value_desc.h>
4042

4143

@@ -68,6 +70,9 @@ class CellRenderer_ValueBase : public Gtk::CellRendererText
6870
bool edit_value_done_called;
6971

7072
synfig::ValueBase saved_data; //Issues 659, 526, 520
73+
74+
etl::loose_handle<synfigapp::CanvasInterface> canvas_interface;
75+
7176
public:
7277
sigc::signal<void, const Glib::ustring&> &signal_secondary_click()
7378
{return signal_secondary_click_; }
@@ -90,11 +95,13 @@ class CellRenderer_ValueBase : public Gtk::CellRendererText
9095
CellRenderer_ValueBase();
9196
~CellRenderer_ValueBase();
9297

98+
void set_canvas_interface(const etl::loose_handle<synfigapp::CanvasInterface>& x);
99+
100+
protected:
93101
ValueBase_Entry *value_entry;
94102

95103
void on_value_editing_done();
96104

97-
protected:
98105
virtual void
99106
render_vfunc(
100107
const ::Cairo::RefPtr< ::Cairo::Context>& cr,

‎synfig-studio/src/gui/dialogs/dialog_color.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ Dialog_Color::get_color() const
9292
return color_edit_widget->get_value();
9393
}
9494

95+
void
96+
Dialog_Color::set_value_desc(const synfigapp::ValueDesc& x)
97+
{
98+
value_desc = x;
99+
}
100+
101+
synfigapp::ValueDesc
102+
Dialog_Color::get_value_desc() const
103+
{
104+
return value_desc;
105+
}
106+
95107
void
96108
Dialog_Color::create_color_edit_widget()
97109
{
@@ -157,4 +169,5 @@ void
157169
Dialog_Color::reset()
158170
{
159171
signal_edited_.clear();
172+
set_value_desc(synfigapp::ValueDesc());
160173
}

‎synfig-studio/src/gui/dialogs/dialog_color.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <gtkmm/dialog.h>
3434
#include <synfig/color.h>
35+
#include <synfigapp/value_desc.h>
3536

3637
/* === M A C R O S ========================================================= */
3738

@@ -49,6 +50,8 @@ class Dialog_Color : public Gtk::Dialog
4950

5051
sigc::signal<void,synfig::Color> signal_edited_;
5152

53+
synfigapp::ValueDesc value_desc;
54+
5255
void create_color_edit_widget();
5356
void create_set_color_button(const char *stock_id,
5457
const Glib::ustring& tip_text, int index,
@@ -68,6 +71,10 @@ class Dialog_Color : public Gtk::Dialog
6871

6972
void set_color(const synfig::Color& x);
7073
synfig::Color get_color() const;
74+
75+
void set_value_desc(const synfigapp::ValueDesc& x);
76+
synfigapp::ValueDesc get_value_desc() const;
77+
7178
void reset();
7279
}; // END of Dialog_Color
7380

‎synfig-studio/src/gui/dialogs/dialog_gradient.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Dialog_Gradient::reset()
129129
{
130130
value_changed_connection.disconnect();
131131
signal_edited_.clear();
132+
set_value_desc(synfigapp::ValueDesc());
132133
}
133134

134135
void
@@ -189,3 +190,15 @@ Dialog_Gradient::edit(const synfigapp::ValueDesc &x, etl::handle<synfigapp::Canv
189190

190191
present();
191192
}
193+
194+
void
195+
Dialog_Gradient::set_value_desc(const synfigapp::ValueDesc& x)
196+
{
197+
value_desc = x;
198+
}
199+
200+
synfigapp::ValueDesc
201+
Dialog_Gradient::get_value_desc() const
202+
{
203+
return value_desc;
204+
}

‎synfig-studio/src/gui/dialogs/dialog_gradient.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class Dialog_Gradient : public Gtk::Dialog
8080
Widget_ColorEdit* widget_color;
8181
Gtk::Button *set_default_button;
8282

83+
synfigapp::ValueDesc value_desc;
84+
8385
void on_changed();
8486

8587
public:
@@ -100,6 +102,9 @@ class Dialog_Gradient : public Gtk::Dialog
100102
//! Interface to external calls to fill in the Gradient Editor Dialog
101103
//! when a Constant ValueNode or a Animated ValueNode is double cliked.
102104
void edit(const synfigapp::ValueDesc &x, etl::handle<synfigapp::CanvasInterface> canvas_interface, synfig::Time time=0);
105+
106+
void set_value_desc(const synfigapp::ValueDesc& x);
107+
synfigapp::ValueDesc get_value_desc() const;
103108
}; // END of Dialog_Gradient
104109

105110
}; // END of namespace studio

‎synfig-studio/src/gui/trees/layertree.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ LayerTree::set_model(Glib::RefPtr<LayerTreeStore> layer_tree_store)
626626
if(cellrenderer_time_track && layer_tree_store_ && layer_tree_store_->canvas_interface())
627627
cellrenderer_time_track->set_canvas_interface(layer_tree_store_->canvas_interface());
628628
#endif // TIMETRACK_IN_PARAMS_PANEL
629+
630+
cellrenderer_value->set_canvas_interface(layer_tree_store_->canvas_interface());
629631
}
630632

631633
void

0 commit comments

Comments
 (0)