[gspell/wip/entry: 8/8] Entry: take into account the inline-spell-checking property



commit 0741c4487ddbc917a3fa317ca1115c89e94593f5
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Oct 29 21:31:08 2016 +0200

    Entry: take into account the inline-spell-checking property
    
    And add Enable button in the UI test.

 gspell/gspell-entry.c |   41 +++++++++++++++++++++++++++++++++--------
 tests/test-entry.c    |   14 +++++++++++++-
 2 files changed, 46 insertions(+), 9 deletions(-)
---
diff --git a/gspell/gspell-entry.c b/gspell/gspell-entry.c
index 51d51f7..d0c5845 100644
--- a/gspell/gspell-entry.c
+++ b/gspell/gspell-entry.c
@@ -90,6 +90,21 @@ set_attributes (GspellEntry   *gspell_entry,
                                  gspell_entry->notify_attributes_handler_id);
 }
 
+static void
+update_attributes (GspellEntry *gspell_entry)
+{
+       PangoAttrList *attr_list;
+
+       /* If attributes have been added or removed from an existing
+        * PangoAttrList, GtkEntry doesn't know that the :attributes property
+        * has been modified. Without this code, GtkEntry can become buggy,
+        * especially with multi-byte characters (displaying them as unknown
+        * char boxes).
+        */
+       attr_list = gtk_entry_get_attributes (gspell_entry->entry);
+       set_attributes (gspell_entry, attr_list);
+}
+
 static gboolean
 remove_underlines_filter (PangoAttribute *attr,
                          gpointer        user_data)
@@ -113,6 +128,8 @@ remove_all_underlines (GspellEntry *gspell_entry)
        pango_attr_list_filter (attr_list,
                                remove_underlines_filter,
                                NULL);
+
+       update_attributes (gspell_entry);
 }
 
 static void
@@ -152,10 +169,14 @@ static void
 recheck_all (GspellEntry *gspell_entry)
 {
        GspellChecker *checker;
-       PangoAttrList *attr_list;
        GSList *words;
        GSList *l;
 
+       if (!gspell_entry->inline_spell_checking)
+       {
+               return;
+       }
+
        checker = get_checker (gspell_entry);
        if (checker == NULL ||
            gspell_checker_get_language (checker) == NULL)
@@ -192,13 +213,7 @@ recheck_all (GspellEntry *gspell_entry)
 
        g_slist_free_full (words, _gspell_entry_word_free);
 
-       /* If more attributes have been added to an existing PangoAttrList,
-        * GtkEntry doesn't know that the :attributes property has been
-        * modified. Without this code, GtkEntry can become buggy, especially
-        * with multi-byte characters (displaying them as unknown char boxes).
-        */
-       attr_list = gtk_entry_get_attributes (gspell_entry->entry);
-       set_attributes (gspell_entry, attr_list);
+       update_attributes (gspell_entry);
 }
 
 /* Connect to the ::changed signal before/after, so that other features (in
@@ -223,6 +238,15 @@ changed_after_cb (GtkEditable *editable,
        recheck_all (gspell_entry);
 }
 
+/* When the underlines need to be updated, call this function, so that all the
+ * underlines attributes are always removed in changed_before_cb().
+ */
+static void
+emit_changed_signal (GspellEntry *gspell_entry)
+{
+       g_signal_emit_by_name (gspell_entry->entry, "changed");
+}
+
 static gboolean
 notify_attributes_idle_cb (gpointer user_data)
 {
@@ -479,6 +503,7 @@ gspell_entry_set_inline_spell_checking (GspellEntry *gspell_entry,
        if (gspell_entry->inline_spell_checking != enable)
        {
                gspell_entry->inline_spell_checking = enable;
+               emit_changed_signal (gspell_entry);
                g_object_notify (G_OBJECT (gspell_entry), "inline-spell-checking");
        }
 }
diff --git a/tests/test-entry.c b/tests/test-entry.c
index aaa5569..75a8d69 100644
--- a/tests/test-entry.c
+++ b/tests/test-entry.c
@@ -49,6 +49,7 @@ create_entry (void)
 
        gtk_entry = GTK_ENTRY (gtk_entry_new ());
        gtk_widget_set_hexpand (GTK_WIDGET (gtk_entry), TRUE);
+       gtk_widget_set_valign (GTK_WIDGET (gtk_entry), GTK_ALIGN_START);
 
        checker = gspell_checker_new (NULL);
        gtk_buffer = gtk_entry_get_buffer (gtk_entry);
@@ -92,7 +93,9 @@ bold_toggled_cb (GtkToggleButton *button,
 static GtkWidget *
 create_sidebar (TestSpell *spell)
 {
+       GspellEntry *gspell_entry;
        GtkWidget *vgrid;
+       GtkWidget *enable_toggle_button;
        GtkWidget *bold_toggle_button;
 
        vgrid = gtk_grid_new ();
@@ -100,6 +103,14 @@ create_sidebar (TestSpell *spell)
        gtk_orientable_set_orientation (GTK_ORIENTABLE (vgrid),
                                        GTK_ORIENTATION_VERTICAL);
 
+       enable_toggle_button = gtk_toggle_button_new_with_label ("Enable");
+       gtk_container_add (GTK_CONTAINER (vgrid), enable_toggle_button);
+
+       gspell_entry = gspell_entry_get_from_gtk_entry (spell->entry);
+       g_object_bind_property (gspell_entry, "inline-spell-checking",
+                               enable_toggle_button, "active",
+                               G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
        bold_toggle_button = gtk_toggle_button_new_with_label ("Bold");
        gtk_container_add (GTK_CONTAINER (vgrid), bold_toggle_button);
 
@@ -124,10 +135,11 @@ test_spell_init (TestSpell *spell)
        gtk_orientable_set_orientation (GTK_ORIENTABLE (spell),
                                        GTK_ORIENTATION_HORIZONTAL);
 
+       spell->entry = create_entry ();
+
        gtk_container_add (GTK_CONTAINER (spell),
                           create_sidebar (spell));
 
-       spell->entry = create_entry ();
        gtk_container_add (GTK_CONTAINER (spell),
                           GTK_WIDGET (spell->entry));
 


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