conf/shortcuts: implement a key to command mapping
Permits users to map keys in their configuration file to an array of meli commands e.g: [shortcuts.listing] commands = [ { command = [ "tag remove trash", "flag unset trash" ], shortcut = "D" }, { command = [ "tag add trash", "flag set trash" ], shortcut = "d" } ] Signed-off-by: Guillaume Ranquet <granquet@baylibre.com>
This commit is contained in:
parent
60f26f9dae
commit
a37d5fc1d1
9 changed files with 140 additions and 0 deletions
|
@ -1013,6 +1013,23 @@ exit_entry = 'i'
|
|||
.\"
|
||||
.sp
|
||||
.Pp
|
||||
.Em commands
|
||||
.sp
|
||||
In addition, each shortcuts section supports a TOML array of commands to associate a key to an array of meli
|
||||
.Em COMMAND
|
||||
.sp
|
||||
.\"
|
||||
.\"
|
||||
.\"
|
||||
.Bd -literal
|
||||
[shortcuts.listing]
|
||||
commands = [ { command = [ "tag remove trash", "flag unset trash" ], shortcut = "D" },
|
||||
{ command = [ "tag add trash", "flag set trash" ], shortcut = "d" } ]
|
||||
.Ed
|
||||
.\"
|
||||
.\"
|
||||
.\"
|
||||
.Pp
|
||||
.Em general
|
||||
.Bl -tag -width 36n
|
||||
.It Ic toggle_help
|
||||
|
|
|
@ -88,6 +88,12 @@ impl DotAddressable for Shortcuts {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct CommandShortcut {
|
||||
pub shortcut: Key,
|
||||
pub command: Vec<String>,
|
||||
}
|
||||
|
||||
/// Create a struct holding all of a Component's shortcuts.
|
||||
#[macro_export]
|
||||
macro_rules! shortcut_key_values {
|
||||
|
@ -100,6 +106,7 @@ macro_rules! shortcut_key_values {
|
|||
#[serde(default)]
|
||||
#[serde(rename = $cname)]
|
||||
pub struct $name {
|
||||
pub commands: Vec<CommandShortcut>,
|
||||
$(pub $fname : Key),*
|
||||
}
|
||||
|
||||
|
@ -122,6 +129,7 @@ macro_rules! shortcut_key_values {
|
|||
impl Default for $name {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
commands : vec![],
|
||||
$($fname: $default),*
|
||||
}
|
||||
}
|
||||
|
|
|
@ -838,6 +838,23 @@ impl Component for ContactList {
|
|||
self.movement = Some(PageMovement::End);
|
||||
return true;
|
||||
}
|
||||
UIEvent::Input(ref key) => {
|
||||
return context
|
||||
.settings
|
||||
.shortcuts
|
||||
.contact_list
|
||||
.commands
|
||||
.iter()
|
||||
.any(|cmd| {
|
||||
if cmd.shortcut == *key {
|
||||
for cmd in &cmd.command {
|
||||
context.replies.push_back(UIEvent::Command(cmd.to_string()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
false
|
||||
})
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1132,6 +1132,23 @@ impl Component for Composer {
|
|||
};
|
||||
return true;
|
||||
}
|
||||
UIEvent::Input(ref key) => {
|
||||
return context
|
||||
.settings
|
||||
.shortcuts
|
||||
.composing
|
||||
.commands
|
||||
.iter()
|
||||
.any(|cmd| {
|
||||
if cmd.shortcut == *key {
|
||||
for cmd in &cmd.command {
|
||||
context.replies.push_back(UIEvent::Command(cmd.to_string()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
false
|
||||
})
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if self.cursor == Cursor::Headers
|
||||
|
|
|
@ -1960,6 +1960,25 @@ impl Component for Listing {
|
|||
)));
|
||||
return true;
|
||||
}
|
||||
UIEvent::Input(ref key) => {
|
||||
return context
|
||||
.settings
|
||||
.shortcuts
|
||||
.listing
|
||||
.commands
|
||||
.iter()
|
||||
.any(|cmd| {
|
||||
if cmd.shortcut == *key {
|
||||
for cmd in &cmd.command {
|
||||
context
|
||||
.replies
|
||||
.push_back(UIEvent::Command(cmd.to_string()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
false
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1415,6 +1415,23 @@ impl Component for ConversationsListing {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
UIEvent::Input(ref key) => {
|
||||
return context
|
||||
.settings
|
||||
.shortcuts
|
||||
.listing
|
||||
.commands
|
||||
.iter()
|
||||
.any(|cmd| {
|
||||
if cmd.shortcut == *key {
|
||||
for cmd in &cmd.command {
|
||||
context.replies.push_back(UIEvent::Command(cmd.to_string()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
false
|
||||
})
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -789,6 +789,23 @@ impl Component for MailView {
|
|||
.push_back(UIEvent::Action(Tab(New(Some(Box::new(new_tab))))));
|
||||
return true;
|
||||
}
|
||||
UIEvent::Input(ref key) => {
|
||||
return context
|
||||
.settings
|
||||
.shortcuts
|
||||
.envelope_view
|
||||
.commands
|
||||
.iter()
|
||||
.any(|cmd| {
|
||||
if cmd.shortcut == *key {
|
||||
for cmd in &cmd.command {
|
||||
context.replies.push_back(UIEvent::Command(cmd.to_string()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
false
|
||||
})
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
false
|
||||
|
|
|
@ -1103,6 +1103,23 @@ impl Component for ThreadView {
|
|||
}
|
||||
false
|
||||
}
|
||||
UIEvent::Input(ref key) => {
|
||||
return context
|
||||
.settings
|
||||
.shortcuts
|
||||
.thread_view
|
||||
.commands
|
||||
.iter()
|
||||
.any(|cmd| {
|
||||
if cmd.shortcut == *key {
|
||||
for cmd in &cmd.command {
|
||||
context.replies.push_back(UIEvent::Command(cmd.to_string()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
false
|
||||
})
|
||||
}
|
||||
_ => {
|
||||
if self
|
||||
.entries
|
||||
|
|
|
@ -835,6 +835,17 @@ impl Component for Pager {
|
|||
String::new(),
|
||||
)));
|
||||
}
|
||||
UIEvent::Input(ref key) => {
|
||||
return context.settings.shortcuts.pager.commands.iter().any(|cmd| {
|
||||
if cmd.shortcut == *key {
|
||||
for cmd in &cmd.command {
|
||||
context.replies.push_back(UIEvent::Command(cmd.to_string()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
false
|
||||
})
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
false
|
||||
|
|
Loading…
Add table
Reference in a new issue