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>pull/344/head
parent
60f26f9dae
commit
a37d5fc1d1
|
@ -1013,6 +1013,23 @@ exit_entry = 'i'
|
||||||
.\"
|
.\"
|
||||||
.sp
|
.sp
|
||||||
.Pp
|
.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
|
.Em general
|
||||||
.Bl -tag -width 36n
|
.Bl -tag -width 36n
|
||||||
.It Ic toggle_help
|
.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.
|
/// Create a struct holding all of a Component's shortcuts.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! shortcut_key_values {
|
macro_rules! shortcut_key_values {
|
||||||
|
@ -100,6 +106,7 @@ macro_rules! shortcut_key_values {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
#[serde(rename = $cname)]
|
#[serde(rename = $cname)]
|
||||||
pub struct $name {
|
pub struct $name {
|
||||||
|
pub commands: Vec<CommandShortcut>,
|
||||||
$(pub $fname : Key),*
|
$(pub $fname : Key),*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +129,7 @@ macro_rules! shortcut_key_values {
|
||||||
impl Default for $name {
|
impl Default for $name {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
commands : vec![],
|
||||||
$($fname: $default),*
|
$($fname: $default),*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -838,6 +838,23 @@ impl Component for ContactList {
|
||||||
self.movement = Some(PageMovement::End);
|
self.movement = Some(PageMovement::End);
|
||||||
return true;
|
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;
|
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
|
if self.cursor == Cursor::Headers
|
||||||
|
|
|
@ -1960,6 +1960,25 @@ impl Component for Listing {
|
||||||
)));
|
)));
|
||||||
return true;
|
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))))));
|
.push_back(UIEvent::Action(Tab(New(Some(Box::new(new_tab))))));
|
||||||
return true;
|
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
|
false
|
||||||
|
|
|
@ -1103,6 +1103,23 @@ impl Component for ThreadView {
|
||||||
}
|
}
|
||||||
false
|
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
|
if self
|
||||||
.entries
|
.entries
|
||||||
|
|
|
@ -835,6 +835,17 @@ impl Component for Pager {
|
||||||
String::new(),
|
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
|
false
|
||||||
|
|
Loading…
Reference in New Issue