enum {
PROP_0,
+ PROP_ITEM_TYPE,
PROP_MODEL,
+ PROP_N_ITEMS,
N_PROPS,
};
g_clear_pointer (&pending, g_hash_table_unref);
g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
+ if (removed != added)
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static void
switch (prop_id)
{
+ case PROP_ITEM_TYPE:
+ g_value_set_gtype (value, gtk_multi_selection_get_item_type (G_LIST_MODEL (self)));
+ break;
+
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
+ case PROP_N_ITEMS:
+ g_value_set_uint (value, gtk_multi_selection_get_n_items (G_LIST_MODEL (self)));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
gobject_class->set_property = gtk_multi_selection_set_property;
gobject_class->dispose = gtk_multi_selection_dispose;
+ /**
+ * GtkMultiSelection:item-type:
+ *
+ * The type of items. See [method@Gio.ListModel.get_item_type].
+ *
+ * Since: 4.8
+ **/
+ properties[PROP_ITEM_TYPE] =
+ g_param_spec_gtype ("item-type", NULL, NULL,
+ G_TYPE_OBJECT,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
/**
* GtkMultiSelection:model: (attributes org.gtk.Property.get=gtk_multi_selection_get_model org.gtk.Property.set=gtk_multi_selection_set_model)
*
G_TYPE_LIST_MODEL,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+ /**
+ * GtkMultiSelection:n-items:
+ *
+ * The number of items. See [method@Gio.ListModel.get_n_items].
+ *
+ * Since: 4.8
+ **/
+ properties[PROP_N_ITEMS] =
+ g_param_spec_uint ("n-items", NULL, NULL,
+ 0, G_MAXUINT, 0,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
gtk_bitset_remove_all (self->selected);
g_hash_table_remove_all (self->items);
g_list_model_items_changed (G_LIST_MODEL (self), 0, n_items_before, 0);
+ if (n_items_before)
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
}
}
+static void
+notify_n_items (GObject *object,
+ GParamSpec *pspec,
+ GString *changes)
+{
+ g_string_append_c (changes, '*');
+}
+
static void
selection_changed (GListModel *model,
guint position,
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
+ g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), selection_quark, changes, free_changes);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
+ g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes);
return result;
}
g_list_store_remove (store, 3);
assert_model (selection, "1 2 3 5");
- assert_changes (selection, "-3");
+ assert_changes (selection, "-3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
insert (store, 3, 99);
assert_model (selection, "1 2 3 99 5");
- assert_changes (selection, "+3");
+ assert_changes (selection, "+3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
splice (store, 3, 2, (guint[]) { 97 }, 1);
assert_model (selection, "1 2 3 97");
- assert_changes (selection, "3-2+1");
+ assert_changes (selection, "3-2+1*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
insert (store, 2, 22);
assert_model (selection, "1 2 22 3 97");
- assert_changes (selection, "+2");
+ assert_changes (selection, "+2*");
assert_selection (selection, "2 3");
assert_selection_changes (selection, "");
assert_selection (selection, "4");
assert_selection_changes (selection, "3:1");
assert_model (filter, "4");
- assert_changes (filter, "+0");
+ assert_changes (filter, "+0*");
ret = gtk_selection_model_unselect_item (selection, 3);
g_assert_true (ret);
assert_selection (selection, "");
assert_selection_changes (selection, "3:1");
assert_model (filter, "");
- assert_changes (filter, "-0");
+ assert_changes (filter, "-0*");
ret = gtk_selection_model_select_item (selection, 1, FALSE);
g_assert_true (ret);
assert_selection (selection, "2");
assert_selection_changes (selection, "1:1");
assert_model (filter, "2");
- assert_changes (filter, "+0");
+ assert_changes (filter, "+0*");
ret = gtk_selection_model_select_item (selection, 0, FALSE);
g_assert_true (ret);
assert_selection (selection, "1 2");
assert_selection_changes (selection, "0:1");
assert_model (filter, "1 2");
- assert_changes (filter, "+0");
+ assert_changes (filter, "+0*");
ret = gtk_selection_model_unselect_item (selection, 0);
g_assert_true (ret);
assert_selection (selection, "2");
assert_selection_changes (selection, "0:1");
assert_model (filter, "2");
- assert_changes (filter, "-0");
+ assert_changes (filter, "-0*");
ret = gtk_selection_model_select_range (selection, 3, 2, FALSE);
g_assert_true (ret);
assert_selection (selection, "2 4 5");
assert_selection_changes (selection, "3:2");
assert_model (filter, "2 4 5");
- assert_changes (filter, "1+2");
+ assert_changes (filter, "1+2*");
ret = gtk_selection_model_unselect_range (selection, 3, 2);
g_assert_true (ret);
assert_selection (selection, "2");
assert_selection_changes (selection, "3:2");
assert_model (filter, "2");
- assert_changes (filter, "1-2");
+ assert_changes (filter, "1-2*");
ret = gtk_selection_model_select_all (selection);
g_assert_true (ret);
assert_selection (selection, "1 2 3 4 5");
assert_selection_changes (selection, "0:5");
assert_model (filter, "1 2 3 4 5");
- assert_changes (filter, "0-1+5");
+ assert_changes (filter, "0-1+5*");
ret = gtk_selection_model_unselect_all (selection);
g_assert_true (ret);
assert_selection (selection, "");
assert_selection_changes (selection, "0:5");
assert_model (filter, "");
- assert_changes (filter, "0-5");
+ assert_changes (filter, "0-5*");
ret = gtk_selection_model_select_range (selection, 1, 3, FALSE);
g_assert_true (ret);
assert_selection (selection, "2 3 4");
assert_selection_changes (selection, "1:3");
assert_model (filter, "2 3 4");
- assert_changes (filter, "0+3");
+ assert_changes (filter, "0+3*");
insert (store, 2, 22);
assert_model (selection, "1 2 22 3 4 5");
- assert_changes (selection, "+2");
+ assert_changes (selection, "+2*");
assert_selection (selection, "2 3 4");
assert_selection_changes (selection, "");
assert_model (filter, "2 3 4");
g_list_store_remove (store, 2);
assert_model (selection, "1 2 3 4 5");
- assert_changes (selection, "-2");
+ assert_changes (selection, "-2*");
assert_selection (selection, "2 3 4");
assert_selection_changes (selection, "");
assert_model (filter, "2 3 4");
/* we retain the selected item across model changes */
gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), m2);
- assert_changes (selection, "0-5+3");
+ assert_changes (selection, "0-5+3*");
assert_selection (selection, "2 3");
assert_selection_changes (selection, "");
gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), NULL);
- assert_changes (selection, "0-3");
+ assert_changes (selection, "0-3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), m2);
- assert_changes (selection, "0+3");
+ assert_changes (selection, "0+3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
/* we retain no selected item across model changes */
gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), m1);
- assert_changes (selection, "0-3+5");
+ assert_changes (selection, "0-3+5*");
assert_selection (selection, "1 2 3");
assert_selection_changes (selection, "");