[gspell] Entry: recheck all when buffer changes



commit ee4299c127b35183d98771889bd3503ec3f08909
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Oct 30 15:31:33 2016 +0100

    Entry: recheck all when buffer changes
    
    With unit test.

 gspell/gspell-entry.c  |   13 +++++++++++++
 testsuite/test-entry.c |   29 +++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/gspell/gspell-entry.c b/gspell/gspell-entry.c
index c2a0d17..7c869d5 100644
--- a/gspell/gspell-entry.c
+++ b/gspell/gspell-entry.c
@@ -278,6 +278,14 @@ 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)
 {
@@ -327,6 +335,11 @@ set_entry (GspellEntry *gspell_entry,
                                G_CALLBACK (changed_after_cb),
                                gspell_entry);
 
+       g_signal_connect (gtk_entry,
+                         "notify::buffer",
+                         G_CALLBACK (notify_buffer_cb),
+                         gspell_entry);
+
        g_assert (gspell_entry->notify_attributes_handler_id == 0);
        gspell_entry->notify_attributes_handler_id =
                g_signal_connect (gtk_entry,
diff --git a/testsuite/test-entry.c b/testsuite/test-entry.c
index aea8514..55baad2 100644
--- a/testsuite/test-entry.c
+++ b/testsuite/test-entry.c
@@ -204,6 +204,34 @@ test_inline_spell_checking_property (void)
        g_object_unref (gtk_entry);
 }
 
+static void
+test_buffer_change (void)
+{
+       GtkEntry *gtk_entry;
+       GtkEntryBuffer *other_buffer;
+       GspellEntry *gspell_entry;
+       GSList *expected_list;
+       const GSList *received_list;
+
+       gtk_entry = create_entry ();
+       gspell_entry = gspell_entry_get_from_gtk_entry (gtk_entry);
+
+       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);
+
+       other_buffer = gtk_entry_buffer_new (NULL, -1);
+       gtk_entry_set_buffer (gtk_entry, other_buffer);
+       g_object_unref (other_buffer);
+       expected_list = NULL;
+       received_list = _gspell_entry_get_misspelled_words (gspell_entry);
+       check_entry_word_list_equal (expected_list, received_list);
+
+       g_object_unref (gtk_entry);
+}
+
 gint
 main (gint    argc,
       gchar **argv)
@@ -212,6 +240,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);
 
        return g_test_run ();
 }


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