Improving undo strings (work in progress)

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

 



Thanks to help from Mitch to get me started, I've had another go at
improving the gimp undo strings for the transform tools.

This patch changes the labels shown under Edit->Undo, Edit->Redo and
also the undo history.

If this goes down well I could do it for more cases. Right now it
affects the following strings in the undo history:

Old:      New:
==============================================
Flip        Flip Horizontal, or Flip Vertical
Rotate      Rotate 15 at (300, 206)
Shear       Shear x=10 y=0
     note: if you enter numbers into both fields in the shear dialogue,
     it accepts them both but only uses one. This is a bug somewhere in
     the shear tool _or_ in the dialogue.  If the latter, the dialogue
     should have just "Amount: " and a horizontal/vertical choice.

Perspective unchanged, since you can't enter the numbers in the dialogue
     box and it would be an exercise in frustration for people to try
     and drag the handles to match the numbers.  I had a patch once that
     used entries there, but abandoned it because supposedly the
     transform tools were all being redone.

Scale       Scale x=300 y=200.
     note: The values in the dialogue box do not show the centre of the
     transform, so you can't always reuse the numbers and get the same
     result.  It's a UI bug. I've left off the centre coordinates here.


Comments?

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/

diff --git a/app/tools/gimpfliptool.c b/app/tools/gimpfliptool.c
index 360e9c0..56e4f99 100644
--- a/app/tools/gimpfliptool.c
+++ b/app/tools/gimpfliptool.c
@@ -64,6 +64,7 @@ static TileManager * gimp_flip_tool_transform     (GimpTransformTool *tool,
                                                    gint              *new_offset_x,
                                                    gint              *new_offset_y);
 
+static gchar *gimp_flip_tool_get_undo_desc (GimpTransformTool  *tr_tool);
 
 G_DEFINE_TYPE (GimpFlipTool, gimp_flip_tool, GIMP_TYPE_TRANSFORM_TOOL)
 
@@ -98,13 +99,33 @@ gimp_flip_tool_class_init (GimpFlipToolClass *klass)
   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;
 }
 
+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_("command", "Flip Horizontal"));
+    case GIMP_ORIENTATION_VERTICAL:
+      return g_strdup(C_("command", "Flip Vertical"));
+    default:
+      /* probably this is not actually reached today, but
+       * could be if someone defined FLIP_DIAGONAL, say...
+       */
+      return g_strdup(C_("command", "Flip"));
+    }
+}
+
+
 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,
@@ -116,7 +137,6 @@ gimp_flip_tool_init (GimpFlipTool *flip_tool)
   gimp_tool_control_set_toggle_tool_cursor (tool->control,
                                             GIMP_TOOL_CURSOR_FLIP_VERTICAL);
 
-  tr_tool->undo_desc = C_("command", "Flip");
 }
 
 static void
diff --git a/app/tools/gimpperspectivetool.c b/app/tools/gimpperspectivetool.c
index 63220b4..8f7c8c6 100644
--- a/app/tools/gimpperspectivetool.c
+++ b/app/tools/gimpperspectivetool.c
@@ -63,6 +63,7 @@ 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;
@@ -171,6 +172,12 @@ gimp_perspective_tool_dialog_update (GimpTransformTool *tr_tool)
       }
 }
 
+static gchar *
+gimp_perspective_tool_get_undo_desc (GimpTransformTool  *tr_tool)
+{
+  return g_strdup(C_("command", "Perspective"));
+}
+
 static void
 gimp_perspective_tool_prepare (GimpTransformTool  *tr_tool)
 {
diff --git a/app/tools/gimprotatetool.c b/app/tools/gimprotatetool.c
index f320541..83594f3 100644
--- a/app/tools/gimprotatetool.c
+++ b/app/tools/gimprotatetool.c
@@ -71,6 +71,7 @@ static void     rotate_angle_changed           (GtkAdjustment       *adj,
                                                 GimpTransformTool   *tr_tool);
 static void     rotate_center_changed          (GtkWidget           *entry,
                                                 GimpTransformTool   *tr_tool);
+static gchar *gimp_rotate_tool_get_undo_desc (GimpTransformTool  *tr_tool);
 
 
 G_DEFINE_TYPE (GimpRotateTool, gimp_rotate_tool, GIMP_TYPE_TRANSFORM_TOOL)
@@ -108,6 +109,17 @@ 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 gchar *
+gimp_rotate_tool_get_undo_desc (GimpTransformTool  *tr_tool)
+{
+  return g_strdup_printf("%s %-3.3g at (%g, %g)",
+    C_("command", "Rotate"),
+    gimp_rad_to_deg (tr_tool->trans_info[ANGLE]),
+    tr_tool->trans_info[CENTER_X],
+    tr_tool->trans_info[CENTER_Y]);
 }
 
 static void
@@ -118,7 +130,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;
diff --git a/app/tools/gimpscaletool.c b/app/tools/gimpscaletool.c
index f2812af..d08eb73 100644
--- a/app/tools/gimpscaletool.c
+++ b/app/tools/gimpscaletool.c
@@ -70,6 +70,8 @@ static void   gimp_scale_tool_size_notify   (GtkWidget          *box,
                                              GParamSpec         *pspec,
                                              GimpTransformTool  *tr_tool);
 
+static gchar *gimp_scale_tool_get_undo_desc (GimpTransformTool  *tr_tool);
+
 
 G_DEFINE_TYPE (GimpScaleTool, gimp_scale_tool, GIMP_TYPE_TRANSFORM_TOOL)
 
@@ -103,6 +105,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 +116,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;
@@ -122,6 +124,17 @@ gimp_scale_tool_init (GimpScaleTool *scale_tool)
   tr_tool->use_mid_handles = TRUE;
 }
 
+static gchar *
+gimp_scale_tool_get_undo_desc (GimpTransformTool  *tr_tool)
+{
+  GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (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("%s x=%d y=%d", C_("command", "Scale"), width, height);
+}
+
+
 static void
 gimp_scale_tool_dialog (GimpTransformTool *tr_tool)
 {
diff --git a/app/tools/gimpsheartool.c b/app/tools/gimpsheartool.c
index f83d340..7d4f1ef 100644
--- a/app/tools/gimpsheartool.c
+++ b/app/tools/gimpsheartool.c
@@ -66,6 +66,7 @@ static void   shear_x_mag_changed           (GtkAdjustment      *adj,
 static void   shear_y_mag_changed           (GtkAdjustment      *adj,
                                              GimpTransformTool  *tr_tool);
 
+static gchar *gimp_shear_tool_get_undo_desc (GimpTransformTool  *tr_tool);
 
 G_DEFINE_TYPE (GimpShearTool, gimp_shear_tool, GIMP_TYPE_TRANSFORM_TOOL)
 
@@ -87,6 +88,15 @@ gimp_shear_tool_register (GimpToolRegisterCallback  callback,
                 data);
 }
 
+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];
+  return g_strdup_printf("%s x=%-3.3g y=%-3.3g", C_("command", "Shear"), x, y);
+}
+
+
 static void
 gimp_shear_tool_class_init (GimpShearToolClass *klass)
 {
@@ -97,6 +107,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 +118,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;
diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c
index 5b2a7cd..0a9588f 100644
--- a/app/tools/gimptransformtool.c
+++ b/app/tools/gimptransformtool.c
@@ -184,6 +184,7 @@ gimp_transform_tool_class_init (GimpTransformToolClass *klass)
   klass->motion                   = NULL;
   klass->recalc_matrix            = NULL;
   klass->transform                = gimp_transform_tool_real_transform;
+  klass->get_undo_desc            = NULL;
 }
 
 static void
@@ -1050,6 +1051,7 @@ gimp_transform_tool_transform (GimpTransformTool *tr_tool,
   const gchar          *null_message   = NULL;
   const gchar          *locked_message = NULL;
   gboolean              new_layer;
+  gchar                *undo_desc = NULL;
 
   switch (options->type)
     {
@@ -1098,8 +1100,12 @@ 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);
+  if (undo_desc)
+    {
+      g_free(undo_desc); /* undo_group_start saves a copy */
+    }
 
   switch (options->type)
     {
diff --git a/app/tools/gimptransformtool.h b/app/tools/gimptransformtool.h
index 04e64e2..d3d8eed 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;
@@ -112,6 +111,7 @@ struct _GimpTransformToolClass
                                    gint               orig_offset_y,
                                    gint              *new_offset_x,
                                    gint              *new_offset_y);
+  gchar *       (* get_undo_desc)     (GimpTransformTool *tool);
 };
 
 
_______________________________________________
Gimp-developer mailing list
Gimp-developer@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux