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
|
@ -1,18 +1,4 @@
|
|||
use gpui::{actions, keymap::Binding, MutableAppContext};
|
||||
|
||||
actions!(
|
||||
gpui::actions!(
|
||||
menu,
|
||||
[Confirm, SelectPrev, SelectNext, SelectFirst, SelectLast,]
|
||||
[Confirm, SelectPrev, SelectNext, SelectFirst, SelectLast]
|
||||
);
|
||||
|
||||
pub fn init(cx: &mut MutableAppContext) {
|
||||
cx.add_bindings([
|
||||
Binding::new("up", SelectPrev, Some("menu")),
|
||||
Binding::new("ctrl-p", SelectPrev, Some("menu")),
|
||||
Binding::new("down", SelectNext, Some("menu")),
|
||||
Binding::new("ctrl-n", SelectNext, Some("menu")),
|
||||
Binding::new("cmd-up", SelectFirst, Some("menu")),
|
||||
Binding::new("cmd-down", SelectLast, Some("menu")),
|
||||
Binding::new("enter", Confirm, Some("menu")),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -256,7 +256,6 @@ impl PaneAxis {
|
|||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum SplitDirection {
|
||||
Up,
|
||||
Down,
|
||||
|
|
|
@ -19,7 +19,6 @@ use gpui::{
|
|||
geometry::{rect::RectF, vector::vec2f, PathBuilder},
|
||||
impl_internal_actions,
|
||||
json::{self, to_string_pretty, ToJson},
|
||||
keymap::Binding,
|
||||
platform::{CursorStyle, WindowOptions},
|
||||
AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, Border, ClipboardItem, Entity,
|
||||
ImageData, ModelHandle, MutableAppContext, PathPromptOptions, PromptLevel, RenderContext, Task,
|
||||
|
@ -32,7 +31,7 @@ pub use pane_group::*;
|
|||
use postage::prelude::Stream;
|
||||
use project::{fs, Fs, Project, ProjectEntryId, ProjectPath, Worktree};
|
||||
use settings::Settings;
|
||||
use sidebar::{Side, Sidebar, SidebarItemId, ToggleSidebarItem, ToggleSidebarItemFocus};
|
||||
use sidebar::{Side, Sidebar, ToggleSidebarItem, ToggleSidebarItemFocus};
|
||||
use status_bar::StatusBar;
|
||||
pub use status_bar::StatusItemView;
|
||||
use std::{
|
||||
|
@ -108,7 +107,6 @@ impl_internal_actions!(
|
|||
|
||||
pub fn init(client: &Arc<Client>, cx: &mut MutableAppContext) {
|
||||
pane::init(cx);
|
||||
menu::init(cx);
|
||||
|
||||
cx.add_global_action(open);
|
||||
cx.add_global_action(move |action: &OpenPaths, cx: &mut MutableAppContext| {
|
||||
|
@ -144,29 +142,6 @@ pub fn init(client: &Arc<Client>, cx: &mut MutableAppContext) {
|
|||
cx.add_action(|workspace: &mut Workspace, _: &ActivateNextPane, cx| {
|
||||
workspace.activate_next_pane(cx)
|
||||
});
|
||||
cx.add_bindings(vec![
|
||||
Binding::new("ctrl-alt-cmd-f", FollowNextCollaborator, None),
|
||||
Binding::new("cmd-s", Save, None),
|
||||
Binding::new("cmd-alt-i", DebugElements, None),
|
||||
Binding::new("cmd-k cmd-left", ActivatePreviousPane, None),
|
||||
Binding::new("cmd-k cmd-right", ActivateNextPane, None),
|
||||
Binding::new(
|
||||
"cmd-shift-!",
|
||||
ToggleSidebarItem(SidebarItemId {
|
||||
side: Side::Left,
|
||||
item_index: 0,
|
||||
}),
|
||||
None,
|
||||
),
|
||||
Binding::new(
|
||||
"cmd-1",
|
||||
ToggleSidebarItemFocus(SidebarItemId {
|
||||
side: Side::Left,
|
||||
item_index: 0,
|
||||
}),
|
||||
None,
|
||||
),
|
||||
]);
|
||||
|
||||
client.add_view_request_handler(Workspace::handle_follow);
|
||||
client.add_view_message_handler(Workspace::handle_unfollow);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue