2024-07-12 19:40:46 +02:00
|
|
|
use cosmic::{
|
|
|
|
|
iced::keyboard::Key,
|
|
|
|
|
iced_core::keyboard::key::Named,
|
|
|
|
|
widget::menu::key_bind::{KeyBind, Modifier},
|
|
|
|
|
};
|
2024-03-17 14:49:24 -07:00
|
|
|
use std::collections::HashMap;
|
2024-01-29 12:21:54 -07:00
|
|
|
|
2024-10-03 13:01:59 -06:00
|
|
|
use crate::{app::Action, tab};
|
2024-01-29 12:21:54 -07:00
|
|
|
|
|
|
|
|
//TODO: load from config
|
2024-10-03 13:01:59 -06:00
|
|
|
pub fn key_binds(mode: &tab::Mode) -> HashMap<KeyBind, Action> {
|
2024-01-29 12:21:54 -07:00
|
|
|
let mut key_binds = HashMap::new();
|
|
|
|
|
|
|
|
|
|
macro_rules! bind {
|
2024-02-28 15:19:07 -07:00
|
|
|
([$($modifier:ident),* $(,)?], $key:expr, $action:ident) => {{
|
2024-01-29 12:21:54 -07:00
|
|
|
key_binds.insert(
|
|
|
|
|
KeyBind {
|
2024-02-28 15:19:07 -07:00
|
|
|
modifiers: vec![$(Modifier::$modifier),*],
|
2024-02-09 07:09:51 -07:00
|
|
|
key: $key,
|
2024-01-29 12:21:54 -07:00
|
|
|
},
|
|
|
|
|
Action::$action,
|
|
|
|
|
);
|
|
|
|
|
}};
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-03 13:01:59 -06:00
|
|
|
// Common keys
|
2024-10-02 13:23:41 -06:00
|
|
|
bind!([], Key::Named(Named::Space), Gallery);
|
2024-02-28 16:16:59 -07:00
|
|
|
bind!([], Key::Named(Named::ArrowDown), ItemDown);
|
|
|
|
|
bind!([], Key::Named(Named::ArrowLeft), ItemLeft);
|
|
|
|
|
bind!([], Key::Named(Named::ArrowRight), ItemRight);
|
|
|
|
|
bind!([], Key::Named(Named::ArrowUp), ItemUp);
|
2025-01-14 17:09:44 -07:00
|
|
|
bind!([], Key::Named(Named::Home), SelectFirst);
|
|
|
|
|
bind!([], Key::Named(Named::End), SelectLast);
|
2024-02-28 16:16:59 -07:00
|
|
|
bind!([Shift], Key::Named(Named::ArrowDown), ItemDown);
|
|
|
|
|
bind!([Shift], Key::Named(Named::ArrowLeft), ItemLeft);
|
|
|
|
|
bind!([Shift], Key::Named(Named::ArrowRight), ItemRight);
|
|
|
|
|
bind!([Shift], Key::Named(Named::ArrowUp), ItemUp);
|
2025-01-14 17:09:44 -07:00
|
|
|
bind!([Shift], Key::Named(Named::Home), SelectFirst);
|
|
|
|
|
bind!([Shift], Key::Named(Named::End), SelectLast);
|
2024-08-29 10:12:03 -06:00
|
|
|
bind!([Ctrl, Shift], Key::Character("n".into()), NewFolder);
|
2024-02-28 15:46:23 -07:00
|
|
|
bind!([], Key::Named(Named::Enter), Open);
|
2024-10-02 13:23:41 -06:00
|
|
|
bind!([Ctrl], Key::Named(Named::Space), Preview);
|
2024-02-11 00:24:35 -05:00
|
|
|
bind!([Ctrl], Key::Character("h".into()), ToggleShowHidden);
|
2024-10-03 13:01:59 -06:00
|
|
|
bind!([Ctrl], Key::Character("a".into()), SelectAll);
|
2024-05-28 10:40:36 -06:00
|
|
|
bind!([Ctrl], Key::Character("=".into()), ZoomIn);
|
2024-07-06 11:52:18 +02:00
|
|
|
bind!([Ctrl], Key::Character("+".into()), ZoomIn);
|
2024-05-28 10:40:36 -06:00
|
|
|
bind!([Ctrl], Key::Character("0".into()), ZoomDefault);
|
|
|
|
|
bind!([Ctrl], Key::Character("-".into()), ZoomOut);
|
2025-03-17 20:55:39 +01:00
|
|
|
// Switch view
|
|
|
|
|
bind!([Ctrl], Key::Character("1".into()), TabViewList);
|
|
|
|
|
bind!([Ctrl], Key::Character("2".into()), TabViewGrid);
|
|
|
|
|
|
2024-10-03 13:01:59 -06:00
|
|
|
// App-only keys
|
|
|
|
|
if matches!(mode, tab::Mode::App) {
|
|
|
|
|
bind!([Ctrl], Key::Character("d".into()), AddToSidebar);
|
|
|
|
|
bind!([Ctrl], Key::Named(Named::Enter), OpenInNewTab);
|
|
|
|
|
bind!([Ctrl], Key::Character(",".into()), Settings);
|
|
|
|
|
bind!([Ctrl], Key::Character("w".into()), TabClose);
|
|
|
|
|
bind!([Ctrl], Key::Character("t".into()), TabNew);
|
|
|
|
|
bind!([Ctrl], Key::Named(Named::Tab), TabNext);
|
|
|
|
|
bind!([Ctrl, Shift], Key::Named(Named::Tab), TabPrev);
|
|
|
|
|
bind!([Ctrl], Key::Character("q".into()), WindowClose);
|
|
|
|
|
bind!([Ctrl], Key::Character("n".into()), WindowNew);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// App and desktop only keys
|
|
|
|
|
if matches!(mode, tab::Mode::App | tab::Mode::Desktop) {
|
|
|
|
|
bind!([Ctrl], Key::Character("c".into()), Copy);
|
|
|
|
|
bind!([Ctrl], Key::Character("x".into()), Cut);
|
2025-03-03 13:44:06 -07:00
|
|
|
bind!([], Key::Named(Named::Delete), Delete);
|
2024-10-03 13:01:59 -06:00
|
|
|
bind!([Shift], Key::Named(Named::Enter), OpenInNewWindow);
|
|
|
|
|
bind!([Ctrl], Key::Character("v".into()), Paste);
|
|
|
|
|
bind!([], Key::Named(Named::F2), Rename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// App and dialog only keys
|
|
|
|
|
if matches!(mode, tab::Mode::App | tab::Mode::Dialog(_)) {
|
|
|
|
|
bind!([Ctrl], Key::Character("l".into()), EditLocation);
|
|
|
|
|
bind!([Alt], Key::Named(Named::ArrowRight), HistoryNext);
|
|
|
|
|
bind!([Alt], Key::Named(Named::ArrowLeft), HistoryPrevious);
|
|
|
|
|
bind!([], Key::Named(Named::Backspace), HistoryPrevious);
|
|
|
|
|
bind!([Alt], Key::Named(Named::ArrowUp), LocationUp);
|
|
|
|
|
bind!([Ctrl], Key::Character("f".into()), SearchActivate);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-29 12:21:54 -07:00
|
|
|
key_binds
|
|
|
|
|
}
|