[nautilus/wip/antoniof/flow-box-preparation: 10/29] view-item-model: Add proper ::file-changed signal




commit bbb2d68113660bf3314fe666a9c6dfdc8adc8f7a
Author: António Fernandes <antoniof gnome org>
Date:   Sat Aug 28 23:09:50 2021 +0100

    view-item-model: Add proper ::file-changed signal
    
    When a file in the view changes, we remove the existing item from the
    model and add a new item for the same file. This ensures the item ui
    is updated (or, rather, recreated).
    
    This is wasteful.
    
    Instead, use a new signal to update the UI.

 src/nautilus-view-icon-controller.c |  9 +--------
 src/nautilus-view-icon-item-ui.c    |  9 +++------
 src/nautilus-view-item-model.c      | 24 ++++++++++++++++++++++++
 src/nautilus-view-item-model.h      |  3 ++-
 4 files changed, 30 insertions(+), 15 deletions(-)
---
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index 7a7609b93..cb88c442c 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -252,9 +252,6 @@ real_clear (NautilusFilesView *files_view)
     nautilus_view_model_remove_all_items (self->model);
 }
 
-
-/* FIXME: ideally this should go into the model so there is not need to
- * recreate the model with the new data */
 static void
 real_file_changed (NautilusFilesView *files_view,
                    NautilusFile      *file,
@@ -262,14 +259,10 @@ real_file_changed (NautilusFilesView *files_view,
 {
     NautilusViewIconController *self;
     NautilusViewItemModel *item_model;
-    NautilusViewItemModel *new_item_model;
 
     self = NAUTILUS_VIEW_ICON_CONTROLLER (files_view);
     item_model = nautilus_view_model_get_item_from_file (self->model, file);
-    nautilus_view_model_remove_item (self->model, item_model);
-    new_item_model = nautilus_view_item_model_new (file,
-                                                   get_icon_size_for_zoom_level (self->zoom_level));
-    nautilus_view_model_add_item (self->model, new_item_model);
+    nautilus_view_item_model_file_changed (item_model);
 }
 
 static GList *
diff --git a/src/nautilus-view-icon-item-ui.c b/src/nautilus-view-icon-item-ui.c
index dc17a55ee..5e27ebb16 100644
--- a/src/nautilus-view-icon-item-ui.c
+++ b/src/nautilus-view-icon-item-ui.c
@@ -57,11 +57,8 @@ update_icon (NautilusViewIconItemUi *self)
 }
 
 static void
-on_view_item_file_changed (GObject    *object,
-                           GParamSpec *pspec,
-                           gpointer    user_data)
+on_file_changed (NautilusViewIconItemUi *self)
 {
-    NautilusViewIconItemUi *self = NAUTILUS_VIEW_ICON_ITEM_UI (user_data);
     NautilusFile *file;
 
     file = nautilus_view_item_model_get_file (self->model);
@@ -148,8 +145,8 @@ set_model (NautilusViewIconItemUi *self,
 
     g_signal_connect (self->model, "notify::icon-size",
                       (GCallback) on_view_item_size_changed, self);
-    g_signal_connect (self->model, "notify::file",
-                      (GCallback) on_view_item_file_changed, self);
+    g_signal_connect_swapped (self->model, "file-changed",
+                              (GCallback) on_file_changed, self);
 }
 
 static void
diff --git a/src/nautilus-view-item-model.c b/src/nautilus-view-item-model.c
index e50f2d800..1513aa45f 100644
--- a/src/nautilus-view-item-model.c
+++ b/src/nautilus-view-item-model.c
@@ -21,6 +21,14 @@ enum
     N_PROPS
 };
 
+enum
+{
+    FILE_CHANGED,
+    LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
 static void
 nautilus_view_item_model_finalize (GObject *object)
 {
@@ -135,6 +143,14 @@ nautilus_view_item_model_class_init (NautilusViewItemModelClass *klass)
                                                           "The UI that reprensents the item model",
                                                           GTK_TYPE_WIDGET,
                                                           G_PARAM_READWRITE));
+
+    signals[FILE_CHANGED] = g_signal_new ("file-changed",
+                                          G_TYPE_FROM_CLASS (klass),
+                                          G_SIGNAL_RUN_LAST,
+                                          0,
+                                          NULL, NULL,
+                                          g_cclosure_marshal_VOID__VOID,
+                                          G_TYPE_NONE, 0);
 }
 
 NautilusViewItemModel *
@@ -205,3 +221,11 @@ nautilus_view_item_model_set_item_ui (NautilusViewItemModel *self,
 
     g_object_notify (G_OBJECT (self), "item-ui");
 }
+
+void
+nautilus_view_item_model_file_changed (NautilusViewItemModel *self)
+{
+    g_return_if_fail (NAUTILUS_IS_VIEW_ITEM_MODEL (self));
+
+    g_signal_emit (self, signals[FILE_CHANGED], 0);
+}
diff --git a/src/nautilus-view-item-model.h b/src/nautilus-view-item-model.h
index 75299010b..9ee99c48f 100644
--- a/src/nautilus-view-item-model.h
+++ b/src/nautilus-view-item-model.h
@@ -28,5 +28,6 @@ void nautilus_view_item_model_set_item_ui (NautilusViewItemModel *self,
                                            GtkWidget             *item_ui);
 
 GtkWidget * nautilus_view_item_model_get_item_ui (NautilusViewItemModel *self);
+void nautilus_view_item_model_file_changed (NautilusViewItemModel *self);
 
-G_END_DECLS
\ No newline at end of file
+G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]