Load workspace and editor key bindings from a JSON file
This commit is contained in:
parent
fd4b81c8fc
commit
3636c9ec25
12 changed files with 326 additions and 293 deletions
|
@ -8,7 +8,6 @@ use gpui::{
|
|||
elements::*,
|
||||
geometry::{rect::RectF, vector::vec2f},
|
||||
impl_actions, impl_internal_actions,
|
||||
keymap::Binding,
|
||||
platform::{CursorStyle, NavigationDirection},
|
||||
AppContext, Entity, MutableAppContext, PromptLevel, Quad, RenderContext, Task, View,
|
||||
ViewContext, ViewHandle, WeakViewHandle,
|
||||
|
@ -41,14 +40,20 @@ pub struct CloseItem {
|
|||
#[derive(Clone, Deserialize)]
|
||||
pub struct ActivateItem(pub usize);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GoBack(pub Option<WeakViewHandle<Pane>>);
|
||||
#[derive(Clone, Deserialize)]
|
||||
pub struct GoBack {
|
||||
#[serde(skip_deserializing)]
|
||||
pub pane: Option<WeakViewHandle<Pane>>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GoForward(pub Option<WeakViewHandle<Pane>>);
|
||||
#[derive(Clone, Deserialize)]
|
||||
pub struct GoForward {
|
||||
#[serde(skip_deserializing)]
|
||||
pub pane: Option<WeakViewHandle<Pane>>,
|
||||
}
|
||||
|
||||
impl_actions!(pane, [Split]);
|
||||
impl_internal_actions!(pane, [CloseItem, ActivateItem, GoBack, GoForward]);
|
||||
impl_actions!(pane, [Split, GoBack, GoForward]);
|
||||
impl_internal_actions!(pane, [CloseItem, ActivateItem]);
|
||||
|
||||
const MAX_NAVIGATION_HISTORY_LEN: usize = 1024;
|
||||
|
||||
|
@ -75,7 +80,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||
Pane::go_back(
|
||||
workspace,
|
||||
action
|
||||
.0
|
||||
.pane
|
||||
.as_ref()
|
||||
.and_then(|weak_handle| weak_handle.upgrade(cx)),
|
||||
cx,
|
||||
|
@ -86,26 +91,13 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||
Pane::go_forward(
|
||||
workspace,
|
||||
action
|
||||
.0
|
||||
.pane
|
||||
.as_ref()
|
||||
.and_then(|weak_handle| weak_handle.upgrade(cx)),
|
||||
cx,
|
||||
)
|
||||
.detach();
|
||||
});
|
||||
|
||||
cx.add_bindings(vec![
|
||||
Binding::new("shift-cmd-{", ActivatePrevItem, Some("Pane")),
|
||||
Binding::new("shift-cmd-}", ActivateNextItem, Some("Pane")),
|
||||
Binding::new("cmd-w", CloseActiveItem, Some("Pane")),
|
||||
Binding::new("alt-cmd-w", CloseInactiveItems, Some("Pane")),
|
||||
Binding::new("cmd-k up", Split(SplitDirection::Up), Some("Pane")),
|
||||
Binding::new("cmd-k down", Split(SplitDirection::Down), Some("Pane")),
|
||||
Binding::new("cmd-k left", Split(SplitDirection::Left), Some("Pane")),
|
||||
Binding::new("cmd-k right", Split(SplitDirection::Right), Some("Pane")),
|
||||
Binding::new("ctrl--", GoBack(None), Some("Pane")),
|
||||
Binding::new("shift-ctrl-_", GoForward(None), Some("Pane")),
|
||||
]);
|
||||
}
|
||||
|
||||
pub enum Event {
|
||||
|
@ -815,8 +807,8 @@ impl View for Pane {
|
|||
.on_navigate_mouse_down(move |direction, cx| {
|
||||
let this = this.clone();
|
||||
match direction {
|
||||
NavigationDirection::Back => cx.dispatch_action(GoBack(Some(this))),
|
||||
NavigationDirection::Forward => cx.dispatch_action(GoForward(Some(this))),
|
||||
NavigationDirection::Back => cx.dispatch_action(GoBack { pane: Some(this) }),
|
||||
NavigationDirection::Forward => cx.dispatch_action(GoForward { pane: Some(this) }),
|
||||
}
|
||||
|
||||
true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue