[nautilus/wip/antoniof/new-list-view-continuation: 18/21] list-view: Hide expander if subdirectory is empty




commit 04508ddbffbf70e10bb8bb0362b8d17ae8587825
Author: António Fernandes <antoniof gnome org>
Date:   Fri Apr 15 12:15:58 2022 +0100

    list-view: Hide expander if subdirectory is empty
    
    The old list view used to add a dummy row with the "(empty)" label.
    
    That solution required a lot of code gymnastics to special case
    the dummy row everywhere, which was error-prone.
    
    So, for the new list view, I wanted to avoid that solution. For
    now, the simplest solution is to follow the example of other
    file managers and hide the expander if the folder is found to be
    empty after trying to expand it.

 src/nautilus-list-view.c  |  7 +++++++
 src/nautilus-view-model.c | 14 +++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 17d67dccc..5717768bb 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -1640,6 +1640,13 @@ on_subdirectory_done_loading (NautilusDirectory *directory,
 
     item = NAUTILUS_VIEW_ITEM_MODEL (gtk_tree_list_row_get_item (row));
     nautilus_view_item_model_set_loading (item, FALSE);
+
+    if (!nautilus_directory_is_not_empty (directory))
+    {
+        /* Collapse to trigger a reassessment of the tree in order to make the
+         * expander disappear. */
+        gtk_tree_list_row_set_expanded (row, FALSE);
+    }
 }
 
 static void
diff --git a/src/nautilus-view-model.c b/src/nautilus-view-model.c
index 6a80d81d0..bb14a5254 100644
--- a/src/nautilus-view-model.c
+++ b/src/nautilus-view-model.c
@@ -1,6 +1,8 @@
 #include "nautilus-view-model.h"
-#include "nautilus-view-item-model.h"
+
+#include "nautilus-directory.h"
 #include "nautilus-global-preferences.h"
+#include "nautilus-view-item-model.h"
 
 struct _NautilusViewModel
 {
@@ -256,6 +258,16 @@ create_model_func (GObject           *item,
     {
         return NULL;
     }
+    else /* Check whether we already know it to be empty. */
+    {
+        g_autoptr (NautilusDirectory) directory = NULL;
+        directory = nautilus_directory_get_for_file (file);
+        if (nautilus_directory_are_all_files_seen (directory) &&
+            !nautilus_directory_is_not_empty (directory))
+        {
+            return NULL;
+        }
+    }
 
     store = g_hash_table_lookup (self->directory_reverse_map, file);
     if (store == NULL)


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