From f230019f7151cc5b317fc3b120c870c0b6246341 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Tue, 2 Mar 2010 11:46:58 +0100 Subject: [PATCH] app: move updating the style editor to an idle function so subsequent signals trigger only one update. --- app/widgets/gimptextstyleeditor.c | 26 ++++++++++++++++++++++++++ app/widgets/gimptextstyleeditor.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/app/widgets/gimptextstyleeditor.c b/app/widgets/gimptextstyleeditor.c index 5cd03bccbe..ed43cc0dbd 100644 --- a/app/widgets/gimptextstyleeditor.c +++ b/app/widgets/gimptextstyleeditor.c @@ -80,6 +80,7 @@ static void gimp_text_style_editor_tag_toggled (GtkToggleButton *toggl GimpTextStyleEditor *editor); static void gimp_text_style_editor_update (GimpTextStyleEditor *editor); +static gboolean gimp_text_style_editor_update_idle (GimpTextStyleEditor *editor); G_DEFINE_TYPE (GimpTextStyleEditor, gimp_text_style_editor, @@ -247,6 +248,12 @@ gimp_text_style_editor_dispose (GObject *object) editor); } + if (editor->update_idle_id) + { + g_source_remove (editor->update_idle_id); + editor->update_idle_id = 0; + } + G_OBJECT_CLASS (parent_class)->dispose (object); } @@ -542,9 +549,26 @@ gimp_text_style_editor_set_font (GimpTextStyleEditor *editor, static void gimp_text_style_editor_update (GimpTextStyleEditor *editor) +{ + if (editor->update_idle_id) + g_source_remove (editor->update_idle_id); + + editor->update_idle_id = + gdk_threads_add_idle ((GSourceFunc) gimp_text_style_editor_update_idle, + editor); +} + +static gboolean +gimp_text_style_editor_update_idle (GimpTextStyleEditor *editor) { GtkTextBuffer *buffer = GTK_TEXT_BUFFER (editor->buffer); + if (editor->update_idle_id) + { + g_source_remove (editor->update_idle_id); + editor->update_idle_id = 0; + } + if (gtk_text_buffer_get_has_selection (buffer)) { GtkTextIter start, end; @@ -667,4 +691,6 @@ gimp_text_style_editor_update (GimpTextStyleEditor *editor) g_slist_free (tags_on); g_slist_free (tags_off); } + + return FALSE; } diff --git a/app/widgets/gimptextstyleeditor.h b/app/widgets/gimptextstyleeditor.h index 602007d376..98953ffbad 100644 --- a/app/widgets/gimptextstyleeditor.h +++ b/app/widgets/gimptextstyleeditor.h @@ -55,6 +55,8 @@ struct _GimpTextStyleEditor GtkWidget *size_label; GList *toggles; + + guint update_idle_id; }; struct _GimpTextStyleEditorClass