feat: display status message on failed operations in Files app
This commit is contained in:
1 parent
5e4e8902c2
commit
2e3055f5f8
8 files changed
+421
-62
No files matched your search
@@ -73,18 +73,28 @@ void filemanager_finish_rename(FileManagerState* fm) {
|
||||
filemanager_build_fullpath(new_path, 512,
|
||||
fm->current_path, fm->rename_buf);
|
||||
|
||||
if (montauk::frename(old_path, new_path) != 0) {
|
||||
montauk::StatusCodes status =
|
||||
filemanager_status_from_result(montauk::frename(old_path, new_path));
|
||||
if (status != montauk::Success && !filemanager_status_is_access_denied(status)) {
|
||||
// Fall back to copy + delete for drivers that don't support rename
|
||||
if (fm->is_dir[fm->rename_idx]) {
|
||||
if (filemanager_copy_dir_recursive(old_path, new_path))
|
||||
filemanager_delete_recursive(old_path);
|
||||
status = filemanager_copy_dir_recursive(old_path, new_path);
|
||||
if (status == montauk::Success)
|
||||
status = filemanager_delete_recursive(old_path);
|
||||
} else {
|
||||
if (filemanager_copy_file(old_path, new_path))
|
||||
montauk::fdelete(old_path);
|
||||
status = filemanager_copy_file(old_path, new_path);
|
||||
if (status == montauk::Success)
|
||||
status = filemanager_status_from_result(montauk::fdelete(old_path));
|
||||
}
|
||||
}
|
||||
|
||||
filemanager_read_dir(fm);
|
||||
|
||||
if (status != montauk::Success) {
|
||||
char heading[192];
|
||||
snprintf(heading, sizeof(heading), "Couldn't rename \"%s\"", path_basename(old_path));
|
||||
filemanager_show_error(fm->desktop, fm, heading, old_path, status);
|
||||
}
|
||||
}
|
||||
|
||||
void filemanager_cancel_rename(FileManagerState* fm) {
|
||||
@@ -98,18 +108,25 @@ void filemanager_new_folder(FileManagerState* fm) {
|
||||
char name[64] = "New Folder";
|
||||
char path[512];
|
||||
filemanager_build_fullpath(path, 512, fm->current_path, name);
|
||||
int attempt = 1;
|
||||
// Try creating; if it fails, append a number
|
||||
if (montauk::fmkdir(path) != 0) {
|
||||
for (attempt = 2; attempt <= 99; attempt++) {
|
||||
snprintf(name, 64, "New Folder %d", attempt);
|
||||
filemanager_build_fullpath(path, 512, fm->current_path, name);
|
||||
if (montauk::fmkdir(path) == 0) break;
|
||||
}
|
||||
// Try creating; if it fails (most likely the name is taken), append a
|
||||
// number. An access error fails the same way for every name, so stop.
|
||||
montauk::StatusCodes status = filemanager_status_from_result(montauk::fmkdir(path));
|
||||
for (int attempt = 2; status != montauk::Success &&
|
||||
!filemanager_status_is_access_denied(status) &&
|
||||
attempt <= 99; attempt++) {
|
||||
snprintf(name, 64, "New Folder %d", attempt);
|
||||
filemanager_build_fullpath(path, 512, fm->current_path, name);
|
||||
status = filemanager_status_from_result(montauk::fmkdir(path));
|
||||
}
|
||||
|
||||
filemanager_read_dir(fm);
|
||||
|
||||
if (status != montauk::Success) {
|
||||
filemanager_show_error(fm->desktop, fm, "Couldn't create a new folder",
|
||||
fm->current_path, status);
|
||||
return;
|
||||
}
|
||||
|
||||
// Select the new folder and start rename
|
||||
for (int i = 0; i < fm->entry_count; i++) {
|
||||
if (montauk::streq(fm->entry_names[i], name)) {
|
||||
@@ -182,9 +199,15 @@ void filemanager_delete_selected(FileManagerState* fm) {
|
||||
}
|
||||
|
||||
montauk::mfree(filtered);
|
||||
montauk::fdelete(fullpath);
|
||||
montauk::StatusCodes status = filemanager_status_from_result(montauk::fdelete(fullpath));
|
||||
filemanager_clear_multi_selection(fm);
|
||||
filemanager_read_dir(fm);
|
||||
|
||||
if (status != montauk::Success) {
|
||||
char heading[192];
|
||||
snprintf(heading, sizeof(heading), "Couldn't delete \"%s\"", path_basename(fullpath));
|
||||
filemanager_show_error(fm->desktop, fm, heading, fullpath, status);
|
||||
}
|
||||
}
|
||||
|
||||
void filemanager_open_ctx_menu(FileManagerState* fm, int local_x, int local_y, int target_idx) {
|
||||
|
||||
Reference in new issue
Block a user