[gspell/wip/entry: 5/6] Entry: re-apply our attributes if the :attributes property has changed



commit 153145a19e75b608d207f511adbe790e326de617
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Oct 28 17:00:05 2016 +0200

    Entry: re-apply our attributes if the :attributes property has changed

 gspell/gspell-entry.c |   34 ++++++++++++++++++++++++++++++++--
 1 files changed, 32 insertions(+), 2 deletions(-)
---
diff --git a/gspell/gspell-entry.c b/gspell/gspell-entry.c
index 3f30c5f..2d30af9 100644
--- a/gspell/gspell-entry.c
+++ b/gspell/gspell-entry.c
@@ -41,6 +41,7 @@ struct _GspellEntry
        GObject parent;
 
        GtkEntry *entry;
+       gulong notify_attributes_handler_id;
        guint inline_spell_checking : 1;
 };
 
@@ -55,6 +56,19 @@ enum
 
 G_DEFINE_TYPE (GspellEntry, gspell_entry, G_TYPE_OBJECT)
 
+static void
+set_attributes (GspellEntry   *gspell_entry,
+               PangoAttrList *attributes)
+{
+       g_signal_handler_block (gspell_entry->entry,
+                               gspell_entry->notify_attributes_handler_id);
+
+       gtk_entry_set_attributes (gspell_entry->entry, attributes);
+
+       g_signal_handler_unblock (gspell_entry->entry,
+                                 gspell_entry->notify_attributes_handler_id);
+}
+
 static gboolean
 remove_underlines_filter (PangoAttribute *attr,
                          gpointer        user_data)
@@ -102,7 +116,7 @@ insert_underline (GspellEntry *gspell_entry,
        if (attr_list == NULL)
        {
                attr_list = pango_attr_list_new ();
-               gtk_entry_set_attributes (gspell_entry->entry, attr_list);
+               set_attributes (gspell_entry, attr_list);
                pango_attr_list_unref (attr_list);
        }
 
@@ -139,7 +153,7 @@ recheck_all (GspellEntry *gspell_entry)
         * with multi-byte characters (displaying them as unknown char boxes).
         */
        attr_list = gtk_entry_get_attributes (gspell_entry->entry);
-       gtk_entry_set_attributes (gspell_entry->entry, attr_list);
+       set_attributes (gspell_entry, attr_list);
 }
 
 /* Connect to the ::changed signal before/after, so that other features (in
@@ -165,6 +179,15 @@ changed_after_cb (GtkEditable *editable,
 }
 
 static void
+notify_attributes_cb (GtkEntry    *gtk_entry,
+                     GParamSpec  *pspec,
+                     GspellEntry *gspell_entry)
+{
+       /* Re-apply our attributes. */
+       recheck_all (gspell_entry);
+}
+
+static void
 set_entry (GspellEntry *gspell_entry,
           GtkEntry    *gtk_entry)
 {
@@ -185,6 +208,13 @@ set_entry (GspellEntry *gspell_entry,
                                 gspell_entry,
                                 G_CONNECT_AFTER);
 
+       g_assert (gspell_entry->notify_attributes_handler_id == 0);
+       gspell_entry->notify_attributes_handler_id =
+               g_signal_connect (gtk_entry,
+                                 "notify::attributes",
+                                 G_CALLBACK (notify_attributes_cb),
+                                 gspell_entry);
+
        g_object_notify (G_OBJECT (gspell_entry), "entry");
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]