summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Sullivan <sullivan@src.gnome.org>2001-03-22 18:08:33 +0000
committerJohn Sullivan <sullivan@src.gnome.org>2001-03-22 18:08:33 +0000
commit40f19a1e1d6d797fb4cbf8eb316d231e13807cdb (patch)
tree24f5eec3bb4273b0b40cea4e4263fe7356f5adab
parentf0e9b1a05faab61437a98134c1241afc91c51448 (diff)
downloadnautilus-40f19a1e1d6d797fb4cbf8eb316d231e13807cdb.tar.gz
reviewed by: Darin Adler <darin@eazel.com>
Fixed bug 1853 (Want preference for always sorting folders first) For now, this is a global preference. Making it per-window later is a possibility. Arlo is working on a design for directory view defaults that may incorporate this. * libnautilus-extensions/nautilus-file.h: * libnautilus-extensions/nautilus-file.c: (nautilus_file_compare_for_sort_reversed): Eliminated this in favor of a parameter to nautilus_file_compare_for_sort. (nautilus_file_compare_for_sort): Add a parameter for reversed, and another for directories_first. (nautilus_file_compare_for_sort_internal): Former guts of nautilus_file_compare_for_sort moved here. (nautilus_self_check_file): Update compare_for_sort self-checks. * libnautilus-extensions/nautilus-global-preferences.h: * libnautilus-extensions/nautilus-global-preferences.c: (global_preferences_install_descriptions), (global_preferences_install_defaults), (global_preferences_install_visibility), (global_preferences_create_dialog): Install an "Always list folders before files" preference in the Icon and List Views section. * src/file-manager/fm-directory-view.h: (sort_directories_first_changed): New function pointer for subclasses to override. * src/file-manager/fm-directory-view.c: (fm_directory_view_should_sort_directories_first): New function for subclasses to call. (sort_directories_first_changed_callback): Call virtual function when preference changes. (fm_directory_view_initialize): Store initial value of preference; install preference callback. (fm_directory_view_destroy): Remove preference callback. * src/file-manager/fm-desktop-icon-view.c: (desktop_icons_compare_callback): Respect preference setting. * src/file-manager/fm-icon-view.c: (icon_container_compare_icons_callback): Update to respect directories_first setting. (icon_container_compare_icons_by_name_callback): Update for API change only. (fm_icon_view_sort_directories_first_changed): Override virtual function; re-sort icon container if in auto-layout mode. (fm_icon_view_initialize_class): Install virtual function override. * src/file-manager/fm-list-view.c: (fm_list_view_initialize_class): Install virtual function override. (list_view_compare_files_for_sort): New function, broken out of fm_list_view_compare_rows, and changed to respect directories_first setting. (fm_list_view_compare_rows): Break out list_view_compare_files_for_sort. (compare_rows_by_name): Update for API change only. (real_sort_directories_first_changed): Override virtual function; re-sort list. (fm_list_view_display_pending_files): Update code that sorts pending items before adding them to list. (fm_list_view_sort_items): Add comment.
-rw-r--r--ChangeLog69
-rw-r--r--libnautilus-extensions/nautilus-file.c82
-rw-r--r--libnautilus-extensions/nautilus-file.h7
-rw-r--r--libnautilus-extensions/nautilus-global-preferences.c18
-rw-r--r--libnautilus-extensions/nautilus-global-preferences.h3
-rw-r--r--libnautilus-private/nautilus-file.c82
-rw-r--r--libnautilus-private/nautilus-file.h7
-rw-r--r--libnautilus-private/nautilus-global-preferences.c18
-rw-r--r--libnautilus-private/nautilus-global-preferences.h3
-rw-r--r--src/file-manager/fm-desktop-icon-view.c5
-rw-r--r--src/file-manager/fm-directory-view.c38
-rw-r--r--src/file-manager/fm-directory-view.h16
-rw-r--r--src/file-manager/fm-icon-view.c34
-rw-r--r--src/file-manager/fm-list-view.c70
14 files changed, 339 insertions, 113 deletions
diff --git a/ChangeLog b/ChangeLog
index a22353d96..cd755f4a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,71 @@
+2001-03-22 John Sullivan <sullivan@eazel.com>
+
+ reviewed by: Darin Adler <darin@eazel.com>
+
+ Fixed bug 1853 (Want preference for always sorting folders first)
+
+ For now, this is a global preference. Making it
+ per-window later is a possibility. Arlo is working on
+ a design for directory view defaults that may incorporate
+ this.
+
+ * libnautilus-extensions/nautilus-file.h:
+ * libnautilus-extensions/nautilus-file.c:
+ (nautilus_file_compare_for_sort_reversed): Eliminated this in
+ favor of a parameter to nautilus_file_compare_for_sort.
+ (nautilus_file_compare_for_sort): Add a parameter for reversed,
+ and another for directories_first.
+ (nautilus_file_compare_for_sort_internal): Former guts of
+ nautilus_file_compare_for_sort moved here.
+ (nautilus_self_check_file): Update compare_for_sort self-checks.
+
+ * libnautilus-extensions/nautilus-global-preferences.h:
+ * libnautilus-extensions/nautilus-global-preferences.c:
+ (global_preferences_install_descriptions),
+ (global_preferences_install_defaults),
+ (global_preferences_install_visibility),
+ (global_preferences_create_dialog): Install an "Always list
+ folders before files" preference in the Icon and List Views
+ section.
+
+ * src/file-manager/fm-directory-view.h:
+ (sort_directories_first_changed): New function pointer for
+ subclasses to override.
+ * src/file-manager/fm-directory-view.c:
+ (fm_directory_view_should_sort_directories_first): New function
+ for subclasses to call.
+ (sort_directories_first_changed_callback): Call virtual function
+ when preference changes.
+ (fm_directory_view_initialize): Store initial value of preference;
+ install preference callback.
+ (fm_directory_view_destroy): Remove preference callback.
+
+ * src/file-manager/fm-desktop-icon-view.c:
+ (desktop_icons_compare_callback): Respect preference
+ setting.
+
+ * src/file-manager/fm-icon-view.c:
+ (icon_container_compare_icons_callback): Update to respect
+ directories_first setting.
+ (icon_container_compare_icons_by_name_callback): Update for API
+ change only.
+ (fm_icon_view_sort_directories_first_changed): Override virtual
+ function; re-sort icon container if in auto-layout mode.
+ (fm_icon_view_initialize_class): Install virtual function override.
+
+ * src/file-manager/fm-list-view.c:
+ (fm_list_view_initialize_class): Install virtual function override.
+ (list_view_compare_files_for_sort): New function, broken out of
+ fm_list_view_compare_rows, and changed to respect directories_first
+ setting.
+ (fm_list_view_compare_rows): Break out list_view_compare_files_for_sort.
+ (compare_rows_by_name): Update for API change only.
+ (real_sort_directories_first_changed): Override virtual function;
+ re-sort list.
+ (fm_list_view_display_pending_files): Update code that sorts
+ pending items before adding them to list.
+ (fm_list_view_sort_items): Add comment.
+
2001-03-22 Ramiro Estrugo <ramiro@eazel.com>
* configure.in: Make the configure report a little easier to read
@@ -73,7 +141,6 @@
(corba_packagedatastruct_fill_from_packagedata):
s/DistributionInfo/TrilobiteDistributionInfo/
->>>>>>> 1.4259
2001-03-21 John Sullivan <sullivan@eazel.com>
reviewed by: Darin Adler <darin@eazel.com>
diff --git a/libnautilus-extensions/nautilus-file.c b/libnautilus-extensions/nautilus-file.c
index 373a55fd1..97175e7cc 100644
--- a/libnautilus-extensions/nautilus-file.c
+++ b/libnautilus-extensions/nautilus-file.c
@@ -1700,22 +1700,10 @@ compare_by_full_path (NautilusFile *file_1, NautilusFile *file_2)
return compare_by_name (file_1, file_2);
}
-/**
- * nautilus_file_compare_for_sort:
- * @file_1: A file object
- * @file_2: Another file object
- * @sort_type: Sort criterion
- *
- * Return value: int < 0 if @file_1 should come before file_2 in a smallest-to-largest
- * sorted list; int > 0 if @file_2 should come before file_1 in a smallest-to-largest
- * sorted list; 0 if @file_1 and @file_2 are equal for this sort criterion. Note
- * that each named sort type may actually break ties several ways, with the name
- * of the sort criterion being the primary but not only differentiator.
- **/
-int
-nautilus_file_compare_for_sort (NautilusFile *file_1,
- NautilusFile *file_2,
- NautilusFileSortType sort_type)
+static int
+nautilus_file_compare_for_sort_internal (NautilusFile *file_1,
+ NautilusFile *file_2,
+ NautilusFileSortType sort_type)
{
int compare;
@@ -1724,11 +1712,6 @@ nautilus_file_compare_for_sort (NautilusFile *file_1,
switch (sort_type) {
case NAUTILUS_FILE_SORT_BY_NAME:
- /* Note: This used to put directories first. I
- * thought that was counterintuitive and removed it,
- * but I can imagine discussing this further.
- * John Sullivan <sullivan@eazel.com>
- */
compare = compare_by_name (file_1, file_2);
if (compare != 0) {
return compare;
@@ -1776,24 +1759,50 @@ nautilus_file_compare_for_sort (NautilusFile *file_1,
}
/**
- * nautilus_file_compare_for_sort_reversed:
+ * nautilus_file_compare_for_sort:
* @file_1: A file object
* @file_2: Another file object
* @sort_type: Sort criterion
+ * @directories_first: Put all directories before any non-directories
+ * @reversed: Reverse the order of the items, except that
+ * the directories_first flag is still respected.
*
- * Return value: The opposite of nautilus_file_compare_for_sort: int > 0 if @file_1
- * should come before file_2 in a smallest-to-largest sorted list; int < 0 if @file_2
- * should come before file_1 in a smallest-to-largest sorted list; 0 if @file_1
- * and @file_2 are equal for this sort criterion. Note that each named sort type
- * may actually break ties several ways, with the name of the sort criterion
- * being the primary but not only differentiator.
+ * Return value: int < 0 if @file_1 should come before file_2 in a
+ * sorted list; int > 0 if @file_2 should come before file_1 in a
+ * sorted list; 0 if @file_1 and @file_2 are equal for this sort criterion. Note
+ * that each named sort type may actually break ties several ways, with the name
+ * of the sort criterion being the primary but not only differentiator.
**/
int
-nautilus_file_compare_for_sort_reversed (NautilusFile *file_1,
- NautilusFile *file_2,
- NautilusFileSortType sort_type)
+nautilus_file_compare_for_sort (NautilusFile *file_1,
+ NautilusFile *file_2,
+ NautilusFileSortType sort_type,
+ gboolean directories_first,
+ gboolean reversed)
{
- return - nautilus_file_compare_for_sort (file_1, file_2, sort_type);
+ int result;
+ gboolean is_directory_1, is_directory_2;
+
+ if (directories_first) {
+ is_directory_1 = nautilus_file_is_directory (file_1);
+ is_directory_2 = nautilus_file_is_directory (file_2);
+
+ if (is_directory_1 && !is_directory_2) {
+ return -1;
+ }
+
+ if (is_directory_2 && !is_directory_1) {
+ return +1;
+ }
+ }
+
+ result = nautilus_file_compare_for_sort_internal (file_1, file_2, sort_type);
+
+ if (reversed) {
+ result = -result;
+ }
+
+ return result;
}
/**
@@ -4821,9 +4830,12 @@ nautilus_self_check_file (void)
NAUTILUS_CHECK_INTEGER_RESULT (GTK_OBJECT (file_1)->ref_count, 1);
NAUTILUS_CHECK_INTEGER_RESULT (GTK_OBJECT (file_2)->ref_count, 1);
- NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_2, NAUTILUS_FILE_SORT_BY_NAME) < 0, TRUE);
- NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort_reversed (file_1, file_2, NAUTILUS_FILE_SORT_BY_NAME) > 0, TRUE);
- NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_NAME) == 0, TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_2, NAUTILUS_FILE_SORT_BY_NAME, FALSE, FALSE) < 0, TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_2, NAUTILUS_FILE_SORT_BY_NAME, FALSE, TRUE) > 0, TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_NAME, FALSE, FALSE) == 0, TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_NAME, TRUE, FALSE) == 0, TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_NAME, FALSE, TRUE) == 0, TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_NAME, TRUE, TRUE) == 0, TRUE);
nautilus_file_unref (file_1);
nautilus_file_unref (file_2);
diff --git a/libnautilus-extensions/nautilus-file.h b/libnautilus-extensions/nautilus-file.h
index 58f71a754..43810f0ad 100644
--- a/libnautilus-extensions/nautilus-file.h
+++ b/libnautilus-extensions/nautilus-file.h
@@ -255,10 +255,9 @@ gboolean nautilus_file_is_local (Nautilu
/* Comparing two file objects for sorting */
int nautilus_file_compare_for_sort (NautilusFile *file_1,
NautilusFile *file_2,
- NautilusFileSortType sort_type);
-int nautilus_file_compare_for_sort_reversed (NautilusFile *file_1,
- NautilusFile *file_2,
- NautilusFileSortType sort_type);
+ NautilusFileSortType sort_type,
+ gboolean directories_first,
+ gboolean reversed);
int nautilus_file_compare_name (NautilusFile *file_1,
const char *pattern);
diff --git a/libnautilus-extensions/nautilus-global-preferences.c b/libnautilus-extensions/nautilus-global-preferences.c
index acba41c8d..14ad7312b 100644
--- a/libnautilus-extensions/nautilus-global-preferences.c
+++ b/libnautilus-extensions/nautilus-global-preferences.c
@@ -208,6 +208,9 @@ global_preferences_install_descriptions (void)
nautilus_preferences_set_description (NAUTILUS_PREFERENCES_SHOW_SPECIAL_FLAGS,
_("Show special flags in Properties window"));
+ nautilus_preferences_set_description (NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
+ _("Always list folders before files"));
+
nautilus_preferences_set_description (NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES,
_("Show only folders (no files) in the tree"));
@@ -308,6 +311,10 @@ global_preferences_install_defaults (void)
NAUTILUS_USER_LEVEL_ADVANCED,
TRUE);
+ nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
+ NAUTILUS_USER_LEVEL_NOVICE,
+ FALSE);
+
nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_SHOW_DESKTOP,
NAUTILUS_USER_LEVEL_NOVICE,
TRUE);
@@ -431,6 +438,9 @@ global_preferences_install_visibility (void)
nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_SHOW_SPECIAL_FLAGS,
NAUTILUS_USER_LEVEL_ADVANCED);
+ nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
+ NAUTILUS_USER_LEVEL_INTERMEDIATE);
+
nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
NAUTILUS_USER_LEVEL_ADVANCED);
@@ -654,6 +664,14 @@ global_preferences_create_dialog (void)
NAUTILUS_PREFERENCES_SHOW_SPECIAL_FLAGS,
NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
+ nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane),
+ _("Sorting Order"));
+
+ nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane),
+ 3,
+ NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
+ NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
+
/*
* Sidebar panels pane
*/
diff --git a/libnautilus-extensions/nautilus-global-preferences.h b/libnautilus-extensions/nautilus-global-preferences.h
index 3c17327f2..ab2452e74 100644
--- a/libnautilus-extensions/nautilus-global-preferences.h
+++ b/libnautilus-extensions/nautilus-global-preferences.h
@@ -92,6 +92,9 @@ BEGIN_GNOME_DECLS
*/
#define NAUTILUS_PREFERENCES_SIDEBAR_PANELS_NAMESPACE "sidebar-panels"
+/* Sorting order */
+#define NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST "preferences/sort_directories_first"
+
/* Directory view */
#define NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY "directory-view/font_family"
#define NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT "directory-view/smooth_font"
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index 373a55fd1..97175e7cc 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -1700,22 +1700,10 @@ compare_by_full_path (NautilusFile *file_1, NautilusFile *file_2)
return compare_by_name (file_1, file_2);
}
-/**
- * nautilus_file_compare_for_sort:
- * @file_1: A file object
- * @file_2: Another file object
- * @sort_type: Sort criterion
- *
- * Return value: int < 0 if @file_1 should come before file_2 in a smallest-to-largest
- * sorted list; int > 0 if @file_2 should come before file_1 in a smallest-to-largest
- * sorted list; 0 if @file_1 and @file_2 are equal for this sort criterion. Note
- * that each named sort type may actually break ties several ways, with the name
- * of the sort criterion being the primary but not only differentiator.
- **/
-int
-nautilus_file_compare_for_sort (NautilusFile *file_1,
- NautilusFile *file_2,
- NautilusFileSortType sort_type)
+static int
+nautilus_file_compare_for_sort_internal (NautilusFile *file_1,
+ NautilusFile *file_2,
+ NautilusFileSortType sort_type)
{
int compare;
@@ -1724,11 +1712,6 @@ nautilus_file_compare_for_sort (NautilusFile *file_1,
switch (sort_type) {
case NAUTILUS_FILE_SORT_BY_NAME:
- /* Note: This used to put directories first. I
- * thought that was counterintuitive and removed it,
- * but I can imagine discussing this further.
- * John Sullivan <sullivan@eazel.com>
- */
compare = compare_by_name (file_1, file_2);
if (compare != 0) {
return compare;
@@ -1776,24 +1759,50 @@ nautilus_file_compare_for_sort (NautilusFile *file_1,
}
/**
- * nautilus_file_compare_for_sort_reversed:
+ * nautilus_file_compare_for_sort:
* @file_1: A file object
* @file_2: Another file object
* @sort_type: Sort criterion
+ * @directories_first: Put all directories before any non-directories
+ * @reversed: Reverse the order of the items, except that
+ * the directories_first flag is still respected.
*
- * Return value: The opposite of nautilus_file_compare_for_sort: int > 0 if @file_1
- * should come before file_2 in a smallest-to-largest sorted list; int < 0 if @file_2
- * should come before file_1 in a smallest-to-largest sorted list; 0 if @file_1
- * and @file_2 are equal for this sort criterion. Note that each named sort type
- * may actually break ties several ways, with the name of the sort criterion
- * being the primary but not only differentiator.
+ * Return value: int < 0 if @file_1 should come before file_2 in a
+ * sorted list; int > 0 if @file_2 should come before file_1 in a
+ * sorted list; 0 if @file_1 and @file_2 are equal for this sort criterion. Note
+ * that each named sort type may actually break ties several ways, with the name
+ * of the sort criterion being the primary but not only differentiator.
**/
int
-nautilus_file_compare_for_sort_reversed (NautilusFile *file_1,
- NautilusFile *file_2,
- NautilusFileSortType sort_type)
+nautilus_file_compare_for_sort (NautilusFile *file_1,
+ NautilusFile *file_2,
+ NautilusFileSortType sort_type,
+ gboolean directories_first,
+ gboolean reversed)
{
- return - nautilus_file_compare_for_sort (file_1, file_2, sort_type);
+ int result;
+ gboolean is_directory_1, is_directory_2;
+
+ if (directories_first) {
+ is_directory_1 = nautilus_file_is_directory (file_1);
+ is_directory_2 = nautilus_file_is_directory (file_2);
+
+ if (is_directory_1 && !is_directory_2) {
+ return -1;
+ }
+
+ if (is_directory_2 && !is_directory_1) {
+ return +1;
+ }
+ }
+
+ result = nautilus_file_compare_for_sort_internal (file_1, file_2, sort_type);
+
+ if (reversed) {
+ result = -result;
+ }
+
+ return result;
}
/**
@@ -4821,9 +4830,12 @@ nautilus_self_check_file (void)
NAUTILUS_CHECK_INTEGER_RESULT (GTK_OBJECT (file_1)->ref_count, 1);
NAUTILUS_CHECK_INTEGER_RESULT (GTK_OBJECT (file_2)->ref_count, 1);
- NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_2, NAUTILUS_FILE_SORT_BY_NAME) < 0, TRUE);
- NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort_reversed (file_1, file_2, NAUTILUS_FILE_SORT_BY_NAME) > 0, TRUE);
- NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_NAME) == 0, TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_2, NAUTILUS_FILE_SORT_BY_NAME, FALSE, FALSE) < 0, TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_2, NAUTILUS_FILE_SORT_BY_NAME, FALSE, TRUE) > 0, TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_NAME, FALSE, FALSE) == 0, TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_NAME, TRUE, FALSE) == 0, TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_NAME, FALSE, TRUE) == 0, TRUE);
+ NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_NAME, TRUE, TRUE) == 0, TRUE);
nautilus_file_unref (file_1);
nautilus_file_unref (file_2);
diff --git a/libnautilus-private/nautilus-file.h b/libnautilus-private/nautilus-file.h
index 58f71a754..43810f0ad 100644
--- a/libnautilus-private/nautilus-file.h
+++ b/libnautilus-private/nautilus-file.h
@@ -255,10 +255,9 @@ gboolean nautilus_file_is_local (Nautilu
/* Comparing two file objects for sorting */
int nautilus_file_compare_for_sort (NautilusFile *file_1,
NautilusFile *file_2,
- NautilusFileSortType sort_type);
-int nautilus_file_compare_for_sort_reversed (NautilusFile *file_1,
- NautilusFile *file_2,
- NautilusFileSortType sort_type);
+ NautilusFileSortType sort_type,
+ gboolean directories_first,
+ gboolean reversed);
int nautilus_file_compare_name (NautilusFile *file_1,
const char *pattern);
diff --git a/libnautilus-private/nautilus-global-preferences.c b/libnautilus-private/nautilus-global-preferences.c
index acba41c8d..14ad7312b 100644
--- a/libnautilus-private/nautilus-global-preferences.c
+++ b/libnautilus-private/nautilus-global-preferences.c
@@ -208,6 +208,9 @@ global_preferences_install_descriptions (void)
nautilus_preferences_set_description (NAUTILUS_PREFERENCES_SHOW_SPECIAL_FLAGS,
_("Show special flags in Properties window"));
+ nautilus_preferences_set_description (NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
+ _("Always list folders before files"));
+
nautilus_preferences_set_description (NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES,
_("Show only folders (no files) in the tree"));
@@ -308,6 +311,10 @@ global_preferences_install_defaults (void)
NAUTILUS_USER_LEVEL_ADVANCED,
TRUE);
+ nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
+ NAUTILUS_USER_LEVEL_NOVICE,
+ FALSE);
+
nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_SHOW_DESKTOP,
NAUTILUS_USER_LEVEL_NOVICE,
TRUE);
@@ -431,6 +438,9 @@ global_preferences_install_visibility (void)
nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_SHOW_SPECIAL_FLAGS,
NAUTILUS_USER_LEVEL_ADVANCED);
+ nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
+ NAUTILUS_USER_LEVEL_INTERMEDIATE);
+
nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
NAUTILUS_USER_LEVEL_ADVANCED);
@@ -654,6 +664,14 @@ global_preferences_create_dialog (void)
NAUTILUS_PREFERENCES_SHOW_SPECIAL_FLAGS,
NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
+ nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane),
+ _("Sorting Order"));
+
+ nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane),
+ 3,
+ NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
+ NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
+
/*
* Sidebar panels pane
*/
diff --git a/libnautilus-private/nautilus-global-preferences.h b/libnautilus-private/nautilus-global-preferences.h
index 3c17327f2..ab2452e74 100644
--- a/libnautilus-private/nautilus-global-preferences.h
+++ b/libnautilus-private/nautilus-global-preferences.h
@@ -92,6 +92,9 @@ BEGIN_GNOME_DECLS
*/
#define NAUTILUS_PREFERENCES_SIDEBAR_PANELS_NAMESPACE "sidebar-panels"
+/* Sorting order */
+#define NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST "preferences/sort_directories_first"
+
/* Directory view */
#define NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY "directory-view/font_family"
#define NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT "directory-view/smooth_font"
diff --git a/src/file-manager/fm-desktop-icon-view.c b/src/file-manager/fm-desktop-icon-view.c
index f442316b5..57891e3d2 100644
--- a/src/file-manager/fm-desktop-icon-view.c
+++ b/src/file-manager/fm-desktop-icon-view.c
@@ -908,7 +908,10 @@ desktop_icons_compare_callback (NautilusIconContainer *container,
category_b = get_sort_category (file_b);
if (category_a == category_b) {
- return nautilus_file_compare_for_sort (file_a, file_b, NAUTILUS_FILE_SORT_BY_NAME);
+ return nautilus_file_compare_for_sort
+ (file_a, file_b, NAUTILUS_FILE_SORT_BY_NAME,
+ fm_directory_view_should_sort_directories_first (FM_DIRECTORY_VIEW (icon_view)),
+ FALSE);
}
/* We know the answer, so prevent the other handlers
diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c
index 3b1ff25c4..fcf0c6641 100644
--- a/src/file-manager/fm-directory-view.c
+++ b/src/file-manager/fm-directory-view.c
@@ -173,6 +173,8 @@ struct FMDirectoryViewDetails
gboolean scripts_invalid;
gboolean reported_load_error;
+ gboolean sort_directories_first;
+
gboolean show_hidden_files;
gboolean show_backup_files;
gboolean ignore_hidden_file_preferences;
@@ -1022,6 +1024,31 @@ smooth_graphics_mode_changed_callback (gpointer callback_data)
smooth_graphics_mode_changed, (view));
}
+gboolean
+fm_directory_view_should_sort_directories_first (FMDirectoryView *view)
+{
+ return view->details->sort_directories_first;
+}
+
+static void
+sort_directories_first_changed_callback (gpointer callback_data)
+{
+ FMDirectoryView *view;
+ gboolean preference_value;
+
+ view = FM_DIRECTORY_VIEW (callback_data);
+
+ preference_value =
+ nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST);
+
+ if (preference_value != view->details->sort_directories_first) {
+ view->details->sort_directories_first = preference_value;
+ NAUTILUS_CALL_METHOD
+ (FM_DIRECTORY_VIEW_CLASS, view,
+ sort_directories_first_changed, (view));
+ }
+}
+
static float fm_directory_view_preferred_zoom_levels[] = {
(float) NAUTILUS_ICON_SIZE_SMALLEST / NAUTILUS_ICON_SIZE_STANDARD,
(float) NAUTILUS_ICON_SIZE_SMALLER / NAUTILUS_ICON_SIZE_STANDARD,
@@ -1126,6 +1153,9 @@ fm_directory_view_initialize (FMDirectoryView *view)
bonobo_object_add_interface (BONOBO_OBJECT (view->details->nautilus_view),
BONOBO_OBJECT (view->details->zoomable));
+ view->details->sort_directories_first =
+ nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST);
+
gtk_signal_connect (GTK_OBJECT (view->details->nautilus_view),
"stop_loading",
GTK_SIGNAL_FUNC (stop_loading_callback),
@@ -1214,6 +1244,11 @@ fm_directory_view_initialize (FMDirectoryView *view)
nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE,
smooth_graphics_mode_changed_callback,
view);
+
+ /* Keep track of changes in sort order */
+ nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
+ sort_directories_first_changed_callback,
+ view);
}
static void
@@ -1274,6 +1309,9 @@ fm_directory_view_destroy (GtkObject *object)
nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE,
smooth_graphics_mode_changed_callback,
view);
+ nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
+ sort_directories_first_changed_callback,
+ view);
g_free (view->details);
diff --git a/src/file-manager/fm-directory-view.h b/src/file-manager/fm-directory-view.h
index 36392c589..7085f6fd9 100644
--- a/src/file-manager/fm-directory-view.h
+++ b/src/file-manager/fm-directory-view.h
@@ -262,13 +262,14 @@ struct FMDirectoryViewClass {
* Icon and list views respond by synchronizing to the new preference
* values and forcing an update if appropriate.
*/
- void (* text_attribute_names_changed)(FMDirectoryView *view);
- void (* embedded_text_policy_changed)(FMDirectoryView *view);
- void (* image_display_policy_changed)(FMDirectoryView *view);
- void (* font_family_changed) (FMDirectoryView *view);
- void (* smooth_font_changed) (FMDirectoryView *view);
- void (* click_policy_changed) (FMDirectoryView *view);
- void (* smooth_graphics_mode_changed)(FMDirectoryView *view);
+ void (* text_attribute_names_changed) (FMDirectoryView *view);
+ void (* embedded_text_policy_changed) (FMDirectoryView *view);
+ void (* image_display_policy_changed) (FMDirectoryView *view);
+ void (* font_family_changed) (FMDirectoryView *view);
+ void (* smooth_font_changed) (FMDirectoryView *view);
+ void (* click_policy_changed) (FMDirectoryView *view);
+ void (* smooth_graphics_mode_changed) (FMDirectoryView *view);
+ void (* sort_directories_first_changed) (FMDirectoryView *view);
};
/* GtkObject support */
@@ -350,6 +351,7 @@ void fm_directory_view_pop_up_selection_context_menu (FMDirect
void fm_directory_view_send_selection_change (FMDirectoryView *view);
gboolean fm_directory_view_should_show_file (FMDirectoryView *view,
NautilusFile *file);
+gboolean fm_directory_view_should_sort_directories_first (FMDirectoryView *view);
void fm_directory_view_update_menus (FMDirectoryView *view);
void fm_directory_view_new_folder (FMDirectoryView *view);
void fm_directory_view_ignore_hidden_file_preferences (FMDirectoryView *view);
diff --git a/src/file-manager/fm-icon-view.c b/src/file-manager/fm-icon-view.c
index e6f48aeb9..9b868564e 100644
--- a/src/file-manager/fm-icon-view.c
+++ b/src/file-manager/fm-icon-view.c
@@ -1479,23 +1479,20 @@ icon_container_compare_icons_callback (NautilusIconContainer *container,
NautilusFile *file_b,
FMIconView *icon_view)
{
- int result;
-
g_assert (FM_IS_ICON_VIEW (icon_view));
g_assert (container == get_icon_container (icon_view));
g_assert (NAUTILUS_IS_FILE (file_a));
g_assert (NAUTILUS_IS_FILE (file_b));
- result = nautilus_file_compare_for_sort
- (file_a, file_b, icon_view->details->sort->sort_type);
-
- if (icon_view->details->sort_reversed) {
- result = -result;
- }
-
- return result;
+ return nautilus_file_compare_for_sort
+ (file_a, file_b, icon_view->details->sort->sort_type,
+ fm_directory_view_should_sort_directories_first (FM_DIRECTORY_VIEW (icon_view)),
+ icon_view->details->sort_reversed);
}
+/* This is used by type-to-select code. It deliberately ignores the
+ * folders-first and reversed-sort settings.
+ */
static int
icon_container_compare_icons_by_name_callback (NautilusIconContainer *container,
NautilusFile *file_a,
@@ -1509,7 +1506,8 @@ icon_container_compare_icons_by_name_callback (NautilusIconContainer *container,
g_assert (NAUTILUS_IS_FILE (file_a));
g_assert (NAUTILUS_IS_FILE (file_b));
- result = nautilus_file_compare_for_sort (file_a, file_b, NAUTILUS_FILE_SORT_BY_NAME);
+ result = nautilus_file_compare_for_sort (file_a, file_b, NAUTILUS_FILE_SORT_BY_NAME,
+ FALSE, FALSE);
return result;
}
@@ -1856,6 +1854,19 @@ fm_icon_view_smooth_graphics_mode_changed (FMDirectoryView *directory_view)
fm_icon_view_update_smooth_graphics_mode (FM_ICON_VIEW (directory_view));
}
+static void
+fm_icon_view_sort_directories_first_changed (FMDirectoryView *directory_view)
+{
+ FMIconView *icon_view;
+
+ icon_view = FM_ICON_VIEW (directory_view);
+
+ if (fm_icon_view_using_auto_layout (icon_view)) {
+ nautilus_icon_container_sort
+ (get_icon_container (icon_view));
+ }
+}
+
/* GtkObject methods. */
static void
@@ -1896,6 +1907,7 @@ fm_icon_view_initialize_class (FMIconViewClass *klass)
fm_directory_view_class->smooth_font_changed = fm_icon_view_smooth_font_changed;
fm_directory_view_class->click_policy_changed = fm_icon_view_click_policy_changed;
fm_directory_view_class->smooth_graphics_mode_changed = fm_icon_view_smooth_graphics_mode_changed;
+ fm_directory_view_class->sort_directories_first_changed = fm_icon_view_sort_directories_first_changed;
klass->clean_up = fm_icon_view_real_clean_up;
diff --git a/src/file-manager/fm-list-view.c b/src/file-manager/fm-list-view.c
index e1fac32ce..ceafffb37 100644
--- a/src/file-manager/fm-list-view.c
+++ b/src/file-manager/fm-list-view.c
@@ -60,7 +60,10 @@ struct FMListViewDetails {
in chunks, to improve responsiveness during loading.
This is the number of files we add to the list, or change
at once. */
-/* FIXME: Why doesn't the icon view need the same thing? */
+/* FIXME: Why doesn't the icon view need the same thing?
+ * (Probably this was added when testing search results and
+ * similar tests weren't done for icon view.)
+ */
#define LIST_VIEW_DISPLAY_PENDING_FILES_GROUP_SIZE 100
/*
@@ -183,6 +186,7 @@ static void real_get_column_specification (FMListVie
int column_number,
FMListViewColumn *specification);
static gboolean real_is_empty (FMDirectoryView *view);
+static void real_sort_directories_first_changed (FMDirectoryView *view);
static void real_start_renaming_item (FMDirectoryView *view,
const char *uri);
@@ -230,6 +234,7 @@ fm_list_view_initialize_class (gpointer klass)
fm_directory_view_class->image_display_policy_changed = fm_list_view_image_display_policy_changed;
fm_directory_view_class->font_family_changed = fm_list_view_font_family_changed;
fm_directory_view_class->smooth_graphics_mode_changed = fm_list_view_update_smooth_graphics_mode;
+ fm_directory_view_class->sort_directories_first_changed = real_sort_directories_first_changed;
fm_list_view_class->adding_file = real_adding_file;
fm_list_view_class->removing_file = real_removing_file;
@@ -306,6 +311,35 @@ column_clicked_callback (NautilusCList *clist, int column, gpointer user_data)
fm_list_view_sort_items (list_view, column, reversed);
}
+/* NautilusCompareFunction-style compare function */
+static int
+list_view_compare_files_for_sort (gconstpointer a, gconstpointer b, gpointer callback_data)
+{
+ FMListView *list_view;
+ NautilusFile *file1;
+ NautilusFile *file2;
+ int result;
+
+ list_view = FM_LIST_VIEW (callback_data);
+ file1 = NAUTILUS_FILE (a);
+ file2 = NAUTILUS_FILE (b);
+
+ result = nautilus_file_compare_for_sort (file1, file2,
+ get_column_sort_criterion (list_view, list_view->details->sort_column),
+ fm_directory_view_should_sort_directories_first (FM_DIRECTORY_VIEW (list_view)),
+ list_view->details->sort_reversed);
+
+ /* Flip the sign in the reversed case since list widget will flip it back.
+ * See comment in fm_list_view_sort_items.
+ */
+ if (list_view->details->sort_reversed) {
+ result = -result;
+ }
+
+ return result;
+}
+
+/* CList-style compare function */
static int
fm_list_view_compare_rows (NautilusCList *clist,
gconstpointer ptr1,
@@ -315,7 +349,6 @@ fm_list_view_compare_rows (NautilusCList *clist,
NautilusCListRow *row2;
NautilusFile *file1;
NautilusFile *file2;
- NautilusFileSortType sort_criterion;
FMListView *list_view;
g_return_val_if_fail (NAUTILUS_IS_LIST (clist), 0);
@@ -344,10 +377,12 @@ fm_list_view_compare_rows (NautilusCList *clist,
list_view = FM_LIST_VIEW (GTK_WIDGET (clist)->parent);
- sort_criterion = get_column_sort_criterion (list_view, clist->sort_column);
- return nautilus_file_compare_for_sort (file1, file2, sort_criterion);
+ return list_view_compare_files_for_sort (file1, file2, list_view);
}
+/* This is used by type-to-select code. It deliberately ignores the
+ * folders-first and reversed-sort settings.
+ */
static int
compare_rows_by_name (gconstpointer a, gconstpointer b, void *callback_data)
{
@@ -362,7 +397,8 @@ compare_rows_by_name (gconstpointer a, gconstpointer b, void *callback_data)
return nautilus_file_compare_for_sort
(NAUTILUS_FILE (row1->data),
NAUTILUS_FILE (row2->data),
- NAUTILUS_FILE_SORT_BY_NAME);
+ NAUTILUS_FILE_SORT_BY_NAME,
+ FALSE, FALSE);
}
static int
@@ -924,6 +960,12 @@ fm_list_view_update_smooth_graphics_mode (FMDirectoryView *directory_view)
}
static void
+real_sort_directories_first_changed (FMDirectoryView *directory_view)
+{
+ nautilus_clist_sort (NAUTILUS_CLIST (get_list (FM_LIST_VIEW (directory_view))));
+}
+
+static void
create_list (FMListView *list_view)
{
int number_of_columns;
@@ -1690,16 +1732,9 @@ fm_list_view_display_pending_files (FMDirectoryView *view,
/* Sort the added items before displaying them, so that they'll be added in order,
and items won't move around. */
- if (FM_LIST_VIEW (view)->details->sort_reversed) {
- *pending_files_added = nautilus_g_list_sort_custom (*pending_files_added,
- (NautilusCompareFunction) nautilus_file_compare_for_sort_reversed,
- GINT_TO_POINTER (sort_criterion));
- }
- else {
- *pending_files_added = nautilus_g_list_sort_custom (*pending_files_added,
- (NautilusCompareFunction) nautilus_file_compare_for_sort,
- GINT_TO_POINTER (sort_criterion));
- }
+ *pending_files_added = nautilus_g_list_sort_custom (*pending_files_added,
+ (NautilusCompareFunction) list_view_compare_files_for_sort,
+ FM_LIST_VIEW (view));
files_added = g_list_split_off_first_n (pending_files_added,
LIST_VIEW_DISPLAY_PENDING_FILES_GROUP_SIZE);
@@ -1798,6 +1833,11 @@ fm_list_view_sort_items (FMListView *list_view,
list_view->details->sort_column = column;
if (reversed != list_view->details->sort_reversed) {
+ /* Set DESCENDING or ASCENDING so the sort-order triangle
+ * in the column header draws correctly; we have to play
+ * games with the sort order in list_view_compare_files_for_sort
+ * to make up for this.
+ */
nautilus_clist_set_sort_type (clist, reversed
? GTK_SORT_DESCENDING
: GTK_SORT_ASCENDING);