[gnome-text-editor] spellcheck: add API to update the spellcheck menu section



commit 8bd46dbe5e70cc1238c6a786fafc1d5e9012e559
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 1 17:40:24 2021 -0700

    spellcheck: add API to update the spellcheck menu section

 src/editor-spell-menu.c | 28 ++++++++++++++++++++++++++++
 src/editor-spell-menu.h | 12 +++++++-----
 2 files changed, 35 insertions(+), 5 deletions(-)
---
diff --git a/src/editor-spell-menu.c b/src/editor-spell-menu.c
index 2996e46..79afcec 100644
--- a/src/editor-spell-menu.c
+++ b/src/editor-spell-menu.c
@@ -26,6 +26,8 @@
 #include "editor-spell-menu.h"
 #include "editor-spell-provider.h"
 
+#define MAX_CORRECTIONS 5
+
 static void
 populate_languages (GMenu *menu)
 {
@@ -85,3 +87,29 @@ editor_spell_menu_new (void)
 
   return G_MENU_MODEL (g_steal_pointer (&menu));
 }
+
+void
+editor_spell_menu_set_corrections (GMenuModel         *menu,
+                                   const char * const *words)
+{
+  GMenu *corrections_menu;
+
+  g_return_if_fail (G_IS_MENU_MODEL (menu));
+
+  if (!(corrections_menu = g_object_get_data (menu, "CORRECTIONS_MENU")))
+    g_return_if_reached ();
+
+  while (g_menu_model_get_n_items (G_MENU_MODEL (corrections_menu)))
+    g_menu_remove (corrections_menu, 0);
+
+  if (words == NULL)
+    return;
+
+  for (guint i = 0; i < MAX_CORRECTIONS && words[i]; i++)
+    {
+      g_autoptr(GMenuItem) item = g_menu_item_new (words[i], NULL);
+
+      g_menu_item_set_action_and_target (item, "spelling.correct", "s", words[i]);
+      g_menu_append_item (corrections_menu, item);
+    }
+}
diff --git a/src/editor-spell-menu.h b/src/editor-spell-menu.h
index b079719..b1833bc 100644
--- a/src/editor-spell-menu.h
+++ b/src/editor-spell-menu.h
@@ -24,10 +24,12 @@
 
 G_BEGIN_DECLS
 
-GMenuModel *editor_spell_menu_new          (void);
-void        editor_spell_menu_set_language (GMenuModel          *menu,
-                                            EditorSpellLanguage *language);
-void        editor_spell_menu_set_word     (GMenuModel          *menu,
-                                            const char          *word);
+GMenuModel *editor_spell_menu_new             (void);
+void        editor_spell_menu_set_language    (GMenuModel          *menu,
+                                               EditorSpellLanguage *language);
+void        editor_spell_menu_set_word        (GMenuModel          *menu,
+                                               const char          *word);
+void        editor_spell_menu_set_corrections (GMenuModel          *menu,
+                                               const char * const  *words);
 
 G_END_DECLS


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