[gedit/wip/spell-checking: 2/2] Add SpellNavigator interface and SpellNavigatorGtv implementation
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/spell-checking: 2/2] Add SpellNavigator interface and SpellNavigatorGtv implementation
- Date: Sun, 2 Aug 2015 11:37:00 +0000 (UTC)
commit 1c80acccfb26ad7a22e0741d26b3c282b521954b
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Aug 1 20:00:33 2015 +0200
Add SpellNavigator interface and SpellNavigatorGtv implementation
plugins/spell/Makefile.am | 4 +
plugins/spell/gedit-spell-navigator-gtv.c | 271 +++++++++++++++++++++++++++++
plugins/spell/gedit-spell-navigator-gtv.h | 47 +++++
plugins/spell/gedit-spell-navigator.c | 97 ++++++++++
plugins/spell/gedit-spell-navigator.h | 62 +++++++
5 files changed, 481 insertions(+), 0 deletions(-)
---
diff --git a/plugins/spell/Makefile.am b/plugins/spell/Makefile.am
index c80ef77..5d6d667 100644
--- a/plugins/spell/Makefile.am
+++ b/plugins/spell/Makefile.am
@@ -34,6 +34,10 @@ plugins_spell_libspell_la_SOURCES = \
plugins/spell/gedit-spell-checker-language.h \
plugins/spell/gedit-spell-language-dialog.c \
plugins/spell/gedit-spell-language-dialog.h \
+ plugins/spell/gedit-spell-navigator.c \
+ plugins/spell/gedit-spell-navigator.h \
+ plugins/spell/gedit-spell-navigator-gtv.c \
+ plugins/spell/gedit-spell-navigator-gtv.h \
plugins/spell/gedit-automatic-spell-checker.c \
plugins/spell/gedit-automatic-spell-checker.h \
plugins/spell/gedit-spell-utils.c \
diff --git a/plugins/spell/gedit-spell-navigator-gtv.c b/plugins/spell/gedit-spell-navigator-gtv.c
new file mode 100644
index 0000000..6a43333
--- /dev/null
+++ b/plugins/spell/gedit-spell-navigator-gtv.c
@@ -0,0 +1,271 @@
+/*
+ * gedit-spell-navigator-gtv.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2015 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gedit-spell-navigator-gtv.h"
+#include "gedit-spell-utils.h"
+
+typedef struct _GeditSpellNavigatorGtvPrivate GeditSpellNavigatorGtvPrivate;
+
+struct _GeditSpellNavigatorGtvPrivate
+{
+ GtkTextView *view;
+ GtkTextBuffer *buffer;
+ GeditSpellChecker *spell_checker;
+
+ /* Delimit the region to spell check. */
+ GtkTextMark *start_mark;
+ GtkTextMark *end_mark;
+};
+
+enum
+{
+ PROP_0,
+ PROP_VIEW,
+ PROP_SPELL_CHECKER,
+};
+
+static void gedit_spell_navigator_iface_init (gpointer g_iface, gpointer iface_data);
+
+G_DEFINE_TYPE_WITH_CODE (GeditSpellNavigatorGtv,
+ gedit_spell_navigator_gtv,
+ G_TYPE_OBJECT,
+ G_ADD_PRIVATE (GeditSpellNavigatorGtv)
+ G_IMPLEMENT_INTERFACE (GEDIT_TYPE_SPELL_NAVIGATOR,
+ gedit_spell_navigator_iface_init))
+
+static void
+init_boundaries (GeditSpellNavigatorGtv *navigator)
+{
+ GeditSpellNavigatorGtvPrivate *priv;
+ GtkTextIter start;
+ GtkTextIter end;
+
+ priv = gedit_spell_navigator_gtv_get_instance_private (navigator);
+
+ g_return_if_fail (priv->start_mark == NULL);
+ g_return_if_fail (priv->end_mark == NULL);
+
+ if (!gtk_text_buffer_get_selection_bounds (priv->buffer, &start, &end))
+ {
+ /* No selection, take the whole buffer. */
+ gtk_text_buffer_get_bounds (priv->buffer, &start, &end);
+ }
+
+ if (gedit_spell_utils_skip_no_spell_check (&start, &end))
+ {
+ if (gtk_text_iter_inside_word (&end))
+ {
+ gtk_text_iter_forward_word_end (&end);
+ }
+ else if (!gtk_text_iter_ends_word (&end) &&
+ !gtk_text_iter_is_end (&end))
+ {
+ gtk_text_iter_backward_word_start (&end);
+ gtk_text_iter_forward_word_end (&end);
+ }
+ }
+ else
+ {
+ /* No spell checking in the specified range. */
+ start = end;
+ }
+
+ priv->start_mark = gtk_text_buffer_create_mark (priv->buffer, NULL, &start, TRUE);
+ priv->end_mark = gtk_text_buffer_create_mark (priv->buffer, NULL, &end, FALSE);
+}
+
+static void
+set_view (GeditSpellNavigatorGtv *navigator,
+ GtkTextView *view)
+{
+ GeditSpellNavigatorGtvPrivate *priv;
+
+ priv = gedit_spell_navigator_gtv_get_instance_private (navigator);
+
+ g_return_if_fail (priv->view == NULL);
+ g_return_if_fail (priv->buffer == NULL);
+
+ priv->view = g_object_ref (view);
+ priv->buffer = g_object_ref (gtk_text_view_get_buffer (view));
+
+ init_boundaries (navigator);
+
+ g_object_notify (G_OBJECT (navigator), "view");
+}
+
+static void
+set_spell_checker (GeditSpellNavigatorGtv *navigator,
+ GeditSpellChecker *spell_checker)
+{
+ GeditSpellNavigatorGtvPrivate *priv;
+
+ priv = gedit_spell_navigator_gtv_get_instance_private (navigator);
+
+ if (g_set_object (&priv->spell_checker, spell_checker))
+ {
+ g_object_notify (G_OBJECT (navigator), "spell-checker");
+ }
+}
+
+static void
+gedit_spell_navigator_gtv_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GeditSpellNavigatorGtvPrivate *priv;
+
+ priv = gedit_spell_navigator_gtv_get_instance_private (GEDIT_SPELL_NAVIGATOR_GTV (object));
+
+ switch (prop_id)
+ {
+ case PROP_VIEW:
+ g_value_set_object (value, priv->view);
+ break;
+
+ case PROP_SPELL_CHECKER:
+ g_value_set_object (value, priv->spell_checker);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gedit_spell_navigator_gtv_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GeditSpellNavigatorGtv *navigator = GEDIT_SPELL_NAVIGATOR_GTV (object);
+
+ switch (prop_id)
+ {
+ case PROP_VIEW:
+ set_view (navigator, g_value_get_object (value));
+ break;
+
+ case PROP_SPELL_CHECKER:
+ set_spell_checker (navigator, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gedit_spell_navigator_gtv_dispose (GObject *object)
+{
+ GeditSpellNavigatorGtvPrivate *priv;
+
+ priv = gedit_spell_navigator_gtv_get_instance_private (GEDIT_SPELL_NAVIGATOR_GTV (object));
+
+ g_clear_object (&priv->view);
+ g_clear_object (&priv->buffer);
+ g_clear_object (&priv->spell_checker);
+
+ G_OBJECT_CLASS (gedit_spell_navigator_gtv_parent_class)->dispose (object);
+}
+
+#if 0
+static void
+gedit_spell_navigator_gtv_finalize (GObject *object)
+{
+
+ G_OBJECT_CLASS (gedit_spell_navigator_gtv_parent_class)->finalize (object);
+}
+#endif
+
+static void
+gedit_spell_navigator_gtv_class_init (GeditSpellNavigatorGtvClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = gedit_spell_navigator_gtv_get_property;
+ object_class->set_property = gedit_spell_navigator_gtv_set_property;
+ object_class->dispose = gedit_spell_navigator_gtv_dispose;
+
+ 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));
+
+ g_object_class_override_property (object_class, PROP_SPELL_CHECKER, "spell-checker");
+}
+
+static void
+gedit_spell_navigator_gtv_init (GeditSpellNavigatorGtv *self)
+{
+}
+
+static gchar *
+gedit_spell_navigator_gtv_get_next_misspelled_word (GeditSpellNavigator *navigator)
+{
+ return NULL;
+}
+
+static void
+gedit_spell_navigator_gtv_change (GeditSpellNavigator *navigator,
+ const gchar *word,
+ const gchar *change_to)
+{
+}
+
+static void
+gedit_spell_navigator_gtv_change_all (GeditSpellNavigator *navigator,
+ const gchar *word,
+ const gchar *change_to)
+{
+}
+
+static void
+gedit_spell_navigator_iface_init (gpointer g_iface,
+ gpointer iface_data)
+{
+ GeditSpellNavigatorInterface *iface = g_iface;
+
+ iface->get_next_misspelled_word = gedit_spell_navigator_gtv_get_next_misspelled_word;
+ iface->change = gedit_spell_navigator_gtv_change;
+ iface->change_all = gedit_spell_navigator_gtv_change_all;
+}
+
+GeditSpellNavigator *
+gedit_spell_navigator_gtv_new (GtkTextView *view,
+ GeditSpellChecker *spell_checker)
+{
+ g_return_val_if_fail (GTK_IS_TEXT_VIEW (view), NULL);
+ g_return_val_if_fail (GEDIT_IS_SPELL_CHECKER (spell_checker), NULL);
+
+ return g_object_new (GEDIT_TYPE_SPELL_NAVIGATOR_GTV,
+ "view", view,
+ "spell-checker", spell_checker,
+ NULL);
+}
+
+/* ex:set ts=8 noet: */
diff --git a/plugins/spell/gedit-spell-navigator-gtv.h b/plugins/spell/gedit-spell-navigator-gtv.h
new file mode 100644
index 0000000..487e3fd
--- /dev/null
+++ b/plugins/spell/gedit-spell-navigator-gtv.h
@@ -0,0 +1,47 @@
+/*
+ * gedit-spell-navigator-gtv.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2015 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GEDIT_SPELL_NAVIGATOR_GTV_H__
+#define __GEDIT_SPELL_NAVIGATOR_GTV_H__
+
+#include <gtk/gtk.h>
+#include "gedit-spell-navigator.h"
+#include "gedit-spell-checker.h"
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_SPELL_NAVIGATOR_GTV (gedit_spell_navigator_gtv_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GeditSpellNavigatorGtv, gedit_spell_navigator_gtv,
+ GEDIT, SPELL_NAVIGATOR_GTV,
+ GObject)
+
+struct _GeditSpellNavigatorGtvClass
+{
+ GObjectClass parent_class;
+};
+
+GeditSpellNavigator * gedit_spell_navigator_gtv_new (GtkTextView *view,
+ GeditSpellChecker *spell_checker);
+
+G_END_DECLS
+
+#endif /* __GEDIT_SPELL_NAVIGATOR_GTV_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/plugins/spell/gedit-spell-navigator.c b/plugins/spell/gedit-spell-navigator.c
new file mode 100644
index 0000000..0189525
--- /dev/null
+++ b/plugins/spell/gedit-spell-navigator.c
@@ -0,0 +1,97 @@
+/*
+ * gedit-spell-navigator.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2015 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gedit-spell-navigator.h"
+#include "gedit-spell-checker.h"
+
+G_DEFINE_INTERFACE (GeditSpellNavigator, gedit_spell_navigator, G_TYPE_OBJECT)
+
+static gchar *
+gedit_spell_navigator_get_next_misspelled_word_default (GeditSpellNavigator *navigator)
+{
+ return NULL;
+}
+
+static void
+gedit_spell_navigator_change_default (GeditSpellNavigator *navigator,
+ const gchar *word,
+ const gchar *change_to)
+{
+}
+
+static void
+gedit_spell_navigator_change_all_default (GeditSpellNavigator *navigator,
+ const gchar *word,
+ const gchar *change_to)
+{
+}
+
+static void
+gedit_spell_navigator_default_init (GeditSpellNavigatorInterface *iface)
+{
+ iface->get_next_misspelled_word = gedit_spell_navigator_get_next_misspelled_word_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_get_next_misspelled_word:
+ * @navigator: a #GeditSpellNavigator.
+ *
+ * Returns: the next misspelled word, or %NULL if finished.
+ */
+gchar *
+gedit_spell_navigator_get_next_misspelled_word (GeditSpellNavigator *navigator)
+{
+ g_return_val_if_fail (GEDIT_IS_SPELL_NAVIGATOR (navigator), NULL);
+
+ return GEDIT_SPELL_NAVIGATOR_GET_IFACE (navigator)->get_next_misspelled_word (navigator);
+}
+
+void
+gedit_spell_navigator_change (GeditSpellNavigator *navigator,
+ const gchar *word,
+ const gchar *change_to)
+{
+ g_return_if_fail (GEDIT_IS_SPELL_NAVIGATOR (navigator));
+
+ GEDIT_SPELL_NAVIGATOR_GET_IFACE (navigator)->change (navigator, word, change_to);
+}
+
+void
+gedit_spell_navigator_change_all (GeditSpellNavigator *navigator,
+ const gchar *word,
+ const gchar *change_to)
+{
+ g_return_if_fail (GEDIT_IS_SPELL_NAVIGATOR (navigator));
+
+ GEDIT_SPELL_NAVIGATOR_GET_IFACE (navigator)->change_all (navigator, word, change_to);
+}
+
+/* ex:set ts=8 noet: */
diff --git a/plugins/spell/gedit-spell-navigator.h b/plugins/spell/gedit-spell-navigator.h
new file mode 100644
index 0000000..87d394b
--- /dev/null
+++ b/plugins/spell/gedit-spell-navigator.h
@@ -0,0 +1,62 @@
+/*
+ * gedit-spell-navigator.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2015 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GEDIT_SPELL_NAVIGATOR_H__
+#define __GEDIT_SPELL_NAVIGATOR_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_SPELL_NAVIGATOR (gedit_spell_navigator_get_type ())
+G_DECLARE_INTERFACE (GeditSpellNavigator, gedit_spell_navigator,
+ GEDIT, SPELL_NAVIGATOR,
+ GObject)
+
+struct _GeditSpellNavigatorInterface
+{
+ GTypeInterface parent_interface;
+
+ gchar * (* get_next_misspelled_word) (GeditSpellNavigator *navigator);
+
+ void (* change) (GeditSpellNavigator *navigator,
+ const gchar *word,
+ const gchar *change_to);
+
+ void (* change_all) (GeditSpellNavigator *navigator,
+ const gchar *word,
+ const gchar *change_to);
+};
+
+gchar * gedit_spell_navigator_get_next_misspelled_word (GeditSpellNavigator *navigator);
+
+void gedit_spell_navigator_change (GeditSpellNavigator *navigator,
+ const gchar *word,
+ const gchar *change_to);
+
+void gedit_spell_navigator_change_all (GeditSpellNavigator *navigator,
+ const gchar *word,
+ const gchar *change_to);
+
+G_END_DECLS
+
+#endif /* __GEDIT_SPELL_NAVIGATOR_H__ */
+
+/* ex:set ts=8 noet: */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]