UI: Allow drag multiple files from Blender File Browser

After c00c8b1b37 its possible to handle drag-n-drop with multiple
paths, this commit enables Blender internal File Browser to have
support to start drag events with multiple files.

Pull Request: https://projects.blender.org/blender/blender/pulls/116474
This commit is contained in:
Guillermo Venegas
2025-05-08 23:56:38 +02:00
committed by Julian Eisel
parent 631c329d19
commit 38c08b515f
3 changed files with 37 additions and 0 deletions

View File

@@ -125,4 +125,8 @@ void ui_but_drag_start(bContext *C, uiBut *but)
if (ELEM(but->dragtype, WM_DRAG_ASSET, WM_DRAG_ID)) {
WM_event_start_drag(C, ICON_NONE, WM_DRAG_ASSET_LIST, nullptr, WM_DRAG_NOP);
}
if (but->dragtype == WM_DRAG_PATH) {
WM_event_drag_path_override_poin_data_with_space_file_paths(C, drag);
}
}

View File

@@ -1548,6 +1548,11 @@ wmDrag *WM_drag_data_create(
*/
void WM_event_start_prepared_drag(bContext *C, wmDrag *drag);
void WM_event_drag_image(wmDrag *drag, const ImBuf *imb, float scale);
/**
* Overrides the `drag.poin` event to include all selected files in the space file where the event
* started.
*/
void WM_event_drag_path_override_poin_data_with_space_file_paths(const bContext *, wmDrag *drag);
void WM_event_drag_preview_icon(wmDrag *drag, int icon_id);
void WM_drag_free(wmDrag *drag);
void WM_drag_data_free(eWM_DragDataType dragtype, void *poin);

View File

@@ -21,8 +21,10 @@
#include "BLT_translation.hh"
#include "BLI_linear_allocator.hh"
#include "BLI_listbase.h"
#include "BLI_math_color.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
@@ -360,6 +362,32 @@ void WM_event_drag_image(wmDrag *drag, const ImBuf *imb, float scale)
drag->imbuf_scale = scale;
}
void WM_event_drag_path_override_poin_data_with_space_file_paths(const bContext *C, wmDrag *drag)
{
BLI_assert(drag->type == WM_DRAG_PATH);
if (!CTX_wm_space_file(C)) {
return;
}
char dirpath[FILE_MAX];
BLI_path_split_dir_part(WM_drag_get_single_path(drag), dirpath, FILE_MAX);
blender::LinearAllocator<> allocator;
blender::Vector<const char *> paths;
const blender::Vector<PointerRNA> files = CTX_data_collection_get(C, "selected_files");
for (const PointerRNA &file_ptr : files) {
const FileDirEntry *file = static_cast<const FileDirEntry *>(file_ptr.data);
char filepath[FILE_MAX];
BLI_path_join(filepath, sizeof(filepath), dirpath, file->name);
paths.append(allocator.copy_string(filepath).c_str());
}
if (paths.is_empty()) {
return;
}
WM_drag_data_free(drag->type, drag->poin);
drag->poin = WM_drag_create_path_data(paths);
}
void WM_event_drag_preview_icon(wmDrag *drag, int icon_id)
{
BLI_assert_msg(!drag->imb, "Drag image and preview are mutually exclusive");