From 2f46a2cbf7a80c85734bd2b7d7cd0b5dc178f43b Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 28 Aug 2013 21:50:13 +0000 Subject: [PATCH] Fix #36595: file browser sorting with link/append would mix together .blend files and directories instead of keeping them separate like regular file browse. --- source/blender/editors/space_file/filelist.c | 34 +++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 8f25ac38963..b427555d1a7 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -152,17 +152,27 @@ static ImBuf *gSpecialFileImages[SPECIAL_IMG_MAX]; /* ******************* SORT ******************* */ +static bool compare_is_directory(const struct direntry *entry) +{ + /* for library browse .blend files may be treated as directories, but + * for sorting purposes they should be considered regular files */ + if (S_ISDIR(entry->type)) + return !(entry->flags & (BLENDERFILE|BLENDERFILE_BACKUP)); + + return false; +} + static int compare_name(const void *a1, const void *a2) { const struct direntry *entry1 = a1, *entry2 = a2; /* type is equal to stat.st_mode */ - if (S_ISDIR(entry1->type)) { - if (S_ISDIR(entry2->type) == 0) return (-1); + if (compare_is_directory(entry1)) { + if (compare_is_directory(entry2) == 0) return (-1); } else { - if (S_ISDIR(entry2->type)) return (1); + if (compare_is_directory(entry2)) return (1); } if (S_ISREG(entry1->type)) { if (S_ISREG(entry2->type) == 0) return (-1); @@ -188,11 +198,11 @@ static int compare_date(const void *a1, const void *a2) /* type is equal to stat.st_mode */ - if (S_ISDIR(entry1->type)) { - if (S_ISDIR(entry2->type) == 0) return (-1); + if (compare_is_directory(entry1)) { + if (compare_is_directory(entry2) == 0) return (-1); } else { - if (S_ISDIR(entry2->type)) return (1); + if (compare_is_directory(entry2)) return (1); } if (S_ISREG(entry1->type)) { if (S_ISREG(entry2->type) == 0) return (-1); @@ -221,11 +231,11 @@ static int compare_size(const void *a1, const void *a2) /* type is equal to stat.st_mode */ - if (S_ISDIR(entry1->type)) { - if (S_ISDIR(entry2->type) == 0) return (-1); + if (compare_is_directory(entry1)) { + if (compare_is_directory(entry2) == 0) return (-1); } else { - if (S_ISDIR(entry2->type)) return (1); + if (compare_is_directory(entry2)) return (1); } if (S_ISREG(entry1->type)) { if (S_ISREG(entry2->type) == 0) return (-1); @@ -262,11 +272,11 @@ static int compare_extension(const void *a1, const void *a2) /* type is equal to stat.st_mode */ - if (S_ISDIR(entry1->type)) { - if (S_ISDIR(entry2->type) == 0) return (-1); + if (compare_is_directory(entry1)) { + if (compare_is_directory(entry2) == 0) return (-1); } else { - if (S_ISDIR(entry2->type)) return (1); + if (compare_is_directory(entry2)) return (1); } if (S_ISREG(entry1->type)) { if (S_ISREG(entry2->type) == 0) return (-1);