From 60350eaa8872023d23d4557dbcd67c308b96b3fb Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Wed, 11 Nov 2020 17:45:39 +0200 Subject: [PATCH] mail/status: add "general" shortcut section --- src/components/mail/listing.rs | 7 ++++++- src/components/mail/status.rs | 24 ++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/components/mail/listing.rs b/src/components/mail/listing.rs index 8e0d19fd..07b8f88d 100644 --- a/src/components/mail/listing.rs +++ b/src/components/mail/listing.rs @@ -1360,7 +1360,11 @@ impl Component for Listing { } fn get_shortcuts(&self, context: &Context) -> ShortcutMaps { - let mut map = self.component.get_shortcuts(context); + let mut map = if let Some(s) = self.status.as_ref() { + s.get_shortcuts(context) + } else { + self.component.get_shortcuts(context) + }; let mut config_map = context.settings.shortcuts.listing.key_values(); if self.focus != ListingFocus::Menu { config_map.remove("open_mailbox"); @@ -1761,6 +1765,7 @@ impl Listing { /* Set to dummy */ self.component = Offline(OfflineListing::new((account_hash, 0))); } + self.status = None; self.set_dirty(true); context .replies diff --git a/src/components/mail/status.rs b/src/components/mail/status.rs index 222dca54..82bd90e1 100644 --- a/src/components/mail/status.rs +++ b/src/components/mail/status.rs @@ -33,11 +33,12 @@ pub struct AccountStatus { impl fmt::Display for AccountStatus { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "status") + write!(f, "{}", AccountStatus::DESCRIPTION) } } impl AccountStatus { + pub const DESCRIPTION: &'static str = "status"; pub fn new(account_pos: usize, theme_default: ThemeAttribute) -> AccountStatus { let default_cell = { let mut ret = Cell::with_char(' '); @@ -397,27 +398,30 @@ impl Component for AccountStatus { context.dirty_areas.push_back(area); } - fn process_event(&mut self, event: &mut UIEvent, _context: &mut Context) -> bool { + fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { + let shortcuts = self.get_shortcuts(context); match *event { UIEvent::Resize => { self.dirty = true; } - UIEvent::Input(Key::Left) if self.cursor.0 != 0 => { + UIEvent::Input(ref key) + if shortcut!(key == shortcuts["general"]["scroll_left"]) && self.cursor.0 != 0 => + { self.cursor.0 -= 1; self.dirty = true; return true; } - UIEvent::Input(Key::Right) => { + UIEvent::Input(ref key) if shortcut!(key == shortcuts["general"]["scroll_right"]) => { self.cursor.0 = self.cursor.0 + 1; self.dirty = true; return true; } - UIEvent::Input(Key::Up) => { + UIEvent::Input(ref key) if shortcut!(key == shortcuts["general"]["scroll_up"]) => { self.cursor.1 = self.cursor.1.saturating_sub(1); self.dirty = true; return true; } - UIEvent::Input(Key::Down) => { + UIEvent::Input(ref key) if shortcut!(key == shortcuts["general"]["scroll_down"]) => { self.cursor.1 = self.cursor.1 + 1; self.dirty = true; return true; @@ -433,6 +437,14 @@ impl Component for AccountStatus { false } + fn get_shortcuts(&self, context: &Context) -> ShortcutMaps { + let config_map: IndexMap<&'static str, Key> = + context.settings.shortcuts.general.key_values(); + let mut ret: ShortcutMaps = Default::default(); + ret.insert("general", config_map); + ret + } + fn is_dirty(&self) -> bool { self.dirty }