mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-14 06:10:21 +00:00
Merge branch '6261-gtkstringlist-lacks-item-type-and-n-items' into 'main'
stringlist: Introduce :item-type and :n-items Closes #6261 See merge request GNOME/gtk!6662
This commit is contained in:
commit
cb5a8a76da
@ -408,9 +408,15 @@ gtk_string_list_buildable_init (GtkBuildableIface *iface)
|
|||||||
/* {{{ GObject implementation */
|
/* {{{ GObject implementation */
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROP_STRINGS = 1
|
PROP_0,
|
||||||
|
PROP_ITEM_TYPE,
|
||||||
|
PROP_N_ITEMS,
|
||||||
|
PROP_STRINGS,
|
||||||
|
N_PROPS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static GParamSpec *properties[N_PROPS] = { NULL, };
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE (GtkStringList, gtk_string_list, G_TYPE_OBJECT,
|
G_DEFINE_TYPE_WITH_CODE (GtkStringList, gtk_string_list, G_TYPE_OBJECT,
|
||||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
||||||
gtk_string_list_buildable_init)
|
gtk_string_list_buildable_init)
|
||||||
@ -427,6 +433,30 @@ gtk_string_list_dispose (GObject *object)
|
|||||||
G_OBJECT_CLASS (gtk_string_list_parent_class)->dispose (object);
|
G_OBJECT_CLASS (gtk_string_list_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_string_list_get_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
GtkStringList *self = GTK_STRING_LIST (object);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_ITEM_TYPE:
|
||||||
|
g_value_set_gtype (value, gtk_string_list_get_item_type (G_LIST_MODEL (self)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_N_ITEMS:
|
||||||
|
g_value_set_uint (value, gtk_string_list_get_n_items (G_LIST_MODEL (self)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_string_list_set_property (GObject *object,
|
gtk_string_list_set_property (GObject *object,
|
||||||
unsigned int prop_id,
|
unsigned int prop_id,
|
||||||
@ -454,17 +484,44 @@ gtk_string_list_class_init (GtkStringListClass *class)
|
|||||||
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
||||||
|
|
||||||
gobject_class->dispose = gtk_string_list_dispose;
|
gobject_class->dispose = gtk_string_list_dispose;
|
||||||
|
gobject_class->get_property = gtk_string_list_get_property;
|
||||||
gobject_class->set_property = gtk_string_list_set_property;
|
gobject_class->set_property = gtk_string_list_set_property;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GtkStringList:item-type:
|
||||||
|
*
|
||||||
|
* The type of items. See [method@Gio.ListModel.get_item_type].
|
||||||
|
*
|
||||||
|
* Since: 4.14
|
||||||
|
**/
|
||||||
|
properties[PROP_ITEM_TYPE] =
|
||||||
|
g_param_spec_gtype ("item-type", NULL, NULL,
|
||||||
|
G_TYPE_OBJECT,
|
||||||
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GtkStringList:n-items:
|
||||||
|
*
|
||||||
|
* The number of items. See [method@Gio.ListModel.get_n_items].
|
||||||
|
*
|
||||||
|
* Since: 4.14
|
||||||
|
**/
|
||||||
|
properties[PROP_N_ITEMS] =
|
||||||
|
g_param_spec_uint ("n-items", NULL, NULL,
|
||||||
|
0, G_MAXUINT, 0,
|
||||||
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GtkStringList:strings:
|
* GtkStringList:strings:
|
||||||
*
|
*
|
||||||
* Since: 4.10
|
* Since: 4.10
|
||||||
*/
|
*/
|
||||||
g_object_class_install_property (gobject_class, PROP_STRINGS,
|
properties[PROP_STRINGS] =
|
||||||
g_param_spec_boxed ("strings", NULL, NULL,
|
g_param_spec_boxed ("strings", NULL, NULL,
|
||||||
G_TYPE_STRV,
|
G_TYPE_STRV,
|
||||||
G_PARAM_WRITABLE|G_PARAM_STATIC_STRINGS|G_PARAM_CONSTRUCT_ONLY));
|
G_PARAM_WRITABLE|G_PARAM_STATIC_STRINGS|G_PARAM_CONSTRUCT_ONLY);
|
||||||
|
|
||||||
|
g_object_class_install_properties (gobject_class, N_PROPS, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -538,6 +595,9 @@ gtk_string_list_splice (GtkStringList *self,
|
|||||||
|
|
||||||
if (n_removals || n_additions)
|
if (n_removals || n_additions)
|
||||||
g_list_model_items_changed (G_LIST_MODEL (self), position, n_removals, n_additions);
|
g_list_model_items_changed (G_LIST_MODEL (self), position, n_removals, n_additions);
|
||||||
|
|
||||||
|
if (n_removals != n_additions)
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -559,6 +619,7 @@ gtk_string_list_append (GtkStringList *self,
|
|||||||
objects_append (&self->items, gtk_string_object_new (string));
|
objects_append (&self->items, gtk_string_object_new (string));
|
||||||
|
|
||||||
g_list_model_items_changed (G_LIST_MODEL (self), objects_get_size (&self->items) - 1, 0, 1);
|
g_list_model_items_changed (G_LIST_MODEL (self), objects_get_size (&self->items) - 1, 0, 1);
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -585,6 +646,7 @@ gtk_string_list_take (GtkStringList *self,
|
|||||||
objects_append (&self->items, gtk_string_object_new_take (string));
|
objects_append (&self->items, gtk_string_object_new_take (string));
|
||||||
|
|
||||||
g_list_model_items_changed (G_LIST_MODEL (self), objects_get_size (&self->items) - 1, 0, 1);
|
g_list_model_items_changed (G_LIST_MODEL (self), objects_get_size (&self->items) - 1, 0, 1);
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user