Show toast on moving to trash
This commit is contained in:
parent
45711e1734
commit
5c82e72c80
4 changed files with 67 additions and 21 deletions
36
src/app.rs
36
src/app.rs
|
|
@ -249,7 +249,9 @@ pub enum Message {
|
|||
TabMessage(Option<Entity>, tab::Message),
|
||||
TabNew,
|
||||
TabRescan(Entity, Location, Vec<tab::Item>),
|
||||
Toast(widget::toaster::ToastMessage),
|
||||
ToggleContextPage(ContextPage),
|
||||
Undo(u64),
|
||||
WindowClose,
|
||||
WindowNew,
|
||||
DndHoverLocTimeout(Location),
|
||||
|
|
@ -262,6 +264,12 @@ pub enum Message {
|
|||
DndDropNav(Entity, Option<ClipboardPaste>, DndAction),
|
||||
}
|
||||
|
||||
impl From<widget::toaster::ToastMessage> for Message {
|
||||
fn from(toast_message: widget::toaster::ToastMessage) -> Self {
|
||||
Self::Toast(toast_message)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum ContextPage {
|
||||
About,
|
||||
|
|
@ -359,6 +367,7 @@ pub struct App {
|
|||
search_active: bool,
|
||||
search_id: widget::Id,
|
||||
search_input: String,
|
||||
toasts: widget::toaster::Toasts<Message>,
|
||||
watcher_opt: Option<(Debouncer<RecommendedWatcher, FileIdMap>, HashSet<PathBuf>)>,
|
||||
nav_dnd_hover: Option<(Location, Instant)>,
|
||||
tab_dnd_hover: Option<(Entity, Instant)>,
|
||||
|
|
@ -980,6 +989,7 @@ impl Application for App {
|
|||
search_active: false,
|
||||
search_id: widget::Id::unique(),
|
||||
search_input: String::new(),
|
||||
toasts: widget::toaster::Toasts::default(),
|
||||
watcher_opt: None,
|
||||
nav_dnd_hover: None,
|
||||
tab_dnd_hover: None,
|
||||
|
|
@ -1530,11 +1540,27 @@ impl Application for App {
|
|||
}
|
||||
}
|
||||
Message::PendingComplete(id) => {
|
||||
let mut commands = Vec::with_capacity(2);
|
||||
if let Some((op, _)) = self.pending_operations.remove(&id) {
|
||||
if let Some(description) = op.toast() {
|
||||
commands.push(
|
||||
self.toasts.push(
|
||||
widget::toaster::Toast::new(description)
|
||||
/*TODO
|
||||
.action(widget::toaster::ToastAction {
|
||||
description: fl!("undo"),
|
||||
message: Message::Undo(id),
|
||||
})
|
||||
*/
|
||||
.duration(widget::toaster::ToastDuration::Long),
|
||||
),
|
||||
);
|
||||
}
|
||||
self.complete_operations.insert(id, op);
|
||||
}
|
||||
// Manually rescan any trash tabs after any operation is completed
|
||||
return self.rescan_trash();
|
||||
commands.push(self.rescan_trash());
|
||||
return Command::batch(commands);
|
||||
}
|
||||
Message::PendingError(id, err) => {
|
||||
if let Some((op, _)) = self.pending_operations.remove(&id) {
|
||||
|
|
@ -1869,6 +1895,9 @@ impl Application for App {
|
|||
}
|
||||
}
|
||||
//TODO: TABRELOAD
|
||||
Message::Toast(toast_message) => {
|
||||
self.toasts.handle_message(&toast_message);
|
||||
}
|
||||
Message::ToggleContextPage(context_page) => {
|
||||
//TODO: ensure context menus are closed
|
||||
if self.context_page == context_page {
|
||||
|
|
@ -1879,6 +1908,9 @@ impl Application for App {
|
|||
}
|
||||
self.set_context_title(context_page.title());
|
||||
}
|
||||
Message::Undo(id) => {
|
||||
log::error!("TODO: Undo {id}");
|
||||
}
|
||||
Message::WindowClose => {
|
||||
return window::close(window::Id::MAIN);
|
||||
}
|
||||
|
|
@ -2376,7 +2408,7 @@ impl Application for App {
|
|||
}
|
||||
}
|
||||
|
||||
let content: Element<_> = tab_column.into();
|
||||
let content: Element<_> = widget::toaster::toaster(&self.toasts, tab_column).into();
|
||||
|
||||
// Uncomment to debug layout:
|
||||
//content.explain(cosmic::iced::Color::WHITE)
|
||||
|
|
|
|||
|
|
@ -198,6 +198,14 @@ fn copy_unique_path(from: &Path, to: &Path) -> PathBuf {
|
|||
}
|
||||
|
||||
impl Operation {
|
||||
pub fn toast(&self) -> Option<String> {
|
||||
match self {
|
||||
Self::Delete { paths } => Some(fl!("moved-to-trash", items = paths.len())),
|
||||
//TODO: more toasts
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Perform the operation
|
||||
pub async fn perform(
|
||||
self,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue