Add a "move to Trash" shortcut

Add send_to_trash shortcut (default value: `D`) to send an entry or
selected entries to the Trash folder.

Closes #389

Resolves: <https://git.meli-email.org/meli/meli/issues/389>
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/482/head
Manos Pitsidianakis 1 month ago
parent 8f0e1d6640
commit 0c0f821000
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -1243,6 +1243,9 @@ Manually request a mailbox refresh.
.It Ic set_seen
Set thread as seen.
.Pq Em n \" default value
.It Ic send_to_trash
Send entry to trash folder.
.Pq Em D \" default value
.It Ic union_modifier
Union modifier.
.Pq Em C-u \" default value

@ -49,6 +49,7 @@ pub enum ListingAction {
Select(String),
SetSeen,
SetUnseen,
SendToTrash,
CopyTo(MailboxPath),
CopyToOtherAccount(AccountName, MailboxPath),
MoveTo(MailboxPath),

@ -174,6 +174,7 @@ shortcut_key_values! { "listing",
search |> "Search within list of e-mails." |> Key::Char('/'),
refresh |> "Manually request a mailbox refresh." |> Key::F(5),
set_seen |> "Set thread as seen." |> Key::Char('n'),
send_to_trash |> "Send entry to trash folder." |> Key::Char('D'),
union_modifier |> "Union modifier." |> Key::Ctrl('u'),
diff_modifier |> "Difference modifier." |> Key::Ctrl('d'),
intersection_modifier |> "Intersection modifier." |> Key::Ctrl('i'),

@ -674,6 +674,51 @@ pub trait MailListingTrait: ListingTrait {
));
}
}
ListingAction::SendToTrash => {
use melib::backends::SpecialUsageMailbox;
let Some(trash_mbox_hash) = account
.special_use_mailbox(SpecialUsageMailbox::Trash)
.or_else(|| account.special_use_mailbox(SpecialUsageMailbox::Junk))
else {
context.replies.push_back(UIEvent::StatusEvent(
StatusEvent::DisplayMessage(
"Cannot send mail to trash because no Trash folder is configured."
.to_string(),
),
));
return;
};
let job = account.backend.write().unwrap().copy_messages(
env_hashes,
mailbox_hash,
trash_mbox_hash,
/* move? */ true,
);
match job {
Err(err) => {
context.replies.push_back(UIEvent::StatusEvent(
StatusEvent::DisplayMessage(err.to_string()),
));
}
Ok(fut) => {
let handle = account.main_loop_handler.job_executor.spawn(
"move-to-trash".into(),
fut,
account.is_async(),
);
account.insert_job(
handle.job_id,
JobRequest::Generic {
name: "taking out the trash".into(),
handle,
on_finish: None,
log_level: LogLevel::INFO,
},
);
}
}
}
ListingAction::Delete => {
let job = account
.backend
@ -1787,7 +1832,8 @@ impl Component for Listing {
| Action::Listing(a @ ListingAction::MoveToOtherAccount(_, _))
| Action::Listing(a @ ListingAction::ExportMbox(_, _))
| Action::Listing(a @ ListingAction::Flag(_))
| Action::Listing(a @ ListingAction::Tag(_)) => {
| Action::Listing(a @ ListingAction::Tag(_))
| Action::Listing(a @ ListingAction::SendToTrash) => {
let focused = self.component.get_focused_items(context);
self.component.perform_action(context, focused, a);
let should_be_unselected: bool = matches!(
@ -1795,6 +1841,7 @@ impl Component for Listing {
ListingAction::Delete
| ListingAction::MoveTo(_)
| ListingAction::MoveToOtherAccount(_, _)
| ListingAction::SendToTrash
);
let mut row_updates: SmallVec<[EnvelopeHash; 8]> = SmallVec::new();
for (k, v) in self.component.selection().iter_mut() {
@ -2012,6 +2059,15 @@ impl Component for Listing {
return true;
}
}
UIEvent::Input(ref key)
if shortcut!(key == shortcuts[Shortcuts::LISTING]["send_to_trash"]) =>
{
let mut event =
UIEvent::Action(Action::Listing(ListingAction::SendToTrash));
if self.process_event(&mut event, context) {
return true;
}
}
UIEvent::Input(ref key)
if shortcut!(key == shortcuts[Shortcuts::LISTING]["refresh"]) =>
{

Loading…
Cancel
Save