Ask for confirmation when deleting from trash

This commit is contained in:
Jason Rodney Hansen 2025-12-14 09:04:25 -07:00 committed by Jacob Kauffmann
parent 84d3659263
commit 456d4b003e
2 changed files with 36 additions and 3 deletions

View file

@ -91,7 +91,7 @@ other-apps = Other applications
related-apps = Related applications related-apps = Related applications
## Permanently delete Dialog ## Permanently delete Dialog
selected-items = the {$items} selected items selected-items = The {$items} selected items
permanently-delete-question = Permanently delete? permanently-delete-question = Permanently delete?
delete = Delete delete = Delete
permanently-delete-warning = {$target} will be permanently deleted. This action can't be undone. permanently-delete-warning = {$target} will be permanently deleted. This action can't be undone.

View file

@ -101,6 +101,9 @@ use crate::{
static PERMANENT_DELETE_BUTTON_ID: LazyLock<widget::Id> = static PERMANENT_DELETE_BUTTON_ID: LazyLock<widget::Id> =
LazyLock::new(|| widget::Id::new("permanent-delete-button")); LazyLock::new(|| widget::Id::new("permanent-delete-button"));
static DELETE_TRASH_BUTTON_ID: LazyLock<widget::Id> =
LazyLock::new(|| widget::Id::new("delete-trash-button"));
static CONFIRM_OPEN_WITH_BUTTON_ID: LazyLock<widget::Id> = static CONFIRM_OPEN_WITH_BUTTON_ID: LazyLock<widget::Id> =
LazyLock::new(|| widget::Id::new("confirm-open-with-button")); LazyLock::new(|| widget::Id::new("confirm-open-with-button"));
@ -534,6 +537,9 @@ pub enum DialogPage {
PermanentlyDelete { PermanentlyDelete {
paths: Box<[PathBuf]>, paths: Box<[PathBuf]>,
}, },
DeleteTrash {
items: Vec<TrashItem>,
},
RenameItem { RenameItem {
from: PathBuf, from: PathBuf,
parent: PathBuf, parent: PathBuf,
@ -2683,8 +2689,10 @@ impl Application for App {
} }
} }
if !trash_items.is_empty() { if !trash_items.is_empty() {
return self return self.update(Message::DialogPush(
.operation(Operation::DeleteTrash { items: trash_items }); DialogPage::DeleteTrash { items: trash_items },
Some(DELETE_TRASH_BUTTON_ID.clone()),
));
} }
} }
} else { } else {
@ -2883,6 +2891,9 @@ impl Application for App {
DialogPage::PermanentlyDelete { paths } => { DialogPage::PermanentlyDelete { paths } => {
tasks.push(self.operation(Operation::PermanentlyDelete { paths })); tasks.push(self.operation(Operation::PermanentlyDelete { paths }));
} }
DialogPage::DeleteTrash { items } => {
tasks.push(self.operation(Operation::DeleteTrash { items }));
}
DialogPage::RenameItem { DialogPage::RenameItem {
from, parent, name, .. from, parent, name, ..
} => { } => {
@ -5323,6 +5334,28 @@ impl Application for App {
target = target target = target
))) )))
} }
DialogPage::DeleteTrash { items } => {
let target = if items.len() == 1 {
format!("\"{}\"", items[0].name.to_string_lossy())
} else {
fl!("selected-items", items = items.len())
};
widget::dialog()
.title(fl!("permanently-delete-question"))
.primary_action(
widget::button::destructive(fl!("delete"))
.on_press(Message::DialogComplete)
.id(DELETE_TRASH_BUTTON_ID.clone()),
)
.secondary_action(
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
)
.control(widget::text(fl!(
"permanently-delete-warning",
target = target
)))
}
DialogPage::RenameItem { DialogPage::RenameItem {
from, from,
parent, parent,