GtkActionable causes warning when used for an action with parameter, after adding the widget to the window
@chpe
Submitted by Christian Persch Link to original bug (#788840)
Description
Created attachment 361345 full testcase
Steps to reproduce:
/* First create a GtkApplicationWindow,
- add some action "test" with parameter "s" to it,
- and create a GtkBox @box, add it to the window */
/* Now let's create some buttons that activates "test" */
/* This works fine: */
button = gtk_button_new ("Test"); gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (button), "win.test::bar"); gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
/* But when the button is added first, before setting the action, we
- get a warning: */
button = gtk_button_new ("Another test"); gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0); gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (button), "win.test::bar");
The warning is this: Gtk-WARNING **: actionhelper: action win.with can't be activated due to parameter type mismatch (parameter type s, target type NULL)
This happens because gtk_actionable_set_detailed_action_name() sets the action name first, then the action target. Setting the action name checks that the action's parameter matches the actionhelper's target, which at that point is still NULL.
The same happens when you do
button = gtk_button_new ("Another test"); gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0); gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "win.test"); gtk_actionable_set_action_target (GTK_ACTIONABLE (button), "s", "foo");
The only way I found to fix it is to invert the order, ie first setting the target and then the action name. However, this prevents me from using gtk_actionable_set_detailed_action_name() since in there the order is action, then target. And one cannot use the workaround of first setting action&target, then adding the widget to the window, e.g. when first using builder to build the widgets, or when changing what action the button will activate.
The way to fix this (IMHO) would have the actionhelper have a method to set action and target at the same time and use that from gtk_actionable_set_detailed_action_name(), and also expose a gtk_actionable_set_action_and_target() analogous to g_menu_item_set_action_and_target() that also allows to set action and target together.
Attachment 361345, "full testcase":
test-actionable.c
Version: 3.22.x