aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-spell-text-view.c
diff options
context:
space:
mode:
Diffstat (limited to 'e-util/e-spell-text-view.c')
-rw-r--r--e-util/e-spell-text-view.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/e-util/e-spell-text-view.c b/e-util/e-spell-text-view.c
new file mode 100644
index 0000000000..283b674d5a
--- /dev/null
+++ b/e-util/e-spell-text-view.c
@@ -0,0 +1,118 @@
+/*
+ * e-spell-text-view.c
+ *
+ * This program 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 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+/* Just a proxy for GtkSpell Text View spell checker */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+
+#ifdef WITH_GTKSPELL
+#include <gtkspell/gtkspell.h>
+#endif
+
+#include "e-spell-text-view.h"
+
+/**
+ * e_spell_text_view_is_supported:
+ *
+ * Returns whether evolution was compiled with GtkSpell3. If it returns
+ * %FALSE, all the other e_spell_text_view_... functions do nothing.
+ *
+ * Returns: Whether evolution was compiled with GtkSpell3
+ *
+ * Since: 3.12
+ **/
+gboolean
+e_spell_text_view_is_supported (void)
+{
+#ifdef WITH_GTKSPELL
+ return TRUE;
+#else /* WITH_GTKSPELL */
+ return FALSE;
+#endif /* WITH_GTKSPELL */
+}
+
+/**
+ * e_spell_text_view_attach:
+ * @text_view: a #GtkTextView
+ *
+ * Attaches a spell checker into the @text_view, if spell-checking is
+ * enabled in Evolution.
+ *
+ * Returns: Whether successfully attached the spell checker
+ *
+ * Since: 3.12
+ **/
+gboolean
+e_spell_text_view_attach (GtkTextView *text_view)
+{
+#ifdef WITH_GTKSPELL
+ GtkSpellChecker *spell;
+ GSettings *settings;
+ gchar **strv;
+ gboolean success;
+
+ settings = g_settings_new ("org.gnome.evolution.mail");
+
+ /* do nothing, if spell-checking is disabled */
+ if (!g_settings_get_boolean (settings, "composer-inline-spelling")) {
+ g_object_unref (settings);
+ return FALSE;
+ }
+
+ strv = g_settings_get_strv (settings, "composer-spell-languages");
+ g_object_unref (settings);
+
+ spell = gtk_spell_checker_new ();
+ g_object_set (G_OBJECT (spell), "decode-language-codes", TRUE, NULL);
+ if (strv)
+ gtk_spell_checker_set_language (spell, strv[0], NULL);
+ success = gtk_spell_checker_attach (spell, text_view);
+
+ g_strfreev (strv);
+
+ return success;
+#else /* WITH_GTKSPELL */
+ return FALSE;
+#endif /* WITH_GTKSPELL */
+}
+
+/**
+ * e_spell_text_view_recheck_all:
+ * @text_view: a #GtkTextView with attached spell checker
+ *
+ * Checks whole content of the @text_view for spell-errors,
+ * if it has previously attached spell-checker with
+ * e_spell_text_view_attach().
+ *
+ * Since: 3.12
+ **/
+void
+e_spell_text_view_recheck_all (GtkTextView *text_view)
+{
+#ifdef WITH_GTKSPELL
+ GtkSpellChecker *spell;
+
+ spell = gtk_spell_checker_get_from_text_view (text_view);
+ if (spell)
+ gtk_spell_checker_recheck_all (spell);
+#endif /* WITH_GTKSPELL */
+}