From 11a2d0deef5ef6b88ba8a48e8504fcab83fdb16a Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 10 Apr 2024 13:56:43 -0400 Subject: [PATCH] feat: dnd to trash --- src/app.rs | 23 +++++++++++++++++------ src/dialog.rs | 3 +++ src/tab.rs | 6 +++++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/app.rs b/src/app.rs index d543b12..33f27f9 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1366,6 +1366,9 @@ impl Application for App { }, )); } + tab::Command::MoveToTrash(paths) => { + self.operation(Operation::Delete { paths }); + } } } return Command::batch(commands); @@ -1436,9 +1439,13 @@ impl Application for App { paths: data.paths, }, )), - Location::Trash => { - // TODO move to trash if action is cut - return Command::none(); + Location::Trash if matches!(action, DndAction::Move) => { + self.operation(Operation::Delete { paths: data.paths }); + Command::none() + } + _ => { + log::warn!("Copy to trash is not supported."); + Command::none() } }; return ret; @@ -1485,9 +1492,13 @@ impl Application for App { paths: data.paths, }, )), - Location::Trash => { - // TODO move to trash if action is cut - return Command::none(); + Location::Trash if matches!(action, DndAction::Move) => { + self.operation(Operation::Delete { paths: data.paths }); + Command::none() + } + _ => { + log::warn!("Copy to trash is not supported."); + Command::none() } }; return ret; diff --git a/src/dialog.rs b/src/dialog.rs index e415052..b47e448 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -637,6 +637,9 @@ impl Application for App { tab::Command::Timeout(_, _) => { log::warn!("Timeout not supported in dialog"); } + tab::Command::MoveToTrash(_) => { + log::warn!("MoveToTrash not supported in dialog"); + } } } return Command::batch(commands); diff --git a/src/tab.rs b/src/tab.rs index e99bc51..d057d68 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -435,6 +435,7 @@ pub enum Command { Scroll(widget::Id, AbsoluteOffset), DropFiles(PathBuf, ClipboardPaste), Timeout(Duration, Message), + MoveToTrash(Vec), } #[derive(Clone, Debug)] @@ -1322,8 +1323,11 @@ impl Tab { } commands.push(Command::DropFiles(to, from)) } + Location::Trash if matches!(from.kind, ClipboardKind::Cut) => { + commands.push(Command::MoveToTrash(from.paths)) + } Location::Trash => { - // TODO + log::warn!("Copy to trash is not supported."); } }; }