[gspell/wip/text-view-class] Rename GspellInlineCheckerTextView -> GspellTextView
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell/wip/text-view-class] Rename GspellInlineCheckerTextView -> GspellTextView
- Date: Fri, 11 Mar 2016 15:46:04 +0000 (UTC)
commit 9d4a85a1cc2fc4b39343f2746a660929a013ca9f
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Mar 11 15:54:21 2016 +0100
Rename GspellInlineCheckerTextView -> GspellTextView
docs/reference/gspell-1.0-sections.txt | 14 +-
docs/reference/gspell-docs.xml | 2 +-
gspell/Makefile.am | 8 +-
gspell/gspell-inline-checker-text-view.c | 340 -------------------
gspell/gspell-text-buffer.c | 4 +-
gspell/gspell-text-view.c | 343 ++++++++++++++++++++
...line-checker-text-view.h => gspell-text-view.h} | 23 +-
gspell/gspell.h | 2 +-
po/POTFILES.in | 2 +-
tests/test-spell.c | 2 +-
10 files changed, 371 insertions(+), 369 deletions(-)
---
diff --git a/docs/reference/gspell-1.0-sections.txt b/docs/reference/gspell-1.0-sections.txt
index 030ac88..9bc9d7f 100644
--- a/docs/reference/gspell-1.0-sections.txt
+++ b/docs/reference/gspell-1.0-sections.txt
@@ -51,15 +51,15 @@ GSPELL_TYPE_TEXT_BUFFER
</SECTION>
<SECTION>
-<FILE>inline-checker-text-view</FILE>
-<TITLE>GspellInlineCheckerTextView</TITLE>
-GspellInlineCheckerTextView
+<FILE>text-view</FILE>
+<TITLE>GspellTextView</TITLE>
+GspellTextView
gspell_text_view_get_inline_checker
-gspell_inline_checker_text_view_set_enabled
-gspell_inline_checker_text_view_get_enabled
+gspell_text_view_get_enabled
+gspell_text_view_set_enabled
<SUBSECTION Standard>
-GSPELL_TYPE_INLINE_CHECKER_TEXT_VIEW
-GspellInlineCheckerTextViewClass
+GSPELL_TYPE_TEXT_VIEW
+GspellTextViewClass
</SECTION>
<SECTION>
diff --git a/docs/reference/gspell-docs.xml b/docs/reference/gspell-docs.xml
index a183f6b..b006ce4 100644
--- a/docs/reference/gspell-docs.xml
+++ b/docs/reference/gspell-docs.xml
@@ -28,7 +28,7 @@
<chapter>
<title>Inline Checkers</title>
- <xi:include href="xml/inline-checker-text-view.xml"/>
+ <xi:include href="xml/text-view.xml"/>
</chapter>
<chapter>
diff --git a/gspell/Makefile.am b/gspell/Makefile.am
index fce324c..f025b4d 100644
--- a/gspell/Makefile.am
+++ b/gspell/Makefile.am
@@ -20,26 +20,26 @@ gspell_public_headers = \
gspell.h \
gspell-checker.h \
gspell-checker-dialog.h \
- gspell-inline-checker-text-view.h \
gspell-language.h \
gspell-language-chooser.h \
gspell-language-chooser-button.h \
gspell-language-chooser-dialog.h \
gspell-navigator.h \
gspell-navigator-text-view.h \
- gspell-text-buffer.h
+ gspell-text-buffer.h \
+ gspell-text-view.h
gspell_public_c_files = \
gspell-checker.c \
gspell-checker-dialog.c \
- gspell-inline-checker-text-view.c \
gspell-language.c \
gspell-language-chooser.c \
gspell-language-chooser-button.c \
gspell-language-chooser-dialog.c \
gspell-navigator.c \
gspell-navigator-text-view.c \
- gspell-text-buffer.c
+ gspell-text-buffer.c \
+ gspell-text-view.c
gspell_private_headers = \
gconstructor.h \
diff --git a/gspell/gspell-text-buffer.c b/gspell/gspell-text-buffer.c
index 6bebe37..d94ae99 100644
--- a/gspell/gspell-text-buffer.c
+++ b/gspell/gspell-text-buffer.c
@@ -24,8 +24,8 @@
* @Title: GspellTextBuffer
* @Short_description: Spell checking support for GtkTextBuffer
*
- * #GspellTextBuffer extends the #GtkTextBuffer class without subclassing it,
- * because the GtkSourceView library has already a #GtkTextBuffer subclass.
+ * #GspellTextBuffer extends the #GtkTextBuffer class but without subclassing
+ * it, because the GtkSourceView library has already a #GtkTextBuffer subclass.
*/
struct _GspellTextBuffer
diff --git a/gspell/gspell-text-view.c b/gspell/gspell-text-view.c
new file mode 100644
index 0000000..097adaa
--- /dev/null
+++ b/gspell/gspell-text-view.c
@@ -0,0 +1,343 @@
+/*
+ * This file is part of gspell, a spell-checking library.
+ *
+ * Copyright 2015, 2016 - 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-buffer.h"
+
+/**
+ * SECTION:text-view
+ * @Title: GspellTextView
+ * @Short_description: Spell checking support for GtkTextView
+ *
+ * #GspellTextView extends the #GtkTextView class with inline spell checking.
+ * 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.
+ *
+ * Note that #GspellTextView extends the #GtkTextView class but without
+ * subclassing it, because the GtkSourceView library has already a #GtkTextView
+ * subclass.
+ */
+
+typedef struct _GspellTextViewPrivate GspellTextViewPrivate;
+
+struct _GspellTextViewPrivate
+{
+ GtkTextView *view;
+ GspellInlineCheckerTextBuffer *inline_checker;
+};
+
+enum
+{
+ PROP_0,
+ PROP_VIEW,
+ PROP_ENABLED,
+};
+
+#define GSPELL_TEXT_VIEW_KEY "gspell-text-view-key"
+
+G_DEFINE_TYPE_WITH_PRIVATE (GspellTextView, gspell_text_view, G_TYPE_OBJECT)
+
+static void
+create_inline_checker (GspellTextView *gspell_view)
+{
+ GspellTextViewPrivate *priv;
+ GtkTextBuffer *buffer;
+
+ priv = gspell_text_view_get_instance_private (gspell_view);
+
+ if (priv->inline_checker != NULL)
+ {
+ return;
+ }
+
+ buffer = gtk_text_view_get_buffer (priv->view);
+ priv->inline_checker = _gspell_inline_checker_text_buffer_new (buffer);
+ _gspell_inline_checker_text_buffer_attach_view (priv->inline_checker,
+ priv->view);
+}
+
+static void
+destroy_inline_checker (GspellTextView *gspell_view)
+{
+ GspellTextViewPrivate *priv;
+
+ priv = gspell_text_view_get_instance_private (gspell_view);
+
+ if (priv->view == NULL || priv->inline_checker == NULL)
+ {
+ return;
+ }
+
+ _gspell_inline_checker_text_buffer_detach_view (priv->inline_checker,
+ priv->view);
+ g_clear_object (&priv->inline_checker);
+}
+
+static void
+notify_buffer_cb (GtkTextView *gtk_view,
+ GParamSpec *pspec,
+ GspellTextView *gspell_view)
+{
+ GspellTextViewPrivate *priv;
+
+ priv = gspell_text_view_get_instance_private (gspell_view);
+
+ if (priv->inline_checker == NULL)
+ {
+ return;
+ }
+
+ destroy_inline_checker (gspell_view);
+ create_inline_checker (gspell_view);
+}
+
+static void
+set_view (GspellTextView *gspell_view,
+ GtkTextView *gtk_view)
+{
+ GspellTextViewPrivate *priv;
+
+ g_return_if_fail (GTK_IS_TEXT_VIEW (gtk_view));
+
+ priv = gspell_text_view_get_instance_private (gspell_view);
+
+ g_assert (priv->view == NULL);
+ g_assert (priv->inline_checker == NULL);
+
+ priv->view = gtk_view;
+
+ g_signal_connect_object (priv->view,
+ "notify::buffer",
+ G_CALLBACK (notify_buffer_cb),
+ gspell_view,
+ 0);
+}
+
+static void
+gspell_text_view_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GspellTextView *gspell_view;
+ GspellTextViewPrivate *priv;
+
+ gspell_view = GSPELL_TEXT_VIEW (object);
+ priv = gspell_text_view_get_instance_private (gspell_view);
+
+ switch (prop_id)
+ {
+ case PROP_VIEW:
+ g_value_set_object (value, priv->view);
+ break;
+
+ case PROP_ENABLED:
+ g_value_set_boolean (value, gspell_text_view_get_enabled (gspell_view));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gspell_text_view_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GspellTextView *gspell_view = GSPELL_TEXT_VIEW (object);
+
+ switch (prop_id)
+ {
+ case PROP_VIEW:
+ set_view (gspell_view, g_value_get_object (value));
+ break;
+
+ case PROP_ENABLED:
+ gspell_text_view_set_enabled (gspell_view, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gspell_text_view_dispose (GObject *object)
+{
+ GspellTextViewPrivate *priv;
+
+ priv = gspell_text_view_get_instance_private (GSPELL_TEXT_VIEW (object));
+
+ if (priv->view != NULL && priv->inline_checker != NULL)
+ {
+ _gspell_inline_checker_text_buffer_detach_view (priv->inline_checker,
+ priv->view);
+ }
+
+ priv->view = NULL;
+ g_clear_object (&priv->inline_checker);
+
+ G_OBJECT_CLASS (gspell_text_view_parent_class)->dispose (object);
+}
+
+static void
+gspell_text_view_class_init (GspellTextViewClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = gspell_text_view_get_property;
+ object_class->set_property = gspell_text_view_set_property;
+ object_class->dispose = gspell_text_view_dispose;
+
+ /**
+ * GspellTextView:view:
+ *
+ * The #GtkTextView.
+ */
+ g_object_class_install_property (object_class,
+ PROP_VIEW,
+ g_param_spec_object ("view",
+ "View",
+ "",
+ GTK_TYPE_TEXT_VIEW,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GspellTextView:enabled:
+ *
+ * Whether the inline spell checking is enabled.
+ */
+ g_object_class_install_property (object_class,
+ PROP_ENABLED,
+ g_param_spec_boolean ("enabled",
+ "Enabled",
+ "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void
+gspell_text_view_init (GspellTextView *gspell_view)
+{
+}
+
+/**
+ * gspell_text_view_get_inline_checker:
+ * @gtk_view: a #GtkTextView.
+ *
+ * Returns the #GspellTextView of @gtk_view. The returned object is guaranteed
+ * to be the same for the lifetime of @gtk_view.
+ *
+ * Returns: (transfer none): the #GspellTextView of @gtk_view.
+ */
+GspellTextView *
+gspell_text_view_get_inline_checker (GtkTextView *gtk_view)
+{
+ GspellTextView *gspell_view;
+
+ g_return_val_if_fail (GTK_IS_TEXT_VIEW (gtk_view), NULL);
+
+ gspell_view = g_object_get_data (G_OBJECT (gtk_view), GSPELL_TEXT_VIEW_KEY);
+
+ if (gspell_view == NULL)
+ {
+ gspell_view = g_object_new (GSPELL_TYPE_TEXT_VIEW,
+ "view", gtk_view,
+ NULL);
+
+ g_object_set_data_full (G_OBJECT (gtk_view),
+ GSPELL_TEXT_VIEW_KEY,
+ gspell_view,
+ g_object_unref);
+ }
+
+ g_return_val_if_fail (GSPELL_IS_TEXT_VIEW (gspell_view), NULL);
+ return gspell_view;
+}
+
+/**
+ * gspell_text_view_set_enabled:
+ * @gspell_view: a #GspellTextView.
+ * @enabled: the new state.
+ *
+ * Enables or disables the inline spell checking.
+ */
+void
+gspell_text_view_set_enabled (GspellTextView *gspell_view,
+ gboolean enabled)
+{
+ g_return_if_fail (GSPELL_IS_TEXT_VIEW (gspell_view));
+
+ enabled = enabled != FALSE;
+
+ if (enabled == gspell_text_view_get_enabled (gspell_view))
+ {
+ return;
+ }
+
+ if (enabled)
+ {
+ create_inline_checker (gspell_view);
+ }
+ else
+ {
+ destroy_inline_checker (gspell_view);
+ }
+
+ g_object_notify (G_OBJECT (gspell_view), "enabled");
+}
+
+/**
+ * gspell_text_view_get_enabled:
+ * @gspell_view: a #GspellTextView.
+ *
+ * Returns: whether the inline spell checking is enabled.
+ */
+gboolean
+gspell_text_view_get_enabled (GspellTextView *gspell_view)
+{
+ GspellTextViewPrivate *priv;
+
+ g_return_val_if_fail (GSPELL_IS_TEXT_VIEW (gspell_view), FALSE);
+
+ priv = gspell_text_view_get_instance_private (gspell_view);
+
+ return priv->inline_checker != NULL;
+}
+
+/* ex:set ts=8 noet: */
diff --git a/gspell/gspell-inline-checker-text-view.h b/gspell/gspell-text-view.h
similarity index 60%
rename from gspell/gspell-inline-checker-text-view.h
rename to gspell/gspell-text-view.h
index 0e4374e..aa521af 100644
--- a/gspell/gspell-inline-checker-text-view.h
+++ b/gspell/gspell-text-view.h
@@ -17,8 +17,8 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef __GSPELL_INLINE_CHECKER_TEXT_VIEW_H__
-#define __GSPELL_INLINE_CHECKER_TEXT_VIEW_H__
+#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."
@@ -28,12 +28,12 @@
G_BEGIN_DECLS
-#define GSPELL_TYPE_INLINE_CHECKER_TEXT_VIEW (gspell_inline_checker_text_view_get_type ())
-G_DECLARE_DERIVABLE_TYPE (GspellInlineCheckerTextView, gspell_inline_checker_text_view,
- GSPELL, INLINE_CHECKER_TEXT_VIEW,
+#define GSPELL_TYPE_TEXT_VIEW (gspell_text_view_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GspellTextView, gspell_text_view,
+ GSPELL, TEXT_VIEW,
GObject)
-struct _GspellInlineCheckerTextViewClass
+struct _GspellTextViewClass
{
GObjectClass parent_class;
@@ -41,16 +41,15 @@ struct _GspellInlineCheckerTextViewClass
gpointer padding[8];
};
-GspellInlineCheckerTextView *
- gspell_text_view_get_inline_checker (GtkTextView *view);
+GspellTextView * gspell_text_view_get_inline_checker (GtkTextView *gtk_view);
-void gspell_inline_checker_text_view_set_enabled (GspellInlineCheckerTextView *inline_checker,
- gboolean enabled);
+void gspell_text_view_set_enabled (GspellTextView *gspell_view,
+ gboolean enabled);
-gboolean gspell_inline_checker_text_view_get_enabled (GspellInlineCheckerTextView *inline_checker);
+gboolean gspell_text_view_get_enabled (GspellTextView *gspell_view);
G_END_DECLS
-#endif /* __GSPELL_INLINE_CHECKER_TEXT_VIEW_H__ */
+#endif /* __GSPELL_TEXT_VIEW_H__ */
/* ex:set ts=8 noet: */
diff --git a/gspell/gspell.h b/gspell/gspell.h
index 62df86e..24135ab 100644
--- a/gspell/gspell.h
+++ b/gspell/gspell.h
@@ -24,7 +24,6 @@
#include <gspell/gspell-checker.h>
#include <gspell/gspell-checker-dialog.h>
-#include <gspell/gspell-inline-checker-text-view.h>
#include <gspell/gspell-language.h>
#include <gspell/gspell-language-chooser.h>
#include <gspell/gspell-language-chooser-button.h>
@@ -32,6 +31,7 @@
#include <gspell/gspell-navigator.h>
#include <gspell/gspell-navigator-text-view.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 81bd1ef..8431042 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,7 +2,6 @@
gspell/gspell-checker.c
gspell/gspell-checker-dialog.c
gspell/gspell-inline-checker-text-buffer.c
-gspell/gspell-inline-checker-text-view.c
gspell/gspell-language.c
gspell/gspell-language-chooser.c
gspell/gspell-language-chooser-button.c
@@ -12,6 +11,7 @@ gspell/gspell-navigator-text-view.c
gspell/gspell-osx.c
gspell/gspell-text-buffer.c
gspell/gspell-text-iter.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 e97bff1..9cd7d59 100644
--- a/tests/test-spell.c
+++ b/tests/test-spell.c
@@ -103,7 +103,7 @@ get_sidebar (TestSpell *spell)
GtkWidget *change_buffer_button;
GspellChecker *checker;
const GspellLanguage *language;
- GspellInlineCheckerTextView *inline_checker;
+ GspellTextView *inline_checker;
sidebar = gtk_grid_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]