Browse Source

shortcuts tidiness

- Unflatten shortcuts configuration table.
  Shortcuts now have to be defined in levels:
  [shortcuts.general]
  ...
  [shortcuts.pager]
  ...

- Add shortcuts for thread view
- Sort alphabetically in help view
jmap
Manos Pitsidianakis 2 years ago
parent
commit
1063bb73b5
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 31
      sample-config
  2. 46
      ui/src/components/mail/view/thread.rs
  3. 9
      ui/src/components/utilities.rs
  4. 28
      ui/src/conf/shortcuts.rs

31
sample-config

@ -64,28 +64,33 @@
#play_sound = true # default, optional
#sound_file = PATH # optional
#[shortcuts]
##shortcuts
# Compact mail listing defaults:
#open_thread = '\n'
#[shortcuts.compact_listing]
#exit_thread = 'i'
#
#[shortcuts.contact-list]
#create_contact = 'c'
#edit_contact = 'e'
# Mail listing defaults
#prev_page = PageUp,
#next_page = PageDown,
#prev_folder = 'K',
#next_folder = 'J',
#prev_account = 'l',
#next_account = 'h',
#new_mail = 'm',
#[shortcuts.listing]
#prev_page = "PageUp"
#next_page = "PageDown"
#prev_folder = 'K'
#next_folder = 'J'
#prev_account = 'l'
#next_account = 'h'
#new_mail = 'm'
#set_seen = 'n'
# Pager defaults
#scroll_up = 'k',
#scroll_down = 'j',
#page_up = PageUp,
#page_down = PageDown,
#[shortcuts.pager]
#scroll_up = 'k'
#scroll_down = 'j'
#page_up = "PageUp"
#page_down = "PageDown"
#[composing]
# required for sending e-mail

46
ui/src/components/mail/view/thread.rs

@ -1009,19 +1009,19 @@ impl Component for ThreadView {
self.set_dirty();
return true;
}
UIEvent::Input(Key::Char('p')) => {
UIEvent::Input(ref key) if *key == shortcuts["toggle_mailview"] => {
self.show_mailview = !self.show_mailview;
self.initiated = false;
self.set_dirty();
return true;
}
UIEvent::Input(Key::Char('t')) => {
UIEvent::Input(ref key) if *key == shortcuts["toggle_threadview"] => {
self.show_thread = !self.show_thread;
self.initiated = false;
self.set_dirty();
return true;
}
UIEvent::Input(Key::Ctrl('r')) => {
UIEvent::Input(ref key) if *key == shortcuts["reverse_thread_order"] => {
self.reversed = !self.reversed;
let expanded_hash = self.entries[self.expanded_pos].index.1;
self.initiate(Some(expanded_hash), context);
@ -1029,7 +1029,7 @@ impl Component for ThreadView {
self.dirty = true;
return true;
}
UIEvent::Input(Key::Char('h')) => {
UIEvent::Input(ref key) if *key == shortcuts["collapse_subtree"] => {
let current_pos = self.current_pos();
self.entries[current_pos].hidden = !self.entries[current_pos].hidden;
self.entries[current_pos].dirty = true;
@ -1095,43 +1095,9 @@ impl Component for ThreadView {
fn get_shortcuts(&self, context: &Context) -> ShortcutMaps {
let mut map = self.mailview.get_shortcuts(context);
//FIXME
let config_map = context.settings.shortcuts.compact_listing.key_values();
let config_map = context.settings.shortcuts.envelope_view.key_values();
map.insert(
ThreadView::DESCRIPTION,
[
("reverse thread order", Key::Ctrl('r')),
("toggle_mailview", Key::Char('p')),
("toggle_subthread visibility", Key::Char('h')),
(
"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')
},
),
]
.iter()
.cloned()
.collect(),
);
map.insert(ThreadView::DESCRIPTION, config_map);
map
}

9
ui/src/components/utilities.rs

@ -1461,10 +1461,12 @@ impl Component for Tabbed {
self.dirty = false;
return;
}
self.help_curr_views = children_maps;
let mut max_length = 5;
let mut max_width = "Use Up, Down, Left, Right to scroll.".len() + 3;
for (desc, shortcuts) in self.help_curr_views.iter() {
let mut shortcuts = children_maps.iter().collect::<Vec<_>>();
shortcuts.sort_by_key(|(k, _)| *k);
for (desc, shortcuts) in shortcuts.iter() {
max_length += shortcuts.len() + 3;
max_width = std::cmp::max(
max_width,
@ -1500,7 +1502,7 @@ impl Component for Tabbed {
);
}
let mut idx = 0;
for (desc, shortcuts) in self.help_curr_views.iter() {
for (desc, shortcuts) in shortcuts.iter() {
write_string_to_grid(
desc,
&mut self.help_content,
@ -1537,6 +1539,7 @@ impl Component for Tabbed {
}
idx += 1;
}
self.help_curr_views = children_maps;
copy_area(
grid,
&self.help_content,

28
ui/src/conf/shortcuts.rs

@ -4,17 +4,19 @@ use fnv::FnvHashMap;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Shortcuts {
#[serde(flatten)]
#[serde(default)]
pub general: GeneralShortcuts,
#[serde(flatten)]
#[serde(default)]
pub listing: ListingShortcuts,
#[serde(flatten)]
#[serde(default)]
pub composing: ComposingShortcuts,
#[serde(flatten)]
#[serde(default)]
pub compact_listing: CompactListingShortcuts,
#[serde(flatten)]
#[serde(default)]
pub contact_list: ContactListShortcuts,
#[serde(flatten)]
#[serde(default)]
pub envelope_view: EnvelopeViewShortcuts,
#[serde(default)]
pub pager: PagerShortcuts,
}
@ -59,7 +61,7 @@ macro_rules! shortcut_key_values {
}
}
shortcut_key_values! { "compact_listing",
shortcut_key_values! { "compact-listing",
/// Shortcut listing for a mail listing in compact mode.
pub struct CompactListingShortcuts {
open_thread: Key |> "Open thread." |> Key::Char('\n'),
@ -118,3 +120,15 @@ shortcut_key_values! { "composing",
edit_mail: Key |> "Edit mail." |> Key::Char('e')
}
}
shortcut_key_values! { "envelope-view",
pub struct EnvelopeViewShortcuts {
reverse_thread_order: Key |> "reverse thread order" |> Key::Ctrl('r'),
toggle_mailview: Key |> "toggle mail view visibility" |> Key::Char('p'),
toggle_threadview: Key |> "toggle thread view visibility" |> Key::Char('t'),
collapse_subtree: Key |> "collapse thread branches" |> Key::Char('h'),
exit_thread: Key |> "exit thread" |> Key::Char('i'),
prev_page: Key |> "Go to previous page." |> Key::PageUp,
next_page: Key |> "Go to next page." |> Key::PageDown
}
}
Loading…
Cancel
Save