Merge branch 'select-list-model-null' into 'master'

gtk: Allow selection models to take null list model during construction

See merge request GNOME/gtk!3309
This commit is contained in:
Emmanuele Bassi 2021-03-17 14:09:37 +00:00
commit 6d4f93bb7f
5 changed files with 27 additions and 3 deletions

View File

@ -378,7 +378,7 @@ gtk_multi_selection_new (GListModel *model)
{
GtkMultiSelection *self;
g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
self = g_object_new (GTK_TYPE_MULTI_SELECTION,
"model", model,

View File

@ -224,7 +224,7 @@ gtk_no_selection_new (GListModel *model)
{
GtkNoSelection *self;
g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
self = g_object_new (GTK_TYPE_NO_SELECTION,
"model", model,

View File

@ -460,7 +460,7 @@ gtk_single_selection_new (GListModel *model)
{
GtkSingleSelection *self;
g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
self = g_object_new (GTK_TYPE_SINGLE_SELECTION,
"model", model,

View File

@ -304,6 +304,17 @@ test_create (void)
g_object_unref (selection);
}
static void
test_create_empty (void)
{
GtkMultiSelection *selection;
selection = gtk_multi_selection_new (NULL);
g_assert_cmpint (g_list_model_get_n_items (G_LIST_MODEL (selection)), ==, 0);
g_object_unref (selection);
}
static void
test_changes (void)
{
@ -682,6 +693,7 @@ main (int argc, char *argv[])
selection_quark = g_quark_from_static_string ("Mana mana, badibidibi");
g_test_add_func ("/multiselection/create", test_create);
g_test_add_func ("/multiselection/create-empty", test_create_empty);
#if GLIB_CHECK_VERSION (2, 58, 0) /* g_list_store_splice() is broken before 2.58 */
g_test_add_func ("/multiselection/changes", test_changes);
#endif

View File

@ -304,6 +304,17 @@ test_create (void)
g_object_unref (selection);
}
static void
test_create_empty (void)
{
GtkSingleSelection *selection;
selection = gtk_single_selection_new (NULL);
g_assert_cmpint (g_list_model_get_n_items (G_LIST_MODEL (selection)), ==, 0);
g_object_unref (selection);
}
static void
test_changes (void)
{
@ -706,6 +717,7 @@ main (int argc, char *argv[])
selection_quark = g_quark_from_static_string ("Mana mana, badibidibi");
g_test_add_func ("/singleselection/create", test_create);
g_test_add_func ("/singleselection/create-empty", test_create_empty);
g_test_add_func ("/singleselection/autoselect", test_autoselect);
g_test_add_func ("/singleselection/autoselect-toggle", test_autoselect_toggle);
g_test_add_func ("/singleselection/selection", test_selection);