[nautilus/wip/antoniof/they-re-here-to-save-the-world: 1/2] starred-directory: Actually implement ::force_reload




commit f2237185a37e617e375474e3d28d200774f1b752
Author: António Fernandes <antoniof gnome org>
Date:   Thu Sep 17 18:29:03 2020 +0100

    starred-directory: Actually implement ::force_reload
    
    The code created to handle the NautilusTagManager::files-changed signal
    has been reused for implemeting the NautilusDirectory::force_reload
    virtual function.
    
    This is conceptually wrong, because the update_files function doesn't
    actually reload the file list. Also, as a side effect, it causes gone
    files to reappear as "ghost files" (files without any attributes).
    
    Instead, let's follow what NautilusSearchDirectory does: clear the
    current file list after unmonitoring the files, and set the file list
    anew the same way it's done on ::init.
    
    Fixes:
    https://gitlab.gnome.org/GNOME/nautilus/-/issues/162
    https://gitlab.gnome.org/GNOME/nautilus/-/issues/167

 src/nautilus-starred-directory.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/src/nautilus-starred-directory.c b/src/nautilus-starred-directory.c
index da00a579b..bed4725bf 100644
--- a/src/nautilus-starred-directory.c
+++ b/src/nautilus-starred-directory.c
@@ -222,12 +222,6 @@ real_is_editable (NautilusDirectory *directory)
     return FALSE;
 }
 
-static void
-real_force_reload (NautilusDirectory *directory)
-{
-    nautilus_starred_directory_update_files (NAUTILUS_STARRED_DIRECTORY (directory));
-}
-
 static void
 real_call_when_ready (NautilusDirectory         *directory,
                       NautilusFileAttributes     file_attributes,
@@ -477,6 +471,31 @@ nautilus_starred_directory_set_files (NautilusFavoriteDirectory *self)
     self->files = file_list;
 }
 
+static void
+real_force_reload (NautilusDirectory *directory)
+{
+    NautilusFavoriteDirectory *self = NAUTILUS_STARRED_DIRECTORY (directory);
+
+    /* Unset current file list */
+    for (GList *l = self->files; l != NULL; l = l->next)
+    {
+        NautilusFile *file = l->data;
+
+        /* Disconnect change handler */
+        g_signal_handlers_disconnect_by_func (file, file_changed, self);
+
+        /* Remove monitors */
+        for (GList *m = self->monitor_list; m != NULL; m = m->next)
+        {
+            nautilus_file_monitor_remove (file, m->data);
+        }
+    }
+    g_clear_list (&self->files, g_object_unref);
+
+    /* Set a fresh file list  */
+    nautilus_starred_directory_set_files (self);
+}
+
 static void
 nautilus_starred_directory_finalize (GObject *object)
 {


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