cosmic-files/src/key_bind.rs

56 lines
2.2 KiB
Rust
Raw Normal View History

use cosmic::widget::menu::key_bind::KeyBind;
use cosmic::{iced::keyboard::Key, iced_core::keyboard::key::Named};
use std::collections::HashMap;
2024-01-29 12:21:54 -07:00
2024-02-01 15:14:14 -07:00
use crate::app::Action;
use cosmic::widget::menu::key_bind::Modifier;
2024-01-29 12:21:54 -07:00
//TODO: load from config
pub fn key_binds() -> HashMap<KeyBind, Action> {
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-02-09 07:09:51 -07:00
bind!([Ctrl], Key::Character("c".into()), Copy);
bind!([Ctrl], Key::Character("x".into()), Cut);
2024-02-28 15:19:07 -07:00
bind!([Ctrl], Key::Character("l".into()), EditLocation);
2024-02-09 07:09:51 -07:00
bind!([Alt], Key::Named(Named::ArrowRight), HistoryNext);
bind!([Alt], Key::Named(Named::ArrowLeft), HistoryPrevious);
2024-02-28 16:16:59 -07:00
// Catch arrow keys
bind!([], Key::Named(Named::ArrowDown), ItemDown);
bind!([], Key::Named(Named::ArrowLeft), ItemLeft);
bind!([], Key::Named(Named::ArrowRight), ItemRight);
bind!([], Key::Named(Named::ArrowUp), ItemUp);
// We also need to catch these when shift is held
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);
2024-02-09 07:09:51 -07:00
bind!([Alt], Key::Named(Named::ArrowUp), LocationUp);
2024-02-28 15:25:33 -07:00
bind!([], Key::Named(Named::Delete), MoveToTrash);
2024-02-28 15:27:27 -07:00
bind!([Ctrl, Shift], Key::Character("N".into()), NewFolder);
bind!([], Key::Named(Named::Enter), Open);
2024-02-09 07:09:51 -07:00
bind!([Ctrl], Key::Character("v".into()), Paste);
2024-02-28 15:19:07 -07:00
bind!([], Key::Named(Named::F2), Rename);
2024-02-09 07:09:51 -07:00
bind!([Ctrl], Key::Character("a".into()), SelectAll);
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("h".into()), ToggleShowHidden);
2024-02-09 07:09:51 -07:00
bind!([Ctrl], Key::Character("q".into()), WindowClose);
bind!([Ctrl], Key::Character("n".into()), WindowNew);
2024-01-29 12:21:54 -07:00
key_binds
}