Skip to content

Commit

Permalink
tiles undo and tiles redo
Browse files Browse the repository at this point in the history
  • Loading branch information
xda2023 committed Dec 23, 2024
1 parent 11dbdb1 commit ab767c5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/ui/src/dock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
37 changes: 32 additions & 5 deletions crates/ui/src/dock/tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pixels> = 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);
Expand Down Expand Up @@ -289,6 +305,14 @@ impl Tiles {
None
}

fn undo(&mut self, _: &Undo, cx: &mut ViewContext<Self>) {

Check failure on line 308 in crates/ui/src/dock/tiles.rs

View workflow job for this annotation

GitHub Actions / Test

unused variable: `cx`
eprintln!("tiles undo");
}

fn redo(&mut self, _: &Redo, cx: &mut ViewContext<Self>) {

Check failure on line 312 in crates/ui/src/dock/tiles.rs

View workflow job for this annotation

GitHub Actions / Test

unused variable: `cx`
eprintln!("tiles redo");
}

/// Produce a vector of AnyElement representing the three possible resize handles
fn render_resize_handles(
&mut self,
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ab767c5

Please sign in to comment.