Fix incorrect rendering of toolbar in right anchored dock

Make dock keybinding activate the dock if it wasn't hidden, and hide it if it was already active
Make clicking the expanded dock wash, hide the dock
Fix some issues with programmatically activating other panes, not hiding the dock
Tweak dock anchor menu text
Swap dock hide button for thin variant
Fix dock sidebar interactions
Add clicked state to search button and fix presenter issue sending clicked events when mouse not overlapping MouseRegion

Co-Authored-By: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
K Simmons 2022-09-13 15:17:27 -07:00
parent 3c88aa3d18
commit 0b5952e1bd
10 changed files with 134 additions and 131 deletions

View file

@ -17,15 +17,16 @@ pub struct MoveDock(pub DockAnchor);
#[derive(PartialEq, Clone)]
pub struct AddDefaultItemToDock;
actions!(workspace, [ToggleDock]);
actions!(workspace, [ToggleDock, ActivateOrHideDock]);
impl_internal_actions!(workspace, [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::move_dock);
}
#[derive(Copy, Clone)]
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum DockPosition {
Shown(DockAnchor),
Hidden(DockAnchor),
@ -72,6 +73,13 @@ impl DockPosition {
DockPosition::Hidden(_) => self,
}
}
fn show(self) -> Self {
match self {
DockPosition::Hidden(anchor) => DockPosition::Shown(anchor),
DockPosition::Shown(_) => self,
}
}
}
pub type DefaultItemFactory =
@ -88,6 +96,9 @@ impl Dock {
pub fn new(cx: &mut ViewContext<Workspace>, default_item_factory: DefaultItemFactory) -> Self {
let anchor = cx.global::<Settings>().default_dock_anchor;
let pane = cx.add_view(|cx| Pane::new(Some(anchor), cx));
pane.update(cx, |pane, cx| {
pane.set_active(false, cx);
});
let pane_id = pane.id();
cx.subscribe(&pane, move |workspace, _, event, cx| {
workspace.handle_pane_event(pane_id, event, cx);
@ -119,6 +130,10 @@ 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| {
@ -139,7 +154,6 @@ impl Dock {
let item_to_add = (workspace.dock.default_item_factory)(workspace, cx);
Pane::add_item(workspace, &pane, item_to_add, true, true, None, cx);
}
cx.focus(pane);
} else if let Some(last_active_center_pane) = workspace.last_active_center_pane.clone() {
cx.focus(last_active_center_pane);
}
@ -151,10 +165,40 @@ impl Dock {
Self::set_dock_position(workspace, workspace.dock.position.hide(), cx);
}
pub fn show(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
Self::set_dock_position(workspace, workspace.dock.position.show(), cx);
}
pub fn hide_on_sidebar_shown(
workspace: &mut Workspace,
sidebar_side: SidebarSide,
cx: &mut ViewContext<Workspace>,
) {
if (sidebar_side == SidebarSide::Right && workspace.dock.is_anchored_at(DockAnchor::Right))
|| workspace.dock.is_anchored_at(DockAnchor::Expanded)
{
Self::hide(workspace, cx);
}
}
fn toggle(workspace: &mut Workspace, _: &ToggleDock, cx: &mut ViewContext<Workspace>) {
Self::set_dock_position(workspace, workspace.dock.position.toggle(), 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 move_dock(
workspace: &mut Workspace,
&MoveDock(new_anchor): &MoveDock,
@ -178,18 +222,19 @@ impl Dock {
.map(|anchor| match anchor {
DockAnchor::Bottom | DockAnchor::Right => {
let mut panel_style = style.panel.clone();
let resize_side = if anchor == DockAnchor::Bottom {
let (resize_side, initial_size) = if anchor == DockAnchor::Bottom {
panel_style.margin = Margin {
top: panel_style.margin.top,
..Default::default()
};
Side::Top
(Side::Top, style.initial_size_bottom)
} else {
panel_style.margin = Margin {
left: panel_style.margin.left,
..Default::default()
};
Side::Left
(Side::Left, style.initial_size_right)
};
enum DockResizeHandle {}
@ -200,7 +245,10 @@ impl Dock {
resize_side as usize,
resize_side,
4.,
self.panel_sizes.get(&anchor).copied().unwrap_or(200.),
self.panel_sizes
.get(&anchor)
.copied()
.unwrap_or(initial_size),
cx,
);
@ -216,18 +264,29 @@ impl Dock {
resizable.flex(style.flex, false).boxed()
}
DockAnchor::Expanded => Container::new(
MouseEventHandler::<Dock>::new(0, cx, |_state, _cx| {
Container::new(ChildView::new(self.pane.clone()).boxed())
DockAnchor::Expanded => {
enum ExpandedDockWash {}
enum ExpandedDockPane {}
Container::new(
MouseEventHandler::<ExpandedDockWash>::new(0, cx, |_state, cx| {
MouseEventHandler::<ExpandedDockPane>::new(0, cx, |_state, _cx| {
ChildView::new(self.pane.clone()).boxed()
})
.capture_all()
.contained()
.with_style(style.maximized)
.boxed()
})
.capture_all()
.with_cursor_style(CursorStyle::Arrow)
.boxed(),
)
.with_background_color(style.wash_color)
.boxed(),
})
.capture_all()
.on_down(MouseButton::Left, |_, cx| {
cx.dispatch_action(ToggleDock);
})
.with_cursor_style(CursorStyle::Arrow)
.boxed(),
)
.with_background_color(style.wash_color)
.boxed()
}
})
}
}

View file

@ -279,6 +279,10 @@ impl Pane {
}
}
pub fn is_active(&self) -> bool {
self.is_active
}
pub fn set_active(&mut self, is_active: bool, cx: &mut ViewContext<Self>) {
self.is_active = is_active;
cx.notify();
@ -1010,9 +1014,9 @@ impl Pane {
action.position,
AnchorCorner::TopRight,
vec![
ContextMenuItem::item("Move Dock Right", MoveDock(DockAnchor::Right)),
ContextMenuItem::item("Move Dock Bottom", MoveDock(DockAnchor::Bottom)),
ContextMenuItem::item("Move Dock Maximized", MoveDock(DockAnchor::Expanded)),
ContextMenuItem::item("Anchor Dock Right", MoveDock(DockAnchor::Right)),
ContextMenuItem::item("Anchor Dock Bottom", MoveDock(DockAnchor::Bottom)),
ContextMenuItem::item("Expand Dock", MoveDock(DockAnchor::Expanded)),
],
cx,
);
@ -1407,9 +1411,12 @@ impl View for Pane {
)
// Add the close dock button if this pane is a dock
.with_children(self.docked.map(|_| {
tab_bar_button(3, "icons/x_mark_12.svg", cx, |_| {
ToggleDock
})
tab_bar_button(
3,
"icons/x_mark_thin_8.svg",
cx,
|_| ToggleDock,
)
}))
.contained()
.with_style(theme.workspace.tab_bar.container)
@ -1426,7 +1433,7 @@ impl View for Pane {
.flex(1., false)
.named("tab bar")
})
.with_child(ChildView::new(&self.toolbar).boxed())
.with_child(ChildView::new(&self.toolbar).expanded().boxed())
.with_child(ChildView::new(active_item).flex(1., true).boxed())
.boxed()
} else {

View file

@ -957,7 +957,6 @@ impl Workspace {
.detach();
let center_pane = cx.add_view(|cx| Pane::new(None, cx));
dbg!(&center_pane);
let pane_id = center_pane.id();
cx.subscribe(&center_pane, move |this, _, event, cx| {
this.handle_pane_event(pane_id, event, cx)
@ -993,7 +992,6 @@ impl Workspace {
let dock = Dock::new(cx, dock_default_factory);
let dock_pane = dock.pane().clone();
dbg!(&dock_pane);
let left_sidebar = cx.add_view(|_| Sidebar::new(SidebarSide::Left));
let right_sidebar = cx.add_view(|_| Sidebar::new(SidebarSide::Right));
@ -1490,9 +1488,9 @@ impl Workspace {
sidebar.set_open(open, cx);
open
});
if open && sidebar_side == SidebarSide::Right && self.dock.is_anchored_at(DockAnchor::Right)
{
Dock::hide(self, cx);
if open {
Dock::hide_on_sidebar_shown(self, sidebar_side, cx);
}
cx.focus_self();
@ -1516,13 +1514,7 @@ impl Workspace {
});
if let Some(active_item) = active_item {
// If there is an active item, that means the sidebar was opened,
// which means we need to check if the dock is open and close it
if action.sidebar_side == SidebarSide::Right
&& self.dock.is_anchored_at(DockAnchor::Right)
{
Dock::hide(self, cx);
}
Dock::hide_on_sidebar_shown(self, action.sidebar_side, cx);
if active_item.is_focused(cx) {
cx.focus_self();
@ -1551,11 +1543,7 @@ impl Workspace {
sidebar.active_item().cloned()
});
if let Some(active_item) = active_item {
// If there is an active item, that means the sidebar was opened,
// which means we need to check if the dock is open and close it
if sidebar_side == SidebarSide::Right && self.dock.is_anchored_at(DockAnchor::Right) {
Dock::hide(self, cx);
}
Dock::hide_on_sidebar_shown(self, sidebar_side, cx);
if active_item.is_focused(cx) {
cx.focus_self();
@ -1726,8 +1714,13 @@ impl Workspace {
});
self.active_item_path_changed(cx);
if &pane != self.dock.pane() {
if &pane == self.dock_pane() {
Dock::show(self, cx);
} else {
self.last_active_center_pane = Some(pane.clone());
if self.dock.is_anchored_at(DockAnchor::Expanded) {
Dock::hide(self, cx);
}
}
cx.notify();
}