[gnome-text-editor] spellcheck: add passthrough API to check and list corrections



commit 9a5bc956075418e442ed0b8e8b4fcd07a209b7b4
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 1 17:40:13 2021 -0700

    spellcheck: add passthrough API to check and list corrections

 src/editor-document-private.h | 108 ++++++++++++++++++++++--------------------
 src/editor-document.c         |  25 ++++++++++
 src/editor-spell-checker.c    |  13 +++++
 src/editor-spell-checker.h    |  20 ++++----
 4 files changed, 105 insertions(+), 61 deletions(-)
---
diff --git a/src/editor-document-private.h b/src/editor-document-private.h
index 73fac11..53b63ce 100644
--- a/src/editor-document-private.h
+++ b/src/editor-document-private.h
@@ -24,57 +24,61 @@
 
 G_BEGIN_DECLS
 
-EditorDocument          *_editor_document_new                     (GFile                    *file,
-                                                                   const gchar              *draft_id);
-const gchar             *_editor_document_get_draft_id            (EditorDocument           *self);
-void                     _editor_document_set_draft_id            (EditorDocument           *self,
-                                                                   const gchar              *draft_id);
-GFile                   *_editor_document_get_draft_file          (EditorDocument           *self);
-gchar                   *_editor_document_dup_uri                 (EditorDocument           *self);
-void                     _editor_document_mark_busy               (EditorDocument           *self);
-void                     _editor_document_unmark_busy             (EditorDocument           *self);
-void                     _editor_document_set_externally_modified (EditorDocument           *self,
-                                                                   gboolean                  
externally_modified);
-gboolean                 _editor_document_get_was_restored        (EditorDocument           *self);
-void                     _editor_document_set_was_restored        (EditorDocument           *self,
-                                                                   gboolean                  was_restored);
-const GtkSourceEncoding *_editor_document_get_encoding            (EditorDocument           *self);
-void                     _editor_document_set_encoding            (EditorDocument           *document,
-                                                                   const GtkSourceEncoding  *encoding);
-GtkSourceNewlineType     _editor_document_get_newline_type        (EditorDocument           *self);
-void                     _editor_document_set_newline_type        (EditorDocument           *self,
-                                                                   GtkSourceNewlineType      newline_type);
-void                     _editor_document_load_async              (EditorDocument           *self,
-                                                                   EditorWindow             *window,
-                                                                   GCancellable             *cancellable,
-                                                                   GAsyncReadyCallback       callback,
-                                                                   gpointer                  user_data);
-gboolean                 _editor_document_load_finish             (EditorDocument           *self,
-                                                                   GAsyncResult             *result,
-                                                                   GError                  **error);
-void                     _editor_document_save_async              (EditorDocument           *self,
-                                                                   GFile                    *file,
-                                                                   GCancellable             *cancellable,
-                                                                   GAsyncReadyCallback       callback,
-                                                                   gpointer                  user_data);
-gboolean                 _editor_document_save_finish             (EditorDocument           *self,
-                                                                   GAsyncResult             *result,
-                                                                   GError                  **error);
-void                     _editor_document_save_draft_async        (EditorDocument           *self,
-                                                                   GCancellable             *cancellable,
-                                                                   GAsyncReadyCallback       callback,
-                                                                   gpointer                  user_data);
-gboolean                 _editor_document_save_draft_finish       (EditorDocument           *self,
-                                                                   GAsyncResult             *result,
-                                                                   GError                  **error);
-void                     _editor_document_guess_language_async    (EditorDocument           *self,
-                                                                   GCancellable             *cancellable,
-                                                                   GAsyncReadyCallback       callback,
-                                                                   gpointer                  user_data);
-gboolean                 _editor_document_guess_language_finish   (EditorDocument           *self,
-                                                                   GAsyncResult             *result,
-                                                                   GError                  **error);
-void                     _editor_document_attach_actions          (EditorDocument           *self,
-                                                                   GtkWidget                *widget);
+EditorDocument           *_editor_document_new                     (GFile                    *file,
+                                                                    const gchar              *draft_id);
+const gchar              *_editor_document_get_draft_id            (EditorDocument           *self);
+void                      _editor_document_set_draft_id            (EditorDocument           *self,
+                                                                    const gchar              *draft_id);
+GFile                    *_editor_document_get_draft_file          (EditorDocument           *self);
+gchar                    *_editor_document_dup_uri                 (EditorDocument           *self);
+void                      _editor_document_mark_busy               (EditorDocument           *self);
+void                      _editor_document_unmark_busy             (EditorDocument           *self);
+void                      _editor_document_set_externally_modified (EditorDocument           *self,
+                                                                    gboolean                  
externally_modified);
+gboolean                  _editor_document_get_was_restored        (EditorDocument           *self);
+void                      _editor_document_set_was_restored        (EditorDocument           *self,
+                                                                    gboolean                  was_restored);
+const GtkSourceEncoding  *_editor_document_get_encoding            (EditorDocument           *self);
+void                      _editor_document_set_encoding            (EditorDocument           *document,
+                                                                    const GtkSourceEncoding  *encoding);
+GtkSourceNewlineType      _editor_document_get_newline_type        (EditorDocument           *self);
+void                      _editor_document_set_newline_type        (EditorDocument           *self,
+                                                                    GtkSourceNewlineType      newline_type);
+void                      _editor_document_load_async              (EditorDocument           *self,
+                                                                    EditorWindow             *window,
+                                                                    GCancellable             *cancellable,
+                                                                    GAsyncReadyCallback       callback,
+                                                                    gpointer                  user_data);
+gboolean                  _editor_document_load_finish             (EditorDocument           *self,
+                                                                    GAsyncResult             *result,
+                                                                    GError                  **error);
+void                      _editor_document_save_async              (EditorDocument           *self,
+                                                                    GFile                    *file,
+                                                                    GCancellable             *cancellable,
+                                                                    GAsyncReadyCallback       callback,
+                                                                    gpointer                  user_data);
+gboolean                  _editor_document_save_finish             (EditorDocument           *self,
+                                                                    GAsyncResult             *result,
+                                                                    GError                  **error);
+void                      _editor_document_save_draft_async        (EditorDocument           *self,
+                                                                    GCancellable             *cancellable,
+                                                                    GAsyncReadyCallback       callback,
+                                                                    gpointer                  user_data);
+gboolean                  _editor_document_save_draft_finish       (EditorDocument           *self,
+                                                                    GAsyncResult             *result,
+                                                                    GError                  **error);
+void                      _editor_document_guess_language_async    (EditorDocument           *self,
+                                                                    GCancellable             *cancellable,
+                                                                    GAsyncReadyCallback       callback,
+                                                                    gpointer                  user_data);
+gboolean                  _editor_document_guess_language_finish   (EditorDocument           *self,
+                                                                    GAsyncResult             *result,
+                                                                    GError                  **error);
+void                      _editor_document_attach_actions          (EditorDocument           *self,
+                                                                    GtkWidget                *widget);
+gboolean                  _editor_document_check_spelling          (EditorDocument           *self,
+                                                                    const char               *word);
+char                    **_editor_document_list_corrections        (EditorDocument           *self,
+                                                                    const char               *word);
 
 G_END_DECLS
diff --git a/src/editor-document.c b/src/editor-document.c
index 11a961c..b9c2512 100644
--- a/src/editor-document.c
+++ b/src/editor-document.c
@@ -1812,3 +1812,28 @@ _editor_document_attach_actions (EditorDocument *self,
 
   gtk_widget_insert_action_group (widget, "spelling", G_ACTION_GROUP (group));
 }
+
+gboolean
+_editor_document_check_spelling (EditorDocument *self,
+                                 const char     *word)
+{
+  g_return_val_if_fail (EDITOR_IS_DOCUMENT (self), FALSE);
+
+  if (self->spell_checker != NULL)
+    return editor_spell_checker_check_word (self->spell_checker, word, -1);
+
+  return TRUE;
+}
+
+char **
+_editor_document_list_corrections (EditorDocument *self,
+                                   const char     *word)
+{
+  g_return_val_if_fail (EDITOR_IS_DOCUMENT (self), NULL);
+  g_return_val_if_fail (word != NULL, NULL);
+
+  if (self->spell_checker == NULL)
+    return NULL;
+
+  return editor_spell_checker_list_corrections (self->spell_checker, word);
+}
diff --git a/src/editor-spell-checker.c b/src/editor-spell-checker.c
index 1d620aa..2f873da 100644
--- a/src/editor-spell-checker.c
+++ b/src/editor-spell-checker.c
@@ -276,3 +276,16 @@ editor_spell_checker_check_word (EditorSpellChecker *self,
 
   return editor_spell_language_contains_word (self->language, word, word_len);
 }
+
+char **
+editor_spell_checker_list_corrections (EditorSpellChecker *self,
+                                       const char         *word)
+{
+  g_return_val_if_fail (EDITOR_IS_SPELL_CHECKER (self), NULL);
+  g_return_val_if_fail (word != NULL, NULL);
+
+  if (self->language == NULL)
+    return NULL;
+
+  return editor_spell_language_list_corrections (self->language, word, -1);
+}
diff --git a/src/editor-spell-checker.h b/src/editor-spell-checker.h
index dc53c42..75cbcc8 100644
--- a/src/editor-spell-checker.h
+++ b/src/editor-spell-checker.h
@@ -28,14 +28,16 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (EditorSpellChecker, editor_spell_checker, EDITOR, SPELL_CHECKER, GObject)
 
-EditorSpellChecker  *editor_spell_checker_new          (EditorSpellProvider *provider,
-                                                        const char          *language);
-EditorSpellProvider *editor_spell_checker_get_provider (EditorSpellChecker  *self);
-const char          *editor_spell_checker_get_language (EditorSpellChecker  *self);
-void                 editor_spell_checker_set_language (EditorSpellChecker  *self,
-                                                        const char          *language);
-gboolean             editor_spell_checker_check_word   (EditorSpellChecker  *self,
-                                                        const char          *word,
-                                                        gssize               word_len);
+EditorSpellChecker   *editor_spell_checker_new              (EditorSpellProvider *provider,
+                                                             const char          *language);
+EditorSpellProvider  *editor_spell_checker_get_provider     (EditorSpellChecker  *self);
+const char           *editor_spell_checker_get_language     (EditorSpellChecker  *self);
+void                  editor_spell_checker_set_language     (EditorSpellChecker  *self,
+                                                             const char          *language);
+gboolean              editor_spell_checker_check_word       (EditorSpellChecker  *self,
+                                                             const char          *word,
+                                                             gssize               word_len);
+char                **editor_spell_checker_list_corrections (EditorSpellChecker  *self,
+                                                             const char          *word);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]