Commit 65216b93 authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

app: group text buffer changes by user actions

Use gtk_text_buffer_begin_user_action() and end_user_action() to group
all text buffer operations triggered by a single editing operation.
Connect to the buffer's "end-user-action" signal instead of to
"changed", "apply-tag" and "remove-tag" separately, so we only update
the text proxy once per user editing.
parent 87d89ce9
......@@ -160,12 +160,7 @@ static gboolean gimp_text_tool_set_drawable (GimpTextTool *text_tool,
GimpDrawable *drawable,
gboolean confirm);
static void gimp_text_tool_buffer_changed (GtkTextBuffer *buffer,
GimpTextTool *text_tool);
void gimp_text_tool_buffer_tagged (GtkTextBuffer *buffer,
GtkTextTag *tag,
GtkTextIter *start,
GtkTextIter *end,
static void gimp_text_tool_buffer_edited (GtkTextBuffer *buffer,
GimpTextTool *text_tool);
......@@ -248,15 +243,9 @@ gimp_text_tool_init (GimpTextTool *text_tool)
text_tool->buffer = gimp_text_buffer_new ();
g_signal_connect (text_tool->buffer, "changed",
G_CALLBACK (gimp_text_tool_buffer_changed),
g_signal_connect (text_tool->buffer, "end-user-action",
G_CALLBACK (gimp_text_tool_buffer_edited),
text_tool);
g_signal_connect_after (text_tool->buffer, "apply-tag",
G_CALLBACK (gimp_text_tool_buffer_tagged),
text_tool);
g_signal_connect_after (text_tool->buffer, "remove-tag",
G_CALLBACK (gimp_text_tool_buffer_tagged),
text_tool);
text_tool->handle_rectangle_change_complete = TRUE;
......@@ -919,10 +908,7 @@ gimp_text_tool_connect (GimpTextTool *text_tool,
GimpTextOptions *options = GIMP_TEXT_TOOL_GET_OPTIONS (tool);
g_signal_handlers_block_by_func (text_tool->buffer,
gimp_text_tool_buffer_changed,
text_tool);
g_signal_handlers_block_by_func (text_tool->buffer,
gimp_text_tool_buffer_tagged,
gimp_text_tool_buffer_edited,
text_tool);
if (text_tool->text)
......@@ -967,10 +953,7 @@ gimp_text_tool_connect (GimpTextTool *text_tool,
}
g_signal_handlers_unblock_by_func (text_tool->buffer,
gimp_text_tool_buffer_tagged,
text_tool);
g_signal_handlers_unblock_by_func (text_tool->buffer,
gimp_text_tool_buffer_changed,
gimp_text_tool_buffer_edited,
text_tool);
}
......@@ -1064,10 +1047,7 @@ gimp_text_tool_text_notify (GimpText *text,
strcmp (pspec->name, "markup") == 0)
{
g_signal_handlers_block_by_func (text_tool->buffer,
gimp_text_tool_buffer_changed,
text_tool);
g_signal_handlers_block_by_func (text_tool->buffer,
gimp_text_tool_buffer_tagged,
gimp_text_tool_buffer_edited,
text_tool);
if (pspec->name[0] == 't')
......@@ -1076,10 +1056,7 @@ gimp_text_tool_text_notify (GimpText *text,
gimp_text_buffer_set_markup (text_tool->buffer, text->markup);
g_signal_handlers_unblock_by_func (text_tool->buffer,
gimp_text_tool_buffer_tagged,
text_tool);
g_signal_handlers_unblock_by_func (text_tool->buffer,
gimp_text_tool_buffer_changed,
gimp_text_tool_buffer_edited,
text_tool);
}
......@@ -1563,8 +1540,8 @@ gimp_text_tool_set_drawable (GimpTextTool *text_tool,
}
static void
gimp_text_tool_buffer_changed (GtkTextBuffer *buffer,
GimpTextTool *text_tool)
gimp_text_tool_buffer_edited (GtkTextBuffer *buffer,
GimpTextTool *text_tool)
{
if (text_tool->text)
{
......@@ -1576,6 +1553,8 @@ gimp_text_tool_buffer_changed (GtkTextBuffer *buffer,
"markup", markup,
NULL);
/* g_printerr ("markup: %s\n", markup); */
g_free (text);
g_free (markup);
}
......@@ -1585,16 +1564,6 @@ gimp_text_tool_buffer_changed (GtkTextBuffer *buffer,
}
}
void
gimp_text_tool_buffer_tagged (GtkTextBuffer *buffer,
GtkTextTag *tag,
GtkTextIter *start,
GtkTextIter *end,
GimpTextTool *text_tool)
{
gimp_text_tool_buffer_changed (buffer, text_tool);
}
/* public functions */
......
......@@ -344,6 +344,8 @@ gimp_text_buffer_change_baseline (GimpTextBuffer *buffer,
span_start = *start;
span_baseline = get_baseline_at_iter (buffer, &iter, &span_tag);
gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
do
{
gint iter_baseline;
......@@ -382,6 +384,8 @@ gimp_text_buffer_change_baseline (GimpTextBuffer *buffer,
iter = *end;
}
while (! gtk_text_iter_equal (&iter, end));
gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
}
static gint
......@@ -468,6 +472,8 @@ gimp_text_buffer_change_spacing (GimpTextBuffer *buffer,
span_start = *start;
span_spacing = get_spacing_at_iter (buffer, &iter, &span_tag);
gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
if (gtk_text_iter_equal (start, end))
{
span_end = span_start;
......@@ -486,6 +492,8 @@ gimp_text_buffer_change_spacing (GimpTextBuffer *buffer,
&span_start, &span_end);
}
gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
return;
}
......@@ -527,6 +535,8 @@ gimp_text_buffer_change_spacing (GimpTextBuffer *buffer,
iter = *end;
}
while (! gtk_text_iter_equal (&iter, end));
gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
}
const gchar *
......@@ -688,6 +698,8 @@ gimp_text_buffer_insert (GimpTextBuffer *buffer,
if (! insert_tags_set)
tags_off = gtk_text_iter_get_toggled_tags (&iter, FALSE);
gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
gtk_text_buffer_insert (GTK_TEXT_BUFFER (buffer), &iter, text, -1);
gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (buffer), &start,
......@@ -720,6 +732,8 @@ gimp_text_buffer_insert (GimpTextBuffer *buffer,
g_slist_free (tags_off);
}
gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
}
gint
......@@ -766,6 +780,8 @@ gimp_text_buffer_load (GimpTextBuffer *buffer,
return FALSE;
}
gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
gimp_text_buffer_set_text (buffer, NULL);
gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (buffer), &iter);
......@@ -797,6 +813,8 @@ gimp_text_buffer_load (GimpTextBuffer *buffer,
fclose (file);
gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
return TRUE;
}
......
......@@ -357,6 +357,8 @@ gimp_text_style_editor_tag_toggled (GtkToggleButton *toggle,
gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
gtk_text_buffer_begin_user_action (buffer);
if (gtk_toggle_button_get_active (toggle))
{
gtk_text_buffer_apply_tag (buffer, tag, &start, &end);
......@@ -365,6 +367,8 @@ gimp_text_style_editor_tag_toggled (GtkToggleButton *toggle,
{
gtk_text_buffer_remove_tag (buffer, tag, &start, &end);
}
gtk_text_buffer_end_user_action (buffer);
}
list = gimp_text_style_editor_list_tags (editor);
......
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