Skip to content

Commit

Permalink
Fix some more windows build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
HazardousPeach committed Oct 15, 2024
1 parent c5bd30d commit 8a06024
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 deletions.
4 changes: 3 additions & 1 deletion src/gui/clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ namespace Toolbox {
return make_clipboard_error<void>(
"Can't set clipboard to mulitple types at once on Windows!");
}
TOOLBOX_ASSERT(formats.size() > 0);
if (formats.size() == 0) {
return make_clipboard_error<void>("The mimedata set on the clipboard has no formats!");
}
auto type = formats[0];

std::optional<Buffer> result = mimedata.get_data(type);
Expand Down
37 changes: 7 additions & 30 deletions src/gui/dragdrop/dragdropmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,6 @@
#elif defined(TOOLBOX_PLATFORM_LINUX)
#endif

static std::vector<std::string_view> splitLines(std::string_view s) {
std::vector<std::string_view> result;
size_t last_pos = 0;
size_t next_newline_pos = s.find('\n', 0);
while (next_newline_pos != std::string::npos) {
if (s[next_newline_pos - 1] == '\r') {
result.push_back(s.substr(last_pos, next_newline_pos - last_pos - 1));
} else {
result.push_back(s.substr(last_pos, next_newline_pos - last_pos));
}
last_pos = next_newline_pos + 1;
next_newline_pos = s.find('\n', last_pos);
}
if (last_pos < s.size()) {
if (s[s.size() - 1] == '\r') {
result.push_back(s.substr(last_pos, s.size() - last_pos - 1));
} else {
result.push_back(s.substr(last_pos));
}
}
return result;
}

namespace Toolbox::UI {

RefPtr<DragAction> DragDropManager::createDragAction(UUID64 source_uuid, MimeData &&data, bool system_level) {
Expand All @@ -59,18 +36,18 @@ namespace Toolbox::UI {
void DragDropManager::shutdown() { OleUninitialize(); }

Result<void, BaseError> DragDropManager::createSystemDragDropSource(MimeData &&data) {
std::string paths = data.get_urls().value_or("");
auto maybe_paths = data.get_urls();
if (!maybe_paths) {
return make_error<void>("DRAG_DROP", "Passed Mimedata did not include urls");
}
std::vector<std::string> paths = maybe_paths.value();

std::vector<PIDLIST_ABSOLUTE> pidls;
std::vector<std::string_view> lines = splitLines(paths);

size_t next_newline_pos = 0;
for (const std::string_view &line : lines) {
if (line.empty()) {
continue;
}
for (const std::string_view &path : paths) {

std::wstring wpath = std::wstring(line.begin(), line.end());
std::wstring wpath = std::wstring(path.begin(), path.end());

PIDLIST_ABSOLUTE pidl = ILCreateFromPathW(wpath.c_str());
if (pidl == NULL) {
Expand Down

0 comments on commit 8a06024

Please sign in to comment.