[Bf-blender-cvs] [f69e968] master: Final 'FileBrowser First Stage' merge.

Bastien Montagne noreply at git.blender.org
Wed Aug 19 22:55:41 CEST 2015


Commit: f69e9681fa32f6f9baafd2aa4a70427864ce6bb5
Author: Bastien Montagne
Date:   Wed Aug 19 22:41:39 2015 +0200
Branches: master
https://developer.blender.org/rBf69e9681fa32f6f9baafd2aa4a70427864ce6bb5

Final 'FileBrowser First Stage' merge.

It basically rewrites most of filelist.c, with some more limited changes in other areas of filebrowser.

>From user perspective, it:
* Removes some info in 'long' drawing mode (owner, permissions) - OS-specific data that do not really matter in Blender!
* Makes short/long display 'fixed' size (among four choices, like thumbnails mode).
* Allows to list several layers of dirtree at once, in a flat way (inside .blend files and/or real directories).
* Consequently, adds datablocks types filtering.
* Uses way less RAM when listing big directories, especially in thumbnail mode (we are talking of several hundred of MiB spared).
* Generates thumbnails way faster.

>From code perspective, it:
* Is ready for asset engine needs (on data structure level in filebrowser's listing).
* Simplifies and makes 'generic' file listing much lighter.
* Separates file listing in three different aspects:
** 'generic' filelisting (in BLI), which becomes a shallow wrapper around stat struct.
** 'filebrowser drawing' filelisting, which only contains current visible subset of the whole list (sliding window), with extra drawing data (strings for size, date/time, preview, etc.).
** 'asset-ready' filelisting, which is used for operations common to 'basic' filehandling and future asset-related one.
* Uses uuid's to handle file selection/state in the browser, instead of using flags in filelisting items.
* Uses much lighter BLI_task handling for previews, instead of heavy 'job' system (using the new 'notifier' timer to handle UI refresh, in similar way to jobs).
* Moves .blend datablocks preview handling to IMB_thumbnail (necessary to avoid storing all datablock previews at once, and gives better consistency and performances too).

Revision: https://developer.blender.org/D1316

Thanks to Campbell & Sergey for the reviews. :)

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

M	release/scripts/startup/bl_ui/space_filebrowser.py
M	source/blender/blenlib/BLI_fileops.h
M	source/blender/blenlib/BLI_fileops_types.h
M	source/blender/blenlib/intern/BLI_filelist.c
M	source/blender/editors/include/ED_fileselect.h
M	source/blender/editors/interface/interface_icons.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/space_file/CMakeLists.txt
M	source/blender/editors/space_file/SConscript
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/file_intern.h
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filelist.h
M	source/blender/editors/space_file/filesel.c
M	source/blender/editors/space_file/space_file.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index 0d900a4..0b9c847 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -40,22 +40,23 @@ class FILEBROWSER_HT_header(Header):
         row.operator("file.parent", text="", icon='FILE_PARENT')
         row.operator("file.refresh", text="", icon='FILE_REFRESH')
 
-        row = layout.row()
-        row.separator()
-
-        row = layout.row(align=True)
+        layout.separator()
         layout.operator_context = 'EXEC_DEFAULT'
-        row.operator("file.directory_new", icon='NEWFOLDER')
+        layout.operator("file.directory_new", icon='NEWFOLDER', text="")
+        layout.separator()
 
         layout.operator_context = 'INVOKE_DEFAULT'
         params = st.params
 
         # can be None when save/reload with a file selector open
         if params:
+            is_lib_browser = params.use_library_browsing
+
+            layout.prop(params, "recursion_level", text="")
+
             layout.prop(params, "display_type", expand=True, text="")
 
-            if params.display_type == 'FILE_IMGDISPLAY':
-                layout.prop(params, "thumbnail_size", text="")
+            layout.prop(params, "thumbnail_size", text="")
 
             layout.prop(params, "sort_method", expand=True, text="")
 
@@ -81,9 +82,17 @@ class FILEBROWSER_HT_header(Header):
                 row.prop(params, "use_filter_sound", text="")
                 row.prop(params, "use_filter_text", text="")
 
+            if is_lib_browser:
+                row.prop(params, "use_filter_blendid", text="")
+                if params.use_filter_blendid:
+                    row.separator()
+                    row.prop(params, "filter_id_category", text="")
+
             row.separator()
             row.prop(params, "filter_search", text="", icon='VIEWZOOM')
 
+        layout.template_running_jobs()
+
 
 class FILEBROWSER_UL_dir(bpy.types.UIList):
     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
@@ -214,5 +223,24 @@ class FILEBROWSER_PT_recent_folders(Panel):
             col.operator("file.reset_recent", icon='X', text="")
 
 
+class FILEBROWSER_PT_advanced_filter(Panel):
+    bl_space_type = 'FILE_BROWSER'
+    bl_region_type = 'TOOLS'
+    bl_category = "Filter"
+    bl_label = "Advanced Filter"
+
+    def draw(self, context):
+        layout = self.layout
+        space = context.space_data
+        params = space.params
+
+        if params and params.use_library_browsing:
+            layout.prop(params, "use_filter_blendid")
+            if params.use_filter_blendid:
+                layout.separator()
+                col = layout.column()
+                col.prop(params, "filter_id")
+
+
 if __name__ == "__main__":  # only for live edit.
     bpy.utils.register_module(__name__)
diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h
index 9384273..ba59c41 100644
--- a/source/blender/blenlib/BLI_fileops.h
+++ b/source/blender/blenlib/BLI_fileops.h
@@ -91,11 +91,19 @@ char  *BLI_current_working_dir(char *dir, const size_t maxlen) ATTR_NONNULL();
 
 /* Filelist */
 
-unsigned int BLI_filelist_dir_contents(const char *dir, struct direntry **filelist);
+unsigned int BLI_filelist_dir_contents(const char *dir, struct direntry **r_filelist);
+void BLI_filelist_entry_duplicate(struct direntry *dst, const struct direntry *src);
 void BLI_filelist_duplicate(
-        struct direntry **dest_filelist, struct direntry *src_filelist, unsigned int nrentries,
-        void *(*dup_poin)(void *));
-void BLI_filelist_free(struct direntry *filelist, unsigned int nrentries, void (*free_poin)(void *));
+        struct direntry **dest_filelist, struct direntry * const src_filelist, const unsigned int nrentries);
+void BLI_filelist_entry_free(struct direntry *entry);
+void BLI_filelist_free(struct direntry *filelist, const unsigned int nrentries);
+
+void BLI_filelist_entry_size_to_string(const struct stat *st, const uint64_t sz, const bool compact, char r_size[]);
+void BLI_filelist_entry_mode_to_string(
+        const struct stat *st, const bool compact, char r_mode1[], char r_mode2[], char r_mode3[]);
+void BLI_filelist_entry_owner_to_string(const struct stat *st, const bool compact, char r_owner[]);
+void BLI_filelist_entry_datetime_to_string(
+        const struct stat *st, const int64_t ts, const bool compact, char r_time[], char r_date[]);
 
 /* Files */
 
diff --git a/source/blender/blenlib/BLI_fileops_types.h b/source/blender/blenlib/BLI_fileops_types.h
index 5a1126b..0cf8c8d 100644
--- a/source/blender/blenlib/BLI_fileops_types.h
+++ b/source/blender/blenlib/BLI_fileops_types.h
@@ -39,7 +39,11 @@
 typedef unsigned int mode_t;
 #endif
 
-struct ImBuf;
+#define FILELIST_DIRENTRY_SIZE_LEN  16
+#define FILELIST_DIRENTRY_MODE_LEN  4
+#define FILELIST_DIRENTRY_OWNER_LEN 16
+#define FILELIST_DIRENTRY_TIME_LEN  8
+#define FILELIST_DIRENTRY_DATE_LEN  16
 
 struct direntry {
 	mode_t  type;
@@ -56,19 +60,6 @@ struct direntry {
 #else
 	struct stat s;
 #endif
-	unsigned int flags;
-	char    size[16];
-	char    mode1[4];
-	char    mode2[4];
-	char    mode3[4];
-	char    owner[16];
-	char    time[8];
-	char    date[16];
-	char    extra[16];
-	void   *poin;
-	int     nr;
-	struct ImBuf *image;
-	unsigned int selflag; /* selection flag */
 };
 
 struct dirlink {
diff --git a/source/blender/blenlib/intern/BLI_filelist.c b/source/blender/blenlib/intern/BLI_filelist.c
index 38a6781..62690ff 100644
--- a/source/blender/blenlib/intern/BLI_filelist.c
+++ b/source/blender/blenlib/intern/BLI_filelist.c
@@ -182,7 +182,6 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
 						/* Hack around for UNC paths on windows - does not support stat on '\\SERVER\foo\..', sigh... */
 						file->type |= S_IFDIR;
 					}
-					file->flags = 0;
 					dir_ctx->nrfiles++;
 					file++;
 					dlink = dlink->next;
@@ -210,130 +209,160 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
 }
 
 /**
- * Fills in the "mode[123]", "size" and "string" fields in the elements of the files
- * array with descriptive details about each item. "string" will have a format similar to "ls -l".
+ * Scans the contents of the directory named *dirname, and allocates and fills in an
+ * array of entries describing them in *filelist.
+ *
+ * \return The length of filelist array.
  */
-static void bli_adddirstrings(struct BuildDirCtx *dir_ctx)
+unsigned int BLI_filelist_dir_contents(const char *dirname,  struct direntry **r_filelist)
 {
-	const char *types[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"};
-	/* symbolic display, indexed by mode field value */
-	int num;
-	double size;
-	struct direntry *file;
-	struct tm *tm;
-	time_t zero = 0;
-
-#ifndef WIN32
-	int mode;
-#endif
-
-	for (num = 0, file = dir_ctx->files; num < dir_ctx->nrfiles; num++, file++) {
+	struct BuildDirCtx dir_ctx;
 
-		/* Mode */
-#ifdef WIN32
-		BLI_strncpy(file->mode1, types[0], sizeof(file->mode1));
-		BLI_strncpy(file->mode2, types[0], sizeof(file->mode2));
-		BLI_strncpy(file->mode3, types[0], sizeof(file->mode3));
-#else
-		mode = file->s.st_mode;
+	dir_ctx.nrfiles = 0;
+	dir_ctx.files = NULL;
 
-		BLI_strncpy(file->mode1, types[(mode & 0700) >> 6], sizeof(file->mode1));
-		BLI_strncpy(file->mode2, types[(mode & 0070) >> 3], sizeof(file->mode2));
-		BLI_strncpy(file->mode3, types[(mode & 0007)],      sizeof(file->mode3));
+	bli_builddir(&dir_ctx, dirname);
 
-		if (((mode & S_ISGID) == S_ISGID) && (file->mode2[2] == '-')) file->mode2[2] = 'l';
+	if (dir_ctx.files) {
+		*r_filelist = dir_ctx.files;
+	}
+	else {
+		// keep blender happy. Blender stores this in a variable
+		// where 0 has special meaning.....
+		*r_filelist = MEM_mallocN(sizeof(**r_filelist), __func__);
+	}
 
-		if (mode & (S_ISUID | S_ISGID)) {
-			if (file->mode1[2] == 'x') file->mode1[2] = 's';
-			else file->mode1[2] = 'S';
+	return dir_ctx.nrfiles;
+}
 
-			if (file->mode2[2] == 'x') file->mode2[2] = 's';
-		}
+/**
+ * Convert given entry's size into human-readable strings.
+ *
+ */
+void BLI_filelist_entry_size_to_string(
+        const struct stat *st, const uint64_t sz, const bool compact, char r_size[FILELIST_DIRENTRY_SIZE_LEN])
+{
+	double size;
+	const char *fmt;
+	const char *units[] = {"KiB", "MiB", "GiB", "TiB", NULL};
+	const char *units_compact[] = {"K", "M", "G", "T", NULL};
+	const char *unit = "B";
+
+	/*
+	 * Seems st_size is signed 32-bit value in *nix and Windows.  This
+	 * 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->st_size : sz);
+
+	if (size > 1024.0) {
+		const char **u;
+		for (u = compact ? units_compact : units, size /= 1024.0; size > 1024.0 && *(u + 1); u++, size /= 1024.0);
+		fmt =  size > 100.0 ? "%.0f %s" : (size > 10.0 ? "%.1f %s" : "%.2f %s");
+		unit = *u;
+	}
+	else {
+		fmt = "%.0f %s";
+	}
 
-		if (mode & S_ISVTX) {
-			if (file->mode3[2] == 'x') file->mode3[2] = 't';
-			else file->mode3[2] = 'T';
-		}
-#endif
+	BLI_snprintf(r_size, sizeof(*r_size) * FILELIST_DIRENTRY_SIZE_LEN, fmt, size, unit);
+}
 
+/**
+ * Convert given entry's modes into human-readable strings.
+ *
+ */
+void BLI_filelist_entry_mode_to_string(
+        const struct stat *st, const bool UNUSED(compact), char r_mode1[FILELIST_DIRENTRY_MODE_LEN],
+        char r_mode2[FILELIST_DIRENTRY_MODE_LEN], char r_mode3[FILELIST_DIRENTRY_MODE_LEN])
+{
+	const char *types[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"};
 
-		/* User */
 #ifdef WIN32
-		strcpy(file->owner, "user");
+	BLI_strncpy(r_mode1, types[0], sizeof(*r_mode1) * FILELIST_DIRENTRY_MODE_LEN);
+	BLI_strncpy(r_mode2, types[0], sizeof(*r_mode2) * FILELIST_DIRENTRY_MODE_LEN);
+	BLI_strncpy(r_mode3, types[0], sizeof(*r_mode3) * FILELIST_DIRENTRY_MODE_LEN);
 #else
-		{
-			struct passwd *pwuser;
-			pwuser = getpwuid(file->s.st_uid);
-			if (pwuser) {
-				BLI_strncpy(file->owner, pwuser->pw_name, sizeof(file->owner));
-			}
-			else {
-				BLI_snprintf(file->owner, sizeof(file->o

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list