IO: Add support for multiple drag-n-drop files #107230

Merged
Brecht Van Lommel merged 20 commits from guishe/blender:dragndrop-files into main 2023-12-12 18:46:22 +01:00
2 changed files with 15 additions and 14 deletions
Showing only changes of commit 1ae824ba8f - Show all commits

View File

@ -1173,15 +1173,11 @@ struct wmDragAssetListItem {
};
struct wmDragPath {
const blender::Vector<std::string> paths;
blender::Vector<std::string> paths;
/* Note that even though the enum type uses bit-flags, this should never have multiple type-bits
* set, so `ELEM()` like comparison is possible. */
const int file_type; /* eFileSel_File_Types */
const std::string tooltip;
wmDragPath(const blender::Vector<std::string> &paths, const std::string &tooltip, int file_type)
: paths(std::move(paths)), file_type(file_type), tooltip(tooltip)
{
}
int file_type; /* eFileSel_File_Types */
std::string tooltip;
};
struct wmDragGreasePencilLayer {

View File

@ -761,27 +761,32 @@ const ListBase *WM_drag_asset_list_get(const wmDrag *drag)
wmDragPath *WM_drag_create_path_data(blender::Span<const char *> paths)
{
wmDragPath *path_data = MEM_new<wmDragPath>("wmDragPath");
path_data->file_type = ED_path_extension_type(paths[0]);
const char *extension = BLI_path_extension(paths[0]);
blender::Vector<std::string> filtered_paths;
for (auto path : paths) {
const char *test_ext = BLI_path_extension(path);
if (extension == test_ext || (extension && test_ext && STREQ(extension, test_ext))) {
filtered_paths.append(path);
path_data->paths.append(path);
}
}
const char *tooltip = paths[0];
const char *tooltip = path_data->paths[0].c_str();
guishe marked this conversation as resolved
Review

No final point in our UI strings: "Dragging {} files"

No final point in our UI strings: `"Dragging {} files"`
char tooltip_buffer[256];
if (filtered_paths.size() > 1) {
if (path_data->paths.size() > 1) {
BLI_snprintf(tooltip_buffer,
ARRAY_SIZE(tooltip_buffer),
TIP_("Dragging %d %s files."),
filtered_paths.size(),
path_data->paths.size(),
extension ? extension : TIP_("Folder"));
tooltip = tooltip_buffer;
}
wmDragPath *path_data = MEM_new<wmDragPath>(
"wmDragPath", filtered_paths, tooltip, ED_path_extension_type(paths[0]));
path_data->tooltip = tooltip;
return path_data;
}