Merge branch 'actionable-fixes' into 'master'

tests: Fix check vs toggle button confusion

Closes #4022

See merge request GNOME/gtk!3656
This commit is contained in:
Matthias Clasen 2021-06-10 13:30:25 +00:00
commit 17f1bb1632
6 changed files with 76 additions and 12 deletions

View File

@ -1015,6 +1015,14 @@ gtk_button_get_gesture (GtkButton *button)
return priv->gesture;
}
GtkActionHelper *
gtk_button_get_action_helper (GtkButton *button)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
return priv->action_helper;
}
/**
* gtk_button_set_child: (attributes org.gtk.Method.set_property=child)
* @button: a `GtkButton`

View File

@ -22,7 +22,9 @@
#include "gtkbutton.h"
#include "gtkgesture.h"
#include "gtkactionhelperprivate.h"
GtkGesture * gtk_button_get_gesture (GtkButton *button);
GtkActionHelper * gtk_button_get_action_helper (GtkButton *button);
#endif /* __GTK_BUTTON_PRIVATE_H__ */

View File

@ -325,10 +325,10 @@ click_released_cb (GtkGestureClick *gesture,
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
gtk_check_button_set_active (self, !priv->active);
if (priv->action_helper)
gtk_action_helper_activate (priv->action_helper);
else
gtk_check_button_set_active (self, !priv->active);
}
static void

View File

@ -202,6 +202,9 @@ gtk_toggle_button_clicked (GtkButton *button)
if (priv->active && (priv->group_prev || priv->group_next))
return;
if (gtk_button_get_action_helper (button))
return;
gtk_toggle_button_set_active (toggle_button, !priv->active);
}

View File

@ -24,8 +24,13 @@ toggle_menu_item (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GVariant *state = g_action_get_state (G_ACTION (action));
gtk_label_set_label (GTK_LABEL (label), "Text set from toggle menu item");
g_simple_action_set_state (action, g_variant_new_boolean (!g_variant_get_boolean (state)));
g_variant_unref (state);
}
static void
@ -39,15 +44,16 @@ submenu_item (GSimpleAction *action,
static void
radio (GSimpleAction *action, GVariant *parameter, gpointer user_data)
{
GVariant *new_state = g_variant_new_string (g_variant_get_string (parameter, NULL));
char *str;
str = g_strdup_printf ("From Radio menu item %s",
g_variant_get_string (new_state, NULL));
g_variant_get_string (parameter, NULL));
gtk_label_set_label (GTK_LABEL (label), str);
g_free (str);
g_simple_action_set_state (action, parameter);
}
@ -57,7 +63,7 @@ static const GActionEntry win_actions[] = {
{ "normal-menu-item", normal_menu_item, NULL, NULL, NULL },
{ "toggle-menu-item", toggle_menu_item, NULL, "true", NULL },
{ "submenu-item", submenu_item, NULL, NULL, NULL },
{ "radio", radio, "s", "1", NULL },
{ "radio", radio, "s", "'1'", NULL },
};
@ -112,6 +118,7 @@ int main (int argc, char **argv)
GtkWidget *button1 = gtk_button_new_with_label ("Change Label Text");
GtkWidget *menu;
GSimpleActionGroup *action_group;
GtkWidget *box1;
action_group = g_simple_action_group_new ();
@ -142,6 +149,50 @@ int main (int argc, char **argv)
gtk_actionable_set_action_name (GTK_ACTIONABLE (button1), "win.change-label-button");
gtk_box_append (GTK_BOX (box), button1);
box1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
button1 = gtk_toggle_button_new_with_label ("Toggle");
gtk_actionable_set_action_name (GTK_ACTIONABLE (button1), "win.toggle-menu-item");
gtk_box_append (GTK_BOX (box1), button1);
button1 = gtk_check_button_new_with_label ("Check");
gtk_actionable_set_action_name (GTK_ACTIONABLE (button1), "win.toggle-menu-item");
gtk_box_append (GTK_BOX (box1), button1);
gtk_box_append (GTK_BOX (box), box1);
box1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
button1 = gtk_toggle_button_new_with_label ("Radio 1");
gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (button1), "win.radio::1");
gtk_box_append (GTK_BOX (box1), button1);
button1 = gtk_toggle_button_new_with_label ("Radio 2");
gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (button1), "win.radio::2");
gtk_box_append (GTK_BOX (box1), button1);
button1 = gtk_toggle_button_new_with_label ("Radio 3");
gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (button1), "win.radio::3");
gtk_box_append (GTK_BOX (box1), button1);
gtk_box_append (GTK_BOX (box), box1);
box1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
button1 = gtk_check_button_new_with_label ("Radio 1");
gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (button1), "win.radio::1");
gtk_box_append (GTK_BOX (box1), button1);
button1 = gtk_check_button_new_with_label ("Radio 2");
gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (button1), "win.radio::2");
gtk_box_append (GTK_BOX (box1), button1);
button1 = gtk_check_button_new_with_label ("Radio 3");
gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (button1), "win.radio::3");
gtk_box_append (GTK_BOX (box1), button1);
gtk_box_append (GTK_BOX (box), box1);
gtk_window_set_child (GTK_WINDOW (window), box);
gtk_widget_show (window);

View File

@ -418,7 +418,7 @@ create_action_treeview (GActionGroup *group)
/* Dynamic menu changes {{{1 */
static void
toggle_sumerian (GtkToggleButton *button, gpointer data)
toggle_sumerian (GtkCheckButton *button, gpointer data)
{
GMenuModel *model;
gboolean adding;
@ -426,7 +426,7 @@ toggle_sumerian (GtkToggleButton *button, gpointer data)
model = g_object_get_data (G_OBJECT (button), "model");
adding = gtk_toggle_button_get_active (button);
adding = gtk_check_button_get_active (button);
m = g_menu_model_get_item_link (model, g_menu_model_get_n_items (model) - 1, G_MENU_LINK_SECTION);
m = g_menu_model_get_item_link (m, g_menu_model_get_n_items (m) - 1, G_MENU_LINK_SUBMENU);
@ -467,7 +467,7 @@ action_list_remove (GtkTreeModel *store,
}
static void
toggle_italic (GtkToggleButton *button, gpointer data)
toggle_italic (GtkCheckButton *button, gpointer data)
{
GMenuModel *model;
GActionGroup *group;
@ -482,7 +482,7 @@ toggle_italic (GtkToggleButton *button, gpointer data)
store = gtk_tree_view_get_model (tv);
adding = gtk_toggle_button_get_active (button);
adding = gtk_check_button_get_active (button);
m = g_menu_model_get_item_link (model, g_menu_model_get_n_items (model) - 1, G_MENU_LINK_SECTION);
if (adding)
@ -503,7 +503,7 @@ toggle_italic (GtkToggleButton *button, gpointer data)
}
static void
toggle_speed (GtkToggleButton *button, gpointer data)
toggle_speed (GtkCheckButton *button, gpointer data)
{
GMenuModel *model;
GActionGroup *group;
@ -519,7 +519,7 @@ toggle_speed (GtkToggleButton *button, gpointer data)
store = gtk_tree_view_get_model (tv);
adding = gtk_toggle_button_get_active (button);
adding = gtk_check_button_get_active (button);
m = g_menu_model_get_item_link (model, 1, G_MENU_LINK_SECTION);
if (adding)