[gedit/wip/spell-shaking] spell-navigator: return the SpellChecker alongside the word



commit 131f5de5341aa0ea37f040c2fefb3a34311074d0
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Aug 6 16:51:19 2015 +0200

    spell-navigator: return the SpellChecker alongside the word
    
    It is more constrained, the spell checker can change only when going to
    another word. Which is more logical, it doesn't make sense to update the
    spell-checker property at another time. So the property is removed.

 plugins/spell/gedit-spell-navigator-gtv.c |   54 +++++++++++++++++++++--------
 plugins/spell/gedit-spell-navigator.c     |   36 ++++++++++---------
 plugins/spell/gedit-spell-navigator.h     |    8 +++-
 3 files changed, 64 insertions(+), 34 deletions(-)
---
diff --git a/plugins/spell/gedit-spell-navigator-gtv.c b/plugins/spell/gedit-spell-navigator-gtv.c
index 5c94506..8055066 100644
--- a/plugins/spell/gedit-spell-navigator-gtv.c
+++ b/plugins/spell/gedit-spell-navigator-gtv.c
@@ -232,7 +232,15 @@ gedit_spell_navigator_gtv_class_init (GeditSpellNavigatorGtvClass *klass)
                                                              G_PARAM_CONSTRUCT_ONLY |
                                                              G_PARAM_STATIC_STRINGS));
 
-       g_object_class_override_property (object_class, PROP_SPELL_CHECKER, "spell-checker");
+       g_object_class_install_property (object_class,
+                                        PROP_SPELL_CHECKER,
+                                        g_param_spec_object ("spell-checker",
+                                                             "Spell Checker",
+                                                             "",
+                                                             GEDIT_TYPE_SPELL_CHECKER,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT |
+                                                             G_PARAM_STATIC_STRINGS));
 }
 
 static void
@@ -264,9 +272,11 @@ select_misspelled_word (GeditSpellNavigatorGtv *navigator)
                                      0.0);
 }
 
-static gchar *
+static gboolean
 gedit_spell_navigator_gtv_goto_next (GeditSpellNavigator  *navigator,
-                                    GError              **error)
+                                    gchar               **word_p,
+                                    GeditSpellChecker   **spell_checker_p,
+                                    GError              **error_p)
 {
        GeditSpellNavigatorGtvPrivate *priv;
        GtkTextIter word_start;
@@ -298,7 +308,7 @@ gedit_spell_navigator_gtv_goto_next (GeditSpellNavigator  *navigator,
 
                if (gtk_text_iter_compare (&end, &word_end) <= 0)
                {
-                       return NULL;
+                       return FALSE;
                }
 
                word_start = word_end;
@@ -309,7 +319,7 @@ gedit_spell_navigator_gtv_goto_next (GeditSpellNavigator  *navigator,
                GtkTextIter word_end;
                gchar *word;
                gboolean correctly_spelled;
-               GError *my_error = NULL;
+               GError *error = NULL;
 
                if (!gtk_text_iter_starts_word (&word_start))
                {
@@ -321,7 +331,7 @@ gedit_spell_navigator_gtv_goto_next (GeditSpellNavigator  *navigator,
                        if (gtk_text_iter_equal (&iter, &word_start))
                        {
                                /* Didn't move, we are at the end. */
-                               return NULL;
+                               return FALSE;
                        }
 
                        gtk_text_iter_backward_word_start (&word_start);
@@ -329,28 +339,28 @@ gedit_spell_navigator_gtv_goto_next (GeditSpellNavigator  *navigator,
 
                if (!gedit_spell_utils_skip_no_spell_check (&word_start, &end))
                {
-                       return NULL;
+                       return FALSE;
                }
 
-               g_return_val_if_fail (gtk_text_iter_starts_word (&word_start), NULL);
+               g_return_val_if_fail (gtk_text_iter_starts_word (&word_start), FALSE);
 
                word_end = word_start;
                gtk_text_iter_forward_word_end (&word_end);
 
                if (gtk_text_iter_compare (&end, &word_end) < 0)
                {
-                       return NULL;
+                       return FALSE;
                }
 
                word = gtk_text_buffer_get_text (priv->buffer, &word_start, &word_end, FALSE);
 
-               correctly_spelled = gedit_spell_checker_check_word (priv->spell_checker, word, &my_error);
+               correctly_spelled = gedit_spell_checker_check_word (priv->spell_checker, word, &error);
 
-               if (my_error != NULL)
+               if (error != NULL)
                {
-                       g_propagate_error (error, my_error);
+                       g_propagate_error (error_p, error);
                        g_free (word);
-                       return NULL;
+                       return FALSE;
                }
 
                if (!correctly_spelled)
@@ -361,14 +371,28 @@ gedit_spell_navigator_gtv_goto_next (GeditSpellNavigator  *navigator,
 
                        select_misspelled_word (GEDIT_SPELL_NAVIGATOR_GTV (navigator));
 
-                       return word;
+                       if (spell_checker_p != NULL)
+                       {
+                               *spell_checker_p = g_object_ref (priv->spell_checker);
+                       }
+
+                       if (word_p != NULL)
+                       {
+                               *word_p = word;
+                       }
+                       else
+                       {
+                               free (word);
+                       }
+
+                       return TRUE;
                }
 
                word_start = word_end;
                g_free (word);
        }
 
-       return NULL;
+       return FALSE;
 }
 
 static void
diff --git a/plugins/spell/gedit-spell-navigator.c b/plugins/spell/gedit-spell-navigator.c
index 56fcbb7..3a23a6e 100644
--- a/plugins/spell/gedit-spell-navigator.c
+++ b/plugins/spell/gedit-spell-navigator.c
@@ -23,11 +23,13 @@
 
 G_DEFINE_INTERFACE (GeditSpellNavigator, gedit_spell_navigator, G_TYPE_OBJECT)
 
-static gchar *
+static gboolean
 gedit_spell_navigator_goto_next_default (GeditSpellNavigator  *navigator,
+                                        gchar               **word,
+                                        GeditSpellChecker   **spell_checker,
                                         GError              **error)
 {
-       return NULL;
+       return FALSE;
 }
 
 static void
@@ -50,36 +52,36 @@ gedit_spell_navigator_default_init (GeditSpellNavigatorInterface *iface)
        iface->goto_next = gedit_spell_navigator_goto_next_default;
        iface->change = gedit_spell_navigator_change_default;
        iface->change_all = gedit_spell_navigator_change_all_default;
-
-       g_object_interface_install_property (iface,
-                                            g_param_spec_object ("spell-checker",
-                                                                 "Spell Checker",
-                                                                 "",
-                                                                 GEDIT_TYPE_SPELL_CHECKER,
-                                                                 G_PARAM_READWRITE |
-                                                                 G_PARAM_CONSTRUCT |
-                                                                 G_PARAM_STATIC_STRINGS));
 }
 
 /**
  * gedit_spell_navigator_goto_next:
  * @navigator: a #GeditSpellNavigator.
+ * @word: (out) (optional): a location to store an allocated string, or %NULL.
+ *   Use g_free() to free the returned string.
+ * @spell_checker: (out) (optional) (transfer full): a location to store the
+ *   #GeditSpellChecker used, or %NULL.
  * @error: (out) (optional): a location to a %NULL #GError, or %NULL.
  *
  * Goes to the next misspelled word. When called the first time, goes to the
  * first misspelled word.
  *
- * Returns: the next misspelled word, or %NULL if finished or if an error
- * occurred.
+ * Returns: %TRUE if a next misspelled word has been found, %FALSE if the spell
+ * checking is finished or if an error occurred.
  */
-gchar *
+gboolean
 gedit_spell_navigator_goto_next (GeditSpellNavigator  *navigator,
+                                gchar               **word,
+                                GeditSpellChecker   **spell_checker,
                                 GError              **error)
 {
-       g_return_val_if_fail (GEDIT_IS_SPELL_NAVIGATOR (navigator), NULL);
-       g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+       g_return_val_if_fail (GEDIT_IS_SPELL_NAVIGATOR (navigator), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-       return GEDIT_SPELL_NAVIGATOR_GET_IFACE (navigator)->goto_next (navigator, error);
+       return GEDIT_SPELL_NAVIGATOR_GET_IFACE (navigator)->goto_next (navigator,
+                                                                      word,
+                                                                      spell_checker,
+                                                                      error);
 }
 
 void
diff --git a/plugins/spell/gedit-spell-navigator.h b/plugins/spell/gedit-spell-navigator.h
index 52d409d..aa67ac4 100644
--- a/plugins/spell/gedit-spell-navigator.h
+++ b/plugins/spell/gedit-spell-navigator.h
@@ -34,7 +34,9 @@ struct _GeditSpellNavigatorInterface
 {
        GTypeInterface parent_interface;
 
-       gchar *         (* goto_next)           (GeditSpellNavigator  *navigator,
+       gboolean        (* goto_next)           (GeditSpellNavigator  *navigator,
+                                                gchar               **word,
+                                                GeditSpellChecker   **spell_checker,
                                                 GError              **error);
 
        void            (* change)              (GeditSpellNavigator *navigator,
@@ -46,7 +48,9 @@ struct _GeditSpellNavigatorInterface
                                                 const gchar         *change_to);
 };
 
-gchar *                gedit_spell_navigator_goto_next         (GeditSpellNavigator  *navigator,
+gboolean       gedit_spell_navigator_goto_next         (GeditSpellNavigator  *navigator,
+                                                        gchar               **word,
+                                                        GeditSpellChecker   **spell_checker,
                                                         GError              **error);
 
 void           gedit_spell_navigator_change            (GeditSpellNavigator *navigator,


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