[nautilus/wip/antoniof/flow-box-preparation: 40/70] 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: 40/70] view-icon-item-ui: Make :model a regular property
- Date: Thu, 23 Dec 2021 01:06:25 +0000 (UTC)
commit ef6fefba4fdd0a713c2a80bf084a88c48718946f
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 recycled 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 2094d8a48..5d7ac8119 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -1034,7 +1034,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 157c3e680..e0de374c6 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,9 +218,14 @@ 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, NULL);
+}
+
+void
+nautilus_view_icon_item_ui_set_model (NautilusViewIconItemUi *self,
+ NautilusViewItemModel *model)
{
- return g_object_new (NAUTILUS_TYPE_VIEW_ICON_ITEM_UI,
- "model", model,
- NULL);
+ 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 577769a92..5eeea61e6 100644
--- a/src/nautilus-view-icon-item-ui.h
+++ b/src/nautilus-view-icon-item-ui.h
@@ -11,6 +11,8 @@ 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);
+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]