[gspell/wip/inline-checker: 1/3] text-view: replace functions by get_inline_checker()



commit fafb27a0679655a4872902437a51ae58e79015c0
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Jan 7 12:24:49 2016 +0100

    text-view: replace functions by get_inline_checker()

 docs/reference/gspell-1.0-sections.txt |    3 +-
 gspell/gspell-text-view.c              |   60 ++++++-------------------------
 gspell/gspell-text-view.h              |    7 ++--
 tests/test-spell.c                     |   17 +++------
 4 files changed, 21 insertions(+), 66 deletions(-)
---
diff --git a/docs/reference/gspell-1.0-sections.txt b/docs/reference/gspell-1.0-sections.txt
index 7dc6daf..a0a1200 100644
--- a/docs/reference/gspell-1.0-sections.txt
+++ b/docs/reference/gspell-1.0-sections.txt
@@ -98,8 +98,7 @@ gspell_text_buffer_get_spell_checker
 <SECTION>
 <FILE>text-view</FILE>
 <TITLE>GtkTextView support</TITLE>
-gspell_text_view_set_inline_checking
-gspell_text_view_get_inline_checking
+gspell_text_view_get_inline_checker
 </SECTION>
 
 <SECTION>
diff --git a/gspell/gspell-text-view.c b/gspell/gspell-text-view.c
index 070903c..886a265 100644
--- a/gspell/gspell-text-view.c
+++ b/gspell/gspell-text-view.c
@@ -30,70 +30,34 @@
 #define INLINE_CHECKER_KEY "gspell-text-view-inline-checker-key"
 
 /**
- * gspell_text_view_set_inline_checking:
+ * gspell_text_view_get_inline_checker:
  * @view: a #GtkTextView.
- * @enable: whether to enable the inline spell checking.
  *
- * Enables or disables inline spell checking.
+ * Returns the #GspellInlineCheckerText of @view. The returned object is
+ * guaranteed to be the same for the lifetime of @view.
  *
- * If enabled, misspelled words are highlighted with a %PANGO_UNDERLINE_ERROR,
- * usually a red wavy underline. Right-clicking a misspelled word pops up a
- * context menu of suggested replacements. The context menu also contains an
- * “Ignore All” item to add the misspelled word to the session dictionary. And
- * an “Add” item to add the word to the personal dictionary.
- *
- * The spell is checked only on the visible region of the #GtkTextView. Note
- * that if a same #GtkTextBuffer is used for several views, the misspelled words
- * are visible in all views, because the highlighting is achieved with a
- * #GtkTextTag added to the buffer.
- *
- * You need to call gspell_text_buffer_set_spell_checker() to associate a
- * #GspellChecker to the #GtkTextBuffer. #GtkTextView:buffer changes are
- * handled, as well as #GspellChecker changes.
+ * Returns: (transfer none): the #GspellInlineCheckerText of @view.
  */
-void
-gspell_text_view_set_inline_checking (GtkTextView *view,
-                                     gboolean     enable)
+GspellInlineCheckerText *
+gspell_text_view_get_inline_checker (GtkTextView *view)
 {
-       g_return_if_fail (GTK_IS_TEXT_VIEW (view));
+       GspellInlineCheckerText *inline_checker;
 
-       if (enable)
-       {
-               GspellInlineCheckerText *inline_checker;
+       g_return_val_if_fail (GTK_IS_TEXT_VIEW (view), NULL);
 
-               if (gspell_text_view_get_inline_checking (view))
-               {
-                       return;
-               }
+       inline_checker = g_object_get_data (G_OBJECT (view), INLINE_CHECKER_KEY);
 
+       if (inline_checker == NULL)
+       {
                inline_checker = _gspell_inline_checker_text_new (view);
-               gspell_inline_checker_text_set_enabled (inline_checker, TRUE);
 
                g_object_set_data_full (G_OBJECT (view),
                                        INLINE_CHECKER_KEY,
                                        inline_checker,
                                        g_object_unref);
        }
-       else
-       {
-               g_object_set_data (G_OBJECT (view),
-                                  INLINE_CHECKER_KEY,
-                                  NULL);
-       }
-}
-
-/**
- * gspell_text_view_get_inline_checking:
- * @view: a #GtkTextView.
- *
- * Returns: whether the inline spell checking is enabled for @view.
- */
-gboolean
-gspell_text_view_get_inline_checking (GtkTextView *view)
-{
-       g_return_val_if_fail (GTK_IS_TEXT_VIEW (view), FALSE);
 
-       return g_object_get_data (G_OBJECT (view), INLINE_CHECKER_KEY) != NULL;
+       return inline_checker;
 }
 
 /* ex:set ts=8 noet: */
diff --git a/gspell/gspell-text-view.h b/gspell/gspell-text-view.h
index 64fd754..0afc4fe 100644
--- a/gspell/gspell-text-view.h
+++ b/gspell/gspell-text-view.h
@@ -25,11 +25,10 @@
 #endif
 
 #include <gtk/gtk.h>
+#include <gspell/gspell-inline-checker-text.h>
 
-void           gspell_text_view_set_inline_checking    (GtkTextView *view,
-                                                        gboolean     enable);
-
-gboolean       gspell_text_view_get_inline_checking    (GtkTextView *view);
+GspellInlineCheckerText *
+               gspell_text_view_get_inline_checker     (GtkTextView *view);
 
 #endif /* __GSPELL_TEXT_VIEW_H__ */
 
diff --git a/tests/test-spell.c b/tests/test-spell.c
index 19c1ede..cf306fd 100644
--- a/tests/test-spell.c
+++ b/tests/test-spell.c
@@ -68,14 +68,6 @@ checker_button_clicked_cb (GtkButton *checker_button,
 }
 
 static void
-highlight_checkbutton_toggled_cb (GtkToggleButton *checkbutton,
-                                 TestSpell       *spell)
-{
-       gboolean enable = gtk_toggle_button_get_active (checkbutton);
-       gspell_text_view_set_inline_checking (spell->view, enable);
-}
-
-static void
 change_buffer_button_clicked_cb (GtkButton *change_buffer_button,
                                 TestSpell *spell)
 {
@@ -103,6 +95,7 @@ get_sidebar (TestSpell *spell)
        GtkWidget *change_buffer_button;
        GspellChecker *checker;
        const GspellLanguage *language;
+       GspellInlineCheckerText *inline_checker;
 
        sidebar = gtk_grid_new ();
 
@@ -141,10 +134,10 @@ get_sidebar (TestSpell *spell)
        gtk_container_add (GTK_CONTAINER (sidebar),
                           highlight_checkbutton);
 
-       g_signal_connect (highlight_checkbutton,
-                         "toggled",
-                         G_CALLBACK (highlight_checkbutton_toggled_cb),
-                         spell);
+       inline_checker = gspell_text_view_get_inline_checker (spell->view);
+       g_object_bind_property (highlight_checkbutton, "active",
+                               inline_checker, "enabled",
+                               G_BINDING_DEFAULT);
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (highlight_checkbutton), TRUE);
 


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