mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 22:20:24 +00:00
Merge branch 'wip/corey/file-chooser-select' into 'main'
Implement set_selection in GtkSingleSelection See merge request GNOME/gtk!6376
This commit is contained in:
commit
997d553520
@ -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)
|
||||
@ -173,12 +173,21 @@ gtk_single_selection_unselect_item (GtkSelectionModel *model,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_single_selection_unselect_all (GtkSelectionModel *model)
|
||||
{
|
||||
GtkSingleSelection *self = GTK_SINGLE_SELECTION (model);
|
||||
|
||||
return gtk_single_selection_unselect_item (model, self->selected);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_single_selection_selection_model_init (GtkSelectionModelInterface *iface)
|
||||
{
|
||||
iface->is_selected = gtk_single_selection_is_selected;
|
||||
iface->get_selection_in_range = gtk_single_selection_get_selection_in_range;
|
||||
iface->select_item = gtk_single_selection_select_item;
|
||||
iface->unselect_all = gtk_single_selection_unselect_all;
|
||||
iface->unselect_item = gtk_single_selection_unselect_item;
|
||||
}
|
||||
|
||||
@ -642,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,
|
||||
@ -660,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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user