If environment variable SYNFIG_TOOLS_CLEAR_SELECTION is set, then unselect all layers...
[synfig.git] / synfig-studio / trunk / src / gtkmm / state_gradient.cpp
index 81c3800..9740e4c 100644 (file)
@@ -51,6 +51,8 @@
 #include "widget_enum.h"
 #include <synfigapp/main.h>
 
+#include "general.h"
+
 #endif
 
 /* === U S I N G =========================================================== */
@@ -133,10 +135,10 @@ public:
        void increment_id();
 
        void make_gradient(const Point& p1, const Point& p2);
-       bool no_egress_on_selection_change;
+       bool egress_on_selection_change;
        Smach::event_result event_layer_selection_changed_handler(const Smach::event& /*x*/)
        {
-               if(!no_egress_on_selection_change)
+               if(egress_on_selection_change)
                        throw Smach::egress_exception();
                return Smach::RESULT_OK;
        }
@@ -214,7 +216,10 @@ StateGradient_Context::increment_id()
        if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
        {
                // figure out how many digits it is
-               for(digits=0;(int)id.size()-1>=digits && id[id.size()-1-digits]<='9' && id[id.size()-1-digits]>='0';digits++)while(false);
+               for (digits = 0;
+                        (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
+                        digits++)
+                       ;
 
                String str_number;
                str_number=String(id,id.size()-digits,id.size());
@@ -248,7 +253,7 @@ StateGradient_Context::StateGradient_Context(CanvasView* canvas_view):
        prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
        entry_id()
 {
-       no_egress_on_selection_change=false;
+       egress_on_selection_change=true;
        // Set up the tool options dialog
        ///options_table.attach(*manage(new Gtk::Label(_("Gradient Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
        options_table.attach(entry_id, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
@@ -337,6 +342,8 @@ StateGradient_Context::~StateGradient_Context()
        // Refresh the work area
        get_work_area()->queue_draw();
 
+       get_canvas_view()->queue_rebuild_ducks();
+
        //get_canvas_view()->show_tables();
 
        get_work_area()->refresh_cursor();
@@ -429,10 +436,14 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2)
        layer->set_description(get_id());
        get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
 
-       no_egress_on_selection_change=true;
+       egress_on_selection_change=false;
+       synfigapp::SelectionManager::LayerList layer_selection;
+       if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
+               layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
        get_canvas_interface()->get_selection_manager()->clear_selected_layers();
-       get_canvas_interface()->get_selection_manager()->set_selected_layer(layer);
-       no_egress_on_selection_change=false;
+       layer_selection.push_back(layer);
+       get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
+       egress_on_selection_change=true;
 
        reset();
        increment_id();