[nautilus/wip/antoniof/flow-box-preparation: 10/18] view-icon-item-ui: Make :model a regular property
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/flow-box-preparation: 10/18] view-icon-item-ui: Make :model a regular property
- Date: Wed, 1 Dec 2021 16:41:09 +0000 (UTC)
commit 97448b1ed5dbdfecf53b84225f134523ac8fb518
Author: António Fernandes <antoniof gnome org>
Date: Sat Aug 28 21:19:06 2021 +0100
view-icon-item-ui: Make :model a regular property
Instead of a contruct-only property.
This prepares for the GTK 4 list widget future, where the same ui may
be recicled to represent different model items.
src/nautilus-view-icon-controller.c | 3 ++-
src/nautilus-view-icon-item-ui.c | 37 +++++++++++++++++++++++++++++++------
src/nautilus-view-icon-item-ui.h | 4 +++-
3 files changed, 36 insertions(+), 8 deletions(-)
---
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index 706cd84db..12e271486 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -1030,7 +1030,8 @@ create_widget_func (gpointer item,
NautilusViewItemModel *item_model = NAUTILUS_VIEW_ITEM_MODEL (item);
NautilusViewIconItemUi *child;
- child = nautilus_view_icon_item_ui_new (item_model);
+ child = nautilus_view_icon_item_ui_new ();
+ nautilus_view_icon_item_ui_set_model (child, item_model);
nautilus_view_item_model_set_item_ui (item_model, GTK_WIDGET (child));
gtk_widget_show_all (GTK_WIDGET (child));
diff --git a/src/nautilus-view-icon-item-ui.c b/src/nautilus-view-icon-item-ui.c
index 4a534e864..dc17a55ee 100644
--- a/src/nautilus-view-icon-item-ui.c
+++ b/src/nautilus-view-icon-item-ui.c
@@ -82,12 +82,16 @@ on_view_item_size_changed (GObject *object,
update_icon (self);
}
+static void
+set_model (NautilusViewIconItemUi *self,
+ NautilusViewItemModel *model);
+
static void
finalize (GObject *object)
{
NautilusViewIconItemUi *self = (NautilusViewIconItemUi *) object;
- g_signal_handlers_disconnect_by_data (self->model, self);
+ set_model (self, NULL);
G_OBJECT_CLASS (nautilus_view_icon_item_ui_parent_class)->finalize (object);
}
@@ -118,6 +122,22 @@ set_model (NautilusViewIconItemUi *self,
{
NautilusFile *file;
+ if (self->model == model)
+ {
+ return;
+ }
+
+ if (self->model != NULL)
+ {
+ g_signal_handlers_disconnect_by_data (self->model, self);
+ g_clear_object (&self->model);
+ }
+
+ if (model == NULL)
+ {
+ return;
+ }
+
self->model = g_object_ref (model);
file = nautilus_view_item_model_get_file (self->model);
@@ -169,7 +189,7 @@ nautilus_view_icon_item_ui_class_init (NautilusViewIconItemUiClass *klass)
"Item model",
"The item model that this UI reprensents",
NAUTILUS_TYPE_VIEW_ITEM_MODEL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ G_PARAM_READWRITE));
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/nautilus/ui/nautilus-view-icon-item-ui.ui");
@@ -198,11 +218,9 @@ nautilus_view_icon_item_ui_init (NautilusViewIconItemUi *self)
}
NautilusViewIconItemUi *
-nautilus_view_icon_item_ui_new (NautilusViewItemModel *model)
+nautilus_view_icon_item_ui_new (void)
{
- return g_object_new (NAUTILUS_TYPE_VIEW_ICON_ITEM_UI,
- "model", model,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_VIEW_ICON_ITEM_UI, NULL);
}
NautilusViewItemModel *
@@ -210,3 +228,10 @@ nautilus_view_icon_item_ui_get_model (NautilusViewIconItemUi *self)
{
return self->model;
}
+
+void
+nautilus_view_icon_item_ui_set_model (NautilusViewIconItemUi *self,
+ NautilusViewItemModel *model)
+{
+ g_object_set (self, "model", model, NULL);
+}
diff --git a/src/nautilus-view-icon-item-ui.h b/src/nautilus-view-icon-item-ui.h
index 55b09b1f1..93e0a9e04 100644
--- a/src/nautilus-view-icon-item-ui.h
+++ b/src/nautilus-view-icon-item-ui.h
@@ -11,8 +11,10 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (NautilusViewIconItemUi, nautilus_view_icon_item_ui, NAUTILUS, VIEW_ICON_ITEM_UI,
GtkFlowBoxChild)
-NautilusViewIconItemUi * nautilus_view_icon_item_ui_new (NautilusViewItemModel *item_model);
+NautilusViewIconItemUi * nautilus_view_icon_item_ui_new (void);
NautilusViewItemModel * nautilus_view_icon_item_ui_get_model (NautilusViewIconItemUi *self);
+void nautilus_view_icon_item_ui_set_model (NautilusViewIconItemUi *self,
+ NautilusViewItemModel *model);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]