diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-11-28 22:16:56 +0200 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-11-28 22:16:56 +0200 |
commit | c04513ac94f6c43e0010a41a7dd1f037a5284b25 (patch) | |
tree | 0826e32ac8383523bdc1eb99b7a2e99f97f4d495 /ui/src/components/mail/listing.rs | |
parent | bb486ca9d867079e3be940465fcee16029629348 (diff) |
ui: add shortcut! macro to compare shortcuts values
This is used in process_event() functions of UI Components. When a key
has been input we have to compare it with the configured shortcuts from
a hashmap.
Add shortcut! macro that checks shortcut hashmaps for the given name and
doesn't panic if it's missing.
Diffstat (limited to 'ui/src/components/mail/listing.rs')
-rw-r--r-- | ui/src/components/mail/listing.rs | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 619f6b3b..9ad0e9d7 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -283,10 +283,11 @@ impl Component for Listing { return true; } - let shortcuts = &self.get_shortcuts(context)[Listing::DESCRIPTION]; + let shortcuts = self.get_shortcuts(context); match *event { UIEvent::Input(ref k) - if k == shortcuts["next_folder"] || k == shortcuts["prev_folder"] => + if shortcut!(k == shortcuts[Listing::DESCRIPTION]["next_folder"]) + || shortcut!(k == shortcuts[Listing::DESCRIPTION]["prev_folder"]) => { let amount = if self.cmd_buf.is_empty() { 1 @@ -305,7 +306,9 @@ impl Component for Listing { }; let folder_length = context.accounts[self.cursor_pos.0].len(); match k { - k if k == shortcuts["next_folder"] && folder_length > 0 => { + k if shortcut!(k == shortcuts[Listing::DESCRIPTION]["next_folder"]) + && folder_length > 0 => + { if self.cursor_pos.1 + amount < folder_length { self.cursor_pos.1 += amount; self.component.set_coordinates(( @@ -318,7 +321,7 @@ impl Component for Listing { return true; } } - k if k == shortcuts["prev_folder"] => { + k if shortcut!(k == shortcuts[Listing::DESCRIPTION]["prev_folder"]) => { if self.cursor_pos.1 >= amount { self.cursor_pos.1 -= amount; self.component.set_coordinates(( @@ -357,7 +360,8 @@ impl Component for Listing { return true; } UIEvent::Input(ref k) - if k == shortcuts["next_account"] || k == shortcuts["prev_account"] => + if shortcut!(k == shortcuts[Listing::DESCRIPTION]["next_account"]) + || shortcut!(k == shortcuts[Listing::DESCRIPTION]["prev_account"]) => { let amount = if self.cmd_buf.is_empty() { 1 @@ -375,7 +379,7 @@ impl Component for Listing { return true; }; match k { - k if k == shortcuts["next_account"] => { + k if shortcut!(k == shortcuts[Listing::DESCRIPTION]["next_account"]) => { if self.cursor_pos.0 + amount < self.accounts.len() { self.cursor_pos = (self.cursor_pos.0 + amount, 0); self.component.set_coordinates((self.cursor_pos.0, 0, None)); @@ -384,7 +388,7 @@ impl Component for Listing { return true; } } - k if k == shortcuts["prev_account"] => { + k if shortcut!(k == shortcuts[Listing::DESCRIPTION]["prev_account"]) => { if self.cursor_pos.0 >= amount { self.cursor_pos = (self.cursor_pos.0 - amount, 0); self.component.set_coordinates((self.cursor_pos.0, 0, None)); @@ -502,7 +506,9 @@ impl Component for Listing { self.component.set_movement(PageMovement::Down(amount)); return true; } - UIEvent::Input(ref key) if key == shortcuts["prev_page"] => { + UIEvent::Input(ref key) + if shortcut!(key == shortcuts[Listing::DESCRIPTION]["prev_page"]) => + { let mult = if self.cmd_buf.is_empty() { 1 } else if let Ok(mult) = self.cmd_buf.parse::<usize>() { @@ -521,7 +527,9 @@ impl Component for Listing { self.component.set_movement(PageMovement::PageUp(mult)); return true; } - UIEvent::Input(ref key) if key == shortcuts["next_page"] => { + UIEvent::Input(ref key) + if shortcut!(key == shortcuts[Listing::DESCRIPTION]["next_page"]) => + { let mult = if self.cmd_buf.is_empty() { 1 } else if let Ok(mult) = self.cmd_buf.parse::<usize>() { @@ -548,17 +556,23 @@ 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 shortcut!(k == shortcuts[Listing::DESCRIPTION]["toggle_menu_visibility"]) => + { self.menu_visibility = !self.menu_visibility; self.set_dirty(); } - UIEvent::Input(ref k) if k == shortcuts["new_mail"] => { + UIEvent::Input(ref k) + if shortcut!(k == shortcuts[Listing::DESCRIPTION]["new_mail"]) => + { context .replies .push_back(UIEvent::Action(Tab(NewDraft(self.cursor_pos.0, None)))); return true; } - UIEvent::Input(ref key) if key == shortcuts["search"] => { + UIEvent::Input(ref key) + if shortcut!(key == shortcuts[Listing::DESCRIPTION]["search"]) => + { context .replies .push_back(UIEvent::ExInput(Key::Paste("filter ".to_string()))); @@ -567,7 +581,9 @@ impl Component for Listing { .push_back(UIEvent::ChangeMode(UIMode::Execute)); return true; } - UIEvent::Input(ref key) if key == shortcuts["set_seen"] => { + UIEvent::Input(ref key) + if shortcut!(key == shortcuts[Listing::DESCRIPTION]["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), |