[gspell/wip/entry] Entry: apply underlines to all words



commit dcb8629bd9f55fa9f8de3d04812802573125d8cd
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Oct 28 14:07:11 2016 +0200

    Entry: apply underlines to all words

 gspell/gspell-entry.c |   72 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 71 insertions(+), 1 deletions(-)
---
diff --git a/gspell/gspell-entry.c b/gspell/gspell-entry.c
index 04626b0..4a70e48 100644
--- a/gspell/gspell-entry.c
+++ b/gspell/gspell-entry.c
@@ -18,6 +18,7 @@
  */
 
 #include "gspell-entry.h"
+#include "gspell-entry-utils.h"
 
 /**
  * SECTION:entry
@@ -54,6 +55,31 @@ enum
 
 G_DEFINE_TYPE (GspellEntry, gspell_entry, G_TYPE_OBJECT)
 
+static gboolean
+remove_underlines_filter (PangoAttribute *attr,
+                         gpointer        user_data)
+{
+       return (attr->klass->type == PANGO_ATTR_UNDERLINE ||
+               attr->klass->type == PANGO_ATTR_UNDERLINE_COLOR);
+}
+
+static void
+remove_all_underlines (GspellEntry *gspell_entry)
+{
+       PangoAttrList *attr_list;
+
+       attr_list = gtk_entry_get_attributes (gspell_entry->entry);
+
+       if (attr_list == NULL)
+       {
+               return;
+       }
+
+       pango_attr_list_filter (attr_list,
+                               remove_underlines_filter,
+                               NULL);
+}
+
 static void
 apply_underline (GspellEntry *gspell_entry,
                 guint        byte_start,
@@ -91,6 +117,40 @@ apply_underline (GspellEntry *gspell_entry,
 }
 
 static void
+recheck_all (GspellEntry *gspell_entry)
+{
+       GSList *words;
+       GSList *l;
+
+       words = _gspell_entry_utils_get_words (gspell_entry->entry);
+
+       for (l = words; l != NULL; l = l->next)
+       {
+               GspellEntryWord *cur_word = l->data;
+
+               apply_underline (gspell_entry,
+                                cur_word->byte_start,
+                                cur_word->byte_end);
+       }
+
+       g_slist_free_full (words, _gspell_entry_word_free);
+}
+
+static void
+changed_before_cb (GtkEditable *editable,
+                  GspellEntry *gspell_entry)
+{
+       remove_all_underlines (gspell_entry);
+}
+
+static void
+changed_after_cb (GtkEditable *editable,
+                 GspellEntry *gspell_entry)
+{
+       recheck_all (gspell_entry);
+}
+
+static void
 set_entry (GspellEntry *gspell_entry,
           GtkEntry    *gtk_entry)
 {
@@ -99,7 +159,17 @@ set_entry (GspellEntry *gspell_entry,
        g_assert (gspell_entry->entry == NULL);
        gspell_entry->entry = gtk_entry;
 
-       apply_underline (gspell_entry, 0, 3);
+       g_signal_connect_object (gtk_entry,
+                                "changed",
+                                G_CALLBACK (changed_before_cb),
+                                gspell_entry,
+                                0);
+
+       g_signal_connect_object (gtk_entry,
+                                "changed",
+                                G_CALLBACK (changed_after_cb),
+                                gspell_entry,
+                                G_CONNECT_AFTER);
 
        g_object_notify (G_OBJECT (gspell_entry), "entry");
 }


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