[gspell/wip/entry: 3/3] Entry: recheck all when GspellChecker:language changes
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell/wip/entry: 3/3] Entry: recheck all when GspellChecker:language changes
- Date: Sun, 30 Oct 2016 17:53:02 +0000 (UTC)
commit 6a5a637bcb2d66a4412a0ab01b4b3deecfc669f4
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Oct 30 17:53:42 2016 +0100
Entry: recheck all when GspellChecker:language changes
One level deeper.
A unit test will be written later, when it'll be possible to force a
NULL language.
gspell/gspell-entry.c | 56 +++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 52 insertions(+), 4 deletions(-)
---
diff --git a/gspell/gspell-entry.c b/gspell/gspell-entry.c
index 1e31747..c7e1e96 100644
--- a/gspell/gspell-entry.c
+++ b/gspell/gspell-entry.c
@@ -44,6 +44,7 @@ struct _GspellEntry
GtkEntry *entry;
GtkEntryBuffer *buffer;
+ GspellChecker *checker;
/* List elements: GspellEntryWord*.
* Used for unit tests.
@@ -70,16 +71,14 @@ G_DEFINE_TYPE (GspellEntry, gspell_entry, G_TYPE_OBJECT)
static GspellChecker *
get_checker (GspellEntry *gspell_entry)
{
- GtkEntryBuffer *gtk_buffer;
GspellEntryBuffer *gspell_buffer;
- gtk_buffer = gtk_entry_get_buffer (gspell_entry->entry);
- if (gtk_buffer == NULL)
+ if (gspell_entry->buffer == NULL)
{
return NULL;
}
- gspell_buffer = gspell_entry_buffer_get_from_gtk_entry_buffer (gtk_buffer);
+ gspell_buffer = gspell_entry_buffer_get_from_gtk_entry_buffer (gspell_entry->buffer);
return gspell_entry_buffer_get_spell_checker (gspell_buffer);
}
@@ -313,10 +312,56 @@ notify_attributes_cb (GtkEntry *gtk_entry,
}
static void
+notify_language_cb (GspellChecker *checker,
+ GParamSpec *pspec,
+ GspellEntry *gspell_entry)
+{
+ emit_changed_signal (gspell_entry);
+}
+
+static void
+set_checker (GspellEntry *gspell_entry,
+ GspellChecker *checker)
+{
+ if (gspell_entry->checker == checker)
+ {
+ return;
+ }
+
+ if (gspell_entry->checker != NULL)
+ {
+ g_signal_handlers_disconnect_by_func (gspell_entry->checker,
+ notify_language_cb,
+ gspell_entry);
+
+ g_object_unref (gspell_entry->checker);
+ }
+
+ gspell_entry->checker = checker;
+
+ if (gspell_entry->checker != NULL)
+ {
+ g_signal_connect (gspell_entry->checker,
+ "notify::language",
+ G_CALLBACK (notify_language_cb),
+ gspell_entry);
+
+ g_object_ref (gspell_entry->checker);
+ }
+}
+
+static void
+update_checker (GspellEntry *gspell_entry)
+{
+ set_checker (gspell_entry, get_checker (gspell_entry));
+}
+
+static void
notify_spell_checker_cb (GspellEntryBuffer *gspell_buffer,
GParamSpec *pspec,
GspellEntry *gspell_entry)
{
+ update_checker (gspell_entry);
emit_changed_signal (gspell_entry);
}
@@ -355,6 +400,8 @@ set_buffer (GspellEntry *gspell_entry,
g_object_ref (gspell_entry->buffer);
}
+
+ update_checker (gspell_entry);
}
static void
@@ -463,6 +510,7 @@ gspell_entry_dispose (GObject *object)
gspell_entry->entry = NULL;
set_buffer (gspell_entry, NULL);
+ set_checker (gspell_entry, NULL);
if (gspell_entry->notify_attributes_idle_id != 0)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]