Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-09-01 16:13:18 +0300
committerJulian Eisel <julian@blender.org>2021-09-01 16:13:18 +0300
commit7ec839adfa99b049f84c2d75834a4e6d20c4a7b7 (patch)
treed80a452c220e6c0cae9109c6e7e60039ec08d747
parent79281336c0555351a1580e4055a57a75509c0832 (diff)
File Browser/BPY: Expose list of selected files in context
Since recently it's possible to query the active file (as object, not just the name), but it's quite useful for scripting to have access to all selected files. This introduces `bpy.context.selected_files`, returning a list of file objects representing files in the File Browser.
-rw-r--r--source/blender/editors/space_file/space_file.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 7deaa2fec60..daf522273a9 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -873,6 +873,7 @@ static void file_space_subtype_item_extend(bContext *UNUSED(C),
static const char *file_context_dir[] = {
"active_file",
+ "selected_files",
"asset_library_ref",
"id",
NULL,
@@ -907,6 +908,20 @@ static int /*eContextResult*/ file_context(const bContext *C,
CTX_data_pointer_set(result, &screen->id, &RNA_FileSelectEntry, file);
return CTX_RESULT_OK;
}
+ if (CTX_data_equals(member, "selected_files")) {
+ const int num_files_filtered = filelist_files_ensure(sfile->files);
+
+ for (int file_index = 0; file_index < num_files_filtered; file_index++) {
+ if (filelist_entry_is_selected(sfile->files, file_index)) {
+ FileDirEntry *entry = filelist_file(sfile->files, file_index);
+ CTX_data_list_add(result, &screen->id, &RNA_FileSelectEntry, entry);
+ }
+ }
+
+ CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
+ return CTX_RESULT_OK;
+ }
+
if (CTX_data_equals(member, "asset_library_ref")) {
FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile);
if (!asset_params) {