diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 3b8159711..b95161ff7 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -417,7 +417,7 @@ impl Component for Listing { self.component.set_movement(PageMovement::End); return true; } - UIEvent::Input(ref k) if k == shortcuts["toggle-menu-visibility"] => { + UIEvent::Input(ref k) if k == shortcuts["toggle_menu_visibility"] => { self.menu_visibility = !self.menu_visibility; self.set_dirty(); } @@ -427,6 +427,17 @@ impl Component for Listing { .push_back(UIEvent::Action(Tab(NewDraft(self.cursor_pos.0, None)))); return true; } + UIEvent::Input(ref key) if *key == shortcuts["set_seen"] => { + let mut event = UIEvent::Action(Action::Listing(ListingAction::SetSeen)); + if match self.component { + Plain(ref mut l) => l.process_event(&mut event, context), + Compact(ref mut l) => l.process_event(&mut event, context), + Threaded(ref mut l) => l.process_event(&mut event, context), + Conversations(ref mut l) => l.process_event(&mut event, context), + } { + return true; + } + } UIEvent::StartupCheck(_) => { self.dirty = true; context @@ -476,52 +487,10 @@ impl Component for Listing { let config_map = context.settings.shortcuts.listing.key_values(); map.insert( Listing::DESCRIPTION.to_string(), - [ - ( - "new_mail", - if let Some(key) = config_map.get("new_mail") { - (*key).clone() - } else { - Key::Char('m') - }, - ), - ( - "prev_folder", - if let Some(key) = config_map.get("prev_folder") { - (*key).clone() - } else { - Key::Char('K') - }, - ), - ( - "next_folder", - if let Some(key) = config_map.get("next_folder") { - (*key).clone() - } else { - Key::Char('J') - }, - ), - ( - "prev_account", - if let Some(key) = config_map.get("prev_account") { - (*key).clone() - } else { - Key::Char('l') - }, - ), - ( - "next_account", - if let Some(key) = config_map.get("next_account") { - (*key).clone() - } else { - Key::Char('h') - }, - ), - ("toggle-menu-visibility", Key::Char('`')), - ] - .iter() - .cloned() - .collect(), + config_map + .into_iter() + .map(|(k, v)| (k, v.clone())) + .collect(), ); map diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index 371fd25f6..8936efed0 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -1116,12 +1116,6 @@ impl Component for CompactListing { self.dirty = true; return true; } - UIEvent::Input(ref key) if *key == shortcuts["set_seen"] => { - let thread_hash = self.get_thread_under_cursor(self.cursor_pos.2, context); - self.perform_action(context, thread_hash, &ListingAction::SetSeen); - self.row_updates.push(thread_hash); - self.set_dirty(); - } UIEvent::Input(ref k) if self.unfocused && *k == shortcuts["exit_thread"] => { self.unfocused = false; self.dirty = true; @@ -1319,59 +1313,10 @@ impl Component for CompactListing { let config_map = context.settings.shortcuts.compact_listing.key_values(); map.insert( CompactListing::DESCRIPTION.to_string(), - [ - ( - "open_thread", - if let Some(key) = config_map.get("open_thread") { - (*key).clone() - } else { - Key::Char('\n') - }, - ), - ( - "prev_page", - if let Some(key) = config_map.get("prev_page") { - (*key).clone() - } else { - Key::PageUp - }, - ), - ( - "next_page", - if let Some(key) = config_map.get("next_page") { - (*key).clone() - } else { - Key::PageDown - }, - ), - ( - "exit_thread", - if let Some(key) = config_map.get("exit_thread") { - (*key).clone() - } else { - Key::Char('i') - }, - ), - ( - "select_entry", - if let Some(key) = config_map.get("select_entry") { - (*key).clone() - } else { - Key::Char('v') - }, - ), - ( - "set_seen", - if let Some(key) = config_map.get("set_seen") { - (*key).clone() - } else { - Key::Char('n') - }, - ), - ] - .iter() - .cloned() - .collect(), + config_map + .into_iter() + .map(|(k, v)| (k, v.clone())) + .collect(), ); map diff --git a/ui/src/components/mail/listing/conversations.rs b/ui/src/components/mail/listing/conversations.rs index 31cce4ce2..2dc370699 100644 --- a/ui/src/components/mail/listing/conversations.rs +++ b/ui/src/components/mail/listing/conversations.rs @@ -1194,16 +1194,11 @@ impl Component for ConversationsListing { return true; } } + self.unfocused = true; self.dirty = true; return true; } - UIEvent::Input(ref key) if *key == shortcuts["set_seen"] => { - let thread_hash = self.get_thread_under_cursor(self.cursor_pos.2, context); - self.perform_action(context, thread_hash, &ListingAction::SetSeen); - self.row_updates.push(thread_hash); - self.set_dirty(); - } UIEvent::Input(ref k) if self.unfocused && *k == shortcuts["exit_thread"] => { self.unfocused = false; self.dirty = true; @@ -1216,6 +1211,7 @@ impl Component for ConversationsListing { UIEvent::Input(ref key) if !self.unfocused && *key == shortcuts["select_entry"] => { let thread_hash = self.get_thread_under_cursor(self.cursor_pos.2, context); self.selection.entry(thread_hash).and_modify(|e| *e = !*e); + return true; } UIEvent::MailboxUpdate((ref idxa, ref idxf)) if (*idxa, *idxf) @@ -1327,6 +1323,7 @@ impl Component for ConversationsListing { Action::Listing(Filter(ref filter_term)) if !self.unfocused => { self.filter(filter_term, context); self.dirty = true; + return true; } Action::Listing(a @ ListingAction::SetSeen) | Action::Listing(a @ ListingAction::SetUnseen) @@ -1401,59 +1398,10 @@ impl Component for ConversationsListing { let config_map = context.settings.shortcuts.compact_listing.key_values(); map.insert( ConversationsListing::DESCRIPTION.to_string(), - [ - ( - "open_thread", - if let Some(key) = config_map.get("open_thread") { - (*key).clone() - } else { - Key::Char('\n') - }, - ), - ( - "prev_page", - if let Some(key) = config_map.get("prev_page") { - (*key).clone() - } else { - Key::PageUp - }, - ), - ( - "next_page", - if let Some(key) = config_map.get("next_page") { - (*key).clone() - } else { - Key::PageDown - }, - ), - ( - "exit_thread", - if let Some(key) = config_map.get("exit_thread") { - (*key).clone() - } else { - Key::Char('i') - }, - ), - ( - "select_entry", - if let Some(key) = config_map.get("select_entry") { - (*key).clone() - } else { - Key::Char('v') - }, - ), - ( - "set_seen", - if let Some(key) = config_map.get("set_seen") { - (*key).clone() - } else { - Key::Char('n') - }, - ), - ] - .iter() - .cloned() - .collect(), + config_map + .into_iter() + .map(|(k, v)| (k, v.clone())) + .collect(), ); map diff --git a/ui/src/conf/shortcuts.rs b/ui/src/conf/shortcuts.rs index 370cc79fd..735921c70 100644 --- a/ui/src/conf/shortcuts.rs +++ b/ui/src/conf/shortcuts.rs @@ -20,7 +20,7 @@ macro_rules! shortcut_key_values { ( $cname:expr, $(#[$outer:meta])* - pub struct $name:ident { $($fname:ident : Key |> $fdesc:expr),* }) => { + pub struct $name:ident { $($fname:ident : Key |> $fdesc:literal |> $default:expr),* }) => { $(#[$outer])* #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(default)] @@ -44,89 +44,56 @@ macro_rules! shortcut_key_values { ].iter().cloned().collect() } } + + impl Default for $name { + fn default() -> Self { + Self { + $($fname: $default),* + } + } + } } } shortcut_key_values! { "compact_listing", /// Shortcut listing for a mail listing in compact mode. pub struct CompactListingShortcuts { - open_thread: Key |> "Open thread.", - exit_thread: Key |> "Exit thread view.", - set_seen: Key |> "Set thread as seen." - } -} - -impl Default for CompactListingShortcuts { - fn default() -> Self { - CompactListingShortcuts { - open_thread: Key::Char('\n'), - exit_thread: Key::Char('i'), - set_seen: Key::Char('n'), - } + open_thread: Key |> "Open thread." |> Key::Char('\n'), + exit_thread: Key |> "Exit thread view." |> Key::Char('i'), + select_entry: Key |> "Select thread entry." |> Key::Char('v') } } shortcut_key_values! { "listing", /// Shortcut listing for a mail listing. pub struct ListingShortcuts { - prev_page: Key |> "Go to previous page.", - next_page: Key |> "Go to next page.", - prev_folder: Key |> "Go to previous folder.", - next_folder: Key |> "Go to next folder.", - prev_account: Key |> "Go to previous account.", - next_account: Key |> "Go to next account.", - new_mail: Key |> "Start new mail draft in new tab." - } -} - -impl Default for ListingShortcuts { - fn default() -> Self { - ListingShortcuts { - prev_page: Key::PageUp, - next_page: Key::PageDown, - prev_folder: Key::Char('K'), - next_folder: Key::Char('J'), - prev_account: Key::Char('l'), - next_account: Key::Char('h'), - new_mail: Key::Char('m'), - } + prev_page: Key |> "Go to previous page." |> Key::PageUp, + next_page: Key |> "Go to next page." |> Key::PageDown, + prev_folder: Key |> "Go to previous folder." |> Key::Char('K'), + next_folder: Key |> "Go to next folder." |> Key::Char('J'), + prev_account: Key |> "Go to previous account." |> Key::Char('l'), + next_account: Key |> "Go to next account." |> Key::Char('h'), + new_mail: Key |> "Start new mail draft in new tab." |> Key::Char('m'), + set_seen: Key |> "Set thread as seen." |> Key::Char('n'), + search: Key |> "Search within list of e-mails." |> Key::Char('/'), + toggle_menu_visibility: Key |> "Toggle visibility of side menu in mail list." |> Key::Char('`') } } shortcut_key_values! { "contact-list", -/// Shortcut listing for the contact list view -pub struct ContactListShortcuts { - create_contact: Key |> "Create new contact.", - edit_contact: Key |> "Edit contact under cursor." -} -} - -impl Default for ContactListShortcuts { - fn default() -> Self { - ContactListShortcuts { - create_contact: Key::Char('c'), - edit_contact: Key::Char('e'), - } + /// Shortcut listing for the contact list view + pub struct ContactListShortcuts { + create_contact: Key |> "Create new contact." |> Key::Char('c'), + edit_contact: Key |> "Edit contact under cursor." |> Key::Char('e') } } shortcut_key_values! { "pager", -/// Shortcut listing for the text pager -pub struct PagerShortcuts { - scroll_up: Key |> "Scroll up pager.", - scroll_down: Key |> "Scroll down pager.", - page_up: Key |> "Go to previous pager page", - page_down: Key |> "Go to next pager page" -} -} - -impl Default for PagerShortcuts { - fn default() -> Self { - PagerShortcuts { - scroll_up: Key::Char('k'), - scroll_down: Key::Char('j'), - page_up: Key::PageUp, - page_down: Key::PageDown, - } + /// Shortcut listing for the text pager + pub struct PagerShortcuts { + scroll_up: Key |> "Scroll up pager." |> Key::Char('k'), + scroll_down: Key |> "Scroll down pager." |> Key::Char('j'), + page_up: Key |> "Go to previous pager page" |> Key::PageUp, + page_down: Key |> "Go to next pager page" |> Key::PageDown } }