I’m trying to get some actions to be selectable from an options menu in GTK4. The actions should be connected to a project view widget that exists in a stack where only one project view is visible at a time. I think I figured out how this is supposed to be done - by making an action group and place it in the project view widget. Then connect this from the menu using action name and namespace. However, I can’t seem to get it to work. I have a couple of actions for the window and those work fine.
I do this in the project view widget to make a named group and attach a number of actions.
const GActionEntry project_entries[] =
{
{"undo", undo_activated, NULL, NULL, NULL},
{"redo", redo_activated, NULL, NULL, NULL},
};
GSimpleActionGroup *action_group = g_simple_action_group_new();
g_action_map_add_action_entries(G_ACTION_MAP(action_group), project_entries, G_N_ELEMENTS(project_entries), view);
gtk_widget_insert_action_group(GTK_WIDGET(view), "project", G_ACTION_GROUP(action_group));
In my menu I attempt to connect the entries to the corresponding group and action.
<section>
<item>
<attribute name="label" translatable="yes">_Undo</attribute>
<attribute name="action">project.undo</attribute>
</item>
</section>
The result is a greyed out entry in the menu. I’m not sure how to figure out what’s wrong. There’s nothing printed to standard out during the application lifetime. Is there something I have to do to ensure that the actions are found in the widget hierarchy?