Minor improvements to dock visuals, rework dock keybindings, and fix panic on split when dock is active
This commit is contained in:
parent
29f46539f0
commit
1ce48f4a94
8 changed files with 165 additions and 110 deletions
|
@ -1,8 +1,8 @@
|
|||
use collections::HashMap;
|
||||
use gpui::{
|
||||
actions,
|
||||
elements::{ChildView, Container, Empty, Margin, MouseEventHandler, Side, Svg},
|
||||
impl_internal_actions, CursorStyle, Element, ElementBox, Entity, MouseButton,
|
||||
elements::{ChildView, Container, Empty, MouseEventHandler, Side, Svg},
|
||||
impl_internal_actions, Border, CursorStyle, Element, ElementBox, Entity, MouseButton,
|
||||
MutableAppContext, RenderContext, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
@ -17,13 +17,37 @@ pub struct MoveDock(pub DockAnchor);
|
|||
#[derive(PartialEq, Clone)]
|
||||
pub struct AddDefaultItemToDock;
|
||||
|
||||
actions!(workspace, [ToggleDock, ActivateOrHideDock]);
|
||||
impl_internal_actions!(workspace, [MoveDock, AddDefaultItemToDock]);
|
||||
actions!(
|
||||
dock,
|
||||
[
|
||||
FocusDock,
|
||||
HideDock,
|
||||
AnchorDockRight,
|
||||
AnchorDockBottom,
|
||||
ExpandDock
|
||||
]
|
||||
);
|
||||
impl_internal_actions!(dock, [MoveDock, AddDefaultItemToDock]);
|
||||
|
||||
pub fn init(cx: &mut MutableAppContext) {
|
||||
cx.add_action(Dock::toggle);
|
||||
cx.add_action(Dock::activate_or_hide_dock);
|
||||
cx.add_action(Dock::focus_dock);
|
||||
cx.add_action(Dock::hide_dock);
|
||||
cx.add_action(Dock::move_dock);
|
||||
cx.add_action(
|
||||
|workspace: &mut Workspace, _: &AnchorDockRight, cx: &mut ViewContext<Workspace>| {
|
||||
Dock::move_dock(workspace, &MoveDock(DockAnchor::Right), cx)
|
||||
},
|
||||
);
|
||||
cx.add_action(
|
||||
|workspace: &mut Workspace, _: &AnchorDockBottom, cx: &mut ViewContext<Workspace>| {
|
||||
Dock::move_dock(workspace, &MoveDock(DockAnchor::Bottom), cx)
|
||||
},
|
||||
);
|
||||
cx.add_action(
|
||||
|workspace: &mut Workspace, _: &ExpandDock, cx: &mut ViewContext<Workspace>| {
|
||||
Dock::move_dock(workspace, &MoveDock(DockAnchor::Expanded), cx)
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
|
@ -60,13 +84,6 @@ impl DockPosition {
|
|||
}
|
||||
}
|
||||
|
||||
fn toggle(self) -> Self {
|
||||
match self {
|
||||
DockPosition::Shown(anchor) => DockPosition::Hidden(anchor),
|
||||
DockPosition::Hidden(anchor) => DockPosition::Shown(anchor),
|
||||
}
|
||||
}
|
||||
|
||||
fn hide(self) -> Self {
|
||||
match self {
|
||||
DockPosition::Shown(anchor) => DockPosition::Hidden(anchor),
|
||||
|
@ -130,10 +147,6 @@ impl Dock {
|
|||
new_position: DockPosition,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
if workspace.dock.position == new_position {
|
||||
return;
|
||||
}
|
||||
|
||||
workspace.dock.position = new_position;
|
||||
// Tell the pane about the new anchor position
|
||||
workspace.dock.pane.update(cx, |pane, cx| {
|
||||
|
@ -184,22 +197,12 @@ impl Dock {
|
|||
}
|
||||
}
|
||||
|
||||
fn toggle(workspace: &mut Workspace, _: &ToggleDock, cx: &mut ViewContext<Workspace>) {
|
||||
Self::set_dock_position(workspace, workspace.dock.position.toggle(), cx);
|
||||
fn focus_dock(workspace: &mut Workspace, _: &FocusDock, cx: &mut ViewContext<Workspace>) {
|
||||
Self::set_dock_position(workspace, workspace.dock.position.show(), cx);
|
||||
}
|
||||
|
||||
fn activate_or_hide_dock(
|
||||
workspace: &mut Workspace,
|
||||
_: &ActivateOrHideDock,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
let dock_pane = workspace.dock_pane().clone();
|
||||
if dock_pane.read(cx).is_active() {
|
||||
Self::hide(workspace, cx);
|
||||
} else {
|
||||
Self::show(workspace, cx);
|
||||
cx.focus(dock_pane);
|
||||
}
|
||||
fn hide_dock(workspace: &mut Workspace, _: &HideDock, cx: &mut ViewContext<Workspace>) {
|
||||
Self::set_dock_position(workspace, workspace.dock.position.hide(), cx);
|
||||
}
|
||||
|
||||
fn move_dock(
|
||||
|
@ -226,16 +229,22 @@ impl Dock {
|
|||
DockAnchor::Bottom | DockAnchor::Right => {
|
||||
let mut panel_style = style.panel.clone();
|
||||
let (resize_side, initial_size) = if anchor == DockAnchor::Bottom {
|
||||
panel_style.margin = Margin {
|
||||
top: panel_style.margin.top,
|
||||
..Default::default()
|
||||
panel_style.border = Border {
|
||||
top: true,
|
||||
bottom: false,
|
||||
left: false,
|
||||
right: false,
|
||||
..panel_style.border
|
||||
};
|
||||
|
||||
(Side::Top, style.initial_size_bottom)
|
||||
} else {
|
||||
panel_style.margin = Margin {
|
||||
left: panel_style.margin.left,
|
||||
..Default::default()
|
||||
panel_style.border = Border {
|
||||
top: false,
|
||||
bottom: false,
|
||||
left: true,
|
||||
right: false,
|
||||
..panel_style.border
|
||||
};
|
||||
(Side::Left, style.initial_size_right)
|
||||
};
|
||||
|
@ -265,7 +274,7 @@ impl Dock {
|
|||
}
|
||||
});
|
||||
|
||||
resizable.flex(style.flex, false).boxed()
|
||||
resizable.flex(5., false).boxed()
|
||||
}
|
||||
DockAnchor::Expanded => {
|
||||
enum ExpandedDockWash {}
|
||||
|
@ -282,7 +291,7 @@ impl Dock {
|
|||
})
|
||||
.capture_all()
|
||||
.on_down(MouseButton::Left, |_, cx| {
|
||||
cx.dispatch_action(ToggleDock);
|
||||
cx.dispatch_action(HideDock);
|
||||
})
|
||||
.with_cursor_style(CursorStyle::Arrow)
|
||||
.boxed(),
|
||||
|
@ -328,7 +337,7 @@ impl View for ToggleDockButton {
|
|||
let dock_position = workspace.unwrap().read(cx).dock.position;
|
||||
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
MouseEventHandler::<Self>::new(0, cx, {
|
||||
let button = MouseEventHandler::<Self>::new(0, cx, {
|
||||
let theme = theme.clone();
|
||||
move |state, _| {
|
||||
let style = theme
|
||||
|
@ -348,17 +357,33 @@ impl View for ToggleDockButton {
|
|||
.boxed()
|
||||
}
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, |_, cx| {
|
||||
cx.dispatch_action(ToggleDock);
|
||||
})
|
||||
.with_tooltip::<Self, _>(
|
||||
0,
|
||||
"Toggle Dock".to_string(),
|
||||
Some(Box::new(ToggleDock)),
|
||||
theme.tooltip.clone(),
|
||||
cx,
|
||||
)
|
||||
.with_cursor_style(CursorStyle::PointingHand);
|
||||
|
||||
if dock_position.is_visible() {
|
||||
button
|
||||
.on_click(MouseButton::Left, |_, cx| {
|
||||
cx.dispatch_action(HideDock);
|
||||
})
|
||||
.with_tooltip::<Self, _>(
|
||||
0,
|
||||
"Hide Dock".into(),
|
||||
Some(Box::new(HideDock)),
|
||||
theme.tooltip.clone(),
|
||||
cx,
|
||||
)
|
||||
} else {
|
||||
button
|
||||
.on_click(MouseButton::Left, |_, cx| {
|
||||
cx.dispatch_action(FocusDock);
|
||||
})
|
||||
.with_tooltip::<Self, _>(
|
||||
0,
|
||||
"Focus Dock".into(),
|
||||
Some(Box::new(FocusDock)),
|
||||
theme.tooltip.clone(),
|
||||
cx,
|
||||
)
|
||||
}
|
||||
.boxed()
|
||||
}
|
||||
}
|
||||
|
@ -478,7 +503,7 @@ mod tests {
|
|||
|
||||
cx.move_dock(DockAnchor::Right);
|
||||
cx.assert_dock_pane_active();
|
||||
cx.toggle_dock();
|
||||
cx.hide_dock();
|
||||
cx.move_dock(DockAnchor::Right);
|
||||
cx.assert_dock_pane_active();
|
||||
}
|
||||
|
@ -600,8 +625,8 @@ mod tests {
|
|||
self.cx.dispatch_action(self.window_id, MoveDock(anchor));
|
||||
}
|
||||
|
||||
pub fn toggle_dock(&self) {
|
||||
self.cx.dispatch_action(self.window_id, ToggleDock);
|
||||
pub fn hide_dock(&self) {
|
||||
self.cx.dispatch_action(self.window_id, HideDock);
|
||||
}
|
||||
|
||||
pub fn open_sidebar(&mut self, sidebar_side: SidebarSide) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue