Commit 6a312a71 authored by Michael Natterer's avatar Michael Natterer 😴

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.
parent 1c01f103
......@@ -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,
......
......@@ -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
......
......@@ -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)
......
......@@ -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;
......
......@@ -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 */
......
......@@ -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",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment