Merge branch 'check-radio-box-fixes' into 'master'

tree: Clicking row should check radio/checkboxes

See merge request GNOME/zenity!16
This commit is contained in:
Logan Rathbone 2021-11-15 15:33:30 +00:00
commit 8b08ea3776

View File

@ -63,32 +63,28 @@ zenity_tree_dialog_untoggle (
} }
static void static void
zenity_tree_toggled_callback ( check_or_radio_label_activated_cb (GtkTreeView *tree_view,
GtkCellRendererToggle *cell, gchar *path_string, gpointer data) { GtkTreePath *path,
GtkTreeModel *model; GtkTreeViewColumn *column,
gpointer user_data)
{
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
GtkTreeIter iter; GtkTreeIter iter;
GtkTreePath *path;
gboolean value; gboolean value;
model = GTK_TREE_MODEL (data);
/* Because this is a radio list, we should untoggle the previous toggle so /* Because this is a radio list, we should untoggle the previous toggle so
* that * that
* we only have one selection at any given time * we only have one selection at any given time
*/ */
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (model), "radio")) == 1) { if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (model), "radio")) == 1) {
gtk_tree_model_foreach (model, zenity_tree_dialog_untoggle, NULL); gtk_tree_model_foreach (model, zenity_tree_dialog_untoggle, NULL);
} }
path = gtk_tree_path_new_from_string (path_string);
gtk_tree_model_get_iter (model, &iter, path); gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, 0, &value, -1); gtk_tree_model_get (model, &iter, 0, &value, -1);
value = !value; value = !value;
gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, value, -1); gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, value, -1);
gtk_tree_path_free (path);
} }
static void static void
@ -453,11 +449,23 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
tree_view = gtk_builder_get_object (builder, "zenity_tree_view"); tree_view = gtk_builder_get_object (builder, "zenity_tree_view");
if (!(tree_data->radiobox || tree_data->checkbox)) if (tree_data->radiobox || tree_data->checkbox)
{
gtk_tree_view_set_activate_on_single_click (GTK_TREE_VIEW(tree_view),
TRUE);
g_signal_connect (tree_view,
"row-activated",
G_CALLBACK (check_or_radio_label_activated_cb),
data);
}
else
{
g_signal_connect (tree_view, g_signal_connect (tree_view,
"row-activated", "row-activated",
G_CALLBACK (zenity_tree_row_activated), G_CALLBACK (zenity_tree_row_activated),
data); data);
}
/* Create an empty list store */ /* Create an empty list store */
model = g_object_new (GTK_TYPE_LIST_STORE, NULL); model = g_object_new (GTK_TYPE_LIST_STORE, NULL);
@ -486,7 +494,14 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (model)); gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (model));
if (!(tree_data->radiobox || tree_data->checkbox)) { if (tree_data->radiobox || tree_data->checkbox)
{
gtk_tree_selection_set_mode (
gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
GTK_SELECTION_SINGLE);
}
else
{
if (tree_data->multi) if (tree_data->multi)
gtk_tree_selection_set_mode ( gtk_tree_selection_set_mode (
gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
@ -495,10 +510,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
gtk_tree_selection_set_mode ( gtk_tree_selection_set_mode (
gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
GTK_SELECTION_SINGLE); GTK_SELECTION_SINGLE);
} else }
gtk_tree_selection_set_mode (
gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
GTK_SELECTION_NONE);
column_index = 0; column_index = 0;
@ -516,11 +528,6 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
G_OBJECT (model), "radio", GINT_TO_POINTER (1)); G_OBJECT (model), "radio", GINT_TO_POINTER (1));
} }
g_signal_connect (cell_renderer,
"toggled",
G_CALLBACK (zenity_tree_toggled_callback),
model);
column = gtk_tree_view_column_new_with_attributes ( column = gtk_tree_view_column_new_with_attributes (
tmp->data, cell_renderer, "active", column_index, NULL); tmp->data, cell_renderer, "active", column_index, NULL);
} else if (tree_data->imagebox) { } else if (tree_data->imagebox) {