[Bf-blender-cvs] [e28fb66] asset-experiments: More sorting fixes and tweaks (things should work rather OK now).

Bastien Montagne noreply at git.blender.org
Mon Dec 8 19:22:09 CET 2014


Commit: e28fb661868af9e23f43818075e5a7fb786e319e
Author: Bastien Montagne
Date:   Mon Dec 8 18:51:38 2014 +0100
Branches: asset-experiments
https://developer.blender.org/rBe28fb661868af9e23f43818075e5a7fb786e319e

More sorting fixes and tweaks (things should work rather OK now).

===================================================================

M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filelist.h

===================================================================

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index d470010..14e61ae 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1150,7 +1150,7 @@ bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, cha
 {
 	/* We might get some data names with slashes, so we have to go up in path until we find blend file itself,
 	 * then we now next path item is group, and everything else is data name. */
-	char *slash, *prev_slash = NULL;
+	char *slash = NULL, *prev_slash = NULL;
 
 	r_dir[0] = '\0';
 	if (r_group) {
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index eb4e571..332b8c5 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -471,7 +471,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
 	align = (FILE_IMGDISPLAY == params->display) ? UI_STYLE_TEXT_CENTER : UI_STYLE_TEXT_LEFT;
 
 	for (i = offset; (i < numfiles) && (i < offset + numfiles_layout); i++) {
-		char path[FILE_MAX_LIBEXTRA], dir[FILE_MAXDIR], *group, *name;
+		char path[FILE_MAX_LIBEXTRA], dir[FILE_MAXDIR], *name;
 		ED_fileselect_layout_tilepos(layout, i, &sx, &sy);
 		sx += (int)(v2d->tot.xmin + 0.1f * UI_UNIT_X);
 		sy = (int)(v2d->tot.ymax - sy);
@@ -479,15 +479,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
 		file = filelist_file(files, i);
 
 		BLI_join_dirfile(path, sizeof(path), filelist_dir(files), file->relname);
-		if (BLO_library_path_explode(path, dir, &group, &name)) {
-			if (!name) {
-				name = group;
-			}
-			BLI_assert(name);
-		}
-		else {
-			name = file->relname;
-		}
+		name = fileentry_uiname(file, dir);
 
 		UI_ThemeColor4(TH_TEXT);
 
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index a849c1f..a6f7876 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -177,6 +177,8 @@ static bool compare_is_directory(const struct direntry *entry)
 static int compare_name(const void *a1, const void *a2)
 {
 	const struct direntry *entry1 = a1, *entry2 = a2;
+	char dir1[FILE_MAX_LIBEXTRA], dir2[FILE_MAX_LIBEXTRA];
+	char *name1, *name2;
 
 	/* type is equal to stat.st_mode */
 
@@ -200,14 +202,19 @@ static int compare_name(const void *a1, const void *a2)
 	if (strcmp(entry2->relname, ".") == 0) return (1);
 	if (strcmp(entry1->relname, "..") == 0) return (-1);
 	if (strcmp(entry2->relname, "..") == 0) return (1);
-	
-	return (BLI_natstrcmp(entry1->relname, entry2->relname));
+
+	name1 = fileentry_uiname(entry1, dir1);
+	name2 = fileentry_uiname(entry2, dir2);
+
+	return BLI_natstrcmp(name1, name2);
 }
 
 static int compare_date(const void *a1, const void *a2)	
 {
 	const struct direntry *entry1 = a1, *entry2 = a2;
-	
+	char dir1[FILE_MAX_LIBEXTRA], dir2[FILE_MAX_LIBEXTRA];
+	char *name1, *name2;
+
 	/* type is equal to stat.st_mode */
 
 	if (compare_is_directory(entry1)) {
@@ -233,13 +240,18 @@ static int compare_date(const void *a1, const void *a2)
 	
 	if (entry1->s.st_mtime < entry2->s.st_mtime) return 1;
 	if (entry1->s.st_mtime > entry2->s.st_mtime) return -1;
-	
-	else return BLI_natstrcmp(entry1->relname, entry2->relname);
+
+	name1 = fileentry_uiname(entry1, dir1);
+	name2 = fileentry_uiname(entry2, dir2);
+
+	return BLI_natstrcmp(name1, name2);
 }
 
 static int compare_size(const void *a1, const void *a2)	
 {
 	const struct direntry *entry1 = a1, *entry2 = a2;
+	char dir1[FILE_MAX_LIBEXTRA], dir2[FILE_MAX_LIBEXTRA];
+	char *name1, *name2;
 
 	/* type is equal to stat.st_mode */
 
@@ -266,7 +278,11 @@ static int compare_size(const void *a1, const void *a2)
 	
 	if (entry1->s.st_size < entry2->s.st_size) return 1;
 	if (entry1->s.st_size > entry2->s.st_size) return -1;
-	else return BLI_natstrcmp(entry1->relname, entry2->relname);
+
+	name1 = fileentry_uiname(entry1, dir1);
+	name2 = fileentry_uiname(entry2, dir2);
+
+	return BLI_natstrcmp(name1, name2);
 }
 
 static int compare_extension(const void *a1, const void *a2)
@@ -291,6 +307,21 @@ static int compare_extension(const void *a1, const void *a2)
 		if (compare_is_directory(entry2)) return (1);
 	}
 
+	if (S_ISREG(entry1->type)) {
+		if (S_ISREG(entry2->type) == 0) return (-1);
+	}
+	else {
+		if (S_ISREG(entry2->type)) return (1);
+	}
+	if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1);
+	if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1);
+
+	/* make sure "." and ".." are always first */
+	if (strcmp(entry1->relname, ".") == 0) return (-1);
+	if (strcmp(entry2->relname, ".") == 0) return (1);
+	if (strcmp(entry1->relname, "..") == 0) return (-1);
+	if (strcmp(entry2->relname, "..") == 0) return (1);
+
 	if ((entry1->flags & BLENDERLIB) && !(entry2->flags & BLENDERLIB)) return -1;
 	if (!(entry1->flags & BLENDERLIB) && (entry2->flags & BLENDERLIB)) return 1;
 	if ((entry1->flags & BLENDERLIB) && (entry2->flags & BLENDERLIB)) {
@@ -318,22 +349,7 @@ static int compare_extension(const void *a1, const void *a2)
 		return BLI_strcasecmp(name1, name2);
 	}
 
-	if (S_ISREG(entry1->type)) {
-		if (S_ISREG(entry2->type) == 0) return (-1);
-	}
-	else {
-		if (S_ISREG(entry2->type)) return (1);
-	}
-	if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1);
-	if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1);
-
-	/* make sure "." and ".." are always first */
-	if (strcmp(entry1->relname, ".") == 0) return (-1);
-	if (strcmp(entry2->relname, ".") == 0) return (1);
-	if (strcmp(entry1->relname, "..") == 0) return (-1);
-	if (strcmp(entry2->relname, "..") == 0) return (1);
-
-	return (BLI_strcasecmp(sufix1, sufix2));
+	return BLI_strcasecmp(sufix1, sufix2);
 }
 
 
@@ -666,6 +682,28 @@ int filelist_numfiles(struct FileList *filelist)
 	return filelist->numfiltered;
 }
 
+char *fileentry_uiname(const struct direntry *entry, char *dir)
+{
+	char *name;
+
+	if (entry->path && entry->flags & BLENDERLIB) {
+		char *group;
+		BLO_library_path_explode(entry->path, dir, &group, &name);
+		if (!name) {
+			name = group;
+		}
+	}
+	else if (entry->type & S_IFDIR) {
+		name = entry->relname;
+	}
+	else {
+		name = (char *)BLI_path_basename(entry->relname);
+	}
+	BLI_assert(name);
+
+	return name;
+}
+
 const char *filelist_dir(struct FileList *filelist)
 {
 	return filelist->dir;
diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h
index cb5fbe8..05b8398 100644
--- a/source/blender/editors/space_file/filelist.h
+++ b/source/blender/editors/space_file/filelist.h
@@ -93,6 +93,8 @@ void                filelist_from_main(struct FileList *filelist);
 void                filelist_freelib(struct FileList *filelist);
 void                filelist_hideparent(struct FileList *filelist, short hide);
 
+char               *fileentry_uiname(const struct direntry *entry, char *dir);
+
 
 struct ListBase *   folderlist_new(void);
 void                folderlist_free(struct ListBase *folderlist);




More information about the Bf-blender-cvs mailing list