diff -r 4ff7361dce95 -r 9f66c31a27ed ui/winui/dnd.cpp --- a/ui/winui/dnd.cpp Wed Jan 31 19:15:41 2024 +0100 +++ b/ui/winui/dnd.cpp Thu Feb 01 19:45:17 2024 +0100 @@ -31,6 +31,13 @@ #include "dnd.h" #include "util.h" +#include + +using namespace winrt; +using namespace Windows::ApplicationModel::DataTransfer; +using namespace Windows::Storage; +using namespace Windows::Storage::Streams; + UIEXPORT void ui_selection_settext(UiDnD* dnd, char* str, int len) { if (dnd->data) { if (len < 0) { @@ -54,6 +61,31 @@ return nullptr; } -UIEXPORT char** ui_selection_geturis(UiDnD* dnd, size_t* nelm) { - return nullptr; + +UIEXPORT UiFileList ui_selection_geturis(UiDnD *dnd) { + UiFileList flist; + flist.files = nullptr; + flist.nfiles = 0; + + if (dnd->dataview.Contains(StandardDataFormats::StorageItems())) { + UiFileList *flist_ptr = &flist; + + // we need to execute this in a different thread + // this could block the main gui thread, but shouldn't happen with a simple uri list + std::thread getDataThread([dnd, flist_ptr]() { + auto items = dnd->dataview.GetStorageItemsAsync().get(); + + char **uris = (char**)calloc(items.Size(), sizeof(char*)); + flist_ptr->files = uris; + flist_ptr->nfiles = items.Size(); + + int i = 0; + for (IStorageItem const& item : items) { + winrt::hstring path = item.Path(); + uris[i++] = wchar2utf8(path.c_str(), path.size()); + } + }); + getDataThread.join(); + } + return flist; }