FileManager: Show progress dialog for file deletions
Progress dialogs are nice! :^) Showing a proper file-deletion animation would be nice, but that is outside the scope of my abilities.
This commit is contained in:
parent
967314023c
commit
469bca9d3a
Notes:
sideshowbarker
2024-07-18 08:34:12 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/469bca9d3a6 Pull-request: https://github.com/SerenityOS/serenity/pull/8117 Reviewed-by: https://github.com/MaxWipfli ✅
3 changed files with 20 additions and 38 deletions
Userland/Applications/FileManager
|
@ -26,6 +26,7 @@ FileOperationProgressWidget::FileOperationProgressWidget(FileOperation operation
|
|||
|
||||
auto& button = *find_descendant_of_type_named<GUI::Button>("button");
|
||||
|
||||
// FIXME: Show a different animation for deletions
|
||||
auto& file_copy_animation = *find_descendant_of_type_named<GUI::ImageWidget>("file_copy_animation");
|
||||
file_copy_animation.load_from_file("/res/graphics/file-flying-animation.gif");
|
||||
file_copy_animation.animate();
|
||||
|
@ -53,6 +54,10 @@ FileOperationProgressWidget::FileOperationProgressWidget(FileOperation operation
|
|||
files_copied_label.set_text("Moving files...");
|
||||
current_file_action_label.set_text("Moving: ");
|
||||
break;
|
||||
case FileOperation::Delete:
|
||||
files_copied_label.set_text("Deleting files...");
|
||||
current_file_action_label.set_text("Deleting: ");
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
@ -168,6 +173,9 @@ void FileOperationProgressWidget::did_progress(off_t bytes_done, off_t total_byt
|
|||
case FileOperation::Move:
|
||||
files_copied_label.set_text(String::formatted("Moving file {} of {}", files_done, total_file_count));
|
||||
break;
|
||||
case FileOperation::Delete:
|
||||
files_copied_label.set_text(String::formatted("Deleting file {} of {}", files_done, total_file_count));
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
|
@ -8,45 +8,14 @@
|
|||
#include "FileUtils.h"
|
||||
#include "FileOperationProgressWidget.h"
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace FileManager {
|
||||
|
||||
HashTable<NonnullRefPtr<GUI::Window>> file_operation_windows;
|
||||
|
||||
void delete_path(String const& path, GUI::Window* parent_window)
|
||||
{
|
||||
struct stat st;
|
||||
if (lstat(path.characters(), &st)) {
|
||||
GUI::MessageBox::show(parent_window,
|
||||
String::formatted("lstat({}) failed: {}", path, strerror(errno)),
|
||||
"Delete failed",
|
||||
GUI::MessageBox::Type::Error);
|
||||
}
|
||||
|
||||
bool is_directory = S_ISDIR(st.st_mode);
|
||||
auto result = Core::File::remove(path, Core::File::RecursionMode::Allowed, false);
|
||||
|
||||
if (result.is_error()) {
|
||||
auto& error = result.error();
|
||||
if (is_directory) {
|
||||
GUI::MessageBox::show(parent_window,
|
||||
String::formatted("Failed to delete directory \"{}\": {}", error.file, error.error_code),
|
||||
"Delete failed",
|
||||
GUI::MessageBox::Type::Error);
|
||||
} else {
|
||||
GUI::MessageBox::show(parent_window,
|
||||
String::formatted("Failed to delete file \"{}\": {}", error.file, error.error_code),
|
||||
"Delete failed",
|
||||
GUI::MessageBox::Type::Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void delete_paths(Vector<String> const& paths, bool should_confirm, GUI::Window* parent_window)
|
||||
{
|
||||
String message;
|
||||
|
@ -66,9 +35,7 @@ void delete_paths(Vector<String> const& paths, bool should_confirm, GUI::Window*
|
|||
return;
|
||||
}
|
||||
|
||||
for (auto& path : paths) {
|
||||
delete_path(path, parent_window);
|
||||
}
|
||||
run_file_operation(FileOperation::Delete, paths, {}, parent_window);
|
||||
}
|
||||
|
||||
void run_file_operation(FileOperation operation, Vector<String> const& sources, String const& destination, GUI::Window* parent_window)
|
||||
|
@ -105,6 +72,9 @@ void run_file_operation(FileOperation operation, Vector<String> const& sources,
|
|||
case FileOperation::Move:
|
||||
file_operation_args.append("Move");
|
||||
break;
|
||||
case FileOperation::Delete:
|
||||
file_operation_args.append("Delete");
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
@ -112,7 +82,9 @@ void run_file_operation(FileOperation operation, Vector<String> const& sources,
|
|||
for (auto& source : sources)
|
||||
file_operation_args.append(source.characters());
|
||||
|
||||
file_operation_args.append(destination.characters());
|
||||
if (operation != FileOperation::Delete)
|
||||
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) {
|
||||
|
@ -140,6 +112,9 @@ void run_file_operation(FileOperation operation, Vector<String> const& sources,
|
|||
case FileOperation::Move:
|
||||
window->set_title("Moving Files...");
|
||||
break;
|
||||
case FileOperation::Delete:
|
||||
window->set_title("Deleting Files...");
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
|
@ -10,16 +10,15 @@
|
|||
#include <AK/String.h>
|
||||
#include <LibCore/Forward.h>
|
||||
#include <LibGUI/Forward.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace FileManager {
|
||||
|
||||
enum class FileOperation {
|
||||
Copy = 0,
|
||||
Move
|
||||
Move,
|
||||
Delete,
|
||||
};
|
||||
|
||||
void delete_path(String const&, GUI::Window*);
|
||||
void delete_paths(Vector<String> const&, bool should_confirm, GUI::Window*);
|
||||
|
||||
void run_file_operation(FileOperation, Vector<String> const& sources, String const& destination, GUI::Window*);
|
||||
|
|
Loading…
Add table
Reference in a new issue