[nautilus/wip/antoniof/column-chooser-dialog-rework] list-view: Introduce helper for column defaults



commit fd1acc41ce7c7ce8cc1b370bbc4b2a3fdc5323bc
Author: António Fernandes <antoniof gnome org>
Date:   Wed Jul 28 11:55:41 2021 +0100

    list-view: Introduce helper for column defaults
    
    This will be used in the next commit.

 src/nautilus-list-view.c | 58 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 44 insertions(+), 14 deletions(-)
---
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 1e1188e8e..89ad9e92b 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -101,6 +101,40 @@ static void on_clipboard_owner_changed (GtkClipboard *clipboard,
 
 G_DEFINE_TYPE (NautilusListView, nautilus_list_view, NAUTILUS_TYPE_FILES_VIEW);
 
+typedef enum {
+    LOCATION_WITH_DEFAULT_COLUMNS_NONE,
+    LOCATION_WITH_DEFAULT_COLUMNS_SEARCH,
+    LOCATION_WITH_DEFAULT_COLUMNS_RECENT,
+    LOCATION_WITH_DEFAULT_COLUMNS_TRASH
+} LocationWithDefaultColumns;
+
+static LocationWithDefaultColumns
+check_location_with_default_columns (NautilusListView *list_view)
+{
+    NautilusFile *file;
+    NautilusDirectory *directory;
+
+    file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
+
+    if (nautilus_file_is_in_trash (file))
+    {
+        return LOCATION_WITH_DEFAULT_COLUMNS_TRASH;
+    }
+
+    if (nautilus_file_is_in_recent (file))
+    {
+        return LOCATION_WITH_DEFAULT_COLUMNS_RECENT;
+    }
+
+    directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (list_view));
+    if (NAUTILUS_IS_SEARCH_DIRECTORY (directory))
+    {
+        return LOCATION_WITH_DEFAULT_COLUMNS_SEARCH;
+    }
+
+    return LOCATION_WITH_DEFAULT_COLUMNS_NONE;
+}
+
 static const char *default_search_visible_columns[] =
 {
     "name", "size", "where", NULL
@@ -2451,23 +2485,21 @@ nautilus_list_view_add_files (NautilusFilesView *view,
 static char **
 get_default_visible_columns (NautilusListView *list_view)
 {
-    NautilusFile *file;
-    NautilusDirectory *directory;
+    LocationWithDefaultColumns location;
 
-    file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
+    location = check_location_with_default_columns (list_view);
 
-    if (nautilus_file_is_in_trash (file))
+    if (location == LOCATION_WITH_DEFAULT_COLUMNS_TRASH)
     {
         return g_strdupv ((gchar **) default_trash_visible_columns);
     }
 
-    if (nautilus_file_is_in_recent (file))
+    if (location == LOCATION_WITH_DEFAULT_COLUMNS_RECENT)
     {
         return g_strdupv ((gchar **) default_recent_visible_columns);
     }
 
-    directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (list_view));
-    if (NAUTILUS_IS_SEARCH_DIRECTORY (directory))
+    if (location == LOCATION_WITH_DEFAULT_COLUMNS_SEARCH)
     {
         return g_strdupv ((gchar **) default_search_visible_columns);
     }
@@ -2541,23 +2573,21 @@ get_visible_columns (NautilusListView *list_view)
 static char **
 get_default_column_order (NautilusListView *list_view)
 {
-    NautilusFile *file;
-    NautilusDirectory *directory;
+    LocationWithDefaultColumns location;
 
-    file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
+    location = check_location_with_default_columns (list_view);
 
-    if (nautilus_file_is_in_trash (file))
+    if (location == LOCATION_WITH_DEFAULT_COLUMNS_TRASH)
     {
         return g_strdupv ((gchar **) default_trash_columns_order);
     }
 
-    if (nautilus_file_is_in_recent (file))
+    if (location == LOCATION_WITH_DEFAULT_COLUMNS_RECENT)
     {
         return g_strdupv ((gchar **) default_recent_columns_order);
     }
 
-    directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (list_view));
-    if (NAUTILUS_IS_SEARCH_DIRECTORY (directory))
+    if (location == LOCATION_WITH_DEFAULT_COLUMNS_SEARCH)
     {
         return g_strdupv ((gchar **) default_search_columns_order);
     }


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