[gnome-text-editor] spellcheck: add plumbing to add word to dictionary
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] spellcheck: add plumbing to add word to dictionary
- Date: Fri, 9 Jul 2021 00:27:23 +0000 (UTC)
commit c981f38fd54449aa6d9ecbdb5ed996ada77dd7a9
Author: Christian Hergert <chergert redhat com>
Date: Thu Jul 8 17:25:51 2021 -0700
spellcheck: add plumbing to add word to dictionary
src/editor-document-private.h | 2 ++
src/editor-document.c | 10 ++++++++++
src/editor-spell-checker.c | 11 +++++++++++
src/editor-spell-checker.h | 2 ++
src/editor-spell-language.c | 11 +++++++++++
src/editor-spell-language.h | 4 ++++
src/enchant/editor-enchant-spell-language.c | 13 +++++++++++++
7 files changed, 53 insertions(+)
---
diff --git a/src/editor-document-private.h b/src/editor-document-private.h
index 53b63ce..b12951b 100644
--- a/src/editor-document-private.h
+++ b/src/editor-document-private.h
@@ -80,5 +80,7 @@ gboolean _editor_document_check_spelling (EditorDocume
const char *word);
char **_editor_document_list_corrections (EditorDocument *self,
const char *word);
+void _editor_document_add_spelling_word (EditorDocument *self,
+ const char *word);
G_END_DECLS
diff --git a/src/editor-document.c b/src/editor-document.c
index b9c2512..5e3e3bc 100644
--- a/src/editor-document.c
+++ b/src/editor-document.c
@@ -1837,3 +1837,13 @@ _editor_document_list_corrections (EditorDocument *self,
return editor_spell_checker_list_corrections (self->spell_checker, word);
}
+
+void
+_editor_document_add_spelling_word (EditorDocument *self,
+ const char *word)
+{
+ g_return_if_fail (EDITOR_IS_DOCUMENT (self));
+
+ if (self->spell_checker != NULL)
+ editor_spell_checker_add_word (self->spell_checker, word);
+}
diff --git a/src/editor-spell-checker.c b/src/editor-spell-checker.c
index 2f873da..3a49b34 100644
--- a/src/editor-spell-checker.c
+++ b/src/editor-spell-checker.c
@@ -289,3 +289,14 @@ editor_spell_checker_list_corrections (EditorSpellChecker *self,
return editor_spell_language_list_corrections (self->language, word, -1);
}
+
+void
+editor_spell_checker_add_word (EditorSpellChecker *self,
+ const char *word)
+{
+ g_return_if_fail (EDITOR_IS_SPELL_CHECKER (self));
+ g_return_if_fail (word != NULL);
+
+ if (self->language != NULL)
+ editor_spell_language_add_word (self->language, word);
+}
diff --git a/src/editor-spell-checker.h b/src/editor-spell-checker.h
index 75cbcc8..1a03cb2 100644
--- a/src/editor-spell-checker.h
+++ b/src/editor-spell-checker.h
@@ -39,5 +39,7 @@ gboolean editor_spell_checker_check_word (EditorSpellChecker
gssize word_len);
char **editor_spell_checker_list_corrections (EditorSpellChecker *self,
const char *word);
+void editor_spell_checker_add_word (EditorSpellChecker *self,
+ const char *word);
G_END_DECLS
diff --git a/src/editor-spell-language.c b/src/editor-spell-language.c
index 33344f1..b39377c 100644
--- a/src/editor-spell-language.c
+++ b/src/editor-spell-language.c
@@ -142,3 +142,14 @@ editor_spell_language_list_corrections (EditorSpellLanguage *self,
return EDITOR_SPELL_LANGUAGE_GET_CLASS (self)->list_corrections (self, word, word_len);
}
+
+void
+editor_spell_language_add_word (EditorSpellLanguage *self,
+ const char *word)
+{
+ g_return_if_fail (EDITOR_IS_SPELL_LANGUAGE (self));
+ g_return_if_fail (word != NULL);
+
+ if (EDITOR_SPELL_LANGUAGE_GET_CLASS (self)->add_word)
+ EDITOR_SPELL_LANGUAGE_GET_CLASS (self)->add_word (self, word);
+}
diff --git a/src/editor-spell-language.h b/src/editor-spell-language.h
index adfe37e..9d8d8b5 100644
--- a/src/editor-spell-language.h
+++ b/src/editor-spell-language.h
@@ -38,6 +38,8 @@ struct _EditorSpellLanguageClass
char **(*list_corrections) (EditorSpellLanguage *self,
const char *word,
gssize word_len);
+ void (*add_word) (EditorSpellLanguage *self,
+ const char *word);
/*< private >*/
gpointer _reserved[8];
@@ -50,5 +52,7 @@ gboolean editor_spell_language_contains_word (EditorSpellLanguage *self,
char **editor_spell_language_list_corrections (EditorSpellLanguage *self,
const char *word,
gssize word_len);
+void editor_spell_language_add_word (EditorSpellLanguage *self,
+ const char *word);
G_END_DECLS
diff --git a/src/enchant/editor-enchant-spell-language.c b/src/enchant/editor-enchant-spell-language.c
index a476fa2..00b6986 100644
--- a/src/enchant/editor-enchant-spell-language.c
+++ b/src/enchant/editor-enchant-spell-language.c
@@ -150,6 +150,18 @@ editor_enchant_spell_language_add_all_to_session (EditorEnchantSpellLanguage *se
enchant_dict_add_to_session (self->native, words[i], -1);
}
+static void
+editor_enchant_spell_language_add_word (EditorSpellLanguage *language,
+ const char *word)
+{
+ EditorEnchantSpellLanguage *self = (EditorEnchantSpellLanguage *)language;
+
+ g_assert (EDITOR_IS_SPELL_LANGUAGE (language));
+ g_assert (word != NULL);
+
+ enchant_dict_add (self->native, word, -1);
+}
+
static void
editor_enchant_spell_language_constructed (GObject *object)
{
@@ -230,6 +242,7 @@ editor_enchant_spell_language_class_init (EditorEnchantSpellLanguageClass *klass
spell_language_class->contains_word = editor_enchant_spell_language_contains_word;
spell_language_class->list_corrections = editor_enchant_spell_language_list_corrections;
+ spell_language_class->add_word = editor_enchant_spell_language_add_word;
properties [PROP_NATIVE] =
g_param_spec_pointer ("native",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]