[gspell/wip/current-word-policy] Implement the GspellCurrentWordPolicy private class
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell/wip/current-word-policy] Implement the GspellCurrentWordPolicy private class
- Date: Thu, 8 Dec 2016 11:09:38 +0000 (UTC)
commit 3d016f2fc8fc73951f848272873313861e74c545
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Dec 8 11:24:06 2016 +0100
Implement the GspellCurrentWordPolicy private class
docs/reference/Makefile.am | 1 +
gspell/Makefile.am | 2 +
gspell/gspell-current-word-policy.c | 156 +++++++++++++++++++++++++++++++++++
gspell/gspell-current-word-policy.h | 70 ++++++++++++++++
po/POTFILES.in | 1 +
5 files changed, 230 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am
index d3f17df..e420954 100644
--- a/docs/reference/Makefile.am
+++ b/docs/reference/Makefile.am
@@ -33,6 +33,7 @@ IGNORE_HFILES = \
gspellregion.h \
gspell-checker-private.h \
gspell-context-menu.h \
+ gspell-current-word-policy.h \
gspell-entry-private.h \
gspell-entry-utils.h \
gspell-init.h \
diff --git a/gspell/Makefile.am b/gspell/Makefile.am
index 825d6cf..cef040a 100644
--- a/gspell/Makefile.am
+++ b/gspell/Makefile.am
@@ -47,6 +47,7 @@ gspell_private_headers = \
gspellregion.h \
gspell-checker-private.h \
gspell-context-menu.h \
+ gspell-current-word-policy.h \
gspell-entry-private.h \
gspell-entry-utils.h \
gspell-init.h \
@@ -57,6 +58,7 @@ gspell_private_headers = \
gspell_private_c_files = \
gspellregion.c \
gspell-context-menu.c \
+ gspell-current-word-policy.c \
gspell-entry-utils.c \
gspell-init.c \
gspell-inline-checker-text-buffer.c \
diff --git a/gspell/gspell-current-word-policy.c b/gspell/gspell-current-word-policy.c
new file mode 100644
index 0000000..d567766
--- /dev/null
+++ b/gspell/gspell-current-word-policy.c
@@ -0,0 +1,156 @@
+/*
+ * This file is part of gspell, a spell-checking library.
+ *
+ * Copyright 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-current-word-policy.h"
+
+/* An object that decides whether to check the current word. When a word is
+ * being typed, it should not be spell-checked, because it would be annoying to
+ * see the red wavy underline appearing and disappearing constantly.
+ *
+ * You need to feed the object with events, and get the result with
+ * _gspell_current_word_policy_get_check_current_word().
+ */
+
+typedef struct _GspellCurrentWordPolicyPrivate GspellCurrentWordPolicyPrivate;
+
+struct _GspellCurrentWordPolicyPrivate
+{
+ guint check_current_word : 1;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GspellCurrentWordPolicy, _gspell_current_word_policy, G_TYPE_OBJECT)
+
+static void
+_gspell_current_word_policy_dispose (GObject *object)
+{
+
+ G_OBJECT_CLASS (_gspell_current_word_policy_parent_class)->dispose (object);
+}
+
+static void
+_gspell_current_word_policy_finalize (GObject *object)
+{
+
+ G_OBJECT_CLASS (_gspell_current_word_policy_parent_class)->finalize (object);
+}
+
+static void
+_gspell_current_word_policy_class_init (GspellCurrentWordPolicyClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = _gspell_current_word_policy_dispose;
+ object_class->finalize = _gspell_current_word_policy_finalize;
+}
+
+static void
+_gspell_current_word_policy_init (GspellCurrentWordPolicy *policy)
+{
+}
+
+GspellCurrentWordPolicy *
+_gspell_current_word_policy_new (void)
+{
+ return g_object_new (GSPELL_TYPE_CURRENT_WORD_POLICY, NULL);
+}
+
+gboolean
+_gspell_current_word_policy_get_check_current_word (GspellCurrentWordPolicy *policy)
+{
+ GspellCurrentWordPolicyPrivate *priv;
+
+ g_return_val_if_fail (GSPELL_IS_CURRENT_WORD_POLICY (policy), TRUE);
+
+ priv = _gspell_current_word_policy_get_instance_private (policy);
+
+ return priv->check_current_word;
+}
+
+/* For other events, it's better to use the more specific feed functions if
+ * possible.
+ */
+void
+_gspell_current_word_policy_set_check_current_word (GspellCurrentWordPolicy *policy,
+ gboolean check_current_word)
+{
+ GspellCurrentWordPolicyPrivate *priv;
+
+ g_return_if_fail (GSPELL_IS_CURRENT_WORD_POLICY (policy));
+
+ priv = _gspell_current_word_policy_get_instance_private (policy);
+
+ priv->check_current_word = check_current_word != FALSE;
+}
+
+/* On GspellChecker::session-cleared signal. */
+void
+_gspell_current_word_policy_session_cleared (GspellCurrentWordPolicy *policy)
+{
+ g_return_if_fail (GSPELL_IS_CURRENT_WORD_POLICY (policy));
+
+ _gspell_current_word_policy_set_check_current_word (policy, TRUE);
+}
+
+/* On GspellChecker::notify::language signal. */
+void
+_gspell_current_word_policy_language_changed (GspellCurrentWordPolicy *policy)
+{
+ g_return_if_fail (GSPELL_IS_CURRENT_WORD_POLICY (policy));
+
+ _gspell_current_word_policy_set_check_current_word (policy, TRUE);
+}
+
+/* When another GspellChecker object is used. */
+void
+_gspell_current_word_policy_checker_changed (GspellCurrentWordPolicy *policy)
+{
+ g_return_if_fail (GSPELL_IS_CURRENT_WORD_POLICY (policy));
+
+ _gspell_current_word_policy_set_check_current_word (policy, TRUE);
+}
+
+/* After a text insertion. */
+void
+_gspell_current_word_policy_several_chars_inserted (GspellCurrentWordPolicy *policy)
+{
+ g_return_if_fail (GSPELL_IS_CURRENT_WORD_POLICY (policy));
+
+ _gspell_current_word_policy_set_check_current_word (policy, TRUE);
+}
+
+/* After a text insertion. */
+void
+_gspell_current_word_policy_single_char_inserted (GspellCurrentWordPolicy *policy,
+ gunichar ch,
+ gboolean empty_selection,
+ gboolean at_cursor_pos)
+{
+ g_return_if_fail (GSPELL_IS_CURRENT_WORD_POLICY (policy));
+
+ if (g_unichar_isalnum (ch) &&
+ empty_selection &&
+ at_cursor_pos)
+ {
+ _gspell_current_word_policy_set_check_current_word (policy, FALSE);
+ }
+ else
+ {
+ _gspell_current_word_policy_set_check_current_word (policy, TRUE);
+ }
+}
diff --git a/gspell/gspell-current-word-policy.h b/gspell/gspell-current-word-policy.h
new file mode 100644
index 0000000..fc5c86f
--- /dev/null
+++ b/gspell/gspell-current-word-policy.h
@@ -0,0 +1,70 @@
+/*
+ * This file is part of gspell, a spell-checking library.
+ *
+ * Copyright 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/>.
+ */
+
+#ifndef GSPELL_CURRENT_WORD_POLICY_H
+#define GSPELL_CURRENT_WORD_POLICY_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GSPELL_TYPE_CURRENT_WORD_POLICY (_gspell_current_word_policy_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GspellCurrentWordPolicy, _gspell_current_word_policy,
+ GSPELL, CURRENT_WORD_POLICY,
+ GObject)
+
+struct _GspellCurrentWordPolicyClass
+{
+ GObjectClass parent_class;
+};
+
+G_GNUC_INTERNAL
+GspellCurrentWordPolicy *
+ _gspell_current_word_policy_new (void);
+
+G_GNUC_INTERNAL
+gboolean _gspell_current_word_policy_get_check_current_word (GspellCurrentWordPolicy *policy);
+
+G_GNUC_INTERNAL
+void _gspell_current_word_policy_set_check_current_word (GspellCurrentWordPolicy *policy,
+ gboolean
check_current_word);
+
+G_GNUC_INTERNAL
+void _gspell_current_word_policy_session_cleared (GspellCurrentWordPolicy *policy);
+
+G_GNUC_INTERNAL
+void _gspell_current_word_policy_language_changed (GspellCurrentWordPolicy *policy);
+
+G_GNUC_INTERNAL
+void _gspell_current_word_policy_checker_changed (GspellCurrentWordPolicy *policy);
+
+G_GNUC_INTERNAL
+void _gspell_current_word_policy_several_chars_inserted (GspellCurrentWordPolicy *policy);
+
+G_GNUC_INTERNAL
+void _gspell_current_word_policy_single_char_inserted (GspellCurrentWordPolicy *policy,
+ gunichar ch,
+ gboolean
empty_selection,
+ gboolean
at_cursor_pos);
+
+G_END_DECLS
+
+#endif /* GSPELL_CURRENT_WORD_POLICY_H */
+
+/* ex:set ts=8 noet: */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 266b24d..f10bd5a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,6 +2,7 @@
gspell/gspell-checker.c
gspell/gspell-checker-dialog.c
gspell/gspell-context-menu.c
+gspell/gspell-current-word-policy.c
gspell/gspell-entry.c
gspell/gspell-entry-buffer.c
gspell/gspell-entry-utils.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]