forked from AuroraMiddleware/gtk
singleselection: Fix model property
1. Make the model property construct-only. Allowing to change the model has invalid side effects. 2. Add a getter for the model property.
This commit is contained in:
parent
6d20fe0bf9
commit
9f5ee77a44
@ -471,6 +471,7 @@ gtk_selection_model_get_type
|
||||
GtkSingleSelection
|
||||
GTK_INVALID_LIST_POSITION
|
||||
gtk_single_selection_new
|
||||
gtk_single_selection_get_model
|
||||
gtk_single_selection_get_selected
|
||||
gtk_single_selection_set_selected
|
||||
gtk_single_selection_get_selected_item
|
||||
|
@ -329,9 +329,8 @@ gtk_single_selection_set_property (GObject *object,
|
||||
case PROP_MODEL:
|
||||
gtk_single_selection_clear_model (self);
|
||||
self->model = g_value_dup_object (value);
|
||||
if (self->model)
|
||||
g_signal_connect (self->model, "items-changed",
|
||||
G_CALLBACK (gtk_single_selection_items_changed_cb), self);
|
||||
g_signal_connect (self->model, "items-changed",
|
||||
G_CALLBACK (gtk_single_selection_items_changed_cb), self);
|
||||
if (self->autoselect)
|
||||
gtk_single_selection_set_selected (self, 0);
|
||||
break;
|
||||
@ -461,7 +460,7 @@ gtk_single_selection_class_init (GtkSingleSelectionClass *klass)
|
||||
P_("The model"),
|
||||
P_("The model being managed"),
|
||||
G_TYPE_LIST_MODEL,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (gobject_class, N_PROPS, properties);
|
||||
}
|
||||
@ -491,6 +490,22 @@ gtk_single_selection_new (GListModel *model)
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_single_selection_get_model:
|
||||
* @self: a #GtkSingleSelection
|
||||
*
|
||||
* Gets the model that @self is wrapping.
|
||||
*
|
||||
* Returns: (transfer none): The model being wrapped
|
||||
**/
|
||||
GListModel *
|
||||
gtk_single_selection_get_model (GtkSingleSelection *self)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_SINGLE_SELECTION (self), NULL);
|
||||
|
||||
return self->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_single_selection_get_selected:
|
||||
* @self: a #GtkSingleSelection
|
||||
|
@ -42,8 +42,10 @@ GDK_AVAILABLE_IN_ALL
|
||||
G_DECLARE_FINAL_TYPE (GtkSingleSelection, gtk_single_selection, GTK, SINGLE_SELECTION, GObject)
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkSingleSelection * gtk_single_selection_new (GListModel *model);
|
||||
GtkSingleSelection * gtk_single_selection_new (GListModel *model);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GListModel * gtk_single_selection_get_model (GtkSingleSelection *self);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
guint gtk_single_selection_get_selected (GtkSingleSelection *self);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
|
@ -109,7 +109,8 @@ test_type (gconstpointer data)
|
||||
instance = G_OBJECT (g_object_ref (gdk_surface_new_temp (display,
|
||||
&(GdkRectangle) { 0, 0, 100, 100 })));
|
||||
}
|
||||
else if (g_type_is_a (type, GTK_TYPE_FILTER_LIST_MODEL))
|
||||
else if (g_type_is_a (type, GTK_TYPE_FILTER_LIST_MODEL) ||
|
||||
g_type_is_a (type, GTK_TYPE_SINGLE_SELECTION))
|
||||
{
|
||||
GListStore *list_store = g_list_store_new (G_TYPE_OBJECT);
|
||||
instance = g_object_new (type,
|
||||
@ -255,7 +256,8 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
if (g_type_is_a (type, GTK_TYPE_FILTER_LIST_MODEL) &&
|
||||
if ((g_type_is_a (type, GTK_TYPE_FILTER_LIST_MODEL) ||
|
||||
g_type_is_a (type, GTK_TYPE_SINGLE_SELECTION)) &&
|
||||
strcmp (pspec->name, "model") == 0)
|
||||
continue;
|
||||
|
||||
|
@ -431,7 +431,8 @@ test_type (gconstpointer data)
|
||||
NULL);
|
||||
gdk_content_formats_unref (formats);
|
||||
}
|
||||
else if (g_type_is_a (type, GTK_TYPE_FILTER_LIST_MODEL))
|
||||
else if (g_type_is_a (type, GTK_TYPE_FILTER_LIST_MODEL) ||
|
||||
g_type_is_a (type, GTK_TYPE_SINGLE_SELECTION))
|
||||
{
|
||||
GListStore *list_store = g_list_store_new (G_TYPE_OBJECT);
|
||||
instance = g_object_new (type,
|
||||
|
@ -64,7 +64,8 @@ test_finalize_object (gconstpointer data)
|
||||
NULL);
|
||||
gdk_content_formats_unref (formats);
|
||||
}
|
||||
else if (g_type_is_a (test_type, GTK_TYPE_FILTER_LIST_MODEL))
|
||||
else if (g_type_is_a (test_type, GTK_TYPE_FILTER_LIST_MODEL) ||
|
||||
g_type_is_a (test_type, GTK_TYPE_SINGLE_SELECTION))
|
||||
{
|
||||
GListStore *list_store = g_list_store_new (G_TYPE_OBJECT);
|
||||
object = g_object_new (test_type,
|
||||
|
Loading…
Reference in New Issue
Block a user