mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:28:12 +00:00
FileManager: Handle drop events in DirectoryView
This makes it possible to drag & drop files to/from the desktop! :^)
This commit is contained in:
parent
5ee29e8a26
commit
4e8c50d92d
3 changed files with 38 additions and 41 deletions
|
@ -667,40 +667,6 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
|
|||
}
|
||||
};
|
||||
|
||||
directory_view.on_drop = [&](const GUI::ModelIndex& index, const GUI::DropEvent& event) {
|
||||
if (!event.mime_data().has_urls())
|
||||
return;
|
||||
auto urls = event.mime_data().urls();
|
||||
if (urls.is_empty()) {
|
||||
dbg() << "No files to drop";
|
||||
return;
|
||||
}
|
||||
|
||||
auto& target_node = directory_view.node(index);
|
||||
if (!target_node.is_directory())
|
||||
return;
|
||||
|
||||
for (auto& url_to_copy : urls) {
|
||||
if (!url_to_copy.is_valid() || url_to_copy.path() == target_node.full_path())
|
||||
continue;
|
||||
auto new_path = String::format("%s/%s",
|
||||
target_node.full_path().characters(),
|
||||
LexicalPath(url_to_copy.path()).basename().characters());
|
||||
|
||||
if (url_to_copy.path() == new_path)
|
||||
continue;
|
||||
|
||||
if (!FileUtils::copy_file_or_directory(url_to_copy.path(), new_path)) {
|
||||
auto error_message = String::format("Could not copy %s into %s.",
|
||||
url_to_copy.to_string().characters(),
|
||||
new_path.characters());
|
||||
GUI::MessageBox::show(window, error_message, "File Manager", GUI::MessageBox::Type::Error);
|
||||
} else {
|
||||
refresh_tree_view();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
tree_view.on_selection = [&](const GUI::ModelIndex& index) {
|
||||
if (directories_model->m_previously_selected_index.is_valid())
|
||||
directories_model->update_node_on_selection(directories_model->m_previously_selected_index, false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue