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.
This commit is contained in:
parent
79281336c0
commit
7ec839adfa
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue