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
3 changed files with 12 additions and 12 deletions
Showing only changes of commit 64280d1a1c - Show all commits

View File

@ -898,7 +898,7 @@ static void node_id_path_drop_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
return;
}
const char* path = WM_drag_get_single_path(drag);
const char *path = WM_drag_get_single_path(drag);
if (path) {
RNA_string_set(drop->ptr, "filepath", path);
RNA_struct_property_unset(drop->ptr, "name");

View File

@ -891,7 +891,7 @@ static void view3d_id_path_drop_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
RNA_struct_property_unset(drop->ptr, "filepath");
return;
}
const char* path = WM_drag_get_single_path(drag);
const char *path = WM_drag_get_single_path(drag);
if (path) {
RNA_string_set(drop->ptr, "filepath", path);
RNA_struct_property_unset(drop->ptr, "image");

View File

@ -1568,17 +1568,17 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_pt
if (ddd->dataType == GHOST_kDragnDropTypeFilenames) {
const GHOST_TStringArray *stra = static_cast<const GHOST_TStringArray *>(ddd->data);
if (stra->count) {
printf("drop file %s\n", stra->strings[0]);
/* try to get icon type from extension */
int icon = ED_file_extension_icon((char *)stra->strings[0]);
wmDragPath *path_data = WM_drag_create_path_data(
blender::Span((char **)stra->strings, stra->count));
WM_event_start_drag(C, icon, WM_DRAG_PATH, path_data, 0.0, WM_DRAG_NOP);
/* Void pointer should point to string, it makes a copy. */
break; /* only one drop element supported now */
}
if (stra->count) {
printf("drop file %s\n", stra->strings[0]);
guishe marked this conversation as resolved Outdated

This printf can be removed imho, it's now not that useful.

If needed, proper logging with CLOG and a loop over all handled filepaths should be done instead.

This printf can be removed imho, it's now not that useful. If needed, proper logging with `CLOG` and a loop over all handled filepaths should be done instead.

Maybe it's better to show which files were discarded

Maybe it's better to show which files were discarded

I would say both...

I would say both...
/* try to get icon type from extension */
int icon = ED_file_extension_icon((char *)stra->strings[0]);
wmDragPath *path_data = WM_drag_create_path_data(
blender::Span((char **)stra->strings, stra->count));
WM_event_start_drag(C, icon, WM_DRAG_PATH, path_data, 0.0, WM_DRAG_NOP);
/* Void pointer should point to string, it makes a copy. */
break; /* only one drop element supported now */
}
}
break;
}