[Bf-blender-cvs] [96aa445] asset-engine: Add a 'check_dir' callback to asset engines, allowing them to control current 'root dir'.

Bastien Montagne noreply at git.blender.org
Thu Mar 31 20:51:49 CEST 2016


Commit: 96aa44552769d9f8910ff2f7d34de8a291459125
Author: Bastien Montagne
Date:   Thu Mar 31 20:50:29 2016 +0200
Branches: asset-engine
https://developer.blender.org/rB96aa44552769d9f8910ff2f7d34de8a291459125

Add a 'check_dir' callback to asset engines, allowing them to control current 'root dir'.

Note that this is hacked around bpyrna incapacity to handle strings as return values of functions callbacks...

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

M	release/scripts/startup/bl_operators/amber.py
M	source/blender/blenkernel/BKE_asset.h
M	source/blender/editors/space_file/filelist.c
M	source/blender/makesrna/intern/rna_asset.c

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

diff --git a/release/scripts/startup/bl_operators/amber.py b/release/scripts/startup/bl_operators/amber.py
index ee2b0c1..b661f62 100644
--- a/release/scripts/startup/bl_operators/amber.py
+++ b/release/scripts/startup/bl_operators/amber.py
@@ -470,6 +470,12 @@ class AssetEngineAmber(AssetEngine):
             return True
         return False
 
+    def check_dir(self, entries):
+        # Stupid code just for test...
+        #~ entries.root_path = entries.root_path + "../"
+        #~ print(entries.root_path)
+        pass
+
     def sort_filter(self, use_sort, use_filter, params, entries):
 #        print(use_sort, use_filter)
         if use_filter:
diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
index 29fead1..f0f530b 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -118,6 +118,10 @@ typedef bool (*ae_load_post)(struct AssetEngine *engine, struct ID *items, const
  * (ae_load_pre, then actual lib loading, then ae_load_post). */
 typedef bool (*ae_update_check)(struct AssetEngine *engine, struct AssetUUIDList *uuids);
 
+/* Check if given dirpath is valid for current asset engine, it can also modify it.
+ * r_dir is assumed to be least FILE_MAX. */
+typedef void (*ae_check_dir)(struct AssetEngine *engine, char *r_dir);
+
 typedef struct AssetEngineType {
 	struct AssetEngineType *next, *prev;
 
@@ -143,6 +147,7 @@ typedef struct AssetEngineType {
 	ae_load_pre load_pre;
 	ae_load_post load_post;
 	ae_update_check update_check;
+	ae_check_dir check_dir;
 
 	/* RNA integration */
 	struct ExtensionRNA ext;
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 834199a..335c71d 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -982,17 +982,27 @@ int filelist_geticon(struct FileList *filelist, const int index, const bool is_m
 
 /* ********** Main ********** */
 
-static void filelist_checkdir_dir(struct FileList *UNUSED(filelist), char *r_dir)
+static void filelist_checkdir_dir(struct FileList *filelist, char *r_dir)
 {
-	BLI_make_exist(r_dir);
+	if (filelist->ae && filelist->ae->type->check_dir) {
+		filelist->ae->type->check_dir(filelist->ae, r_dir);
+	}
+	else {
+		BLI_make_exist(r_dir);
+	}
 }
 
-static void filelist_checkdir_lib(struct FileList *UNUSED(filelist), char *r_dir)
+static void filelist_checkdir_lib(struct FileList *filelist, char *r_dir)
 {
-	char dir[FILE_MAXDIR];
-	if (!BLO_library_path_explode(r_dir, dir, NULL, NULL)) {
-		/* if not a valid library, we need it to be a valid directory! */
-		BLI_make_exist(r_dir);
+	if (filelist->ae && filelist->ae->type->check_dir) {
+		filelist->ae->type->check_dir(filelist->ae, r_dir);
+	}
+	else {
+		char dir[FILE_MAXDIR];
+		if (!BLO_library_path_explode(r_dir, dir, NULL, NULL)) {
+			/* if not a valid library, we need it to be a valid directory! */
+			BLI_make_exist(r_dir);
+		}
 	}
 }
 
diff --git a/source/blender/makesrna/intern/rna_asset.c b/source/blender/makesrna/intern/rna_asset.c
index cbd903a..db4d8d3 100644
--- a/source/blender/makesrna/intern/rna_asset.c
+++ b/source/blender/makesrna/intern/rna_asset.c
@@ -434,6 +434,31 @@ static bool rna_ae_load_pre(AssetEngine *engine, AssetUUIDList *uuids, struct Fi
 	return ret_success;
 }
 
+static void rna_ae_check_dir(AssetEngine *engine, char *r_dir)
+{
+	extern FunctionRNA rna_AssetEngine_check_dir_func;
+	PointerRNA ptr;
+	PropertyRNA *parm;
+	ParameterList list;
+	FunctionRNA *func;
+
+	/* XXX Hacking around bpyrna incapacity to handle strings as return values... To be fixed... some day... */
+	FileDirEntryArr entries = {0};
+	FileDirEntryArr *entries_p = &entries;
+	BLI_strncpy(entries.root, r_dir, FILE_MAX);
+
+	RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
+	func = &rna_AssetEngine_check_dir_func;
+
+	RNA_parameter_list_create(&list, &ptr, func);
+	RNA_parameter_set_lookup(&list, "entries", &entries_p);
+	engine->type->ext.call(NULL, &ptr, func, &list);
+
+	BLI_strncpy(r_dir, entries.root, FILE_MAX);
+
+	RNA_parameter_list_free(&list);
+}
+
 static bool rna_ae_sort_filter(
         AssetEngine *engine, const bool use_sort, const bool use_filter,
         FileSelectParams *params, FileDirEntryArr *entries_r)
@@ -550,7 +575,7 @@ static StructRNA *rna_AssetEngine_register(Main *bmain, ReportList *reports, voi
 	AssetEngineType *aet, dummyaet = {NULL};
 	AssetEngine dummyengine = {NULL};
 	PointerRNA dummyptr;
-	int have_function[8];
+	int have_function[9];
 
 	/* setup dummy engine & engine type to store static properties in */
 	dummyengine.type = &dummyaet;
@@ -591,9 +616,11 @@ static StructRNA *rna_AssetEngine_register(Main *bmain, ReportList *reports, voi
 
 	aet->load_pre = (have_function[4]) ? rna_ae_load_pre : NULL;
 
-	aet->sort_filter = (have_function[5]) ? rna_ae_sort_filter : NULL;
-	aet->entries_block_get = (have_function[6]) ? rna_ae_entries_block_get : NULL;
-	aet->entries_uuid_get = (have_function[7]) ? rna_ae_entries_uuid_get : NULL;
+	aet->check_dir = (have_function[5]) ? rna_ae_check_dir : NULL;
+
+	aet->sort_filter = (have_function[6]) ? rna_ae_sort_filter : NULL;
+	aet->entries_block_get = (have_function[7]) ? rna_ae_entries_block_get : NULL;
+	aet->entries_uuid_get = (have_function[8]) ? rna_ae_entries_uuid_get : NULL;
 
 	BLI_addtail(&asset_engines, aet);
 
@@ -1061,6 +1088,12 @@ static void rna_def_asset_engine(BlenderRNA *brna)
 	parm = RNA_def_boolean(func, "success_return", 0, "", "Success");
 	RNA_def_function_output(func, parm);
 
+	/* Pre-load callback */
+	func = RNA_def_function(srna, "check_dir", NULL);
+	RNA_def_function_ui_description(func, "Check if given path is valid (as in, can be listed) for this engine");
+	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
+	RNA_def_pointer(func, "entries", "AssetList", "", "Fake List of asset entries (only use/modify its root_path!)");
+
 	/* Sorting/filtering callback */
 	func = RNA_def_function(srna, "sort_filter", NULL);
 	RNA_def_function_ui_description(func, "Sort and/or filter the assets (on engine's side)");




More information about the Bf-blender-cvs mailing list