diff --git a/gtk/gtksingleselection.c b/gtk/gtksingleselection.c index 3b5257b2f7..40e13843c4 100644 --- a/gtk/gtksingleselection.c +++ b/gtk/gtksingleselection.c @@ -164,7 +164,7 @@ gtk_single_selection_unselect_item (GtkSelectionModel *model, { GtkSingleSelection *self = GTK_SINGLE_SELECTION (model); - if (!self->can_unselect) + if (!self->can_unselect || self->autoselect) return FALSE; if (self->selected == position) @@ -651,7 +651,8 @@ gtk_single_selection_get_selected (GtkSingleSelection *self) * value of the [property@Gtk.SingleSelection:autoselect] property: * If it is set, no change will occur and the old item will stay * selected. If it is unset, the selection will be unset and no item - * will be selected. + * will be selected. This also applies if [property@Gtk.SingleSelection:can-unselect] + * is set to %FALSE. */ void gtk_single_selection_set_selected (GtkSingleSelection *self, @@ -669,7 +670,12 @@ gtk_single_selection_set_selected (GtkSingleSelection *self, new_selected = g_list_model_get_item (self->model, position); if (new_selected == NULL) - position = GTK_INVALID_LIST_POSITION; + { + if (!self->can_unselect || self->autoselect) + return; + + position = GTK_INVALID_LIST_POSITION; + } if (self->selected == position) return; diff --git a/testsuite/gtk/singleselection.c b/testsuite/gtk/singleselection.c index 0f6aee9e6b..a1c30e24fc 100644 --- a/testsuite/gtk/singleselection.c +++ b/testsuite/gtk/singleselection.c @@ -626,6 +626,14 @@ test_can_unselect (void) gtk_single_selection_set_can_unselect (GTK_SINGLE_SELECTION (selection), TRUE); + assert_selection (selection, "1"); + ret = gtk_selection_model_unselect_item (selection, 0); + g_assert_false (ret); + assert_selection (selection, "1"); + assert_selection_changes (selection, ""); + + gtk_single_selection_set_autoselect (GTK_SINGLE_SELECTION (selection), FALSE); + assert_selection (selection, "1"); ret = gtk_selection_model_unselect_item (selection, 0); g_assert_true (ret);