[gedit/wip/spell-checking] Add SpellNavigator interface and SpellNavigatorGtv implementation



commit 68e04af919ce082c80b99dae2d1034e7368f7981
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 |  215 +++++++++++++++++++++++++++++
 plugins/spell/gedit-spell-navigator-gtv.h |   42 ++++++
 plugins/spell/gedit-spell-navigator.c     |   87 ++++++++++++
 plugins/spell/gedit-spell-navigator.h     |   62 ++++++++
 5 files changed, 410 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..dc1e6cd
--- /dev/null
+++ b/plugins/spell/gedit-spell-navigator-gtv.c
@@ -0,0 +1,215 @@
+/*
+ * 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-navigator.h"
+#include "gedit-spell-checker.h"
+
+typedef struct _GeditSpellNavigatorGtvPrivate GeditSpellNavigatorGtvPrivate;
+
+struct _GeditSpellNavigatorGtvPrivate
+{
+       GtkTextView *view;
+       GeditSpellChecker *spell_checker;
+};
+
+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
+set_view (GeditSpellNavigatorGtv *navigator,
+         GtkTextView            *view)
+{
+       GeditSpellNavigatorGtvPrivate *priv;
+
+       priv = gedit_spell_navigator_gtv_get_instance_private (navigator);
+
+       g_return_if_fail (priv->view == NULL);
+       priv->view = g_object_ref (view);
+
+       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->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_install_property (object_class,
+                                        PROP_SPELL_CHECKER,
+                                        g_param_spec_object ("spell-checker",
+                                                             "Spell Checker",
+                                                             "",
+                                                             GEDIT_TYPE_SPELL_CHECKER,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY |
+                                                             G_PARAM_STATIC_STRINGS));
+}
+
+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;
+}
+
+/* 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..19cc807
--- /dev/null
+++ b/plugins/spell/gedit-spell-navigator-gtv.h
@@ -0,0 +1,42 @@
+/*
+ * 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>
+
+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;
+};
+
+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..93ee3e6
--- /dev/null
+++ b/plugins/spell/gedit-spell-navigator.c
@@ -0,0 +1,87 @@
+/*
+ * 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"
+
+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;
+}
+
+/**
+ * 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]