[Bf-blender-cvs] [7ec839adfa9] master: File Browser/BPY: Expose list of selected files in context

Julian Eisel noreply at git.blender.org
Wed Sep 1 15:30:23 CEST 2021


Commit: 7ec839adfa99b049f84c2d75834a4e6d20c4a7b7
Author: Julian Eisel
Date:   Wed Sep 1 15:13:18 2021 +0200
Branches: master
https://developer.blender.org/rB7ec839adfa99b049f84c2d75834a4e6d20c4a7b7

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.

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

M	source/blender/editors/space_file/space_file.c

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

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) {



More information about the Bf-blender-cvs mailing list