mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:37:46 +00:00
FileManager: Combine drag&drop file copies into one progress window
This fixes #6902. Previously, dragging and dropping multiple files would create a window for each file or directory that was selected. Now, we combine them and show one progress window for the whole batch. :^)
This commit is contained in:
parent
3267556ce4
commit
9060310840
1 changed files with 21 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -49,7 +50,7 @@ enum class FileOperation {
|
|||
|
||||
static HashTable<RefPtr<GUI::Window>> file_operation_windows;
|
||||
|
||||
static void run_file_operation([[maybe_unused]] FileOperation operation, String const& source, String const& destination, GUI::Window* parent_window)
|
||||
static void run_file_operation([[maybe_unused]] FileOperation operation, Vector<String> const& sources, String const& destination, GUI::Window* parent_window)
|
||||
{
|
||||
int pipe_fds[2];
|
||||
if (pipe(pipe_fds) < 0) {
|
||||
|
@ -72,8 +73,19 @@ static void run_file_operation([[maybe_unused]] FileOperation operation, String
|
|||
perror("dup2");
|
||||
_exit(1);
|
||||
}
|
||||
if (execlp("/bin/FileOperation", "/bin/FileOperation", "Copy", source.characters(), LexicalPath::dirname(destination).characters(), nullptr) < 0) {
|
||||
perror("execlp");
|
||||
|
||||
Vector<char const*> file_operation_args;
|
||||
file_operation_args.append("/bin/FileOperation");
|
||||
file_operation_args.append("Copy");
|
||||
|
||||
for (auto& source : sources)
|
||||
file_operation_args.append(source.characters());
|
||||
|
||||
file_operation_args.append(destination.characters());
|
||||
file_operation_args.append(nullptr);
|
||||
|
||||
if (execvp(file_operation_args.first(), const_cast<char**>(file_operation_args.data())) < 0) {
|
||||
perror("execvp");
|
||||
_exit(1);
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
|
@ -622,6 +634,7 @@ void DirectoryView::handle_drop(GUI::ModelIndex const& index, GUI::DropEvent con
|
|||
return;
|
||||
|
||||
bool had_accepted_drop = false;
|
||||
Vector<String> paths_to_copy;
|
||||
for (auto& url_to_copy : urls) {
|
||||
if (!url_to_copy.is_valid() || url_to_copy.path() == target_node.full_path())
|
||||
continue;
|
||||
|
@ -629,9 +642,13 @@ void DirectoryView::handle_drop(GUI::ModelIndex const& index, GUI::DropEvent con
|
|||
if (url_to_copy.path() == new_path)
|
||||
continue;
|
||||
|
||||
run_file_operation(FileOperation::Copy, url_to_copy.path(), new_path, window());
|
||||
paths_to_copy.append(url_to_copy.path());
|
||||
had_accepted_drop = true;
|
||||
}
|
||||
|
||||
if (!paths_to_copy.is_empty())
|
||||
run_file_operation(FileOperation::Copy, paths_to_copy, target_node.full_path(), window());
|
||||
|
||||
if (had_accepted_drop && on_accepted_drop)
|
||||
on_accepted_drop();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue