ui/view: move reply and edit to view.rs

reply and edit actions where only in view/thread.rs, so simple envelope
views had no way to reply. view.rs is used standalone or within
view/thread.rs so it is the appropriate place for the actions.
jmap
Manos Pitsidianakis 2019-11-17 11:25:24 +02:00
parent f8a2ce0bed
commit 62f3d12253
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 27 additions and 37 deletions

View File

@ -707,11 +707,35 @@ impl Component for MailView {
let shortcuts = &self.get_shortcuts(context)[MailView::DESCRIPTION];
match *event {
UIEvent::Input(ref k) if *k == shortcuts["reply"] => {
let account = &context.accounts[self.coordinates.0];
let folder_hash = account[self.coordinates.1].unwrap().folder.hash();
let envelope: EnvelopeRef = account.collection.get_env(self.coordinates.2);
let thread_hash = envelope.thread();
let threads = &account.collection.threads[&folder_hash];
let root_thread_hash = melib::find_root_hash(&threads.thread_nodes, thread_hash);
let root_idx = threads
.root_iter()
.position(|t| t == root_thread_hash)
.unwrap();
context.replies.push_back(UIEvent::Action(Tab(Reply(
(self.coordinates.0, self.coordinates.1, root_idx),
thread_hash,
))));
return true;
}
UIEvent::Input(ref k) if *k == shortcuts["edit"] => {
context.replies.push_back(UIEvent::Action(Tab(Edit(
self.coordinates.0,
self.coordinates.2,
))));
return true;
}
UIEvent::Input(ref key)
if !self.mode.is_contact_selector()
&& *key == shortcuts["add_addresses_to_contacts"] =>
{
let account = &mut context.accounts[self.coordinates.0];
let account = &context.accounts[self.coordinates.0];
let envelope: EnvelopeRef = account.collection.get_env(self.coordinates.2);
let mut entries = Vec::new();
@ -1296,6 +1320,8 @@ impl Component for MailView {
let mut our_map = FnvHashMap::with_capacity_and_hasher(4, Default::default());
our_map.insert("add_addresses_to_contacts", Key::Char('c'));
our_map.insert("view_raw_source", Key::Alt('r'));
our_map.insert("reply", Key::Char('R'));
our_map.insert("edit", Key::Char('e'));
if self.mode.is_attachment()
|| self.mode == ViewMode::Subview
|| self.mode == ViewMode::Raw

View File

@ -950,41 +950,6 @@ impl Component for ThreadView {
let shortcuts = &self.get_shortcuts(context)[ThreadView::DESCRIPTION];
match *event {
UIEvent::Input(Key::Char('R')) => {
context.replies.push_back(UIEvent::Action(Tab(Reply(
self.coordinates,
self.entries[self.expanded_pos].index.1,
))));
return true;
}
UIEvent::Input(Key::Char('e')) => {
{
let account = &context.accounts[self.coordinates.0];
let mailbox = &account[self.coordinates.1].unwrap();
let threads = &account.collection.threads[&mailbox.folder.hash()];
let thread_node =
&threads.thread_nodes()[&threads.root_set(self.coordinates.2)];
let i = if let Some(i) = thread_node.message() {
i
} else {
threads.thread_nodes()[&thread_node.children()[0]]
.message()
.unwrap()
};
let envelope: EnvelopeRef = account.collection.get_env(i);
let op = account.operation(envelope.hash());
debug!(
"sending action edit for {}, {}",
envelope.message_id(),
op.description()
);
context.replies.push_back(UIEvent::Action(Tab(Edit(
self.coordinates.0,
envelope.hash(),
))));
}
return true;
}
UIEvent::Input(Key::Up) => {
if self.cursor_pos > 0 {
self.new_cursor_pos = self.new_cursor_pos.saturating_sub(1);
@ -1111,7 +1076,6 @@ impl Component for ThreadView {
map.insert(
ThreadView::DESCRIPTION.to_string(),
[
("reply", Key::Char('R')),
("reverse thread order", Key::Ctrl('r')),
("toggle_mailview", Key::Char('p')),
("toggle_subthread visibility", Key::Char('h')),