diff --git a/crates/ui/src/dock/mod.rs b/crates/ui/src/dock/mod.rs index 10348966..d873283a 100644 --- a/crates/ui/src/dock/mod.rs +++ b/crates/ui/src/dock/mod.rs @@ -23,6 +23,7 @@ pub use tab_panel::*; pub use tiles::*; pub fn init(cx: &mut AppContext) { + tiles::init(cx); cx.set_global(PanelRegistry::new()); } diff --git a/crates/ui/src/dock/tiles.rs b/crates/ui/src/dock/tiles.rs index ead8e0d1..1e36dba3 100644 --- a/crates/ui/src/dock/tiles.rs +++ b/crates/ui/src/dock/tiles.rs @@ -14,16 +14,32 @@ use crate::{ use super::{DockArea, Panel, PanelEvent, PanelInfo, PanelState, PanelView, TabPanel, TileMeta}; use gpui::{ - canvas, div, point, px, size, AnyElement, AppContext, Bounds, DismissEvent, DragMoveEvent, - Entity, EntityId, EventEmitter, FocusHandle, FocusableView, Half, InteractiveElement, - IntoElement, MouseButton, MouseDownEvent, MouseUpEvent, ParentElement, Pixels, Point, Render, - ScrollHandle, Size, StatefulInteractiveElement, Styled, ViewContext, VisualContext, WeakView, - WindowContext, + actions, canvas, div, point, px, size, AnyElement, AppContext, Bounds, DismissEvent, + DragMoveEvent, Entity, EntityId, EventEmitter, FocusHandle, FocusableView, Half, + InteractiveElement, IntoElement, KeyBinding, MouseButton, MouseDownEvent, MouseUpEvent, + ParentElement, Pixels, Point, Render, ScrollHandle, Size, StatefulInteractiveElement, Styled, + ViewContext, VisualContext, WeakView, WindowContext, }; +actions!(tiles, [Undo, Redo,]); + const MINIMUM_SIZE: Size = size(px(100.), px(100.)); const DRAG_BAR_HEIGHT: Pixels = px(30.); const HANDLE_SIZE: Pixels = px(20.0); +const CONTEXT: &str = "Tiles"; + +pub fn init(cx: &mut AppContext) { + cx.bind_keys([ + #[cfg(target_os = "macos")] + KeyBinding::new("cmd-z", Undo, Some(CONTEXT)), + #[cfg(target_os = "macos")] + KeyBinding::new("cmd-shift-z", Redo, Some(CONTEXT)), + #[cfg(not(target_os = "macos"))] + KeyBinding::new("ctrl-z", Undo, Some(CONTEXT)), + #[cfg(not(target_os = "macos"))] + KeyBinding::new("ctrl-y", Redo, Some(CONTEXT)), + ]); +} #[derive(Clone, Render)] pub struct DragMoving(EntityId); @@ -289,6 +305,14 @@ impl Tiles { None } + fn undo(&mut self, _: &Undo, cx: &mut ViewContext) { + eprintln!("tiles undo"); + } + + fn redo(&mut self, _: &Redo, cx: &mut ViewContext) { + eprintln!("tiles redo"); + } + /// Produce a vector of AnyElement representing the three possible resize handles fn render_resize_handles( &mut self, @@ -641,6 +665,9 @@ impl Render for Tiles { div() .relative() + .key_context(CONTEXT) + .on_action(cx.listener(Self::undo)) + .on_action(cx.listener(Self::redo)) .bg(cx.theme().background) .child( div()