[gspell/wip/entry: 2/2] Entry: re-apply our attributes if the :attributes property has changed
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell/wip/entry: 2/2] Entry: re-apply our attributes if the :attributes property has changed
- Date: Fri, 28 Oct 2016 15:03:07 +0000 (UTC)
commit 1309188dd40caee7fb4a947912281cfd158dee80
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 | 46 +++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 43 insertions(+), 3 deletions(-)
---
diff --git a/gspell/gspell-entry.c b/gspell/gspell-entry.c
index 3f30c5f..f676bde 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");
}
@@ -241,7 +271,17 @@ gspell_entry_dispose (GObject *object)
{
GspellEntry *gspell_entry = GSPELL_ENTRY (object);
- gspell_entry->entry = NULL;
+ if (gspell_entry->entry != NULL)
+ {
+ if (gspell_entry->notify_attributes_handler_id != 0)
+ {
+ g_signal_handler_disconnect (gspell_entry->entry,
+ gspell_entry->notify_attributes_handler_id);
+ gspell_entry->notify_attributes_handler_id = 0;
+ }
+
+ gspell_entry->entry = NULL;
+ }
G_OBJECT_CLASS (gspell_entry_parent_class)->dispose (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]