From 35b5729bcc7f37d9788bc481aa94899fc5187e7e Mon Sep 17 00:00:00 2001 From: Jehan Date: Mon, 30 Jan 2023 00:02:17 +0100 Subject: [PATCH] app: add all our actions in the GApplication. Right now, our actions are added both in the GActionMap (a.k.a. as GApplication|GtkApplication) and with the old GtkActionGroup API. The later code is meant to be removed soon. A major difference with the old implementation is that we don't add the actions in separate action groups. Even though GLib has a GActionGroup concept, these don't seem to be used at all when adding actions on the GtkApplication level. It might mean that eventually we will even remove the GimpActionGroup code and move everything up one level. Of course, I am still evaluating if we really want an action group concept, in which case, we could simply recreate it, but I'm actually unsure how useful it is. The only place where I see a use to this is in the shortcut settings (to organize actions by groups), but even there, it was rarely useful to me. I usually rather search for actions by text search anyway. --- app/app.c | 2 ++ app/core/gimp.h | 2 ++ app/widgets/gimpactiongroup.c | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/app/app.c b/app/app.c index af86865269..2a398f1fc3 100644 --- a/app/app.c +++ b/app/app.c @@ -247,6 +247,8 @@ app_run (const gchar *full_prog_name, app = gimp_console_app_new (gimp, quit, as_new, filenames, batch_interpreter, batch_commands); #endif + gimp->app = app; + gimp_cpu_accel_set_use (use_cpu_accel); /* Check if the user's gimp_directory exists */ diff --git a/app/core/gimp.h b/app/core/gimp.h index 0e9d91a2de..45cf74a412 100644 --- a/app/core/gimp.h +++ b/app/core/gimp.h @@ -36,6 +36,8 @@ struct _Gimp { GimpObject parent_instance; + GApplication *app; + GimpCoreConfig *config; GimpCoreConfig *edit_config; /* don't use this one, it's just * for the preferences dialog diff --git a/app/widgets/gimpactiongroup.c b/app/widgets/gimpactiongroup.c index e13fe257e9..59aac9c8d8 100644 --- a/app/widgets/gimpactiongroup.c +++ b/app/widgets/gimpactiongroup.c @@ -326,6 +326,24 @@ gimp_action_group_add_action_with_accel (GimpActionGroup *action_group, GimpAction *action, const gchar *accelerator) { + + /* Making sure all our Gimp*Action classes are also GAction. */ + g_return_if_fail (G_IS_ACTION (action)); + + g_action_map_add_action (G_ACTION_MAP (action_group->gimp->app), G_ACTION (action)); + if ((accelerator != NULL && g_strcmp0 (accelerator, "") != 0)) + { + gchar* detailed_action_name; + + detailed_action_name = g_strdup_printf ("app.%s", + g_action_get_name (G_ACTION (action))); + gtk_application_set_accels_for_action (GTK_APPLICATION (action_group->gimp->app), + detailed_action_name, + (const char*[]) { accelerator, NULL }); + g_free (detailed_action_name); + } + + /* TODO: remove the old logic with GtkAction. */ gtk_action_group_add_action_with_accel ((GtkActionGroup *) action_group, (GtkAction *) action, accelerator);