[gimp] app: simplify GimpTool::undo() and ::redo()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: simplify GimpTool::undo() and ::redo()
- Date: Sun, 9 Jul 2017 15:23:20 +0000 (UTC)
commit 6a312a71f3359a7f609f1b28beab781198349409
Author: Michael Natterer <mitch gimp org>
Date: Sun Jul 9 17:22:06 2017 +0200
app: simplify GimpTool::undo() and ::redo()
Check for gimp_tool_can_undo() and can_redo() in gimptool.c, before
calling undo() and redo(), instead of doing the same in each tool
individually.
app/tools/gimpblendtool.c | 12 +-------
app/tools/gimpforegroundselecttool.c | 48 ++++++++++++---------------------
app/tools/gimpiscissorstool.c | 10 +-----
app/tools/gimptool.c | 4 +-
app/tools/gimptransformtool.c | 17 +++---------
app/tools/gimpwarptool.c | 11 --------
6 files changed, 28 insertions(+), 74 deletions(-)
---
diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c
index 6c1e30c..a3aa248 100644
--- a/app/tools/gimpblendtool.c
+++ b/app/tools/gimpblendtool.c
@@ -443,9 +443,8 @@ gimp_blend_tool_can_undo (GimpTool *tool,
GimpDisplay *display)
{
GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);
- GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
- if (display != draw_tool->display || ! blend_tool->undo_stack)
+ if (! blend_tool->undo_stack)
return NULL;
return _("Blend Step");
@@ -456,9 +455,8 @@ gimp_blend_tool_can_redo (GimpTool *tool,
GimpDisplay *display)
{
GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);
- GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
- if (display != draw_tool->display || ! blend_tool->redo_stack)
+ if (! blend_tool->redo_stack)
return NULL;
return _("Blend Step");
@@ -471,9 +469,6 @@ gimp_blend_tool_undo (GimpTool *tool,
GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);
BlendInfo *info;
- if (! gimp_blend_tool_can_undo (tool, display))
- return FALSE;
-
info = blend_info_new (blend_tool->start_x,
blend_tool->start_y,
blend_tool->end_x,
@@ -502,9 +497,6 @@ gimp_blend_tool_redo (GimpTool *tool,
GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);
BlendInfo *info;
- if (! gimp_blend_tool_can_redo (tool, display))
- return FALSE;
-
info = blend_info_new (blend_tool->start_x,
blend_tool->start_y,
blend_tool->end_x,
diff --git a/app/tools/gimpforegroundselecttool.c b/app/tools/gimpforegroundselecttool.c
index 4aa51d0..2f036e5 100644
--- a/app/tools/gimpforegroundselecttool.c
+++ b/app/tools/gimpforegroundselecttool.c
@@ -713,25 +713,19 @@ gimp_foreground_select_tool_undo (GimpTool *tool,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
+ StrokeUndo *undo = fg_select->undo_stack->data;
- if (fg_select->undo_stack)
- {
- StrokeUndo *undo = fg_select->undo_stack->data;
-
- gimp_foreground_select_undo_pop (undo, fg_select->trimap);
+ gimp_foreground_select_undo_pop (undo, fg_select->trimap);
- fg_select->undo_stack = g_list_remove (fg_select->undo_stack, undo);
- fg_select->redo_stack = g_list_prepend (fg_select->redo_stack, undo);
+ fg_select->undo_stack = g_list_remove (fg_select->undo_stack, undo);
+ fg_select->redo_stack = g_list_prepend (fg_select->redo_stack, undo);
- if (fg_select->state == MATTING_STATE_PREVIEW_MASK)
- gimp_foreground_select_tool_preview (fg_select);
- else
- gimp_foreground_select_tool_set_trimap (fg_select);
-
- return TRUE;
- }
+ if (fg_select->state == MATTING_STATE_PREVIEW_MASK)
+ gimp_foreground_select_tool_preview (fg_select);
+ else
+ gimp_foreground_select_tool_set_trimap (fg_select);
- return FALSE;
+ return TRUE;
}
static gboolean
@@ -739,25 +733,19 @@ gimp_foreground_select_tool_redo (GimpTool *tool,
GimpDisplay *display)
{
GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);
+ StrokeUndo *undo = fg_select->redo_stack->data;
- if (fg_select->redo_stack)
- {
- StrokeUndo *undo = fg_select->redo_stack->data;
-
- gimp_foreground_select_undo_pop (undo, fg_select->trimap);
-
- fg_select->redo_stack = g_list_remove (fg_select->redo_stack, undo);
- fg_select->undo_stack = g_list_prepend (fg_select->undo_stack, undo);
+ gimp_foreground_select_undo_pop (undo, fg_select->trimap);
- if (fg_select->state == MATTING_STATE_PREVIEW_MASK)
- gimp_foreground_select_tool_preview (fg_select);
- else
- gimp_foreground_select_tool_set_trimap (fg_select);
+ fg_select->redo_stack = g_list_remove (fg_select->redo_stack, undo);
+ fg_select->undo_stack = g_list_prepend (fg_select->undo_stack, undo);
- return TRUE;
- }
+ if (fg_select->state == MATTING_STATE_PREVIEW_MASK)
+ gimp_foreground_select_tool_preview (fg_select);
+ else
+ gimp_foreground_select_tool_set_trimap (fg_select);
- return FALSE;
+ return TRUE;
}
static void
diff --git a/app/tools/gimpiscissorstool.c b/app/tools/gimpiscissorstool.c
index eafe7e2..a4df02f 100644
--- a/app/tools/gimpiscissorstool.c
+++ b/app/tools/gimpiscissorstool.c
@@ -1111,7 +1111,7 @@ gimp_iscissors_tool_can_undo (GimpTool *tool,
{
GimpIscissorsTool *iscissors = GIMP_ISCISSORS_TOOL (tool);
- if (display != tool->display || ! iscissors->undo_stack)
+ if (! iscissors->undo_stack)
return NULL;
return _("Modify Scissors Curve");
@@ -1123,7 +1123,7 @@ gimp_iscissors_tool_can_redo (GimpTool *tool,
{
GimpIscissorsTool *iscissors = GIMP_ISCISSORS_TOOL (tool);
- if (display != tool->display || ! iscissors->redo_stack)
+ if (! iscissors->redo_stack)
return NULL;
return _("Modify Scissors Curve");
@@ -1135,9 +1135,6 @@ gimp_iscissors_tool_undo (GimpTool *tool,
{
GimpIscissorsTool *iscissors = GIMP_ISCISSORS_TOOL (tool);
- if (! gimp_iscissors_tool_can_undo (tool, display))
- return FALSE;
-
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
iscissors->redo_stack = g_list_prepend (iscissors->redo_stack,
@@ -1166,9 +1163,6 @@ gimp_iscissors_tool_redo (GimpTool *tool,
{
GimpIscissorsTool *iscissors = GIMP_ISCISSORS_TOOL (tool);
- if (! gimp_iscissors_tool_can_redo (tool, display))
- return FALSE;
-
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
if (! iscissors->undo_stack)
diff --git a/app/tools/gimptool.c b/app/tools/gimptool.c
index 4500792..b61ecec 100644
--- a/app/tools/gimptool.c
+++ b/app/tools/gimptool.c
@@ -1202,7 +1202,7 @@ gimp_tool_undo (GimpTool *tool,
g_return_val_if_fail (GIMP_IS_TOOL (tool), FALSE);
g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
- if (display == tool->display)
+ if (gimp_tool_can_undo (tool, display))
return GIMP_TOOL_GET_CLASS (tool)->undo (tool, display);
return FALSE;
@@ -1215,7 +1215,7 @@ gimp_tool_redo (GimpTool *tool,
g_return_val_if_fail (GIMP_IS_TOOL (tool), FALSE);
g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
- if (display == tool->display)
+ if (gimp_tool_can_redo (tool, display))
return GIMP_TOOL_GET_CLASS (tool)->redo (tool, display);
return FALSE;
diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c
index cd90d18..f8bc991 100644
--- a/app/tools/gimptransformtool.c
+++ b/app/tools/gimptransformtool.c
@@ -519,11 +519,9 @@ static const gchar *
gimp_transform_tool_can_undo (GimpTool *tool,
GimpDisplay *display)
{
- GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
- GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
+ GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
- if (display != draw_tool->display || ! tr_tool->undo_list ||
- ! tr_tool->undo_list->next)
+ if (! tr_tool->undo_list || ! tr_tool->undo_list->next)
return NULL;
return _("Transform Step");
@@ -533,10 +531,9 @@ static const gchar *
gimp_transform_tool_can_redo (GimpTool *tool,
GimpDisplay *display)
{
- GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
- GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
+ GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
- if (display != draw_tool->display || ! tr_tool->redo_list)
+ if (! tr_tool->redo_list)
return NULL;
return _("Transform Step");
@@ -549,9 +546,6 @@ gimp_transform_tool_undo (GimpTool *tool,
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
GList *item;
- if (! gimp_transform_tool_can_undo (tool, display))
- return FALSE;
-
item = g_list_next (tr_tool->undo_list);
/* Move prev_trans_info from undo_list to redo_list */
@@ -582,9 +576,6 @@ gimp_transform_tool_redo (GimpTool *tool,
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
GList *item;
- if (! gimp_transform_tool_can_redo (tool, display))
- return FALSE;
-
item = tr_tool->redo_list;
/* Move prev_trans_info from redo_list to undo_list */
diff --git a/app/tools/gimpwarptool.c b/app/tools/gimpwarptool.c
index c23c67d..40765dc 100644
--- a/app/tools/gimpwarptool.c
+++ b/app/tools/gimpwarptool.c
@@ -504,16 +504,8 @@ gimp_warp_tool_undo (GimpTool *tool,
GimpWarpTool *wt = GIMP_WARP_TOOL (tool);
GeglNode *to_delete;
GeglNode *prev_node;
- const gchar *type;
-
- if (! wt->render_node)
- return FALSE;
to_delete = gegl_node_get_producer (wt->render_node, "aux", NULL);
- type = gegl_node_get_operation (to_delete);
-
- if (strcmp (type, "gegl:warp"))
- return FALSE;
wt->redo_stack = g_list_prepend (wt->redo_stack, to_delete);
@@ -539,9 +531,6 @@ gimp_warp_tool_redo (GimpTool *tool,
GimpWarpTool *wt = GIMP_WARP_TOOL (tool);
GeglNode *to_add;
- if (! wt->render_node || ! wt->redo_stack)
- return FALSE;
-
to_add = wt->redo_stack->data;
gegl_node_connect_to (to_add, "output",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]