[gnome-builder] plugins/spellcheck: fix action group usage



commit 2f3816c22c6f0e259498c12f5f515e8485fb4401
Author: Christian Hergert <chergert redhat com>
Date:   Wed Oct 5 15:25:31 2022 -0700

    plugins/spellcheck: fix action group usage
    
    This had mismatched gtk/panel widget actions but additionally we want to
    use the rest of the IdePage infrastructure to do the action group
    attachment of actions (so they can connect to the frame).
    
    Fix all the actions to use the proper prefix of "spellcheck" to match the
    plugin module-name.

 src/plugins/spellcheck/editor-spell-menu.c           | 10 +++++-----
 src/plugins/spellcheck/gbp-spell-editor-page-addin.c | 18 +++++++++++++-----
 2 files changed, 18 insertions(+), 10 deletions(-)
---
diff --git a/src/plugins/spellcheck/editor-spell-menu.c b/src/plugins/spellcheck/editor-spell-menu.c
index eca23769e..c84cf162e 100644
--- a/src/plugins/spellcheck/editor-spell-menu.c
+++ b/src/plugins/spellcheck/editor-spell-menu.c
@@ -88,7 +88,7 @@ editor_spell_corrections_get_item_attributes (GMenuModel  *model,
   correction = self->corrections[position];
 
   ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
-  g_hash_table_insert (ht, g_strdup (G_MENU_ATTRIBUTE_ACTION), g_variant_ref_sink (g_variant_new_string 
("page.spelling.correct")));
+  g_hash_table_insert (ht, g_strdup (G_MENU_ATTRIBUTE_ACTION), g_variant_ref_sink (g_variant_new_string 
("page.spellcheck.correct")));
   g_hash_table_insert (ht, g_strdup (G_MENU_ATTRIBUTE_TARGET), g_variant_ref_sink (g_variant_new_string 
(correction)));
   g_hash_table_insert (ht, g_strdup (G_MENU_ATTRIBUTE_LABEL), g_variant_ref_sink (g_variant_new_string 
(correction)));
 
@@ -233,7 +233,7 @@ populate_languages (GMenu *menu)
       g_assert (G_IS_MENU (group_menu));
 
       item = g_menu_item_new (name, NULL);
-      g_menu_item_set_action_and_target (item, "page.spelling.language", "s", code);
+      g_menu_item_set_action_and_target (item, "page.spellcheck.language", "s", code);
       g_menu_append_item (group_menu, item);
     }
 }
@@ -245,9 +245,9 @@ editor_spell_menu_new (void)
   static GMenuItem *languages_item;
   g_autoptr(GMenu) menu = g_menu_new ();
   g_autoptr(GMenuModel) corrections_menu = editor_spell_corrections_new ();
-  g_autoptr(GMenuItem) add_item = g_menu_item_new (_("Add to Dictionary"), "page.spelling.add");
-  g_autoptr(GMenuItem) ignore_item = g_menu_item_new (_("Ignore"), "page.spelling.ignore");
-  g_autoptr(GMenuItem) check_item = g_menu_item_new (_("Check Spelling"), "page.spelling.enabled");
+  g_autoptr(GMenuItem) add_item = g_menu_item_new (_("Add to Dictionary"), "page.spellcheck.add");
+  g_autoptr(GMenuItem) ignore_item = g_menu_item_new (_("Ignore"), "page.spellcheck.ignore");
+  g_autoptr(GMenuItem) check_item = g_menu_item_new (_("Check Spelling"), "page.spellcheck.enabled");
 
   if (languages_menu == NULL)
     {
diff --git a/src/plugins/spellcheck/gbp-spell-editor-page-addin.c 
b/src/plugins/spellcheck/gbp-spell-editor-page-addin.c
index b390f7fcc..64e355c0e 100644
--- a/src/plugins/spellcheck/gbp-spell-editor-page-addin.c
+++ b/src/plugins/spellcheck/gbp-spell-editor-page-addin.c
@@ -32,8 +32,12 @@
 struct _GbpSpellEditorPageAddin
 {
   GObject              parent_instance;
+
+  /* Borrowed references */
   IdeEditorPage       *page;
   GbpSpellBufferAddin *buffer_addin;
+
+  /* Owned references */
   GMenuModel          *menu;
   GMenu               *spell_section;
   GSimpleActionGroup  *actions;
@@ -221,9 +225,6 @@ gbp_spell_editor_page_addin_load (IdeEditorPageAddin *addin,
                                    self);
   g_action_map_add_action (G_ACTION_MAP (self->actions),
                            gbp_spell_buffer_addin_get_enabled_action (self->buffer_addin));
-  panel_widget_insert_action_group (PANEL_WIDGET (page),
-                                    "spelling",
-                                    G_ACTION_GROUP (self->actions));
 
   g_signal_connect_object (view,
                            "populate-menu",
@@ -246,8 +247,6 @@ gbp_spell_editor_page_addin_unload (IdeEditorPageAddin *addin,
   g_assert (GBP_IS_SPELL_EDITOR_PAGE_ADDIN (self));
   g_assert (IDE_IS_EDITOR_PAGE (page));
 
-  gtk_widget_insert_action_group (GTK_WIDGET (page), "spelling", NULL);
-
   view = ide_editor_page_get_view (page);
   ide_source_view_remove_menu (view, G_MENU_MODEL (self->spell_section));
 
@@ -259,17 +258,26 @@ gbp_spell_editor_page_addin_unload (IdeEditorPageAddin *addin,
   g_clear_object (&self->spell_section);
   g_clear_object (&self->actions);
 
+  g_clear_pointer (&self->spelling_word, g_free);
+
   self->buffer_addin = NULL;
   self->page = NULL;
 
   IDE_EXIT;
 }
 
+static GActionGroup *
+gbp_spell_editor_page_addin_ref_action_group (IdeEditorPageAddin *addin)
+{
+  return g_object_ref (G_ACTION_GROUP (GBP_SPELL_EDITOR_PAGE_ADDIN (addin)->actions));
+}
+
 static void
 editor_page_addin_iface_init (IdeEditorPageAddinInterface *iface)
 {
   iface->load = gbp_spell_editor_page_addin_load;
   iface->unload = gbp_spell_editor_page_addin_unload;
+  iface->ref_action_group = gbp_spell_editor_page_addin_ref_action_group;
 }
 
 G_DEFINE_FINAL_TYPE_WITH_CODE (GbpSpellEditorPageAddin, gbp_spell_editor_page_addin, G_TYPE_OBJECT,


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