[PATCH] Enforce sorting of directories before files



From bug 310919 [1]:
"(...) (I)f you have the 'Sort folders before files' option turned on,
the folders may end up at the bottom of the view depending on the
sorting order of the column."

Proposed patch attached.

[1] http://bugzilla.gnome.org/show_bug.cgi?id=310919

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.370
diff -u -p -r1.370 nautilus-file.c
--- libnautilus-private/nautilus-file.c	22 Aug 2005 21:17:58 -0000	1.370
+++ libnautilus-private/nautilus-file.c	28 Aug 2005 22:48:14 -0000
@@ -2116,26 +2142,38 @@ compare_by_full_path (NautilusFile *file
 }
 
 static int
+compare_by_is_directory (NautilusFile *file_1, NautilusFile *file_2)
+{
+	gboolean is_directory_1, is_directory_2;
+
+	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;
+	}
+
+	return 0;
+}
+
+static int
 nautilus_file_compare_for_sort_internal (NautilusFile *file_1,
 					 NautilusFile *file_2,
-					 gboolean directories_first)
+					 gboolean directories_first,
+					 gboolean reversed)
 {
 	int compare;
 	GnomeVFSDrive *drive1, *drive2;
 	GnomeVFSVolume *volume1, *volume2;
 
-	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;
+		compare = compare_by_is_directory (file_1, file_2);
+		if (compare != 0) {
+			return reversed ? -compare : compare;
 		}
 	}
 
@@ -2203,7 +2241,7 @@ nautilus_file_compare_for_sort (Nautilus
 		return 0;
 	}
 	
-	result = nautilus_file_compare_for_sort_internal (file_1, file_2, directories_first);
+	result = nautilus_file_compare_for_sort_internal (file_1, file_2, directories_first, reversed);
 	
 	if (result == 0) {
 		switch (sort_type) {
@@ -2307,7 +2345,7 @@ nautilus_file_compare_for_sort_by_attrib
 	
 	/* it is a normal attribute, compare by strings */
 
-	result = nautilus_file_compare_for_sort_internal (file_1, file_2, directories_first);
+	result = nautilus_file_compare_for_sort_internal (file_1, file_2, directories_first, reversed);
 	
 	if (result == 0) {
 		char *value_1;

Attachment: signature.asc
Description: This is a digitally signed message part



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