[gimp] Bug 701159 - Wrong name in transform tool dialogs...



commit b13c68fda6dcedd43d7e2f4633191f9ddc6cdf3f
Author: Michael Natterer <mitch gimp org>
Date:   Wed Feb 5 00:54:39 2014 +0100

    Bug 701159 - Wrong name in transform tool dialogs...
    
    ...when acting on a path or selection
    
    Factor out the code that checks if an active item exists and if it's
    transformable (not locked etc.) and use that function in more places.
    This fixes both the wrong dialog labels and the tool running into
    broken states when the selection or a path are being transformed.

 app/tools/gimptransformtool.c |  208 ++++++++++++++++++++++-------------------
 1 files changed, 110 insertions(+), 98 deletions(-)
---
diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c
index 4c7f7a7..d874e5b 100644
--- a/app/tools/gimptransformtool.c
+++ b/app/tools/gimptransformtool.c
@@ -170,6 +170,11 @@ static void      gimp_transform_tool_response               (GimpToolGui
 
 static void      gimp_transform_tool_free_trans             (gpointer               data);
 static void      gimp_transform_tool_update_sensitivity     (GimpTransformTool     *tr_tool);
+static GimpItem *gimp_transform_tool_get_active_item        (GimpTransformTool     *tr_tool,
+                                                             GimpImage             *image);
+static GimpItem *gimp_transform_tool_check_active_item      (GimpTransformTool     *tr_tool,
+                                                             GimpImage             *display,
+                                                             GError               **error);
 
 
 G_DEFINE_TYPE (GimpTransformTool, gimp_transform_tool, GIMP_TYPE_DRAW_TOOL)
@@ -261,32 +266,17 @@ gimp_transform_tool_initialize (GimpTool     *tool,
   GimpTransformTool *tr_tool  = GIMP_TRANSFORM_TOOL (tool);
   GimpImage         *image    = gimp_display_get_image (display);
   GimpDrawable      *drawable = gimp_image_get_active_drawable (image);
+  GimpItem          *item;
 
   if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
     {
       return FALSE;
     }
 
-  if (gimp_item_is_content_locked (GIMP_ITEM (drawable)))
-    {
-      g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
-                           _("The active layer's pixels are locked."));
-      return FALSE;
-    }
-
-  if (gimp_item_is_position_locked (GIMP_ITEM (drawable)))
-    {
-      g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
-                           _("The active layer's position and size are locked."));
-      return FALSE;
-    }
+  item = gimp_transform_tool_check_active_item (tr_tool, image, error);
 
-  if (! gimp_item_is_visible (GIMP_ITEM (drawable)))
-    {
-      g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
-                           _("The active layer is not visible."));
-      return FALSE;
-    }
+  if (! item)
+    return FALSE;
 
   if (display != tool->display)
     {
@@ -712,13 +702,10 @@ gimp_transform_tool_cursor_update (GimpTool         *tool,
                                    GdkModifierType   state,
                                    GimpDisplay      *display)
 {
-  GimpTransformTool    *tr_tool = GIMP_TRANSFORM_TOOL (tool);
-  GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tool);
-  GimpCursorType        cursor;
-  GimpCursorModifier    modifier = GIMP_CURSOR_MODIFIER_NONE;
-  GimpImage            *image    = gimp_display_get_image (display);
-
-  cursor = gimp_tool_control_get_cursor (tool->control);
+  GimpTransformTool  *tr_tool  = GIMP_TRANSFORM_TOOL (tool);
+  GimpImage          *image    = gimp_display_get_image (display);
+  GimpCursorType      cursor   = gimp_tool_control_get_cursor (tool->control);
+  GimpCursorModifier  modifier = GIMP_CURSOR_MODIFIER_NONE;
 
   if (tr_tool->use_handles)
     {
@@ -774,30 +761,8 @@ gimp_transform_tool_cursor_update (GimpTool         *tool,
                                                               &modifier);
     }
 
-  switch (options->type)
-    {
-      GimpDrawable *drawable = NULL;
-      GimpVectors  *vectors  = NULL;
-
-    case GIMP_TRANSFORM_TYPE_LAYER:
-      drawable = gimp_image_get_active_drawable (image);
-      if (gimp_item_is_content_locked (GIMP_ITEM (drawable))  ||
-          gimp_item_is_position_locked (GIMP_ITEM (drawable)) ||
-          ! gimp_item_is_visible (GIMP_ITEM (drawable)))
-        modifier = GIMP_CURSOR_MODIFIER_BAD;
-      break;
-
-    case GIMP_TRANSFORM_TYPE_SELECTION:
-      break;
-
-    case GIMP_TRANSFORM_TYPE_PATH:
-      vectors = gimp_image_get_active_vectors (image);
-      if (! vectors ||
-          gimp_item_is_content_locked (GIMP_ITEM (vectors)) ||
-          gimp_item_is_position_locked (GIMP_ITEM (vectors)))
-        modifier = GIMP_CURSOR_MODIFIER_BAD;
-      break;
-    }
+  if (! gimp_transform_tool_check_active_item (tr_tool, image, NULL))
+    modifier = GIMP_CURSOR_MODIFIER_BAD;
 
   gimp_tool_control_set_cursor          (tool->control, cursor);
   gimp_tool_control_set_cursor_modifier (tool->control, modifier);
@@ -1370,63 +1335,23 @@ gimp_transform_tool_transform (GimpTransformTool *tr_tool,
   GimpTransformOptions *options        = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tool);
   GimpContext          *context        = GIMP_CONTEXT (options);
   GimpImage            *image          = gimp_display_get_image (display);
-  GimpItem             *active_item    = NULL;
+  GimpItem             *active_item;
   GeglBuffer           *orig_buffer    = NULL;
   gint                  orig_offset_x  = 0;
   gint                  orig_offset_y  = 0;
   GeglBuffer           *new_buffer;
   gint                  new_offset_x;
   gint                  new_offset_y;
-  const gchar          *null_message   = NULL;
-  const gchar          *locked_message = NULL;
   gchar                *undo_desc      = NULL;
   gboolean              new_layer      = FALSE;
+  GError               *error          = NULL;
 
-  switch (options->type)
-    {
-    case GIMP_TRANSFORM_TYPE_LAYER:
-      active_item  = GIMP_ITEM (gimp_image_get_active_drawable (image));
-      null_message = _("There is no layer to transform.");
-
-      if (gimp_item_is_content_locked (active_item))
-        locked_message = _("The active layer's pixels are locked.");
-      else
-        locked_message = _("The active layer's position and size are locked.");
-      break;
-
-    case GIMP_TRANSFORM_TYPE_SELECTION:
-      active_item  = GIMP_ITEM (gimp_image_get_mask (image));
-      /* cannot happen, so don't translate these messages */
-      null_message = "There is no selection to transform.";
-
-      if (gimp_item_is_content_locked (active_item))
-        locked_message = "The selection's pixels are locked.";
-      else
-        locked_message = "The selection's position and size are locked.";
-      break;
-
-    case GIMP_TRANSFORM_TYPE_PATH:
-      active_item  = GIMP_ITEM (gimp_image_get_active_vectors (image));
-      null_message = _("There is no path to transform.");
-
-      if (gimp_item_is_content_locked (active_item))
-        locked_message = _("The active path's strokes are locked.");
-      else
-        locked_message = _("The active path's position is locked.");
-      break;
-    }
+  active_item = gimp_transform_tool_check_active_item (tr_tool, image, &error);
 
   if (! active_item)
     {
-      gimp_tool_message_literal (tool, display, null_message);
-      gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
-      return;
-    }
-
-  if (gimp_item_is_content_locked (active_item) ||
-      gimp_item_is_position_locked (active_item))
-    {
-      gimp_tool_message_literal (tool, display, locked_message);
+      gimp_tool_message_literal (tool, display, error->message);
+      g_clear_error (&error);
       gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
       return;
     }
@@ -1746,11 +1671,11 @@ gimp_transform_tool_prepare (GimpTransformTool *tr_tool,
 {
   if (tr_tool->gui)
     {
-      GimpImage    *image    = gimp_display_get_image (display);
-      GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+      GimpImage *image = gimp_display_get_image (display);
+      GimpItem  *item  = gimp_transform_tool_get_active_item (tr_tool, image);
 
       gimp_tool_gui_set_shell (tr_tool->gui, gimp_display_get_shell (display));
-      gimp_tool_gui_set_viewable (tr_tool->gui, GIMP_VIEWABLE (drawable));
+      gimp_tool_gui_set_viewable (tr_tool->gui, GIMP_VIEWABLE (item));
     }
 
   if (GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->prepare)
@@ -1857,3 +1782,90 @@ gimp_transform_tool_update_sensitivity (GimpTransformTool *tr_tool)
   gimp_tool_gui_set_response_sensitive (tr_tool->gui, RESPONSE_RESET,
                                         g_list_next (tr_tool->undo_list) != NULL);
 }
+
+static GimpItem *
+gimp_transform_tool_get_active_item (GimpTransformTool *tr_tool,
+                                     GimpImage         *image)
+{
+  GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
+
+  switch (options->type)
+    {
+    case GIMP_TRANSFORM_TYPE_LAYER:
+      return GIMP_ITEM (gimp_image_get_active_drawable (image));
+
+    case GIMP_TRANSFORM_TYPE_SELECTION:
+      return GIMP_ITEM (gimp_image_get_mask (image));
+
+    case GIMP_TRANSFORM_TYPE_PATH:
+      return GIMP_ITEM (gimp_image_get_active_vectors (image));
+    }
+
+  return NULL;
+}
+
+static GimpItem *
+gimp_transform_tool_check_active_item (GimpTransformTool  *tr_tool,
+                                       GimpImage          *image,
+                                       GError            **error)
+{
+  GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
+  GimpItem             *item;
+  const gchar          *null_message   = NULL;
+  const gchar          *locked_message = NULL;
+
+  item = gimp_transform_tool_get_active_item (tr_tool, image);
+
+  switch (options->type)
+    {
+    case GIMP_TRANSFORM_TYPE_LAYER:
+      null_message = _("There is no layer to transform.");
+
+      if (item && gimp_item_is_content_locked (item))
+        locked_message = _("The active layer's pixels are locked.");
+      else
+        locked_message = _("The active layer's position and size are locked.");
+
+      if (item && ! gimp_item_is_visible (item))
+        {
+          g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
+                               _("The active layer is not visible."));
+          return NULL;
+        }
+      break;
+
+    case GIMP_TRANSFORM_TYPE_SELECTION:
+      /* cannot happen, so don't translate these messages */
+      null_message = "There is no selection to transform.";
+
+      if (item && gimp_item_is_content_locked (item))
+        locked_message = "The selection's pixels are locked.";
+      else
+        locked_message = "The selection's position and size are locked.";
+      break;
+
+    case GIMP_TRANSFORM_TYPE_PATH:
+      null_message = _("There is no path to transform.");
+
+      if (item && gimp_item_is_content_locked (item))
+        locked_message = _("The active path's strokes are locked.");
+      else
+        locked_message = _("The active path's position is locked.");
+      break;
+    }
+
+  if (! item)
+    {
+      g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, null_message);
+      return NULL;
+    }
+
+  if (gimp_item_is_content_locked (item) ||
+      gimp_item_is_position_locked (item))
+    {
+      g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, locked_message);
+      return NULL;
+    }
+
+  return item;
+}


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