[gspell/wip/entry] Entry: recheck all when GspellEntryBuffer:spell-checker changes
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell/wip/entry] Entry: recheck all when GspellEntryBuffer:spell-checker changes
- Date: Sun, 30 Oct 2016 16:31:27 +0000 (UTC)
commit af49e3bdac2c86ce9f0830e9ea2f6b39fad77c5f
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Oct 30 17:15:27 2016 +0100
Entry: recheck all when GspellEntryBuffer:spell-checker changes
One level deeper.
gspell/gspell-entry.c | 72 ++++++++++++++++++++++++++++++++++++++++++-----
testsuite/test-entry.c | 46 ++++++++++++++++++++++++++++++
2 files changed, 110 insertions(+), 8 deletions(-)
---
diff --git a/gspell/gspell-entry.c b/gspell/gspell-entry.c
index 4cacba3..1e31747 100644
--- a/gspell/gspell-entry.c
+++ b/gspell/gspell-entry.c
@@ -43,6 +43,7 @@ struct _GspellEntry
GObject parent;
GtkEntry *entry;
+ GtkEntryBuffer *buffer;
/* List elements: GspellEntryWord*.
* Used for unit tests.
@@ -281,14 +282,6 @@ emit_changed_signal (GspellEntry *gspell_entry)
g_signal_emit_by_name (gspell_entry->entry, "changed");
}
-static void
-notify_buffer_cb (GtkEntry *gtk_entry,
- GParamSpec *pspec,
- GspellEntry *gspell_entry)
-{
- emit_changed_signal (gspell_entry);
-}
-
static gboolean
notify_attributes_idle_cb (gpointer user_data)
{
@@ -320,6 +313,66 @@ notify_attributes_cb (GtkEntry *gtk_entry,
}
static void
+notify_spell_checker_cb (GspellEntryBuffer *gspell_buffer,
+ GParamSpec *pspec,
+ GspellEntry *gspell_entry)
+{
+ emit_changed_signal (gspell_entry);
+}
+
+static void
+set_buffer (GspellEntry *gspell_entry,
+ GtkEntryBuffer *gtk_buffer)
+{
+ GspellEntryBuffer *gspell_buffer;
+
+ if (gspell_entry->buffer == gtk_buffer)
+ {
+ return;
+ }
+
+ if (gspell_entry->buffer != NULL)
+ {
+ gspell_buffer = gspell_entry_buffer_get_from_gtk_entry_buffer (gspell_entry->buffer);
+
+ g_signal_handlers_disconnect_by_func (gspell_buffer,
+ notify_spell_checker_cb,
+ gspell_entry);
+
+ g_object_unref (gspell_entry->buffer);
+ }
+
+ gspell_entry->buffer = gtk_buffer;
+
+ if (gspell_entry->buffer != NULL)
+ {
+ gspell_buffer = gspell_entry_buffer_get_from_gtk_entry_buffer (gspell_entry->buffer);
+
+ g_signal_connect (gspell_buffer,
+ "notify::spell-checker",
+ G_CALLBACK (notify_spell_checker_cb),
+ gspell_entry);
+
+ g_object_ref (gspell_entry->buffer);
+ }
+}
+
+static void
+update_buffer (GspellEntry *gspell_entry)
+{
+ set_buffer (gspell_entry, gtk_entry_get_buffer (gspell_entry->entry));
+}
+
+static void
+notify_buffer_cb (GtkEntry *gtk_entry,
+ GParamSpec *pspec,
+ GspellEntry *gspell_entry)
+{
+ update_buffer (gspell_entry);
+ emit_changed_signal (gspell_entry);
+}
+
+static void
set_entry (GspellEntry *gspell_entry,
GtkEntry *gtk_entry)
{
@@ -350,6 +403,8 @@ set_entry (GspellEntry *gspell_entry,
G_CALLBACK (notify_attributes_cb),
gspell_entry);
+ update_buffer (gspell_entry);
+
g_object_notify (G_OBJECT (gspell_entry), "entry");
}
@@ -407,6 +462,7 @@ gspell_entry_dispose (GObject *object)
GspellEntry *gspell_entry = GSPELL_ENTRY (object);
gspell_entry->entry = NULL;
+ set_buffer (gspell_entry, NULL);
if (gspell_entry->notify_attributes_idle_id != 0)
{
diff --git a/testsuite/test-entry.c b/testsuite/test-entry.c
index 55baad2..403b5ae 100644
--- a/testsuite/test-entry.c
+++ b/testsuite/test-entry.c
@@ -232,6 +232,51 @@ test_buffer_change (void)
g_object_unref (gtk_entry);
}
+static void
+test_spell_checker_change (void)
+{
+ GtkEntry *gtk_entry;
+ GspellEntry *gspell_entry;
+ GtkEntryBuffer *gtk_buffer;
+ GspellEntryBuffer *gspell_buffer;
+ GSList *expected_list;
+ const GSList *received_list;
+ const GspellLanguage *lang;
+ GspellChecker *other_checker;
+
+ gtk_entry = create_entry ();
+ gspell_entry = gspell_entry_get_from_gtk_entry (gtk_entry);
+ gtk_buffer = gtk_entry_get_buffer (gtk_entry);
+ gspell_buffer = gspell_entry_buffer_get_from_gtk_entry_buffer (gtk_buffer);
+
+ gtk_entry_set_text (gtk_entry, "auienrst");
+ expected_list = add_word (NULL, "auienrst", 0, 8);
+ received_list = _gspell_entry_get_misspelled_words (gspell_entry);
+ check_entry_word_list_equal (expected_list, received_list);
+ free_word_list (expected_list);
+
+ /* Set NULL spell checker */
+ gspell_entry_buffer_set_spell_checker (gspell_buffer, NULL);
+ expected_list = NULL;
+ received_list = _gspell_entry_get_misspelled_words (gspell_entry);
+ check_entry_word_list_equal (expected_list, received_list);
+
+ /* Set another spell checker */
+ lang = gspell_language_lookup ("en_US");
+ g_assert (lang != NULL);
+
+ other_checker = gspell_checker_new (lang);
+ gspell_entry_buffer_set_spell_checker (gspell_buffer, other_checker);
+ g_object_unref (other_checker);
+
+ expected_list = add_word (NULL, "auienrst", 0, 8);
+ received_list = _gspell_entry_get_misspelled_words (gspell_entry);
+ check_entry_word_list_equal (expected_list, received_list);
+ free_word_list (expected_list);
+
+ g_object_unref (gtk_entry);
+}
+
gint
main (gint argc,
gchar **argv)
@@ -241,6 +286,7 @@ main (gint argc,
g_test_add_func ("/entry-utils/get-words", test_get_words);
g_test_add_func ("/entry/inline-spell-checking-property", test_inline_spell_checking_property);
g_test_add_func ("/entry/buffer-change", test_buffer_change);
+ g_test_add_func ("/entry/spell-checker-change", test_spell_checker_change);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]