[gimp/metadata-browser] Bug 678890 - Selection box handles do not respond after changing layer



commit 5a61f58fbe147bd0a7e8b77504358d01b7bc4980
Author: Michael Natterer <mitch gimp org>
Date:   Thu Jul 26 18:17:01 2012 +0200

    Bug 678890 - Selection box handles do not respond after changing layer
    
    Make sure that temporarily setting/unsetting tool->control's "preserve
    tool across image changes" does not mess up the default value:
    
    Introduce gimp_tool_control_push/pop_preserve() which restores the old
    state automatically, and use it in all tools, instead of saying
    set_preserve(TRUE/FALSE) around image changes.

 app/tools/gimpcagetool.c            |    8 ++++----
 app/tools/gimpimagemaptool.c        |   24 ++++++++++++------------
 app/tools/gimprectangleselecttool.c |   24 ++++++++++++------------
 app/tools/gimptoolcontrol.c         |   27 +++++++++++++++++++++++++++
 app/tools/gimptoolcontrol.h         |    6 ++++++
 app/tools/gimptransformtool.c       |    4 ++--
 6 files changed, 63 insertions(+), 30 deletions(-)
---
diff --git a/app/tools/gimpcagetool.c b/app/tools/gimpcagetool.c
index 299f018..28d4a40 100644
--- a/app/tools/gimpcagetool.c
+++ b/app/tools/gimpcagetool.c
@@ -237,13 +237,13 @@ gimp_cage_tool_control (GimpTool       *tool,
 
       if (ct->image_map)
         {
-          gimp_tool_control_set_preserve (tool->control, TRUE);
+          gimp_tool_control_push_preserve (tool->control, TRUE);
 
           gimp_image_map_abort (ct->image_map);
           g_object_unref (ct->image_map);
           ct->image_map = NULL;
 
-          gimp_tool_control_set_preserve (tool->control, FALSE);
+          gimp_tool_control_pop_preserve (tool->control);
 
           gimp_image_flush (gimp_display_get_image (tool->display));
         }
@@ -426,13 +426,13 @@ gimp_cage_tool_key_press (GimpTool    *tool,
         }
       else if (ct->tool_state == DEFORM_STATE_WAIT)
         {
-          gimp_tool_control_set_preserve (tool->control, TRUE);
+          gimp_tool_control_push_preserve (tool->control, TRUE);
 
           gimp_image_map_commit (ct->image_map);
           g_object_unref (ct->image_map);
           ct->image_map = NULL;
 
-          gimp_tool_control_set_preserve (tool->control, FALSE);
+          gimp_tool_control_pop_preserve (tool->control);
 
           gimp_image_flush (gimp_display_get_image (display));
 
diff --git a/app/tools/gimpimagemaptool.c b/app/tools/gimpimagemaptool.c
index bf94a5b..cf31208 100644
--- a/app/tools/gimpimagemaptool.c
+++ b/app/tools/gimpimagemaptool.c
@@ -462,13 +462,13 @@ gimp_image_map_tool_control (GimpTool       *tool,
         {
           GimpImage *image;
 
-          gimp_tool_control_set_preserve (tool->control, TRUE);
+          gimp_tool_control_push_preserve (tool->control, TRUE);
 
           gimp_image_map_abort (image_map_tool->image_map);
           g_object_unref (image_map_tool->image_map);
           image_map_tool->image_map = NULL;
 
-          gimp_tool_control_set_preserve (tool->control, FALSE);
+          gimp_tool_control_pop_preserve (tool->control);
 
           /* don't call gimp_image_flush() here, because the tool
            * might be cancelled from some other place opening an undo
@@ -542,19 +542,19 @@ gimp_image_map_tool_options_notify (GimpTool         *tool,
 
       if (im_options->preview)
         {
-          gimp_tool_control_set_preserve (tool->control, TRUE);
+          gimp_tool_control_push_preserve (tool->control, TRUE);
 
           gimp_image_map_tool_map (image_map_tool);
 
-          gimp_tool_control_set_preserve (tool->control, FALSE);
+          gimp_tool_control_pop_preserve (tool->control);
         }
       else
         {
-          gimp_tool_control_set_preserve (tool->control, TRUE);
+          gimp_tool_control_push_preserve (tool->control, TRUE);
 
           gimp_image_map_clear (image_map_tool->image_map);
 
-          gimp_tool_control_set_preserve (tool->control, FALSE);
+          gimp_tool_control_pop_preserve (tool->control);
 
           gimp_image_map_tool_flush (image_map_tool->image_map,
                                      image_map_tool);
@@ -732,7 +732,7 @@ gimp_image_map_tool_response (GtkWidget        *widget,
         {
           GimpImageMapOptions *options = GIMP_IMAGE_MAP_TOOL_GET_OPTIONS (tool);
 
-          gimp_tool_control_set_preserve (tool->control, TRUE);
+          gimp_tool_control_push_preserve (tool->control, TRUE);
 
           if (! options->preview)
             gimp_image_map_tool_map (image_map_tool);
@@ -741,7 +741,7 @@ gimp_image_map_tool_response (GtkWidget        *widget,
           g_object_unref (image_map_tool->image_map);
           image_map_tool->image_map = NULL;
 
-          gimp_tool_control_set_preserve (tool->control, FALSE);
+          gimp_tool_control_pop_preserve (tool->control);
 
           gimp_image_flush (gimp_display_get_image (tool->display));
 
@@ -810,11 +810,11 @@ gimp_image_map_tool_preview (GimpImageMapTool *image_map_tool)
 
   if (image_map_tool->image_map && options->preview)
     {
-      gimp_tool_control_set_preserve (tool->control, TRUE);
+      gimp_tool_control_push_preserve (tool->control, TRUE);
 
       gimp_image_map_tool_map (image_map_tool);
 
-      gimp_tool_control_set_preserve (tool->control, FALSE);
+      gimp_tool_control_pop_preserve (tool->control);
     }
 }
 
@@ -825,11 +825,11 @@ gimp_image_map_tool_gegl_notify (GObject          *config,
 {
   if (im_tool->image_map)
     {
-      gimp_tool_control_set_preserve (GIMP_TOOL (im_tool)->control, TRUE);
+      gimp_tool_control_push_preserve (GIMP_TOOL (im_tool)->control, TRUE);
 
       gimp_image_map_tool_create_map (im_tool);
 
-      gimp_tool_control_set_preserve (GIMP_TOOL (im_tool)->control, FALSE);
+      gimp_tool_control_pop_preserve (GIMP_TOOL (im_tool)->control);
 
       gimp_image_map_tool_preview (im_tool);
     }
diff --git a/app/tools/gimprectangleselecttool.c b/app/tools/gimprectangleselecttool.c
index 2f80f36..446c7f9 100644
--- a/app/tools/gimprectangleselecttool.c
+++ b/app/tools/gimprectangleselecttool.c
@@ -419,11 +419,11 @@ gimp_rectangle_select_tool_button_press (GimpTool            *tool,
       if (undo && priv->undo == undo)
         {
           /* prevent this change from halting the tool */
-          gimp_tool_control_set_preserve (tool->control, TRUE);
+          gimp_tool_control_push_preserve (tool->control, TRUE);
 
           gimp_image_undo (image);
 
-          gimp_tool_control_set_preserve (tool->control, FALSE);
+          gimp_tool_control_pop_preserve (tool->control);
 
           /* we will need to redo if the user cancels or executes */
           priv->redo = gimp_undo_stack_peek (redo_stack);
@@ -475,12 +475,12 @@ gimp_rectangle_select_tool_button_release (GimpTool              *tool,
       if (redo && priv->redo == redo)
         {
           /* prevent this from halting the tool */
-          gimp_tool_control_set_preserve (tool->control, TRUE);
+          gimp_tool_control_push_preserve (tool->control, TRUE);
 
           gimp_image_redo (image);
           priv->redo = NULL;
 
-          gimp_tool_control_set_preserve (tool->control, FALSE);
+          gimp_tool_control_pop_preserve (tool->control);
         }
     }
 
@@ -492,11 +492,11 @@ gimp_rectangle_select_tool_button_release (GimpTool              *tool,
       if (priv->redo)
         {
           /* prevent this from halting the tool */
-          gimp_tool_control_set_preserve (tool->control, TRUE);
+          gimp_tool_control_push_preserve (tool->control, TRUE);
 
           gimp_image_redo (image);
 
-          gimp_tool_control_set_preserve (tool->control, FALSE);
+          gimp_tool_control_pop_preserve (tool->control);
         }
 
       priv->use_saved_op = TRUE;  /* is this correct? */
@@ -782,7 +782,7 @@ gimp_rectangle_select_tool_execute (GimpRectangleTool *rectangle,
           GimpChannelOps  operation;
 
           /* prevent this change from halting the tool */
-          gimp_tool_control_set_preserve (tool->control, TRUE);
+          gimp_tool_control_push_preserve (tool->control, TRUE);
 
           /* We can conceptually think of a click outside of the
            * selection as adding a 0px selection. Behave intuitivly
@@ -804,7 +804,7 @@ gimp_rectangle_select_tool_execute (GimpRectangleTool *rectangle,
               break;
             }
 
-          gimp_tool_control_set_preserve (tool->control, FALSE);
+          gimp_tool_control_pop_preserve (tool->control);
         }
     }
 
@@ -841,12 +841,12 @@ gimp_rectangle_select_tool_cancel (GimpRectangleTool *rectangle)
       if (undo && priv->undo == undo)
         {
           /* prevent this change from halting the tool */
-          gimp_tool_control_set_preserve (tool->control, TRUE);
+          gimp_tool_control_push_preserve (tool->control, TRUE);
 
           gimp_image_undo (image);
           gimp_image_flush (image);
 
-          gimp_tool_control_set_preserve (tool->control, FALSE);
+          gimp_tool_control_pop_preserve (tool->control);
         }
     }
 
@@ -868,7 +868,7 @@ gimp_rectangle_select_tool_rectangle_change_complete (GimpRectangleTool *rectang
   priv          = GIMP_RECTANGLE_SELECT_TOOL_GET_PRIVATE (rect_sel_tool);
 
   /* prevent change in selection from halting the tool */
-  gimp_tool_control_set_preserve (tool->control, TRUE);
+  gimp_tool_control_push_preserve (tool->control, TRUE);
 
   if (tool->display && ! gimp_tool_control_is_active (tool->control))
     {
@@ -917,7 +917,7 @@ gimp_rectangle_select_tool_rectangle_change_complete (GimpRectangleTool *rectang
       gimp_image_flush (image);
     }
 
-  gimp_tool_control_set_preserve (tool->control, FALSE);
+  gimp_tool_control_pop_preserve (tool->control);
 
   gimp_rectangle_select_tool_update_option_defaults (rect_sel_tool, FALSE);
 
diff --git a/app/tools/gimptoolcontrol.c b/app/tools/gimptoolcontrol.c
index 58c29f2..c7e939e 100644
--- a/app/tools/gimptoolcontrol.c
+++ b/app/tools/gimptoolcontrol.c
@@ -90,6 +90,8 @@ gimp_tool_control_finalize (GObject *object)
 {
   GimpToolControl *control = GIMP_TOOL_CONTROL (object);
 
+  g_slist_free (control->preserve_stack);
+
   g_free (control->action_value_1);
   g_free (control->action_value_2);
   g_free (control->action_value_3);
@@ -172,6 +174,31 @@ gimp_tool_control_get_preserve (GimpToolControl *control)
 }
 
 void
+gimp_tool_control_push_preserve (GimpToolControl *control,
+                                 gboolean         preserve)
+{
+  g_return_if_fail (GIMP_IS_TOOL_CONTROL (control));
+
+  control->preserve_stack =
+    g_slist_prepend (control->preserve_stack,
+                     GINT_TO_POINTER (control->preserve));
+
+  control->preserve = preserve ? TRUE : FALSE;
+}
+
+void
+gimp_tool_control_pop_preserve (GimpToolControl *control)
+{
+  g_return_if_fail (GIMP_IS_TOOL_CONTROL (control));
+  g_return_if_fail (control->preserve_stack != NULL);
+
+  control->preserve = GPOINTER_TO_INT (control->preserve_stack->data);
+
+  control->preserve_stack = g_slist_delete_link (control->preserve_stack,
+                                                 control->preserve_stack);
+}
+
+void
 gimp_tool_control_set_scroll_lock (GimpToolControl *control,
                                    gboolean         scroll_lock)
 {
diff --git a/app/tools/gimptoolcontrol.h b/app/tools/gimptoolcontrol.h
index 2ed3348..398a8b7 100644
--- a/app/tools/gimptoolcontrol.h
+++ b/app/tools/gimptoolcontrol.h
@@ -42,6 +42,8 @@ struct _GimpToolControl
 
   gboolean             preserve;           /*  Preserve this tool across       *
                                             *  drawable changes                */
+  GSList              *preserve_stack;     /*  for push/pop preserve           */
+
   gboolean             scroll_lock;        /*  allow scrolling or not          */
   gboolean             handle_empty_image; /*  invoke the tool on images       *
                                             *  without active drawable         */
@@ -100,6 +102,10 @@ void           gimp_tool_control_set_preserve     (GimpToolControl *control,
                                                    gboolean         preserve);
 gboolean       gimp_tool_control_get_preserve     (GimpToolControl *control);
 
+void           gimp_tool_control_push_preserve    (GimpToolControl *control,
+                                                   gboolean         preserve);
+void           gimp_tool_control_pop_preserve     (GimpToolControl *control);
+
 void           gimp_tool_control_set_scroll_lock  (GimpToolControl *control,
                                                    gboolean         scroll_lock);
 gboolean       gimp_tool_control_get_scroll_lock  (GimpToolControl *control);
diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c
index 2d64f46..48b1cb7 100644
--- a/app/tools/gimptransformtool.c
+++ b/app/tools/gimptransformtool.c
@@ -1101,7 +1101,7 @@ gimp_transform_tool_transform (GimpTransformTool *tr_tool,
   gimp_draw_tool_stop (GIMP_DRAW_TOOL (tr_tool));
 
   /*  We're going to dirty this image, but we want to keep the tool around  */
-  gimp_tool_control_set_preserve (tool->control, TRUE);
+  gimp_tool_control_push_preserve (tool->control, TRUE);
 
   undo_desc = GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->get_undo_desc (tr_tool);
   gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_TRANSFORM, undo_desc);
@@ -1186,7 +1186,7 @@ gimp_transform_tool_transform (GimpTransformTool *tr_tool,
   /*  We're done dirtying the image, and would like to be restarted if
    *  the image gets dirty while the tool exists
    */
-  gimp_tool_control_set_preserve (tool->control, FALSE);
+  gimp_tool_control_pop_preserve (tool->control);
 
   gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]