[gspell/wip/entry: 4/6] Entry: check words by the GspellChecker



commit eccc9a34adac6180019b1440cdb262c2a902322b
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Oct 29 21:16:51 2016 +0200

    Entry: check words by the GspellChecker

 gspell/gspell-entry.c |   50 +++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 46 insertions(+), 4 deletions(-)
---
diff --git a/gspell/gspell-entry.c b/gspell/gspell-entry.c
index e97654a..51d51f7 100644
--- a/gspell/gspell-entry.c
+++ b/gspell/gspell-entry.c
@@ -18,6 +18,7 @@
  */
 
 #include "gspell-entry.h"
+#include "gspell-entry-buffer.h"
 #include "gspell-entry-utils.h"
 
 /**
@@ -59,6 +60,23 @@ enum
 
 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)
+       {
+               return NULL;
+       }
+
+       gspell_buffer = gspell_entry_buffer_get_from_gtk_entry_buffer (gtk_buffer);
+
+       return gspell_entry_buffer_get_spell_checker (gspell_buffer);
+}
+
 static void
 set_attributes (GspellEntry   *gspell_entry,
                PangoAttrList *attributes)
@@ -133,19 +151,43 @@ insert_underline (GspellEntry *gspell_entry,
 static void
 recheck_all (GspellEntry *gspell_entry)
 {
+       GspellChecker *checker;
        PangoAttrList *attr_list;
        GSList *words;
        GSList *l;
 
+       checker = get_checker (gspell_entry);
+       if (checker == NULL ||
+           gspell_checker_get_language (checker) == NULL)
+       {
+               return;
+       }
+
        words = _gspell_entry_utils_get_words (gspell_entry->entry);
 
        for (l = words; l != NULL; l = l->next)
        {
                GspellEntryWord *cur_word = l->data;
+               GError *error = NULL;
+               gboolean correctly_spelled;
+
+               correctly_spelled = gspell_checker_check_word (checker,
+                                                              cur_word->word_str, -1,
+                                                              &error);
 
-               insert_underline (gspell_entry,
-                                 cur_word->byte_start,
-                                 cur_word->byte_end);
+               if (error != NULL)
+               {
+                       g_warning ("Inline spell checker: %s", error->message);
+                       g_clear_error (&error);
+                       break;
+               }
+
+               if (!correctly_spelled)
+               {
+                       insert_underline (gspell_entry,
+                                         cur_word->byte_start,
+                                         cur_word->byte_end);
+               }
        }
 
        g_slist_free_full (words, _gspell_entry_word_free);


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