[gnome-builder] plugins/c-pack: use automatic action group registration
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/c-pack: use automatic action group registration
- Date: Fri, 29 Jul 2022 00:01:14 +0000 (UTC)
commit 0a5dbb1b6dfbbe4293505e5f1f814600ff9ebc26
Author: Christian Hergert <chergert redhat com>
Date: Thu Jul 28 17:00:49 2022 -0700
plugins/c-pack: use automatic action group registration
src/plugins/c-pack/cpack-editor-page-addin.c | 36 ++++++++++++++++++----------
src/plugins/c-pack/gtk/keybindings.json | 2 +-
2 files changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/src/plugins/c-pack/cpack-editor-page-addin.c b/src/plugins/c-pack/cpack-editor-page-addin.c
index 4c9bd144a..f211c0029 100644
--- a/src/plugins/c-pack/cpack-editor-page-addin.c
+++ b/src/plugins/c-pack/cpack-editor-page-addin.c
@@ -29,7 +29,8 @@
struct _CpackEditorPageAddin
{
- GObject parent_instance;
+ GObject parent_instance;
+ GSimpleActionGroup *actions;
};
static void
@@ -64,31 +65,41 @@ format_decls_cb (GSimpleAction *action,
}
static GActionEntry entries[] = {
- { "format-decls", format_decls_cb },
+ { "format", format_decls_cb },
};
static void
cpack_editor_page_addin_load (IdeEditorPageAddin *addin,
- IdeEditorPage *view)
+ IdeEditorPage *page)
{
- g_autoptr(GActionMap) group = NULL;
+ CpackEditorPageAddin *self = (CpackEditorPageAddin *)addin;
g_assert (CPACK_IS_EDITOR_PAGE_ADDIN (addin));
- g_assert (IDE_IS_EDITOR_PAGE (view));
+ g_assert (IDE_IS_EDITOR_PAGE (page));
- group = G_ACTION_MAP (g_simple_action_group_new ());
- g_action_map_add_action_entries (group, entries, G_N_ELEMENTS (entries), view);
- gtk_widget_insert_action_group (GTK_WIDGET (view), "cpack", G_ACTION_GROUP (group));
+ self->actions = g_simple_action_group_new ();
+ g_action_map_add_action_entries (G_ACTION_MAP (self->actions),
+ entries,
+ G_N_ELEMENTS (entries),
+ page);
}
static void
cpack_editor_page_addin_unload (IdeEditorPageAddin *addin,
- IdeEditorPage *view)
+ IdeEditorPage *page)
{
+ CpackEditorPageAddin *self = (CpackEditorPageAddin *)addin;
+
g_assert (CPACK_IS_EDITOR_PAGE_ADDIN (addin));
- g_assert (IDE_IS_EDITOR_PAGE (view));
+ g_assert (IDE_IS_EDITOR_PAGE (page));
- gtk_widget_insert_action_group (GTK_WIDGET (view), "cpack", NULL);
+ g_clear_object (&self->actions);
+}
+
+static GActionGroup *
+cpack_editor_page_addin_ref_action_group (IdeEditorPageAddin *addin)
+{
+ return g_object_ref (G_ACTION_GROUP (CPACK_EDITOR_PAGE_ADDIN (addin)->actions));
}
static void
@@ -96,10 +107,11 @@ iface_init (IdeEditorPageAddinInterface *iface)
{
iface->load = cpack_editor_page_addin_load;
iface->unload = cpack_editor_page_addin_unload;
+ iface->ref_action_group = cpack_editor_page_addin_ref_action_group;
}
G_DEFINE_FINAL_TYPE_WITH_CODE (CpackEditorPageAddin, cpack_editor_page_addin, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (IDE_TYPE_EDITOR_PAGE_ADDIN, iface_init))
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_EDITOR_PAGE_ADDIN, iface_init))
static void
cpack_editor_page_addin_class_init (CpackEditorPageAddinClass *klass)
diff --git a/src/plugins/c-pack/gtk/keybindings.json b/src/plugins/c-pack/gtk/keybindings.json
index 619aa645d..01b554c03 100644
--- a/src/plugins/c-pack/gtk/keybindings.json
+++ b/src/plugins/c-pack/gtk/keybindings.json
@@ -1 +1 @@
-{ "trigger" : "<Control><Shift>f", "action" : "cpack.format-decls", "when" : "inEditorWithLanguage(\"chdr\")
&& hasSelection()", "phase" : "capture" },
+{ "trigger" : "<Control><Shift>f", "action" : "page.c-pack.format", "when" : "hasSelection() &&
(inEditorWithLanguage(\"chdr\") || inEditorWithLanguage(\"c\"))", "phase" : "capture" },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]