[gspell/wip/inline-checker] Extend GtkTextView with inline spell checking feature



commit b0b5396ef71071d49fa981278f0d27e6d69f1a54
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Dec 31 17:47:58 2015 +0100

    Extend GtkTextView with inline spell checking feature

 gspell/Makefile.am        |    6 +++-
 gspell/gspell-text-view.c |   59 +++++++++++++++++++++++++++++++++++++++++++++
 gspell/gspell-text-view.h |   36 +++++++++++++++++++++++++++
 gspell/gspell.h           |    1 +
 po/POTFILES.in            |    1 +
 tests/test-spell.c        |   31 +----------------------
 6 files changed, 103 insertions(+), 31 deletions(-)
---
diff --git a/gspell/Makefile.am b/gspell/Makefile.am
index 2178ee4..31f21c4 100644
--- a/gspell/Makefile.am
+++ b/gspell/Makefile.am
@@ -26,7 +26,8 @@ gspell_public_headers =                               \
        gspell-language-chooser-dialog.h        \
        gspell-navigator.h                      \
        gspell-navigator-gtv.h                  \
-       gspell-text-buffer.h
+       gspell-text-buffer.h                    \
+       gspell-text-view.h
 
 gspell_public_c_files =                                \
        gspell-checker.c                        \
@@ -38,7 +39,8 @@ gspell_public_c_files =                               \
        gspell-language-chooser-dialog.c        \
        gspell-navigator.c                      \
        gspell-navigator-gtv.c                  \
-       gspell-text-buffer.c
+       gspell-text-buffer.c                    \
+       gspell-text-view.c
 
 gspell_private_headers =                       \
        gconstructor.h                          \
diff --git a/gspell/gspell-text-view.c b/gspell/gspell-text-view.c
new file mode 100644
index 0000000..3b88154
--- /dev/null
+++ b/gspell/gspell-text-view.c
@@ -0,0 +1,59 @@
+/*
+ * This file is part of gspell, a spell-checking library.
+ *
+ * Copyright 2015 - Sébastien Wilmet
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gspell-text-view.h"
+#include "gspell-inline-checker-text.h"
+
+#define INLINE_CHECKER_KEY "gspell-text-view-inline-checker-key"
+
+void
+gspell_text_view_set_inline_checking (GtkTextView *view,
+                                     gboolean     enable)
+{
+       g_return_if_fail (GTK_IS_TEXT_VIEW (view));
+
+       if (enable)
+       {
+               if (gspell_text_view_get_inline_checking (view))
+               {
+                       return;
+               }
+
+               g_object_set_data_full (G_OBJECT (view),
+                                       INLINE_CHECKER_KEY,
+                                       gspell_inline_checker_text_new (view),
+                                       g_object_unref);
+       }
+       else
+       {
+               g_object_set_data (G_OBJECT (view),
+                                  INLINE_CHECKER_KEY,
+                                  NULL);
+       }
+}
+
+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;
+}
+
+/* ex:set ts=8 noet: */
diff --git a/gspell/gspell-text-view.h b/gspell/gspell-text-view.h
new file mode 100644
index 0000000..64fd754
--- /dev/null
+++ b/gspell/gspell-text-view.h
@@ -0,0 +1,36 @@
+/*
+ * This file is part of gspell, a spell-checking library.
+ *
+ * Copyright 2015 - Sébastien Wilmet
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GSPELL_TEXT_VIEW_H__
+#define __GSPELL_TEXT_VIEW_H__
+
+#if !defined (__GSPELL_H_INSIDE__) && !defined (GSPELL_COMPILATION)
+#error "Only <gspell/gspell.h> can be included directly."
+#endif
+
+#include <gtk/gtk.h>
+
+void           gspell_text_view_set_inline_checking    (GtkTextView *view,
+                                                        gboolean     enable);
+
+gboolean       gspell_text_view_get_inline_checking    (GtkTextView *view);
+
+#endif /* __GSPELL_TEXT_VIEW_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/gspell/gspell.h b/gspell/gspell.h
index b635a81..08acd1e 100644
--- a/gspell/gspell.h
+++ b/gspell/gspell.h
@@ -32,6 +32,7 @@
 #include <gspell/gspell-navigator.h>
 #include <gspell/gspell-navigator-gtv.h>
 #include <gspell/gspell-text-buffer.h>
+#include <gspell/gspell-text-view.h>
 
 #undef __GSPELL_H_INSIDE__
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 656133b..86b44c5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -12,6 +12,7 @@ gspell/gspell-navigator.c
 gspell/gspell-navigator-gtv.c
 gspell/gspell-osx.c
 gspell/gspell-text-buffer.c
+gspell/gspell-text-view.c
 gspell/gspell-utils.c
 gspell/resources/checker-dialog.ui
 gspell/resources/language-dialog.ui
diff --git a/tests/test-spell.c b/tests/test-spell.c
index 8ce8095..643e4a0 100644
--- a/tests/test-spell.c
+++ b/tests/test-spell.c
@@ -29,7 +29,6 @@ struct _TestSpell
        GtkGrid parent;
 
        GtkTextView *view;
-       GspellInlineCheckerText *inline_spell;
 };
 
 G_DEFINE_TYPE (TestSpell, test_spell, GTK_TYPE_GRID)
@@ -42,21 +41,8 @@ get_spell_checker (TestSpell *spell)
 }
 
 static void
-test_spell_dispose (GObject *object)
-{
-       TestSpell *spell = TEST_SPELL (object);
-
-       g_clear_object (&spell->inline_spell);
-
-       G_OBJECT_CLASS (test_spell_parent_class)->dispose (object);
-}
-
-static void
 test_spell_class_init (TestSpellClass *klass)
 {
-       GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-       object_class->dispose = test_spell_dispose;
 }
 
 static void
@@ -85,21 +71,8 @@ static void
 highlight_checkbutton_toggled_cb (GtkToggleButton *checkbutton,
                                  TestSpell       *spell)
 {
-       if (gtk_toggle_button_get_active (checkbutton))
-       {
-               g_assert (spell->inline_spell == NULL);
-
-               /* A real application needs to check if
-                * gspell_checker_get_language() != NULL. If it is NULL, the
-                * inline spell checker should not be created and a warning
-                * should be printed to say that no dictionaries are available.
-                */
-               spell->inline_spell = gspell_inline_checker_text_new (spell->view);
-       }
-       else
-       {
-               g_clear_object (&spell->inline_spell);
-       }
+       gboolean enable = gtk_toggle_button_get_active (checkbutton);
+       gspell_text_view_set_inline_checking (spell->view, enable);
 }
 
 static void


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