Skip to content

Commit 60c698e

Browse files
authored
Merge pull request #236 from ChisomUma/master
feat: Assigning hotkeys to actions and quicklinks
2 parents ae576e0 + 1e63910 commit 60c698e

5 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/app/tile.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ pub struct Tile {
179179
pub struct Hotkeys {
180180
pub toggle: HotKey,
181181
pub clipboard_hotkey: HotKey,
182+
pub shells: HashMap<u32, String>,
182183
}
183184

184185
impl Tile {

src/app/tile/elm.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,22 @@ pub fn new(hotkey: HotKey, config: &Config) -> (Tile, Task<Message>) {
6060
options.par_sort_by_key(|x| x.display_name.len());
6161
let options = AppIndex::from_apps(options);
6262

63+
let mut shells_map = HashMap::new();
64+
for shell in &config.shells {
65+
if let Some(hk_str) = &shell.hotkey
66+
&& let Ok(hk) = hk_str.parse::<HotKey>()
67+
{
68+
shells_map.insert(hk.id, shell.command.clone());
69+
}
70+
}
71+
6372
let hotkeys = Hotkeys {
6473
toggle: hotkey,
6574
clipboard_hotkey: config
6675
.clipboard_hotkey
6776
.parse()
6877
.unwrap_or("SUPER+SHIFT+C".parse().unwrap()),
78+
shells: shells_map,
6979
};
7080

7181
let home = std::env::var("HOME").unwrap_or("/".to_string());

src/app/tile/update.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
284284
}
285285

286286
Message::KeyPressed(hk_id) => {
287+
if let Some(cmd) = tile.hotkeys.shells.get(&hk_id) {
288+
return Task::done(Message::RunFunction(Function::RunShellCommand(cmd.clone())));
289+
}
290+
287291
let is_clipboard_hotkey = tile.hotkeys.clipboard_hotkey.id == hk_id;
288292
let is_open_hotkey = hk_id == tile.hotkeys.toggle.id;
289293

src/config.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,11 @@ impl Default for Buffer {
180180
/// Alias is the text that is used to call this command / search for it
181181
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
182182
pub struct Shelly {
183-
command: String,
184-
icon_path: Option<String>,
185-
alias: String,
186-
alias_lc: String,
183+
pub command: String,
184+
pub icon_path: Option<String>,
185+
pub alias: String,
186+
pub alias_lc: String,
187+
pub hotkey: Option<String>,
187188
}
188189

189190
impl ToApp for Shelly {

src/main.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,18 @@ fn main() -> iced::Result {
7676
.parse()
7777
.unwrap_or("SUPER+SHIFT+C".parse().unwrap());
7878

79-
let hotkeys = vec![show_hide, cbhist];
79+
let mut hotkeys = vec![show_hide, cbhist];
80+
for shell in &config.shells {
81+
if let Some(hk_str) = &shell.hotkey
82+
&& let Ok(hk) = hk_str.parse::<HotKey>()
83+
{
84+
hotkeys.push(hk);
85+
}
86+
}
8087

8188
manager
8289
.register_all(&hotkeys)
83-
.expect("Unable to register hotkey");
90+
.expect("Unable to register hotkeys");
8491

8592
info!("Hotkeys loaded");
8693
info!("Starting rustcast");

0 commit comments

Comments
 (0)