[Bf-blender-cvs] [8644862] asset-experiments: Add progressbar to dirlist job.
Bastien Montagne
noreply at git.blender.org
Thu Dec 11 20:12:36 CET 2014
Commit: 8644862fac961be61454acb90463722cf6404da5
Author: Bastien Montagne
Date: Thu Dec 11 20:07:32 2014 +0100
Branches: asset-experiments
https://developer.blender.org/rB8644862fac961be61454acb90463722cf6404da5
Add progressbar to dirlist job.
Progressbar value is quite chaotic currently, will check that later.
Also, fixed G.main still being used in job, and factorized once more time code.
===================================================================
M release/scripts/startup/bl_ui/space_filebrowser.py
M source/blender/editors/interface/interface_templates.c
M source/blender/editors/space_file/filelist.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index 9c51acc..8d4acf5 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -87,6 +87,8 @@ class FILEBROWSER_HT_header(Header):
row.separator()
row.prop(params, "filter_search", text="")
+ layout.template_running_jobs()
+
if __name__ == "__main__": # only for live edit.
bpy.utils.register_module(__name__)
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 9e974fe..4dec899 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -3310,7 +3310,8 @@ void uiTemplateOperatorSearch(uiLayout *layout)
#define B_STOPCOMPO 4
#define B_STOPSEQ 5
#define B_STOPCLIP 6
-#define B_STOPOTHER 7
+#define B_STOPFILE 7
+#define B_STOPOTHER 8
static void do_running_jobs(bContext *C, void *UNUSED(arg), int event)
{
@@ -3333,6 +3334,9 @@ static void do_running_jobs(bContext *C, void *UNUSED(arg), int event)
case B_STOPCLIP:
WM_jobs_stop(CTX_wm_manager(C), CTX_wm_area(C), NULL);
break;
+ case B_STOPFILE:
+ WM_jobs_stop(CTX_wm_manager(C), CTX_wm_area(C), NULL);
+ break;
case B_STOPOTHER:
G.is_break = true;
break;
@@ -3363,6 +3367,12 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C)
owner = sa;
handle_event = B_STOPCLIP;
}
+ else if (sa->spacetype == SPACE_FILE) {
+ if (WM_jobs_test(wm, sa, WM_JOB_TYPE_FILESEL_READDIR)) {
+ owner = sa;
+ }
+ handle_event = B_STOPFILE;
+ }
else {
Scene *scene;
/* another scene can be rendering too, for example via compositor */
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index a8e3c56..c28540d 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -124,8 +124,8 @@ typedef struct FileList {
struct BlendHandle *libfiledata;
bool hide_parent;
- void (*read_jobf)(struct FileList *, short *stop, short *do_update, ThreadMutex *lock);
- bool (*filterf)(struct direntry *file, const char *dir, FileListFilter *filter);
+ void (*read_jobf)(struct FileList *, const char *, short *, short *, float *, ThreadMutex *);
+ bool (*filterf)(struct direntry *, const char *, FileListFilter *);
bool use_recursion;
short recursion_level;
@@ -460,9 +460,9 @@ ListBase *folderlist_duplicate(ListBase *folderlist)
/* ------------------FILELIST------------------------ */
-static void filelist_readjob_main(struct FileList *, short *stop, short *do_update, ThreadMutex *lock);
-static void filelist_readjob_lib(struct FileList *, short *stop, short *do_update, ThreadMutex *lock);
-static void filelist_readjob_dir(struct FileList *, short *stop, short *do_update, ThreadMutex *lock);
+static void filelist_readjob_main(struct FileList *, const char *, short *, short *, float *, ThreadMutex *);
+static void filelist_readjob_lib(struct FileList *, const char *, short *, short *, float *, ThreadMutex *);
+static void filelist_readjob_dir(struct FileList *, const char *, short *, short *, float *, ThreadMutex *);
/* helper, could probably go in BKE actually? */
static int groupname_to_code(const char *group);
@@ -1661,12 +1661,14 @@ static void filelist_readjob_main_rec(struct FileList *filelist)
}
#endif
-static void filelist_readjob_dir_rec(
+static void filelist_readjob_dir_lib_rec(
+ const bool do_lib, const char *main_name,
FileList *filelist, int *filelist_buffsize, const char *dir, const char *filter_glob, const int recursion_level,
- short *stop, short *do_update, ThreadMutex *lock)
+ short *stop, short *do_update, float *progress, int *done_files, ThreadMutex *lock)
{
/* only used if recursing, will contain all non-immediate children then. */
- struct direntry *file, *files;
+ struct direntry *file, *files = NULL;
+ bool is_lib = do_lib;
int num_files = 0;
int i;
@@ -1674,41 +1676,87 @@ static void filelist_readjob_dir_rec(
return;
}
- num_files = BLI_dir_contents(dir, &files);
+ if (do_lib) {
+ filelist_readjob_list_lib(dir, &files, &num_files);
+
+ if (!files) {
+ is_lib = false;
+ num_files = BLI_dir_contents(dir, &files);
+ }
+ }
+ else {
+ num_files = BLI_dir_contents(dir, &files);
+ }
+
+ if (!files) {
+ return;
+ }
+
/* We only set filtypes for our own level, sub ones will be set by subcalls. */
filelist_setfiletypes(dir, files, num_files, filter_glob);
+ if (do_lib) {
+ /* Promote blend files from mere file status to prestigious directory one! */
+ for (i = 0, file = files; i < num_files; i++, file++) {
+ if (BLO_has_bfile_extension(file->relname)) {
+ char name[FILE_MAX];
+
+ BLI_join_dirfile(name, sizeof(name), dir, file->relname);
+
+ /* prevent current file being used as acceptable dir */
+ if (BLI_path_cmp(main_name, name) != 0) {
+ file->type &= ~S_IFMT;
+ file->type |= S_IFDIR;
+ }
+ }
+ }
+ }
+
BLI_mutex_lock(lock);
filelist_readjob_merge_sublist(&filelist->filelist, filelist_buffsize, &filelist->numfiles, filelist->dir,
dir, files, num_files, recursion_level != 0);
+ (*done_files)++;
+ *progress = (float)(*done_files) / filelist->numfiles;
+
+ //~ printf("%f (%d / %d)\n", *progress, *done_files, filelist->numfiles);
+
BLI_mutex_unlock(lock);
*do_update = true;
- if (!*stop && filelist->use_recursion && recursion_level < FILELIST_MAX_RECURSION) {
+ /* in case it's a lib we don't care anymore about max recursion level... */
+ if (!*stop && filelist->use_recursion && ((do_lib && is_lib) || (recursion_level < FILELIST_MAX_RECURSION))) {
for (i = 0, file = files; i < num_files && !*stop; i++, file++) {
char subdir[FILE_MAX];
- if (FILENAME_IS_BREADCRUMBS(file->relname) || (file->type & S_IFDIR) == 0) {
+ if (FILENAME_IS_BREADCRUMBS(file->relname)) {
+ /* do not increase done_files here, we completly ignore those. */
+ continue;
+ }
+ else if ((file->type & S_IFDIR) == 0) {
+ (*done_files)++;
continue;
}
BLI_join_dirfile(subdir, sizeof(subdir), dir, file->relname);
- BLI_cleanup_dir(G.main->name, subdir);
- filelist_readjob_dir_rec(filelist, filelist_buffsize, subdir, filter_glob, recursion_level + 1,
- stop, do_update, lock);
+ BLI_cleanup_dir(main_name, subdir);
+ filelist_readjob_dir_lib_rec(do_lib, main_name,
+ filelist, filelist_buffsize, subdir, filter_glob, recursion_level + 1,
+ stop, do_update, progress, done_files, lock);
}
}
BLI_free_filelist(files, num_files);
}
-static void filelist_readjob_dir(FileList *filelist, short *stop, short *do_update, ThreadMutex *lock)
+static void filelist_readjob_dir(
+ FileList *filelist, const char *main_name, short *stop, short *do_update, float *progress, ThreadMutex *lock)
{
char dir[FILE_MAX];
char filter_glob[64]; /* TODO should be define! */
int filelist_buffsize = 0;
+ int done_files = 0;
BLI_assert(filelist->fidx == NULL);
BLI_assert(filelist->filelist == NULL);
@@ -1720,84 +1768,19 @@ static void filelist_readjob_dir(FileList *filelist, short *stop, short *do_upda
BLI_mutex_unlock(lock);
- BLI_cleanup_dir(G.main->name, dir);
+ BLI_cleanup_dir(main_name, dir);
- filelist_readjob_dir_rec(filelist, &filelist_buffsize, dir, filter_glob, 0, stop, do_update, lock);
+ filelist_readjob_dir_lib_rec(false, main_name, filelist, &filelist_buffsize, dir, filter_glob, 0,
+ stop, do_update, progress, &done_files, lock);
}
-static void filelist_readjob_lib_rec(
- FileList *filelist, int *filelist_buffsize, const char *dir, const char *filter_glob, const int recursion_level,
- const char *main_name, short *stop, short *do_update, ThreadMutex *lock)
-{
- /* only used if recursing, will contain all non-immediate children then. */
- struct direntry *file, *files = NULL;
- bool is_lib = true;
- int num_files = 0;
- int i;
-
- if (!filelist) {
- return;
- }
-
- BLI_cleanup_dir(G.main->name, filelist->dir);
- filelist_readjob_list_lib(dir, &files, &num_files);
-
- if (!files) {
- is_lib = false;
- num_files = BLI_dir_contents(dir, &files);
- }
-
- /* We only set filtypes for our own level, sub ones will be set by subcalls. */
- filelist_setfiletypes(dir, files, num_files, filter_glob);
-
- /* Promote blend files from mere file status to prestigious directory one! */
- for (i = 0, file = files; i < num_files; i++, file++) {
- if (BLO_has_bfile_extension(file->relname)) {
- char name[FILE_MAX];
-
- BLI_join_dirfile(name, sizeof(name), dir, file->relname);
-
- /* prevent current file being used as acceptable dir */
- if (BLI_path_cmp(main_name, name) != 0) {
- file->type &= ~S_IFMT;
- file->type |= S_IFDIR;
- }
- }
- }
-
- BLI_mutex_lock(lock);
-
- filelist_readjob_merge_sublist(&filelist->filelist, filelist_buffsize, &filelist->numfiles, filelist->dir,
- dir, files, num_files, recursion_level != 0);
-
- BLI_mutex_unlock(lock);
-
- *do_update = true;
-
- /* in case it's a lib we don't care anymore about max recursion level... */
- if (!*stop && filelist->use_recursion && (is_lib || (recursion_level < FILELIST_MAX_RECURSION))) {
- for (i = 0, file = files; i < num_files && !*stop; i++, file++) {
- char subdir[FILE_MAX];
-
- if (FILENAME_IS_BREADCRUMBS(file->relname) || (file->type & S_IFDIR) == 0) {
- continue;
- }
-
- BLI_join_dirfile(subdir, sizeof(subdir), dir, file->relname);
- BLI_cleanup_dir(G.main->name, subdir);
- filelist_readjob_lib_rec(filelist, filelist_buffsize, subdir, filter_glob, recursion_level + 1,
- main_name, stop, do_update, lock);
- }
- }
- BLI_free_filelist(files, num_files);
-}
-
-static void filelist_readjob_lib(FileList *filelist, short *stop, short *do_update, ThreadMutex *lock)
+static void filelist_readjob_lib(
+ FileList *filelist,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list