1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 11:47:45 +00:00

FileManager: Allow drag&drop onto breadcrumb bar directories :^)

You can now drop dragged items onto directories in the breadcrumb bar
and we'll copy them to that directory for you. Pretty cool!
This commit is contained in:
Andreas Kling 2021-01-08 18:59:50 +01:00
parent 6159630fa0
commit 3b3233aaf0

View file

@ -889,24 +889,16 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
} }
}; };
tree_view.on_drop = [&](const GUI::ModelIndex& index, const GUI::DropEvent& event) { auto copy_urls_to_directory = [&](const Vector<URL>& urls, const String& directory) {
if (!event.mime_data().has_urls())
return;
auto urls = event.mime_data().urls();
if (urls.is_empty()) { if (urls.is_empty()) {
dbgln("No files to drop"); dbgln("No files to copy");
return; return;
} }
bool had_accepted_copy = false;
auto& target_node = directories_model->node(index);
if (!target_node.is_directory())
return;
bool had_accepted_drop = false;
for (auto& url_to_copy : urls) { for (auto& url_to_copy : urls) {
if (!url_to_copy.is_valid() || url_to_copy.path() == target_node.full_path()) if (!url_to_copy.is_valid() || url_to_copy.path() == directory)
continue; continue;
auto new_path = String::formatted("{}/{}", target_node.full_path(), LexicalPath(url_to_copy.path()).basename()); auto new_path = String::formatted("{}/{}", directory, LexicalPath(url_to_copy.path()).basename());
if (url_to_copy.path() == new_path) if (url_to_copy.path() == new_path)
continue; continue;
@ -914,13 +906,29 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
auto error_message = String::formatted("Could not copy {} into {}.", url_to_copy.to_string(), new_path); auto error_message = String::formatted("Could not copy {} into {}.", url_to_copy.to_string(), new_path);
GUI::MessageBox::show(window, error_message, "File Manager", GUI::MessageBox::Type::Error); GUI::MessageBox::show(window, error_message, "File Manager", GUI::MessageBox::Type::Error);
} else { } else {
had_accepted_drop = true; had_accepted_copy = true;
} }
} }
if (had_accepted_drop) if (had_accepted_copy)
refresh_tree_view(); refresh_tree_view();
}; };
breadcrumb_bar.on_drop = [&](size_t segment_index, const GUI::DropEvent& event) {
if (!event.mime_data().has_urls())
return;
copy_urls_to_directory(event.mime_data().urls(), breadcrumb_bar.segment_data(segment_index));
};
tree_view.on_drop = [&](const GUI::ModelIndex& index, const GUI::DropEvent& event) {
if (!event.mime_data().has_urls())
return;
auto& target_node = directories_model->node(index);
if (!target_node.is_directory())
return;
copy_urls_to_directory(event.mime_data().urls(), target_node.full_path());
;
};
directory_view.open(initial_location); directory_view.open(initial_location);
directory_view.set_focus(true); directory_view.set_focus(true);