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

FileManager: Show progress dialog for pasted files

For now, this is a slight step backwards, as Cut does not remove the
source files. This will be rectified next.
This commit is contained in:
Sam Atkins 2021-06-17 15:00:01 +01:00 committed by Andreas Kling
parent d8fb8b9583
commit 516764ef17
2 changed files with 13 additions and 10 deletions

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -21,5 +22,5 @@ enum class FileOperation {
void delete_path(String const&, GUI::Window*); void delete_path(String const&, GUI::Window*);
void delete_paths(Vector<String> const&, bool should_confirm, GUI::Window*); void delete_paths(Vector<String> const&, bool should_confirm, GUI::Window*);
void run_file_operation([[maybe_unused]] FileOperation operation, Vector<String> const& sources, String const& destination, GUI::Window* parent_window); void run_file_operation(FileOperation, Vector<String> const& sources, String const& destination, GUI::Window*);
} }

View file

@ -160,12 +160,13 @@ void do_paste(String const& target_directory, GUI::Window* window)
return; return;
} }
bool should_delete_src = false; FileOperation file_operation = FileOperation::Copy;
if (copied_lines[0] == "#cut") { // cut operation encoded as a text/uri-list commen if (copied_lines[0] == "#cut") { // cut operation encoded as a text/uri-list comment
should_delete_src = true; file_operation = FileOperation::Cut;
copied_lines.remove(0); copied_lines.remove(0);
} }
Vector<String> source_paths;
for (auto& uri_as_string : copied_lines) { for (auto& uri_as_string : copied_lines) {
if (uri_as_string.is_empty()) if (uri_as_string.is_empty())
continue; continue;
@ -176,13 +177,14 @@ void do_paste(String const& target_directory, GUI::Window* window)
} }
auto new_path = String::formatted("{}/{}", target_directory, url.basename()); auto new_path = String::formatted("{}/{}", target_directory, url.basename());
if (auto result = Core::File::copy_file_or_directory(new_path, url.path()); result.is_error()) { if (url.path() == new_path)
auto error_message = String::formatted("Could not paste '{}': {}", url.path(), result.error().error_code); continue;
GUI::MessageBox::show(window, error_message, "File Manager", GUI::MessageBox::Type::Error);
} else if (should_delete_src) { source_paths.append(url.path());
delete_path(url.path(), window);
}
} }
if (!source_paths.is_empty())
run_file_operation(file_operation, source_paths, target_directory, window);
} }
void do_create_link(Vector<String> const& selected_file_paths, GUI::Window* window) void do_create_link(Vector<String> const& selected_file_paths, GUI::Window* window)