[gimp] app: improve the undo strings of the transform tools



commit 5a7c517574e11893139930f6190a0e6c2a325704
Author: Michael Natterer <mitch gimp org>
Date:   Sat Aug 27 08:37:30 2011 +0200

    app: improve the undo strings of the transform tools
    
    Apply modified patch from Liam Quin which replaces the hardcoded
    undo strings by dynamic ones returned by a new virtual function
    of GimpTransformTool.

 app/tools/gimpfliptool.c        |   32 +++++++++++++++++++++++-----
 app/tools/gimpperspectivetool.c |   19 +++++++++++-----
 app/tools/gimprotatetool.c      |   37 ++++++++++++++++++++++----------
 app/tools/gimpscaletool.c       |   29 +++++++++++++++++--------
 app/tools/gimpsheartool.c       |   44 ++++++++++++++++++++++++++++++--------
 app/tools/gimptransformtool.c   |    7 ++++-
 app/tools/gimptransformtool.h   |    2 +-
 7 files changed, 124 insertions(+), 46 deletions(-)
---
diff --git a/app/tools/gimpfliptool.c b/app/tools/gimpfliptool.c
index 360e9c0..47b3889 100644
--- a/app/tools/gimpfliptool.c
+++ b/app/tools/gimpfliptool.c
@@ -56,6 +56,7 @@ static void          gimp_flip_tool_cursor_update (GimpTool          *tool,
                                                    GdkModifierType    state,
                                                    GimpDisplay       *display);
 
+static gchar       * gimp_flip_tool_get_undo_desc (GimpTransformTool *tool);
 static TileManager * gimp_flip_tool_transform     (GimpTransformTool *tool,
                                                    GimpItem          *item,
                                                    TileManager       *orig_tiles,
@@ -94,17 +95,17 @@ gimp_flip_tool_class_init (GimpFlipToolClass *klass)
   GimpToolClass          *tool_class  = GIMP_TOOL_CLASS (klass);
   GimpTransformToolClass *trans_class = GIMP_TRANSFORM_TOOL_CLASS (klass);
 
-  tool_class->modifier_key  = gimp_flip_tool_modifier_key;
-  tool_class->cursor_update = gimp_flip_tool_cursor_update;
+  tool_class->modifier_key   = gimp_flip_tool_modifier_key;
+  tool_class->cursor_update  = gimp_flip_tool_cursor_update;
 
-  trans_class->transform    = gimp_flip_tool_transform;
+  trans_class->get_undo_desc = gimp_flip_tool_get_undo_desc;
+  trans_class->transform     = gimp_flip_tool_transform;
 }
 
 static void
 gimp_flip_tool_init (GimpFlipTool *flip_tool)
 {
   GimpTool *tool = GIMP_TOOL (flip_tool);
-  GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (flip_tool);
 
   gimp_tool_control_set_snap_to            (tool->control, FALSE);
   gimp_tool_control_set_precision          (tool->control,
@@ -115,8 +116,6 @@ gimp_flip_tool_init (GimpFlipTool *flip_tool)
                                             GIMP_TOOL_CURSOR_FLIP_HORIZONTAL);
   gimp_tool_control_set_toggle_tool_cursor (tool->control,
                                             GIMP_TOOL_CURSOR_FLIP_VERTICAL);
-
-  tr_tool->undo_desc = C_("command", "Flip");
 }
 
 static void
@@ -176,6 +175,27 @@ gimp_flip_tool_cursor_update (GimpTool         *tool,
   GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
 }
 
+static gchar *
+gimp_flip_tool_get_undo_desc (GimpTransformTool *tr_tool)
+{
+  GimpFlipOptions *options = GIMP_FLIP_TOOL_GET_OPTIONS (tr_tool);
+
+  switch (options->flip_type)
+    {
+    case GIMP_ORIENTATION_HORIZONTAL:
+      return g_strdup (C_("undo-type", "Flip horizontally"));
+
+    case GIMP_ORIENTATION_VERTICAL:
+      return g_strdup (C_("undo-type", "Flip vertically"));
+
+    default:
+      /* probably this is not actually reached today, but
+       * could be if someone defined FLIP_DIAGONAL, say...
+       */
+      return g_strdup (C_("undo-desc", "Flip"));
+    }
+}
+
 static TileManager *
 gimp_flip_tool_transform (GimpTransformTool *trans_tool,
                           GimpItem          *active_item,
diff --git a/app/tools/gimpperspectivetool.c b/app/tools/gimpperspectivetool.c
index 63220b4..632842b 100644
--- a/app/tools/gimpperspectivetool.c
+++ b/app/tools/gimpperspectivetool.c
@@ -58,11 +58,12 @@ enum
 
 /*  local function prototypes  */
 
-static void   gimp_perspective_tool_dialog        (GimpTransformTool *tr_tool);
-static void   gimp_perspective_tool_dialog_update (GimpTransformTool *tr_tool);
-static void   gimp_perspective_tool_prepare       (GimpTransformTool *tr_tool);
-static void   gimp_perspective_tool_motion        (GimpTransformTool *tr_tool);
-static void   gimp_perspective_tool_recalc_matrix (GimpTransformTool *tr_tool);
+static void    gimp_perspective_tool_dialog        (GimpTransformTool *tr_tool);
+static void    gimp_perspective_tool_dialog_update (GimpTransformTool *tr_tool);
+static void    gimp_perspective_tool_prepare       (GimpTransformTool *tr_tool);
+static void    gimp_perspective_tool_motion        (GimpTransformTool *tr_tool);
+static void    gimp_perspective_tool_recalc_matrix (GimpTransformTool *tr_tool);
+static gchar * gimp_perspective_tool_get_undo_desc (GimpTransformTool *tr_tool);
 
 
 G_DEFINE_TYPE (GimpPerspectiveTool, gimp_perspective_tool,
@@ -97,6 +98,7 @@ gimp_perspective_tool_class_init (GimpPerspectiveToolClass *klass)
   trans_class->prepare       = gimp_perspective_tool_prepare;
   trans_class->motion        = gimp_perspective_tool_motion;
   trans_class->recalc_matrix = gimp_perspective_tool_recalc_matrix;
+  trans_class->get_undo_desc = gimp_perspective_tool_get_undo_desc;
 }
 
 static void
@@ -108,7 +110,6 @@ gimp_perspective_tool_init (GimpPerspectiveTool *perspective_tool)
   gimp_tool_control_set_tool_cursor (tool->control,
                                      GIMP_TOOL_CURSOR_PERSPECTIVE);
 
-  tr_tool->undo_desc     = C_("command", "Perspective");
   tr_tool->progress_text = _("Perspective transformation");
 
   tr_tool->use_grid      = TRUE;
@@ -248,3 +249,9 @@ gimp_perspective_tool_recalc_matrix (GimpTransformTool *tr_tool)
                                      tr_tool->trans_info[X3],
                                      tr_tool->trans_info[Y3]);
 }
+
+static gchar *
+gimp_perspective_tool_get_undo_desc (GimpTransformTool *tr_tool)
+{
+  return g_strdup (C_("undo-type", "Perspective"));
+}
diff --git a/app/tools/gimprotatetool.c b/app/tools/gimprotatetool.c
index f320541..18b8e42 100644
--- a/app/tools/gimprotatetool.c
+++ b/app/tools/gimprotatetool.c
@@ -59,17 +59,20 @@ enum
 
 /*  local function prototypes  */
 
-static gboolean gimp_rotate_tool_key_press     (GimpTool            *tool,
-                                                GdkEventKey         *kevent,
-                                                GimpDisplay         *display);
-static void     gimp_rotate_tool_dialog        (GimpTransformTool   *tr_tool);
-static void     gimp_rotate_tool_dialog_update (GimpTransformTool   *tr_tool);
-static void     gimp_rotate_tool_prepare       (GimpTransformTool   *tr_tool);
-static void     gimp_rotate_tool_motion        (GimpTransformTool   *tr_tool);
-static void     gimp_rotate_tool_recalc_matrix (GimpTransformTool   *tr_tool);
-static void     rotate_angle_changed           (GtkAdjustment       *adj,
-                                                GimpTransformTool   *tr_tool);
-static void     rotate_center_changed          (GtkWidget           *entry,
+static gboolean  gimp_rotate_tool_key_press     (GimpTool           *tool,
+                                                 GdkEventKey        *kevent,
+                                                 GimpDisplay        *display);
+
+static void      gimp_rotate_tool_dialog        (GimpTransformTool  *tr_tool);
+static void      gimp_rotate_tool_dialog_update (GimpTransformTool  *tr_tool);
+static void      gimp_rotate_tool_prepare       (GimpTransformTool  *tr_tool);
+static void      gimp_rotate_tool_motion        (GimpTransformTool  *tr_tool);
+static void      gimp_rotate_tool_recalc_matrix (GimpTransformTool  *tr_tool);
+static gchar   * gimp_rotate_tool_get_undo_desc (GimpTransformTool  *tr_tool);
+
+static void      rotate_angle_changed           (GtkAdjustment      *adj,
+                                                 GimpTransformTool  *tr_tool);
+static void      rotate_center_changed          (GtkWidget          *entry,
                                                 GimpTransformTool   *tr_tool);
 
 
@@ -108,6 +111,7 @@ gimp_rotate_tool_class_init (GimpRotateToolClass *klass)
   trans_class->prepare       = gimp_rotate_tool_prepare;
   trans_class->motion        = gimp_rotate_tool_motion;
   trans_class->recalc_matrix = gimp_rotate_tool_recalc_matrix;
+  trans_class->get_undo_desc = gimp_rotate_tool_get_undo_desc;
 }
 
 static void
@@ -118,7 +122,6 @@ gimp_rotate_tool_init (GimpRotateTool *rotate_tool)
 
   gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_ROTATE);
 
-  tr_tool->undo_desc     = C_("command", "Rotate");
   tr_tool->progress_text = _("Rotating");
 
   tr_tool->use_grid      = TRUE;
@@ -363,6 +366,16 @@ gimp_rotate_tool_recalc_matrix (GimpTransformTool *tr_tool)
                                        tr_tool->trans_info[ANGLE]);
 }
 
+static gchar *
+gimp_rotate_tool_get_undo_desc (GimpTransformTool  *tr_tool)
+{
+  return g_strdup_printf (C_("undo-type",
+                             "Rotate by %-3.3g around (%g, %g)"),
+                          gimp_rad_to_deg (tr_tool->trans_info[ANGLE]),
+                          tr_tool->trans_info[CENTER_X],
+                          tr_tool->trans_info[CENTER_Y]);
+}
+
 static void
 rotate_angle_changed (GtkAdjustment     *adj,
                       GimpTransformTool *tr_tool)
diff --git a/app/tools/gimpscaletool.c b/app/tools/gimpscaletool.c
index f2812af..6120265 100644
--- a/app/tools/gimpscaletool.c
+++ b/app/tools/gimpscaletool.c
@@ -60,15 +60,16 @@ enum
 
 /*  local function prototypes  */
 
-static void   gimp_scale_tool_dialog        (GimpTransformTool  *tr_tool);
-static void   gimp_scale_tool_dialog_update (GimpTransformTool  *tr_tool);
-static void   gimp_scale_tool_prepare       (GimpTransformTool  *tr_tool);
-static void   gimp_scale_tool_motion        (GimpTransformTool  *tr_tool);
-static void   gimp_scale_tool_recalc_matrix (GimpTransformTool  *tr_tool);
+static void    gimp_scale_tool_dialog        (GimpTransformTool  *tr_tool);
+static void    gimp_scale_tool_dialog_update (GimpTransformTool  *tr_tool);
+static void    gimp_scale_tool_prepare       (GimpTransformTool  *tr_tool);
+static void    gimp_scale_tool_motion        (GimpTransformTool  *tr_tool);
+static void    gimp_scale_tool_recalc_matrix (GimpTransformTool  *tr_tool);
+static gchar * gimp_scale_tool_get_undo_desc (GimpTransformTool  *tr_tool);
 
-static void   gimp_scale_tool_size_notify   (GtkWidget          *box,
-                                             GParamSpec         *pspec,
-                                             GimpTransformTool  *tr_tool);
+static void    gimp_scale_tool_size_notify   (GtkWidget          *box,
+                                              GParamSpec         *pspec,
+                                              GimpTransformTool  *tr_tool);
 
 
 G_DEFINE_TYPE (GimpScaleTool, gimp_scale_tool, GIMP_TYPE_TRANSFORM_TOOL)
@@ -103,6 +104,7 @@ gimp_scale_tool_class_init (GimpScaleToolClass *klass)
   trans_class->prepare       = gimp_scale_tool_prepare;
   trans_class->motion        = gimp_scale_tool_motion;
   trans_class->recalc_matrix = gimp_scale_tool_recalc_matrix;
+  trans_class->get_undo_desc = gimp_scale_tool_get_undo_desc;
 }
 
 static void
@@ -113,7 +115,6 @@ gimp_scale_tool_init (GimpScaleTool *scale_tool)
 
   gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_RESIZE);
 
-  tr_tool->undo_desc       = C_("command", "Scale");
   tr_tool->progress_text   = _("Scaling");
 
   tr_tool->use_grid        = TRUE;
@@ -328,6 +329,16 @@ gimp_scale_tool_recalc_matrix (GimpTransformTool *tr_tool)
                                tr_tool->trans_info[Y1] - tr_tool->trans_info[Y0]);
 }
 
+static gchar *
+gimp_scale_tool_get_undo_desc (GimpTransformTool *tr_tool)
+{
+  gint width  = ROUND (tr_tool->trans_info[X1] - tr_tool->trans_info[X0]);
+  gint height = ROUND (tr_tool->trans_info[Y1] - tr_tool->trans_info[Y0]);
+
+  return g_strdup_printf (C_("undo-type", "Scale to %d x %d"),
+                          width, height);
+}
+
 static void
 gimp_scale_tool_size_notify (GtkWidget         *box,
                              GParamSpec        *pspec,
diff --git a/app/tools/gimpsheartool.c b/app/tools/gimpsheartool.c
index f83d340..084a89f 100644
--- a/app/tools/gimpsheartool.c
+++ b/app/tools/gimpsheartool.c
@@ -54,17 +54,18 @@ enum
 
 /*  local function prototypes  */
 
-static void   gimp_shear_tool_dialog        (GimpTransformTool  *tr_tool);
-static void   gimp_shear_tool_dialog_update (GimpTransformTool  *tr_tool);
+static void    gimp_shear_tool_dialog        (GimpTransformTool  *tr_tool);
+static void    gimp_shear_tool_dialog_update (GimpTransformTool  *tr_tool);
 
-static void   gimp_shear_tool_prepare       (GimpTransformTool  *tr_tool);
-static void   gimp_shear_tool_motion        (GimpTransformTool  *tr_tool);
-static void   gimp_shear_tool_recalc_matrix (GimpTransformTool  *tr_tool);
+static void    gimp_shear_tool_prepare       (GimpTransformTool  *tr_tool);
+static void    gimp_shear_tool_motion        (GimpTransformTool  *tr_tool);
+static void    gimp_shear_tool_recalc_matrix (GimpTransformTool  *tr_tool);
+static gchar * gimp_shear_tool_get_undo_desc (GimpTransformTool  *tr_tool);
 
-static void   shear_x_mag_changed           (GtkAdjustment      *adj,
-                                             GimpTransformTool  *tr_tool);
-static void   shear_y_mag_changed           (GtkAdjustment      *adj,
-                                             GimpTransformTool  *tr_tool);
+static void    shear_x_mag_changed           (GtkAdjustment      *adj,
+                                              GimpTransformTool  *tr_tool);
+static void    shear_y_mag_changed           (GtkAdjustment      *adj,
+                                              GimpTransformTool  *tr_tool);
 
 
 G_DEFINE_TYPE (GimpShearTool, gimp_shear_tool, GIMP_TYPE_TRANSFORM_TOOL)
@@ -97,6 +98,7 @@ gimp_shear_tool_class_init (GimpShearToolClass *klass)
   trans_class->prepare       = gimp_shear_tool_prepare;
   trans_class->motion        = gimp_shear_tool_motion;
   trans_class->recalc_matrix = gimp_shear_tool_recalc_matrix;
+  trans_class->get_undo_desc = gimp_shear_tool_get_undo_desc;
 }
 
 static void
@@ -107,7 +109,6 @@ gimp_shear_tool_init (GimpShearTool *shear_tool)
 
   gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_SHEAR);
 
-  tr_tool->undo_desc     = C_("command", "Shear");
   tr_tool->progress_text = _("Shearing");
 
   tr_tool->use_grid      = TRUE;
@@ -242,6 +243,29 @@ gimp_shear_tool_recalc_matrix (GimpTransformTool *tr_tool)
                                amount);
 }
 
+static gchar *
+gimp_shear_tool_get_undo_desc (GimpTransformTool *tr_tool)
+{
+  gdouble x = tr_tool->trans_info[XSHEAR];
+  gdouble y = tr_tool->trans_info[YSHEAR];
+
+  switch ((gint) tr_tool->trans_info[HORZ_OR_VERT])
+    {
+    case GIMP_ORIENTATION_HORIZONTAL:
+      return g_strdup_printf (C_("undo-type", "Shear horizontally by %-3.3g"),
+                              x);
+
+    case GIMP_ORIENTATION_VERTICAL:
+      return g_strdup_printf (C_("undo-type", "Shear vertically by %-3.3g"),
+                              y);
+
+    default:
+      /* e.g. user entered numbers but no notification callback */
+      return g_strdup_printf (C_("undo-type", "Shear horizontally by %-3.3g, vertically by %-3.3g"),
+                              x, y);
+    }
+}
+
 static void
 shear_x_mag_changed (GtkAdjustment     *adj,
                      GimpTransformTool *tr_tool)
diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c
index 5b2a7cd..21cbf3f 100644
--- a/app/tools/gimptransformtool.c
+++ b/app/tools/gimptransformtool.c
@@ -183,6 +183,7 @@ gimp_transform_tool_class_init (GimpTransformToolClass *klass)
   klass->prepare                  = NULL;
   klass->motion                   = NULL;
   klass->recalc_matrix            = NULL;
+  klass->get_undo_desc            = NULL;
   klass->transform                = gimp_transform_tool_real_transform;
 }
 
@@ -1049,6 +1050,7 @@ gimp_transform_tool_transform (GimpTransformTool *tr_tool,
   gint                  new_offset_y;
   const gchar          *null_message   = NULL;
   const gchar          *locked_message = NULL;
+  gchar                *undo_desc      = NULL;
   gboolean              new_layer;
 
   switch (options->type)
@@ -1098,8 +1100,9 @@ gimp_transform_tool_transform (GimpTransformTool *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_image_undo_group_start (image, GIMP_UNDO_GROUP_TRANSFORM,
-                               tr_tool->undo_desc);
+  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);
+  g_free (undo_desc);
 
   switch (options->type)
     {
diff --git a/app/tools/gimptransformtool.h b/app/tools/gimptransformtool.h
index 04e64e2..290d576 100644
--- a/app/tools/gimptransformtool.h
+++ b/app/tools/gimptransformtool.h
@@ -89,7 +89,6 @@ struct _GimpTransformTool
 
   GimpCanvasItem *handles[TRANSFORM_HANDLE_CENTER + 1];
 
-  const gchar    *undo_desc;
   const gchar    *progress_text;
 
   GtkWidget      *dialog;
@@ -105,6 +104,7 @@ struct _GimpTransformToolClass
   void          (* prepare)       (GimpTransformTool *tool);
   void          (* motion)        (GimpTransformTool *tool);
   void          (* recalc_matrix) (GimpTransformTool *tool);
+  gchar       * (* get_undo_desc) (GimpTransformTool *tool);
   TileManager * (* transform)     (GimpTransformTool *tool,
                                    GimpItem          *item,
                                    TileManager       *orig_tiles,



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