[gedit/wip/spell-checking] spell-plugin: misc clean-ups



commit 403a1466b5e1a05cb6f21c5e8f2b4e28bc53aad1
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Aug 1 13:45:15 2015 +0200

    spell-plugin: misc clean-ups

 plugins/spell/gedit-spell-plugin.c |   91 +++++++++++++++++++++---------------
 1 files changed, 53 insertions(+), 38 deletions(-)
---
diff --git a/plugins/spell/gedit-spell-plugin.c b/plugins/spell/gedit-spell-plugin.c
index ce364f8..35ec3d3 100644
--- a/plugins/spell/gedit-spell-plugin.c
+++ b/plugins/spell/gedit-spell-plugin.c
@@ -324,7 +324,7 @@ get_check_range (GeditDocument *doc)
 
 static void
 update_current (GeditDocument *doc,
-               gint           current)
+               gint           current_offset)
 {
        CheckRange *range;
        GtkTextIter iter;
@@ -333,13 +333,13 @@ update_current (GeditDocument *doc,
        gedit_debug (DEBUG_PLUGINS);
 
        g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
-       g_return_if_fail (current >= 0);
+       g_return_if_fail (current_offset >= 0);
 
        range = get_check_range (doc);
        g_return_if_fail (range != NULL);
 
        gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc),
-                                           &iter, current);
+                                           &iter, current_offset);
 
        if (!gtk_text_iter_inside_word (&iter))
        {
@@ -352,10 +352,9 @@ update_current (GeditDocument *doc,
                        gtk_text_iter_backward_word_start (&iter);
                }
        }
-       else
+       else if (!gtk_text_iter_starts_word (&iter))
        {
-               if (!gtk_text_iter_starts_word (&iter))
-                       gtk_text_iter_backward_word_start (&iter);
+               gtk_text_iter_backward_word_start (&iter);
        }
 
        gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc),
@@ -397,17 +396,17 @@ set_check_range (GeditDocument *doc,
                range = g_new0 (CheckRange, 1);
 
                range->start_mark = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc),
-                                                                "check_range_start_mark",
+                                                                NULL,
                                                                 &iter,
                                                                 TRUE);
 
                range->end_mark = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc),
-                                                              "check_range_end_mark",
+                                                              NULL,
                                                               &iter,
                                                               FALSE);
 
                range->current_mark = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc),
-                                                                  "check_range_current_mark",
+                                                                  NULL,
                                                                   &iter,
                                                                   TRUE);
 
@@ -433,7 +432,9 @@ set_check_range (GeditDocument *doc,
                else
                {
                        if (!gtk_text_iter_ends_word (end))
+                       {
                                gtk_text_iter_forward_word_end (end);
+                       }
                }
        }
        else
@@ -445,6 +446,7 @@ set_check_range (GeditDocument *doc,
        gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc),
                                   range->start_mark,
                                   start);
+
        gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc),
                                   range->end_mark,
                                   end);
@@ -557,10 +559,7 @@ get_next_misspelled_word (GeditView *view,
        GeditSpellChecker *checker;
        GError *error = NULL;
 
-       g_return_val_if_fail (view != NULL, NULL);
-
        doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
-       g_return_val_if_fail (doc != NULL, NULL);
 
        range = get_check_range (doc);
        g_return_val_if_fail (range != NULL, NULL);
@@ -646,34 +645,38 @@ select_misspelled_word (GeditView *view,
 }
 
 static void
-ignore_cb (GeditSpellCheckerDialog *dialog,
-          const gchar             *w,
-          GeditView               *view)
+goto_next_misspelled_word (GeditSpellCheckerDialog *dialog,
+                          GeditView               *view)
 {
        gchar *word = NULL;
-       gint word_start_offset, word_end_offset;
+       gint word_start_offset;
+       gint word_end_offset;
 
        gedit_debug (DEBUG_PLUGINS);
 
-       g_return_if_fail (w != NULL);
-       g_return_if_fail (view != NULL);
-
        word = get_next_misspelled_word (view, &word_start_offset, &word_end_offset);
        if (word == NULL)
        {
                gedit_spell_checker_dialog_set_completed (dialog);
-
                return;
        }
 
        select_misspelled_word (view, word_start_offset, word_end_offset);
 
-       gedit_spell_checker_dialog_set_misspelled_word (GEDIT_SPELL_CHECKER_DIALOG (dialog), word);
+       gedit_spell_checker_dialog_set_misspelled_word (dialog, word);
 
        g_free (word);
 }
 
 static void
+ignore_cb (GeditSpellCheckerDialog *dialog,
+          const gchar             *word,
+          GeditView               *view)
+{
+       goto_next_misspelled_word (dialog, view);
+}
+
+static void
 change_cb (GeditSpellCheckerDialog *dialog,
           const gchar             *word,
           const gchar             *change,
@@ -726,8 +729,7 @@ change_cb (GeditSpellCheckerDialog *dialog,
 
        update_current (doc, range->mw_start + g_utf8_strlen (change, -1));
 
-       /* go to next misspelled word */
-       ignore_cb (dialog, word, view);
+       goto_next_misspelled_word (dialog, view);
 }
 
 static void
@@ -790,8 +792,7 @@ change_all_cb (GeditSpellCheckerDialog *dialog,
 
        update_current (doc, range->mw_start + g_utf8_strlen (change, -1));
 
-       /* go to next misspelled word */
-       ignore_cb (dialog, word, view);
+       goto_next_misspelled_word (dialog, view);
 
        g_object_unref (search_settings);
        g_object_unref (search_context);
@@ -802,11 +803,7 @@ add_word_cb (GeditSpellCheckerDialog *dialog,
             const gchar             *word,
             GeditView               *view)
 {
-       g_return_if_fail (view != NULL);
-       g_return_if_fail (word != NULL);
-
-       /* go to next misspelled word */
-       ignore_cb (dialog, word, view);
+       goto_next_misspelled_word (dialog, view);
 }
 
 static void
@@ -893,8 +890,10 @@ spell_cb (GSimpleAction *action,
        GeditDocument *doc;
        GeditSpellChecker *checker;
        GtkWidget *dialog;
-       GtkTextIter start, end;
-       gint word_start_offset, word_end_offset;
+       GtkTextIter start;
+       GtkTextIter end;
+       gint word_start_offset;
+       gint word_end_offset;
        gchar *word;
 
        gedit_debug (DEBUG_PLUGINS);
@@ -905,7 +904,6 @@ spell_cb (GSimpleAction *action,
        g_return_if_fail (view != NULL);
 
        doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
-       g_return_if_fail (doc != NULL);
 
        checker = get_spell_checker_from_document (doc);
        g_return_if_fail (checker != NULL);
@@ -950,13 +948,30 @@ spell_cb (GSimpleAction *action,
        dialog = gedit_spell_checker_dialog_new (GTK_WINDOW (priv->window), checker);
        gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
 
-       g_signal_connect (dialog, "ignore", G_CALLBACK (ignore_cb), view);
-       g_signal_connect (dialog, "ignore_all", G_CALLBACK (ignore_cb), view);
+       g_signal_connect (dialog,
+                         "ignore",
+                         G_CALLBACK (ignore_cb),
+                         view);
+
+       g_signal_connect (dialog,
+                         "ignore-all",
+                         G_CALLBACK (ignore_cb),
+                         view);
+
+       g_signal_connect (dialog,
+                         "change",
+                         G_CALLBACK (change_cb),
+                         view);
 
-       g_signal_connect (dialog, "change", G_CALLBACK (change_cb), view);
-       g_signal_connect (dialog, "change_all", G_CALLBACK (change_all_cb), view);
+       g_signal_connect (dialog,
+                         "change-all",
+                         G_CALLBACK (change_all_cb),
+                         view);
 
-       g_signal_connect (dialog, "add_word_to_personal", G_CALLBACK (add_word_cb), view);
+       g_signal_connect (dialog,
+                         "add-word-to-personal",
+                         G_CALLBACK (add_word_cb),
+                         view);
 
        gedit_spell_checker_dialog_set_misspelled_word (GEDIT_SPELL_CHECKER_DIALOG (dialog), word);
 



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