Allow actions to be deserialized from JSON
Introduce separate macro for implementing 'internal' actions which are not intended to be loaded from keymaps.
This commit is contained in:
parent
1778622960
commit
fd4b81c8fc
26 changed files with 559 additions and 335 deletions
|
@ -7,13 +7,14 @@ use gpui::{
|
|||
actions,
|
||||
elements::*,
|
||||
geometry::{rect::RectF, vector::vec2f},
|
||||
impl_actions,
|
||||
impl_actions, impl_internal_actions,
|
||||
keymap::Binding,
|
||||
platform::{CursorStyle, NavigationDirection},
|
||||
AppContext, Entity, MutableAppContext, PromptLevel, Quad, RenderContext, Task, View,
|
||||
ViewContext, ViewHandle, WeakViewHandle,
|
||||
};
|
||||
use project::{ProjectEntryId, ProjectPath};
|
||||
use serde::Deserialize;
|
||||
use settings::Settings;
|
||||
use std::{any::Any, cell::RefCell, cmp, mem, path::Path, rc::Rc};
|
||||
use util::ResultExt;
|
||||
|
@ -28,13 +29,16 @@ actions!(
|
|||
]
|
||||
);
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Deserialize)]
|
||||
pub struct Split(pub SplitDirection);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CloseItem(pub CloseItemParams);
|
||||
pub struct CloseItem {
|
||||
pub item_id: usize,
|
||||
pub pane: WeakViewHandle<Pane>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Deserialize)]
|
||||
pub struct ActivateItem(pub usize);
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -43,13 +47,8 @@ pub struct GoBack(pub Option<WeakViewHandle<Pane>>);
|
|||
#[derive(Clone)]
|
||||
pub struct GoForward(pub Option<WeakViewHandle<Pane>>);
|
||||
|
||||
impl_actions!(pane, [Split, CloseItem, ActivateItem, GoBack, GoForward,]);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CloseItemParams {
|
||||
pub item_id: usize,
|
||||
pub pane: WeakViewHandle<Pane>,
|
||||
}
|
||||
impl_actions!(pane, [Split]);
|
||||
impl_internal_actions!(pane, [CloseItem, ActivateItem, GoBack, GoForward]);
|
||||
|
||||
const MAX_NAVIGATION_HISTORY_LEN: usize = 1024;
|
||||
|
||||
|
@ -66,8 +65,8 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||
cx.add_async_action(Pane::close_active_item);
|
||||
cx.add_async_action(Pane::close_inactive_items);
|
||||
cx.add_async_action(|workspace: &mut Workspace, action: &CloseItem, cx| {
|
||||
let pane = action.0.pane.upgrade(cx)?;
|
||||
Some(Pane::close_item(workspace, pane, action.0.item_id, cx))
|
||||
let pane = action.pane.upgrade(cx)?;
|
||||
Some(Pane::close_item(workspace, pane, action.item_id, cx))
|
||||
});
|
||||
cx.add_action(|pane: &mut Pane, action: &Split, cx| {
|
||||
pane.split(action.0, cx);
|
||||
|
@ -747,10 +746,10 @@ impl Pane {
|
|||
.on_click({
|
||||
let pane = pane.clone();
|
||||
move |cx| {
|
||||
cx.dispatch_action(CloseItem(CloseItemParams {
|
||||
cx.dispatch_action(CloseItem {
|
||||
item_id,
|
||||
pane: pane.clone(),
|
||||
}))
|
||||
})
|
||||
}
|
||||
})
|
||||
.named("close-tab-icon")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue