diff --git a/source/blender/editors/interface/interface_drag.cc b/source/blender/editors/interface/interface_drag.cc index d0198a96362..5f32bb1040b 100644 --- a/source/blender/editors/interface/interface_drag.cc +++ b/source/blender/editors/interface/interface_drag.cc @@ -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); + } } diff --git a/source/blender/windowmanager/WM_api.hh b/source/blender/windowmanager/WM_api.hh index c810ea65725..1d315e66cdd 100644 --- a/source/blender/windowmanager/WM_api.hh +++ b/source/blender/windowmanager/WM_api.hh @@ -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); diff --git a/source/blender/windowmanager/intern/wm_dragdrop.cc b/source/blender/windowmanager/intern/wm_dragdrop.cc index 616a703b280..a1fcf2c927e 100644 --- a/source/blender/windowmanager/intern/wm_dragdrop.cc +++ b/source/blender/windowmanager/intern/wm_dragdrop.cc @@ -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 paths; + const blender::Vector files = CTX_data_collection_get(C, "selected_files"); + for (const PointerRNA &file_ptr : files) { + const FileDirEntry *file = static_cast(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");