[gnome-builder/wip/gtk4-port] plugins/spellcheck: add action for toggling spellcheck on document



commit 3e539d4c8cc4ad61db521acdd27d7ff2c288f99e
Author: Christian Hergert <chergert redhat com>
Date:   Thu Apr 7 17:45:52 2022 -0700

    plugins/spellcheck: add action for toggling spellcheck on document

 src/plugins/spellcheck/gbp-spell-buffer-addin.c      | 12 ++++++++++++
 src/plugins/spellcheck/gbp-spell-buffer-addin.h      | 17 +++++++++--------
 src/plugins/spellcheck/gbp-spell-editor-page-addin.c |  2 ++
 3 files changed, 23 insertions(+), 8 deletions(-)
---
diff --git a/src/plugins/spellcheck/gbp-spell-buffer-addin.c b/src/plugins/spellcheck/gbp-spell-buffer-addin.c
index 691909d22..56ba26dc9 100644
--- a/src/plugins/spellcheck/gbp-spell-buffer-addin.c
+++ b/src/plugins/spellcheck/gbp-spell-buffer-addin.c
@@ -37,6 +37,7 @@ struct _GbpSpellBufferAddin
   IdeBuffer *buffer;
   EditorSpellChecker *checker;
   EditorTextBufferSpellAdapter *adapter;
+  GPropertyAction *enabled_action;
 };
 
 static void
@@ -99,6 +100,8 @@ gbp_spell_buffer_addin_load (IdeBufferAddin *addin,
                            self,
                            G_CONNECT_SWAPPED);
 
+  self->enabled_action = g_property_action_new ("enabled", self->adapter, "enabled");
+
   editor_text_buffer_spell_adapter_set_enabled (self->adapter, TRUE);
 
   IDE_EXIT;
@@ -121,6 +124,7 @@ gbp_spell_buffer_addin_unload (IdeBufferAddin *addin,
 
   g_clear_object (&self->checker);
   g_clear_object (&self->adapter);
+  g_clear_object (&self->enabled_action);
 
   self->buffer = NULL;
 
@@ -204,3 +208,11 @@ gbp_spell_buffer_addin_list_corrections (GbpSpellBufferAddin *self,
 
   return NULL;
 }
+
+GAction *
+gbp_spell_buffer_addin_get_enabled_action (GbpSpellBufferAddin *self)
+{
+  g_return_val_if_fail (GBP_IS_SPELL_BUFFER_ADDIN (self), NULL);
+
+  return G_ACTION (self->enabled_action);
+}
diff --git a/src/plugins/spellcheck/gbp-spell-buffer-addin.h b/src/plugins/spellcheck/gbp-spell-buffer-addin.h
index 657f90e9d..ae0fa3b7a 100644
--- a/src/plugins/spellcheck/gbp-spell-buffer-addin.h
+++ b/src/plugins/spellcheck/gbp-spell-buffer-addin.h
@@ -28,13 +28,14 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GbpSpellBufferAddin, gbp_spell_buffer_addin, GBP, SPELL_BUFFER_ADDIN, GObject)
 
-void       gbp_spell_buffer_addin_add_word         (GbpSpellBufferAddin *self,
-                                                    const char          *word);
-void       gbp_spell_buffer_addin_ignore_word      (GbpSpellBufferAddin *self,
-                                                    const char          *word);
-gboolean   gbp_spell_buffer_addin_check_spelling   (GbpSpellBufferAddin *self,
-                                                    const char          *word);
-char     **gbp_spell_buffer_addin_list_corrections (GbpSpellBufferAddin *self,
-                                                    const char          *word);
+void       gbp_spell_buffer_addin_add_word           (GbpSpellBufferAddin *self,
+                                                      const char          *word);
+void       gbp_spell_buffer_addin_ignore_word        (GbpSpellBufferAddin *self,
+                                                      const char          *word);
+gboolean   gbp_spell_buffer_addin_check_spelling     (GbpSpellBufferAddin *self,
+                                                      const char          *word);
+char     **gbp_spell_buffer_addin_list_corrections   (GbpSpellBufferAddin *self,
+                                                      const char          *word);
+GAction   *gbp_spell_buffer_addin_get_enabled_action (GbpSpellBufferAddin *self);
 
 G_END_DECLS
diff --git a/src/plugins/spellcheck/gbp-spell-editor-page-addin.c 
b/src/plugins/spellcheck/gbp-spell-editor-page-addin.c
index 9e1c9ae76..7ce5c7174 100644
--- a/src/plugins/spellcheck/gbp-spell-editor-page-addin.c
+++ b/src/plugins/spellcheck/gbp-spell-editor-page-addin.c
@@ -246,6 +246,8 @@ gbp_spell_editor_page_addin_load (IdeEditorPageAddin *addin,
                                    actions,
                                    G_N_ELEMENTS (actions),
                                    self);
+  g_action_map_add_action (G_ACTION_MAP (self->actions),
+                           gbp_spell_buffer_addin_get_enabled_action (self->buffer_addin));
   gtk_widget_insert_action_group (GTK_WIDGET (page),
                                   "spelling",
                                   G_ACTION_GROUP (self->actions));


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