diff options
author | Julian Eisel <julian@blender.org> | 2021-09-01 16:13:18 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-09-01 16:13:18 +0300 |
commit | 7ec839adfa99b049f84c2d75834a4e6d20c4a7b7 (patch) | |
tree | d80a452c220e6c0cae9109c6e7e60039ec08d747 /source/blender/editors | |
parent | 79281336c0555351a1580e4055a57a75509c0832 (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.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_file/space_file.c | 15 |
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) { |