Commit a03183b2 authored by Ell's avatar Ell

app: streamline text-tool drawing blocking/unblocking logic

The various functions of the text tool currently block and unblock
drawing (through gimp_text_tool_[un]block_drawing()) implicitly,
and in a non-symmetric fashion, which makes the tool's logic rather
fragile.  Instead, require blocking/unblocking to be done
symmetrically, and explicitly block/unblock drawing as necessary in
all functions.
parent a1caa175
...@@ -1330,9 +1330,15 @@ gimp_text_tool_layer_notify (GimpTextLayer *layer, ...@@ -1330,9 +1330,15 @@ gimp_text_tool_layer_notify (GimpTextLayer *layer,
} }
static gboolean static gboolean
gimp_text_tool_apply_idle (gpointer text_tool) gimp_text_tool_apply_idle (GimpTextTool *text_tool)
{ {
return gimp_text_tool_apply (text_tool, TRUE); text_tool->idle_id = 0;
gimp_text_tool_apply (text_tool, TRUE);
gimp_text_tool_unblock_drawing (text_tool);
return G_SOURCE_REMOVE;
} }
static void static void
...@@ -1366,6 +1372,7 @@ gimp_text_tool_proxy_notify (GimpText *text, ...@@ -1366,6 +1372,7 @@ gimp_text_tool_proxy_notify (GimpText *text,
{ {
gimp_text_tool_block_drawing (text_tool); gimp_text_tool_block_drawing (text_tool);
gimp_text_tool_apply (text_tool, TRUE); gimp_text_tool_apply (text_tool, TRUE);
gimp_text_tool_unblock_drawing (text_tool);
} }
gimp_text_tool_block_drawing (text_tool); gimp_text_tool_block_drawing (text_tool);
...@@ -1386,18 +1393,19 @@ gimp_text_tool_proxy_notify (GimpText *text, ...@@ -1386,18 +1393,19 @@ gimp_text_tool_proxy_notify (GimpText *text,
* including undo * including undo
*/ */
gimp_text_tool_block_drawing (text_tool);
text_tool->pending = g_list_append (text_tool->pending, text_tool->pending = g_list_append (text_tool->pending,
(gpointer) pspec); (gpointer) pspec);
if (text_tool->idle_id) if (! text_tool->idle_id)
g_source_remove (text_tool->idle_id); {
gimp_text_tool_block_drawing (text_tool);
text_tool->idle_id = text_tool->idle_id =
g_idle_add_full (G_PRIORITY_LOW, g_idle_add_full (G_PRIORITY_LOW,
gimp_text_tool_apply_idle, text_tool, (GSourceFunc) gimp_text_tool_apply_idle,
NULL); text_tool,
NULL);
}
} }
} }
} }
...@@ -1461,12 +1469,16 @@ gimp_text_tool_text_notify (GimpText *text, ...@@ -1461,12 +1469,16 @@ gimp_text_tool_text_notify (GimpText *text,
gimp_text_tool_buffer_begin_edit, gimp_text_tool_buffer_begin_edit,
text_tool); text_tool);
} }
gimp_text_tool_unblock_drawing (text_tool);
} }
static void static void
gimp_text_tool_text_changed (GimpText *text, gimp_text_tool_text_changed (GimpText *text,
GimpTextTool *text_tool) GimpTextTool *text_tool)
{ {
gimp_text_tool_block_drawing (text_tool);
/* we need to redraw the rectangle in any case because whatever /* we need to redraw the rectangle in any case because whatever
* changes to the text can change its size * changes to the text can change its size
*/ */
...@@ -1645,8 +1657,6 @@ gimp_text_tool_create_layer (GimpTextTool *text_tool, ...@@ -1645,8 +1657,6 @@ gimp_text_tool_create_layer (GimpTextTool *text_tool,
else else
{ {
gimp_text_tool_frame_item (text_tool); gimp_text_tool_frame_item (text_tool);
gimp_text_tool_unblock_drawing (text_tool);
} }
gimp_image_undo_group_end (image); gimp_image_undo_group_end (image);
...@@ -1654,6 +1664,8 @@ gimp_text_tool_create_layer (GimpTextTool *text_tool, ...@@ -1654,6 +1664,8 @@ gimp_text_tool_create_layer (GimpTextTool *text_tool,
gimp_image_flush (image); gimp_image_flush (image);
gimp_text_tool_set_drawable (text_tool, GIMP_DRAWABLE (layer), FALSE); gimp_text_tool_set_drawable (text_tool, GIMP_DRAWABLE (layer), FALSE);
gimp_text_tool_unblock_drawing (text_tool);
} }
#define RESPONSE_NEW 1 #define RESPONSE_NEW 1
...@@ -1880,24 +1892,25 @@ gimp_text_tool_set_drawable (GimpTextTool *text_tool, ...@@ -1880,24 +1892,25 @@ gimp_text_tool_set_drawable (GimpTextTool *text_tool,
static void static void
gimp_text_tool_block_drawing (GimpTextTool *text_tool) gimp_text_tool_block_drawing (GimpTextTool *text_tool)
{ {
if (! text_tool->drawing_blocked) if (text_tool->drawing_blocked == 0)
{ {
gimp_draw_tool_pause (GIMP_DRAW_TOOL (text_tool)); gimp_draw_tool_pause (GIMP_DRAW_TOOL (text_tool));
gimp_text_tool_clear_layout (text_tool); gimp_text_tool_clear_layout (text_tool);
text_tool->drawing_blocked = TRUE;
} }
text_tool->drawing_blocked++;
} }
static void static void
gimp_text_tool_unblock_drawing (GimpTextTool *text_tool) gimp_text_tool_unblock_drawing (GimpTextTool *text_tool)
{ {
g_return_if_fail (text_tool->drawing_blocked == TRUE); g_return_if_fail (text_tool->drawing_blocked > 0);
text_tool->drawing_blocked = FALSE; text_tool->drawing_blocked--;
gimp_draw_tool_resume (GIMP_DRAW_TOOL (text_tool)); if (text_tool->drawing_blocked == 0)
gimp_draw_tool_resume (GIMP_DRAW_TOOL (text_tool));
} }
static void static void
...@@ -1938,6 +1951,8 @@ gimp_text_tool_buffer_end_edit (GimpTextBuffer *buffer, ...@@ -1938,6 +1951,8 @@ gimp_text_tool_buffer_end_edit (GimpTextBuffer *buffer,
{ {
gimp_text_tool_create_layer (text_tool, NULL); gimp_text_tool_create_layer (text_tool, NULL);
} }
gimp_text_tool_unblock_drawing (text_tool);
} }
static void static void
...@@ -1982,7 +1997,7 @@ gimp_text_tool_ensure_layout (GimpTextTool *text_tool) ...@@ -1982,7 +1997,7 @@ gimp_text_tool_ensure_layout (GimpTextTool *text_tool)
return text_tool->layout != NULL; return text_tool->layout != NULL;
} }
gboolean void
gimp_text_tool_apply (GimpTextTool *text_tool, gimp_text_tool_apply (GimpTextTool *text_tool,
gboolean push_undo) gboolean push_undo)
{ {
...@@ -1996,15 +2011,17 @@ gimp_text_tool_apply (GimpTextTool *text_tool, ...@@ -1996,15 +2011,17 @@ gimp_text_tool_apply (GimpTextTool *text_tool,
{ {
g_source_remove (text_tool->idle_id); g_source_remove (text_tool->idle_id);
text_tool->idle_id = 0; text_tool->idle_id = 0;
gimp_text_tool_unblock_drawing (text_tool);
} }
g_return_val_if_fail (text_tool->text != NULL, FALSE); g_return_if_fail (text_tool->text != NULL);
g_return_val_if_fail (text_tool->layer != NULL, FALSE); g_return_if_fail (text_tool->layer != NULL);
layer = text_tool->layer; layer = text_tool->layer;
image = gimp_item_get_image (GIMP_ITEM (layer)); image = gimp_item_get_image (GIMP_ITEM (layer));
g_return_val_if_fail (layer->text == text_tool->text, FALSE); g_return_if_fail (layer->text == text_tool->text);
/* Walk over the list of changes and figure out if we are changing /* Walk over the list of changes and figure out if we are changing
* a single property or need to push a full text undo. * a single property or need to push a full text undo.
...@@ -2083,10 +2100,6 @@ gimp_text_tool_apply (GimpTextTool *text_tool, ...@@ -2083,10 +2100,6 @@ gimp_text_tool_apply (GimpTextTool *text_tool,
gimp_text_tool_frame_item (text_tool); gimp_text_tool_frame_item (text_tool);
gimp_image_flush (image); gimp_image_flush (image);
gimp_text_tool_unblock_drawing (text_tool);
return FALSE;
} }
gboolean gboolean
......
...@@ -62,7 +62,7 @@ struct _GimpTextTool ...@@ -62,7 +62,7 @@ struct _GimpTextTool
gboolean text_box_fixed; gboolean text_box_fixed;
GimpTextLayout *layout; GimpTextLayout *layout;
gboolean drawing_blocked; gint drawing_blocked;
GimpToolWidget *widget; GimpToolWidget *widget;
GimpToolWidget *grab_widget; GimpToolWidget *grab_widget;
...@@ -125,7 +125,7 @@ GimpTextDirection ...@@ -125,7 +125,7 @@ GimpTextDirection
/* only for the text editor */ /* only for the text editor */
void gimp_text_tool_clear_layout (GimpTextTool *text_tool); void gimp_text_tool_clear_layout (GimpTextTool *text_tool);
gboolean gimp_text_tool_ensure_layout (GimpTextTool *text_tool); gboolean gimp_text_tool_ensure_layout (GimpTextTool *text_tool);
gboolean gimp_text_tool_apply (GimpTextTool *text_tool, void gimp_text_tool_apply (GimpTextTool *text_tool,
gboolean push_undo); gboolean push_undo);
......
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