[Bf-blender-cvs] [b239c24] asset-experiments: FileBrowser: only generate size/date/time strings when needed!

Bastien Montagne noreply at git.blender.org
Wed Apr 15 17:43:58 CEST 2015


Commit: b239c249acd8d8c45709f522748d37b36b75f578
Author: Bastien Montagne
Date:   Wed Apr 15 17:43:05 2015 +0200
Branches: asset-experiments
https://developer.blender.org/rBb239c249acd8d8c45709f522748d37b36b75f578

FileBrowser: only generate size/date/time strings when needed!

Also, cleanup remaining cruft from modes/owner stuff.

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

M	source/blender/blenlib/BLI_fileops.h
M	source/blender/blenlib/intern/BLI_filelist.c
M	source/blender/editors/include/ED_fileselect.h
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filesel.c
M	source/blender/makesdna/DNA_space_types.h

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

diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h
index fb9d445..0a043ea 100644
--- a/source/blender/blenlib/BLI_fileops.h
+++ b/source/blender/blenlib/BLI_fileops.h
@@ -97,10 +97,10 @@ void BLI_filelist_duplicate(struct direntry **dest_filelist, struct direntry *sr
 void BLI_filelist_entry_free(struct direntry *entry);
 void BLI_filelist_free(struct direntry *filelist, unsigned int nrentries);
 
-void BLI_filelist_entry_size_to_string(struct stat *st, char r_size[]);
+void BLI_filelist_entry_size_to_string(struct stat *st, const uint64_t sz, char r_size[]);
 void BLI_filelist_entry_mode_to_string(struct stat *st, char r_mode1[], char r_mode2[], char r_mode3[]);
 void BLI_filelist_entry_owner_to_string(struct stat *st, char r_owner[]);
-void BLI_filelist_entry_datetime_to_string(struct stat *st, char r_time[], char r_date[]);
+void BLI_filelist_entry_datetime_to_string(struct stat *st, const int64_t ts, char r_time[], char r_date[]);
 
 /* Files */
 
diff --git a/source/blender/blenlib/intern/BLI_filelist.c b/source/blender/blenlib/intern/BLI_filelist.c
index a450fee..d5f1e96 100644
--- a/source/blender/blenlib/intern/BLI_filelist.c
+++ b/source/blender/blenlib/intern/BLI_filelist.c
@@ -239,7 +239,7 @@ unsigned int BLI_filelist_dir_contents(const char *dirname,  struct direntry **f
  * Convert given entry's size into human-readable strings.
  *
  */
-void BLI_filelist_entry_size_to_string(struct stat *st, char r_size[FILELIST_DIRENTRY_SIZE_LEN])
+void BLI_filelist_entry_size_to_string(struct stat *st, const uint64_t sz, char r_size[FILELIST_DIRENTRY_SIZE_LEN])
 {
 	double size;
 	const char *fmt;
@@ -249,7 +249,7 @@ void BLI_filelist_entry_size_to_string(struct stat *st, char r_size[FILELIST_DIR
 	 * will buy us some time until files get bigger than 4GB or until
 	 * everyone starts using __USE_FILE_OFFSET64 or equivalent.
 	 */
-	size = (double)st->st_size;
+	size = (double)(st ? st->st_size : sz);
 
 	if (size > 1024.0 * 1024.0 * 1024.0) {
 		size /= (1024.0 * 1024.0 * 1024.0);
@@ -331,9 +331,9 @@ void BLI_filelist_entry_owner_to_string(struct stat *st, char r_owner[FILELIST_D
  * Convert given entry's time into human-readable strings.
  */
 void BLI_filelist_entry_datetime_to_string(
-        struct stat *st, char r_time[FILELIST_DIRENTRY_TIME_LEN], char r_date[FILELIST_DIRENTRY_DATE_LEN])
+        struct stat *st, const int64_t ts, char r_time[FILELIST_DIRENTRY_TIME_LEN], char r_date[FILELIST_DIRENTRY_DATE_LEN])
 {
-	const struct tm *tm = localtime(&st->st_mtime);
+	const struct tm *tm = localtime(st ? &st->st_mtime : &ts);
 	const time_t zero = 0;
 
 	/* Prevent impossible dates in windows. */
diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h
index b81ea55..bfc78fc 100644
--- a/source/blender/editors/include/ED_fileselect.h
+++ b/source/blender/editors/include/ED_fileselect.h
@@ -40,17 +40,13 @@ struct wmWindowManager;
 #define FILE_LAYOUT_HOR 1
 #define FILE_LAYOUT_VER 2
 
-#define MAX_FILE_COLUMN 8
+#define MAX_FILE_COLUMN 4
 
 typedef enum FileListColumns {
 	COLUMN_NAME = 0,
 	COLUMN_DATE,
 	COLUMN_TIME,
 	COLUMN_SIZE,
-	COLUMN_MODE1,
-	COLUMN_MODE2,
-	COLUMN_MODE3,
-	COLUMN_OWNER
 } FileListColumns;
 
 typedef struct FileLayout {
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index bf955cc..3221d55 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -570,9 +570,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
 				width = layout->tile_w - (ICON_DEFAULT_WIDTH_SCALE + 0.2f * UI_UNIT_X);
 			}
 			else if (params->display == FILE_LONGDISPLAY) {
-				width = layout->column_widths[COLUMN_NAME]  + layout->column_widths[COLUMN_MODE1] +
-				        layout->column_widths[COLUMN_MODE2] + layout->column_widths[COLUMN_MODE3] +
-				        (column_space * 3.5f);
+				width = layout->column_widths[COLUMN_NAME] + (column_space * 3.5f);
 			}
 			else {
 				BLI_assert(params->display == FILE_IMGDISPLAY);
@@ -604,29 +602,18 @@ void file_draw_list(const bContext *C, ARegion *ar)
 		else if (params->display == FILE_LONGDISPLAY) {
 			sx += (int)layout->column_widths[COLUMN_NAME] + column_space;
 
-#if 0
-#ifndef WIN32
-			/* rwx rwx rwx */
-			file_draw_string(sx, sy, file->entry->mode1, layout->column_widths[COLUMN_MODE1], layout->tile_h, align);
-			sx += layout->column_widths[COLUMN_MODE1] + column_space;
-
-			file_draw_string(sx, sy, file->entry->mode2, layout->column_widths[COLUMN_MODE2], layout->tile_h, align);
-			sx += layout->column_widths[COLUMN_MODE2] + column_space;
-
-			file_draw_string(sx, sy, file->entry->mode3, layout->column_widths[COLUMN_MODE3], layout->tile_h, align);
-			sx += layout->column_widths[COLUMN_MODE3] + column_space;
-
-			file_draw_string(sx, sy, file->entry->owner, layout->column_widths[COLUMN_OWNER], layout->tile_h, align);
-			sx += layout->column_widths[COLUMN_OWNER] + column_space;
-#endif
-#endif
+			if (file->entry->date_str[0] == '\0') {
+				BLI_filelist_entry_datetime_to_string(NULL, file->entry->time, file->entry->time_str, file->entry->date_str);
+			}
 			file_draw_string(sx, sy, file->entry->date_str, layout->column_widths[COLUMN_DATE], layout->tile_h, align);
 			sx += (int)layout->column_widths[COLUMN_DATE] + column_space;
-
 			file_draw_string(sx, sy, file->entry->time_str, layout->column_widths[COLUMN_TIME], layout->tile_h, align);
 			sx += (int)layout->column_widths[COLUMN_TIME] + column_space;
 
 			if (!(file->typeflag & FILE_TYPE_DIR)) {
+				if (file->entry->size_str[0] == '\0') {
+					BLI_filelist_entry_size_to_string(NULL, file->entry->size, file->entry->size_str);
+				}
 				file_draw_string(sx, sy, file->entry->size_str, layout->column_widths[COLUMN_SIZE], layout->tile_h, align);
 				sx += (int)layout->column_widths[COLUMN_SIZE] + column_space;
 			}
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index cd02567..71f4d37 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -1388,10 +1388,8 @@ static FileDirEntry *filelist_file_create_entry(FileList *filelist, const int in
 	rev = MEM_callocN(sizeof(*rev), __func__);
 
 	rev->size = (uint64_t)entry->st.st_size;
-	BLI_filelist_entry_size_to_string(&entry->st, rev->size_str);
 
 	rev->time = (int64_t)entry->st.st_mtime;
-	BLI_filelist_entry_datetime_to_string(&entry->st, rev->time_str, rev->date_str);
 
 	ret->entry = rev;
 	ret->relpath = BLI_strdup(entry->relpath);
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 83d26c0..7299d1a 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -480,7 +480,7 @@ float file_font_pointsize(void)
 #endif
 }
 
-static void column_widths(struct FileList *files, struct FileLayout *layout)
+static void column_widths(struct FileList *UNUSED(files), struct FileLayout *layout)
 {
 	int i;
 
@@ -488,43 +488,12 @@ static void column_widths(struct FileList *files, struct FileLayout *layout)
 		layout->column_widths[i] = 0;
 	}
 
-#if 0
-	{
-	int numfiles = filelist_numfiles(files);
-	for (i = 0; (i < numfiles); ++i) {
-		FileDirEntry *file = filelist_file(files, i);
-		if (file) {
-			float len;
-			len = file_string_width(file->relpath);
-			if (len > layout->column_widths[COLUMN_NAME]) layout->column_widths[COLUMN_NAME] = len;
-			len = file_string_width(file->entry->date_str);
-			if (len > layout->column_widths[COLUMN_DATE]) layout->column_widths[COLUMN_DATE] = len;
-			len = file_string_width(file->entry->time_str);
-			if (len > layout->column_widths[COLUMN_TIME]) layout->column_widths[COLUMN_TIME] = len;
-			len = file_string_width(file->entry->size_str);
-			if (len > layout->column_widths[COLUMN_SIZE]) layout->column_widths[COLUMN_SIZE] = len;
-			len = file_string_width(file->entry->mode1);
-			if (len > layout->column_widths[COLUMN_MODE1]) layout->column_widths[COLUMN_MODE1] = len;
-			len = file_string_width(file->entry->mode2);
-			if (len > layout->column_widths[COLUMN_MODE2]) layout->column_widths[COLUMN_MODE2] = len;
-			len = file_string_width(file->entry->mode3);
-			if (len > layout->column_widths[COLUMN_MODE3]) layout->column_widths[COLUMN_MODE3] = len;
-			len = file_string_width(file->entry->owner);
-			if (len > layout->column_widths[COLUMN_OWNER]) layout->column_widths[COLUMN_OWNER] = len;
-		}
-	}
-	}
-#else
-	UNUSED_VARS(files);
-	{
-		/* Biggest possible reasonable values...
-		 * TODO: better ways to get those! */
-		layout->column_widths[COLUMN_NAME] = file_string_width("WMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWM");
-		layout->column_widths[COLUMN_DATE] = file_string_width("23-Mar-89");
-		layout->column_widths[COLUMN_TIME] = file_string_width("23:59");
-		layout->column_widths[COLUMN_SIZE] = file_string_width("987.6 MiB");
-	}
-#endif
+	/* Biggest possible reasonable values...
+	 * TODO: better ways to get those! */
+	layout->column_widths[COLUMN_NAME] = file_string_width("WMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWM");
+	layout->column_widths[COLUMN_DATE] = file_string_width("23-Dec-89");
+	layout->column_widths[COLUMN_TIME] = file_string_width("23:59");
+	layout->column_widths[COLUMN_SIZE] = file_string_width("987.64 MiB");
 }
 
 void ED_fileselect_init_layout(struct SpaceFile *sfile, ARegion *ar)
@@ -593,12 +562,6 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, ARegion *ar)
 		else {
 			maxlen = ICON_DEFAULT_WIDTH_SCALE + column_icon_space +
 			         (int)layout->column_widths[COLUMN_NAME] + column_space +
-#ifndef WIN32
-			         (int)layout->column_widths[COLUMN_MODE1] + column_space +
-			         (int)layout->column_widths[COLUMN_MODE2] + column_space +
-			         (int)layout->column_widths[COLUMN_MODE3] + column_space +
-			         (int)layout->column_widths[COLUMN_OWNER] + column_space +
-#endif
 			         (int)layout->column_widths[COLUMN_DATE] + column_space +
 			         (int)layout->column_widths[COLUMN_TIME] + column_space +
 			         (int)layout->column_widths[COLUMN_SIZE] + column_space;
diff --git a/source/ble

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list