[Bf-blender-cvs] [65b4905] asset-experiments: Add name/description fields to entries themselves too.

Bastien Montagne noreply at git.blender.org
Sun Mar 1 11:51:51 CET 2015


Commit: 65b49051fb91d5bfc62fc48a290bba0bb51f9c94
Author: Bastien Montagne
Date:   Sun Mar 1 11:42:28 2015 +0100
Branches: asset-experiments
https://developer.blender.org/rB65b49051fb91d5bfc62fc48a290bba0bb51f9c94

Add name/description fields to entries themselves too.

This allows us to greatly simplifies sorting (and avoid recomputing UI name each and everytime!).
Also, correctly free entries/variants names/descriptions.

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

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
M	source/blender/makesdna/DNA_space_types.h

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

diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 479d107..995250d 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -485,7 +485,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], *name;
+		char path[FILE_MAX_LIBEXTRA];
 		ED_fileselect_layout_tilepos(layout, i, &sx, &sy);
 		sx += (int)(v2d->tot.xmin + 0.1f * UI_UNIT_X);
 		sy = (int)(v2d->tot.ymax - sy);
@@ -493,7 +493,6 @@ void file_draw_list(const bContext *C, ARegion *ar)
 		file = filelist_file(files, i);
 
 		BLI_join_dirfile(path, sizeof(path), root, file->relpath);
-		name = fileentry_uiname(root, file, dir);
 
 		UI_ThemeColor4(TH_TEXT);
 
@@ -566,7 +565,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
 
 		if (!(file->selflag & FILE_SEL_EDITING)) {
 			int tpos = (FILE_IMGDISPLAY == params->display) ? sy - layout->tile_h + layout->textheight : sy;
-			file_draw_string(sx + 1, tpos, name, (float)textwidth, textheight, align);
+			file_draw_string(sx + 1, tpos, file->name, (float)textwidth, textheight, align);
 		}
 
 		if (params->display == FILE_SHORTDISPLAY) {
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index c6b076e..3eaf712 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -336,12 +336,10 @@ static int compare_direntry_generic(const FileDirEntry *entry1, const FileDirEnt
 	return 0;
 }
 
-static int compare_name(void *user_data, const void *a1, const void *a2)
+static int compare_name(void *UNUSED(user_data), const void *a1, const void *a2)
 {
-	const char *root = user_data;
 	const FileDirEntry *entry1 = a1;
 	const FileDirEntry *entry2 = a2;
-	char dir1[FILE_MAX_LIBEXTRA], dir2[FILE_MAX_LIBEXTRA];
 	char *name1, *name2;
 	int ret;
 
@@ -349,18 +347,16 @@ static int compare_name(void *user_data, const void *a1, const void *a2)
 		return ret;
 	}
 
-	name1 = fileentry_uiname(root, entry1, dir1);
-	name2 = fileentry_uiname(root, entry2, dir2);
+	name1 = entry1->name;
+	name2 = entry2->name;
 
 	return BLI_natstrcmp(name1, name2);
 }
 
-static int compare_date(void *user_data, const void *a1, const void *a2)
+static int compare_date(void *UNUSED(user_data), const void *a1, const void *a2)
 {
-	const char *root = user_data;
 	const FileDirEntry *entry1 = a1;
 	const FileDirEntry *entry2 = a2;
-	char dir1[FILE_MAX_LIBEXTRA], dir2[FILE_MAX_LIBEXTRA];
 	char *name1, *name2;
 	int ret;
 
@@ -371,18 +367,16 @@ static int compare_date(void *user_data, const void *a1, const void *a2)
 	if (entry1->entry->time < entry2->entry->time) return 1;
 	if (entry1->entry->time > entry2->entry->time) return -1;
 
-	name1 = fileentry_uiname(root, entry1, dir1);
-	name2 = fileentry_uiname(root, entry2, dir2);
+	name1 = entry1->name;
+	name2 = entry2->name;
 
 	return BLI_natstrcmp(name1, name2);
 }
 
-static int compare_size(void *user_data, const void *a1, const void *a2)
+static int compare_size(void *UNUSED(user_data), const void *a1, const void *a2)
 {
-	const char *root = user_data;
 	const FileDirEntry *entry1 = a1;
 	const FileDirEntry *entry2 = a2;
-	char dir1[FILE_MAX_LIBEXTRA], dir2[FILE_MAX_LIBEXTRA];
 	char *name1, *name2;
 	int ret;
 
@@ -393,8 +387,8 @@ static int compare_size(void *user_data, const void *a1, const void *a2)
 	if (entry1->entry->size < entry2->entry->size) return 1;
 	if (entry1->entry->size > entry2->entry->size) return -1;
 
-	name1 = fileentry_uiname(root, entry1, dir1);
-	name2 = fileentry_uiname(root, entry2, dir2);
+	name1 = entry1->name;
+	name2 = entry2->name;
 
 	return BLI_natstrcmp(name1, name2);
 }
@@ -947,6 +941,12 @@ static void filelist_checkdir_main(struct FileList *filelist, char *r_dir)
 
 static void filelist_entry_free(FileDirEntry *entry, const bool clear)
 {
+	if (entry->name) {
+		MEM_freeN(entry->name);
+	}
+	if (entry->description) {
+		MEM_freeN(entry->description);
+	}
 	if (entry->relpath) {
 		MEM_freeN(entry->relpath);
 	}
@@ -959,6 +959,12 @@ static void filelist_entry_free(FileDirEntry *entry, const bool clear)
 		FileDirEntryVariant *var;
 
 		for (var = entry->variants.first; var; var = var->next) {
+			if (var->name) {
+				MEM_freeN(var->name);
+			}
+			if (var->description) {
+				MEM_freeN(var->description);
+			}
 			BLI_freelistN(&var->revisions);
 		}
 
@@ -1055,7 +1061,7 @@ int filelist_numfiles(struct FileList *filelist)
 	return filelist->numfiltered;
 }
 
-char *fileentry_uiname(const char *root, const FileDirEntry *entry, char *dir)
+static const char *fileentry_uiname(const char *root, const FileDirEntry *entry, char *buff)
 {
 	char *name;
 
@@ -1064,7 +1070,7 @@ char *fileentry_uiname(const char *root, const FileDirEntry *entry, char *dir)
 		char *group;
 
 		BLI_join_dirfile(abspath, sizeof(abspath), root, entry->relpath);
-		BLO_library_path_explode(abspath, dir, &group, &name);
+		BLO_library_path_explode(abspath, buff, &group, &name);
 		if (!name) {
 			name = group;
 		}
@@ -1742,6 +1748,7 @@ static void filelist_readjob_do(
 			/* Only thing we change in direntry here, so we need to free it first. */
 			MEM_freeN(entry->relpath);
 			entry->relpath = BLI_strdup(dir + 2);  /* + 2 to remove '//' added by BLI_path_rel */
+			entry->name = BLI_strdup(fileentry_uiname(root, entry, dir));
 
 			/* Here we decide whether current filedirentry is to be listed too, or not. */
 			if (max_recursion && (is_lib || (recursion_level <= max_recursion))) {
@@ -1763,7 +1770,6 @@ static void filelist_readjob_do(
 					nbr_todo_dirs++;
 				}
 			}
-
 		}
 
 		if (nbr_entries) {
diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h
index a23b83d..fd1dd66 100644
--- a/source/blender/editors/space_file/filelist.h
+++ b/source/blender/editors/space_file/filelist.h
@@ -114,8 +114,6 @@ struct BlendHandle *filelist_lib(struct FileList *filelist);
 bool                filelist_islibrary(struct FileList *filelist, char *dir, char **group);
 void                filelist_freelib(struct FileList *filelist);
 
-char               *fileentry_uiname(const char *root, const struct FileDirEntry *entry, char *dir);
-
 void                filelist_readjob_start(struct FileList *filelist, const struct bContext *C);
 void                filelist_readjob_stop(struct wmWindowManager *wm, struct FileList *filelist);
 int                 filelist_readjob_running(struct wmWindowManager *wm, struct FileList *filelist);
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 06120f0..bccdaef 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -757,6 +757,9 @@ typedef struct FileDirEntryRevision {
 	 */
 	char uuid[24];  /* ASSET_UUID_LENGTH */
 
+	/* Shall we also add a description to revisions? Could contain commit messages e.g.
+	 * But would also likely make explode memory usage? */
+
 	uint64_t size;
 	int64_t time;
 	/* Those are direct copy from direntry. We may rework that later, but really not top priority. */
@@ -800,6 +803,9 @@ typedef struct FileDirEntry {
 	 */
 	char uuid[24];  /* ASSET_UUID_LENGTH */
 
+	char *name;
+	char *description;
+
 	/* Either point to active variant/revision if available, or own entry (in mere filebrowser case). */
 	FileDirEntryRevision *entry;




More information about the Bf-blender-cvs mailing list