From f82a9bbdc3484b6173089328560260cd4545d9ed Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 25 Mar 2025 12:22:32 -0600 Subject: [PATCH] YTK: fix non-namespaced handling of action names in GtkUIManager GTK+ 2.x only looked up action *names* and ignored the namespacing offered by action groups. This means that if there are two actions in different groups with the same name, GtkUIManager may not find the one intended when it is referenced in a menus definition file. This commit changes that - if the action name contains a '/' character it is assumed to contain both the action group name and the action name, and it will only look for the action within the named group. --- libs/tk/ytk/gtkuimanager.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/libs/tk/ytk/gtkuimanager.c b/libs/tk/ytk/gtkuimanager.c index 8cbeda9e85..211dea92d5 100644 --- a/libs/tk/ytk/gtkuimanager.c +++ b/libs/tk/ytk/gtkuimanager.c @@ -1935,22 +1935,41 @@ get_action_by_name (GtkUIManager *merge, const gchar *action_name) { GList *tmp; + char const * group_name = NULL; if (!action_name) return NULL; - + + if (group_name = strchr (action_name, '/')) { + char const * an = group_name + 1; + group_name = g_strndup (action_name, group_name - action_name); + printf ("from %s group name will be %s\n", action_name, group_name); + action_name = an; + } + + /* lookup name */ for (tmp = merge->private_data->action_groups; tmp != NULL; tmp = tmp->next) { GtkActionGroup *action_group = tmp->data; GtkAction *action; - + + if (group_name) { + if (strcmp (gtk_action_group_get_name (action_group), group_name)) { + printf ("checking group %s against %s failed\n", gtk_action_group_get_name (action_group), group_name); + continue; + } + } + action = gtk_action_group_get_action (action_group, action_name); - if (action) - return action; + if (action) { + g_free (group_name); + return action; + } } + g_free (group_name); return NULL; }