Rename Sidebar to Dock

This commit is contained in:
Nathan Sobo 2023-05-05 16:04:36 -06:00 committed by Antonio Scandurra
parent 1919a826f9
commit 03f8c1206a
18 changed files with 133 additions and 146 deletions

View file

@ -39,8 +39,8 @@
{ {
"context": "Workspace", "context": "Workspace",
"bindings": { "bindings": {
"cmd-\\": "workspace::ToggleLeftSidebar", "cmd-\\": "workspace::ToggleLeftDock",
"cmd-k cmd-b": "workspace::ToggleLeftSidebar", "cmd-k cmd-b": "workspace::ToggleLeftDock",
"cmd-t": "file_finder::Toggle", "cmd-t": "file_finder::Toggle",
"cmd-shift-r": "project_symbols::Toggle" "cmd-shift-r": "project_symbols::Toggle"
} }

View file

@ -349,7 +349,7 @@
"workspace::ActivatePane", "workspace::ActivatePane",
8 8
], ],
"cmd-b": "workspace::ToggleLeftSidebar", "cmd-b": "workspace::ToggleLeftDock",
"cmd-shift-f": "workspace::NewSearch", "cmd-shift-f": "workspace::NewSearch",
"cmd-k cmd-t": "theme_selector::Toggle", "cmd-k cmd-t": "theme_selector::Toggle",
"cmd-k cmd-s": "zed::OpenKeymap", "cmd-k cmd-s": "zed::OpenKeymap",

View file

@ -65,7 +65,7 @@
"bindings": { "bindings": {
"cmd-shift-a": "command_palette::Toggle", "cmd-shift-a": "command_palette::Toggle",
"cmd-alt-o": "project_symbols::Toggle", "cmd-alt-o": "project_symbols::Toggle",
"cmd-1": "workspace::ToggleLeftSidebar", "cmd-1": "workspace::ToggleLeftDock",
"cmd-6": "diagnostics::Deploy" "cmd-6": "diagnostics::Deploy"
} }
} }

View file

@ -45,7 +45,7 @@
{ {
"context": "Workspace", "context": "Workspace",
"bindings": { "bindings": {
"cmd-k cmd-b": "workspace::ToggleLeftSidebar", "cmd-k cmd-b": "workspace::ToggleLeftDock",
"cmd-t": "file_finder::Toggle", "cmd-t": "file_finder::Toggle",
"shift-cmd-r": "project_symbols::Toggle", "shift-cmd-r": "project_symbols::Toggle",
// Currently busted: https://github.com/zed-industries/feedback/issues/898 // Currently busted: https://github.com/zed-industries/feedback/issues/898

View file

@ -68,7 +68,7 @@
{ {
"context": "Workspace", "context": "Workspace",
"bindings": { "bindings": {
"cmd-alt-ctrl-d": "workspace::ToggleLeftSidebar", "cmd-alt-ctrl-d": "workspace::ToggleLeftDock",
"cmd-t": "file_finder::Toggle", "cmd-t": "file_finder::Toggle",
"cmd-shift-t": "project_symbols::Toggle" "cmd-shift-t": "project_symbols::Toggle"
} }

View file

@ -64,7 +64,7 @@ impl View for CopilotButton {
let style = theme let style = theme
.workspace .workspace
.status_bar .status_bar
.sidebar_buttons .panel_buttons
.item .item
.style_for(state, active); .style_for(state, active);

View file

@ -40,7 +40,7 @@ impl View for DeployFeedbackButton {
let style = &theme let style = &theme
.workspace .workspace
.status_bar .status_bar
.sidebar_buttons .panel_buttons
.item .item
.style_for(state, active); .style_for(state, active);

View file

@ -1327,7 +1327,7 @@ impl Entity for ProjectPanel {
type Event = Event; type Event = Event;
} }
impl workspace::sidebar::SidebarItem for ProjectPanel { impl workspace::dock::DockItem for ProjectPanel {
fn should_show_badge(&self, _: &AppContext) -> bool { fn should_show_badge(&self, _: &AppContext) -> bool {
false false
} }

View file

@ -52,7 +52,7 @@ impl View for TerminalButton {
let style = theme let style = theme
.workspace .workspace
.status_bar .status_bar
.sidebar_buttons .panel_buttons
.item .item
.style_for(state, active); .style_for(state, active);

View file

@ -61,7 +61,7 @@ pub struct Workspace {
pub pane_divider: Border, pub pane_divider: Border,
pub leader_border_opacity: f32, pub leader_border_opacity: f32,
pub leader_border_width: f32, pub leader_border_width: f32,
pub sidebar: Sidebar, pub dock: Dock,
pub status_bar: StatusBar, pub status_bar: StatusBar,
pub toolbar: Toolbar, pub toolbar: Toolbar,
pub breadcrumb_height: f32, pub breadcrumb_height: f32,
@ -335,16 +335,16 @@ pub struct StatusBar {
pub auto_update_progress_message: TextStyle, pub auto_update_progress_message: TextStyle,
pub auto_update_done_message: TextStyle, pub auto_update_done_message: TextStyle,
pub lsp_status: Interactive<StatusBarLspStatus>, pub lsp_status: Interactive<StatusBarLspStatus>,
pub sidebar_buttons: StatusBarSidebarButtons, pub panel_buttons: StatusBarPanelButtons,
pub diagnostic_summary: Interactive<StatusBarDiagnosticSummary>, pub diagnostic_summary: Interactive<StatusBarDiagnosticSummary>,
pub diagnostic_message: Interactive<ContainedText>, pub diagnostic_message: Interactive<ContainedText>,
} }
#[derive(Deserialize, Default)] #[derive(Deserialize, Default)]
pub struct StatusBarSidebarButtons { pub struct StatusBarPanelButtons {
pub group_left: ContainerStyle, pub group_left: ContainerStyle,
pub group_right: ContainerStyle, pub group_right: ContainerStyle,
pub item: Interactive<SidebarItem>, pub item: Interactive<DockItem>,
pub badge: ContainerStyle, pub badge: ContainerStyle,
} }
@ -375,14 +375,14 @@ pub struct StatusBarLspStatus {
} }
#[derive(Deserialize, Default)] #[derive(Deserialize, Default)]
pub struct Sidebar { pub struct Dock {
pub initial_size: f32, pub initial_size: f32,
#[serde(flatten)] #[serde(flatten)]
pub container: ContainerStyle, pub container: ContainerStyle,
} }
#[derive(Clone, Deserialize, Default)] #[derive(Clone, Deserialize, Default)]
pub struct SidebarItem { pub struct DockItem {
#[serde(flatten)] #[serde(flatten)]
pub container: ContainerStyle, pub container: ContainerStyle,
pub icon_color: Color, pub icon_color: Color,

View file

@ -10,7 +10,7 @@ use gpui::{
use settings::{settings_file::SettingsFile, Settings}; use settings::{settings_file::SettingsFile, Settings};
use workspace::{ use workspace::{
item::Item, open_new, sidebar::SidebarSide, AppState, PaneBackdrop, Welcome, Workspace, item::Item, open_new, dock::DockPosition, AppState, PaneBackdrop, Welcome, Workspace,
WorkspaceId, WorkspaceId,
}; };
@ -29,7 +29,7 @@ pub fn init(cx: &mut AppContext) {
pub fn show_welcome_experience(app_state: &Arc<AppState>, cx: &mut AppContext) { pub fn show_welcome_experience(app_state: &Arc<AppState>, cx: &mut AppContext) {
open_new(&app_state, cx, |workspace, cx| { open_new(&app_state, cx, |workspace, cx| {
workspace.toggle_sidebar(SidebarSide::Left, cx); workspace.toggle_dock(DockPosition::Left, cx);
let welcome_page = cx.add_view(|cx| WelcomePage::new(workspace, cx)); let welcome_page = cx.add_view(|cx| WelcomePage::new(workspace, cx));
workspace.add_item_to_center(Box::new(welcome_page.clone()), cx); workspace.add_item_to_center(Box::new(welcome_page.clone()), cx);
cx.focus(&welcome_page); cx.focus(&welcome_page);

View file

@ -7,7 +7,7 @@ use serde::Deserialize;
use settings::Settings; use settings::Settings;
use std::rc::Rc; use std::rc::Rc;
pub trait SidebarItem: View { pub trait DockItem: View {
fn should_activate_item_on_event(&self, _: &Self::Event, _: &AppContext) -> bool { fn should_activate_item_on_event(&self, _: &Self::Event, _: &AppContext) -> bool {
false false
} }
@ -19,16 +19,16 @@ pub trait SidebarItem: View {
} }
} }
pub trait SidebarItemHandle { pub trait DockItemHandle {
fn id(&self) -> usize; fn id(&self) -> usize;
fn should_show_badge(&self, cx: &WindowContext) -> bool; fn should_show_badge(&self, cx: &WindowContext) -> bool;
fn is_focused(&self, cx: &WindowContext) -> bool; fn is_focused(&self, cx: &WindowContext) -> bool;
fn as_any(&self) -> &AnyViewHandle; fn as_any(&self) -> &AnyViewHandle;
} }
impl<T> SidebarItemHandle for ViewHandle<T> impl<T> DockItemHandle for ViewHandle<T>
where where
T: SidebarItem, T: DockItem,
{ {
fn id(&self) -> usize { fn id(&self) -> usize {
self.id() self.id()
@ -47,26 +47,26 @@ where
} }
} }
impl From<&dyn SidebarItemHandle> for AnyViewHandle { impl From<&dyn DockItemHandle> for AnyViewHandle {
fn from(val: &dyn SidebarItemHandle) -> Self { fn from(val: &dyn DockItemHandle) -> Self {
val.as_any().clone() val.as_any().clone()
} }
} }
pub struct Sidebar { pub struct Dock {
sidebar_side: SidebarSide, position: DockPosition,
items: Vec<Item>, items: Vec<Item>,
is_open: bool, is_open: bool,
active_item_ix: usize, active_item_ix: usize,
} }
#[derive(Clone, Copy, Debug, Deserialize, PartialEq)] #[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
pub enum SidebarSide { pub enum DockPosition {
Left, Left,
Right, Right,
} }
impl SidebarSide { impl DockPosition {
fn to_resizable_side(self) -> Side { fn to_resizable_side(self) -> Side {
match self { match self {
Self::Left => Side::Right, Self::Left => Side::Right,
@ -78,27 +78,27 @@ impl SidebarSide {
struct Item { struct Item {
icon_path: &'static str, icon_path: &'static str,
tooltip: String, tooltip: String,
view: Rc<dyn SidebarItemHandle>, view: Rc<dyn DockItemHandle>,
_subscriptions: [Subscription; 2], _subscriptions: [Subscription; 2],
} }
pub struct SidebarButtons { pub struct PanelButtons {
sidebar: ViewHandle<Sidebar>, dock: ViewHandle<Dock>,
workspace: WeakViewHandle<Workspace>, workspace: WeakViewHandle<Workspace>,
} }
#[derive(Clone, Debug, Deserialize, PartialEq)] #[derive(Clone, Debug, Deserialize, PartialEq)]
pub struct ToggleSidebarItem { pub struct ToggleDockItem {
pub sidebar_side: SidebarSide, pub dock_position: DockPosition,
pub item_index: usize, pub item_index: usize,
} }
impl_actions!(workspace, [ToggleSidebarItem]); impl_actions!(workspace, [ToggleDockItem]);
impl Sidebar { impl Dock {
pub fn new(sidebar_side: SidebarSide) -> Self { pub fn new(position: DockPosition) -> Self {
Self { Self {
sidebar_side, position,
items: Default::default(), items: Default::default(),
active_item_ix: 0, active_item_ix: 0,
is_open: false, is_open: false,
@ -126,7 +126,7 @@ impl Sidebar {
cx.notify(); cx.notify();
} }
pub fn add_item<T: SidebarItem>( pub fn add_item<T: DockItem>(
&mut self, &mut self,
icon_path: &'static str, icon_path: &'static str,
tooltip: String, tooltip: String,
@ -171,7 +171,7 @@ impl Sidebar {
cx.notify(); cx.notify();
} }
pub fn active_item(&self) -> Option<&Rc<dyn SidebarItemHandle>> { pub fn active_item(&self) -> Option<&Rc<dyn DockItemHandle>> {
if self.is_open { if self.is_open {
self.items.get(self.active_item_ix).map(|item| &item.view) self.items.get(self.active_item_ix).map(|item| &item.view)
} else { } else {
@ -180,25 +180,25 @@ impl Sidebar {
} }
} }
impl Entity for Sidebar { impl Entity for Dock {
type Event = (); type Event = ();
} }
impl View for Sidebar { impl View for Dock {
fn ui_name() -> &'static str { fn ui_name() -> &'static str {
"Sidebar" "Dock"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if let Some(active_item) = self.active_item() { if let Some(active_item) = self.active_item() {
enum ResizeHandleTag {} enum ResizeHandleTag {}
let style = &cx.global::<Settings>().theme.workspace.sidebar; let style = &cx.global::<Settings>().theme.workspace.dock;
ChildView::new(active_item.as_any(), cx) ChildView::new(active_item.as_any(), cx)
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.with_resize_handle::<ResizeHandleTag>( .with_resize_handle::<ResizeHandleTag>(
self.sidebar_side as usize, self.position as usize,
self.sidebar_side.to_resizable_side(), self.position.to_resizable_side(),
4., 4.,
style.initial_size, style.initial_size,
cx, cx,
@ -210,43 +210,43 @@ impl View for Sidebar {
} }
} }
impl SidebarButtons { impl PanelButtons {
pub fn new( pub fn new(
sidebar: ViewHandle<Sidebar>, dock: ViewHandle<Dock>,
workspace: WeakViewHandle<Workspace>, workspace: WeakViewHandle<Workspace>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Self { ) -> Self {
cx.observe(&sidebar, |_, _, cx| cx.notify()).detach(); cx.observe(&dock, |_, _, cx| cx.notify()).detach();
Self { sidebar, workspace } Self { dock, workspace }
} }
} }
impl Entity for SidebarButtons { impl Entity for PanelButtons {
type Event = (); type Event = ();
} }
impl View for SidebarButtons { impl View for PanelButtons {
fn ui_name() -> &'static str { fn ui_name() -> &'static str {
"SidebarToggleButton" "DockToggleButton"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let theme = &cx.global::<Settings>().theme; let theme = &cx.global::<Settings>().theme;
let tooltip_style = theme.tooltip.clone(); let tooltip_style = theme.tooltip.clone();
let theme = &theme.workspace.status_bar.sidebar_buttons; let theme = &theme.workspace.status_bar.panel_buttons;
let sidebar = self.sidebar.read(cx); let dock = self.dock.read(cx);
let item_style = theme.item.clone(); let item_style = theme.item.clone();
let badge_style = theme.badge; let badge_style = theme.badge;
let active_ix = sidebar.active_item_ix; let active_ix = dock.active_item_ix;
let is_open = sidebar.is_open; let is_open = dock.is_open;
let sidebar_side = sidebar.sidebar_side; let dock_position = dock.position;
let group_style = match sidebar_side { let group_style = match dock_position {
SidebarSide::Left => theme.group_left, DockPosition::Left => theme.group_left,
SidebarSide::Right => theme.group_right, DockPosition::Right => theme.group_right,
}; };
#[allow(clippy::needless_collect)] #[allow(clippy::needless_collect)]
let items = sidebar let items = dock
.items .items
.iter() .iter()
.map(|item| (item.icon_path, item.tooltip.clone(), item.view.clone())) .map(|item| (item.icon_path, item.tooltip.clone(), item.view.clone()))
@ -255,8 +255,8 @@ impl View for SidebarButtons {
Flex::row() Flex::row()
.with_children(items.into_iter().enumerate().map( .with_children(items.into_iter().enumerate().map(
|(ix, (icon_path, tooltip, item_view))| { |(ix, (icon_path, tooltip, item_view))| {
let action = ToggleSidebarItem { let action = ToggleDockItem {
sidebar_side, dock_position,
item_index: ix, item_index: ix,
}; };
MouseEventHandler::<Self, _>::new(ix, cx, |state, cx| { MouseEventHandler::<Self, _>::new(ix, cx, |state, cx| {
@ -291,7 +291,7 @@ impl View for SidebarButtons {
let action = action.clone(); let action = action.clone();
cx.window_context().defer(move |cx| { cx.window_context().defer(move |cx| {
workspace.update(cx, |workspace, cx| { workspace.update(cx, |workspace, cx| {
workspace.toggle_sidebar_item(&action, cx) workspace.toggle_panel(&action, cx)
}); });
}); });
} }
@ -312,7 +312,7 @@ impl View for SidebarButtons {
} }
} }
impl StatusItemView for SidebarButtons { impl StatusItemView for PanelButtons {
fn set_active_pane_item( fn set_active_pane_item(
&mut self, &mut self,
_: Option<&dyn crate::ItemHandle>, _: Option<&dyn crate::ItemHandle>,

View file

@ -766,7 +766,7 @@ impl<T: FollowableItem> FollowableItemHandle for ViewHandle<T> {
#[cfg(test)] #[cfg(test)]
pub(crate) mod test { pub(crate) mod test {
use super::{Item, ItemEvent}; use super::{Item, ItemEvent};
use crate::{sidebar::SidebarItem, ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId}; use crate::{dock::DockItem, ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
use gpui::{ use gpui::{
elements::Empty, AnyElement, AppContext, Element, Entity, ModelHandle, Task, View, elements::Empty, AnyElement, AppContext, Element, Entity, ModelHandle, Task, View,
ViewContext, ViewHandle, WeakViewHandle, ViewContext, ViewHandle, WeakViewHandle,
@ -1060,5 +1060,5 @@ pub(crate) mod test {
} }
} }
impl SidebarItem for TestItem {} impl DockItem for TestItem {}
} }

View file

@ -9,7 +9,7 @@ pub mod pane_group;
mod persistence; mod persistence;
pub mod searchable; pub mod searchable;
pub mod shared_screen; pub mod shared_screen;
pub mod sidebar; pub mod dock;
mod status_bar; mod status_bar;
mod toolbar; mod toolbar;
@ -74,7 +74,7 @@ use project::{Project, ProjectEntryId, ProjectPath, Worktree, WorktreeId};
use serde::Deserialize; use serde::Deserialize;
use settings::{Autosave, Settings}; use settings::{Autosave, Settings};
use shared_screen::SharedScreen; use shared_screen::SharedScreen;
use sidebar::{Sidebar, SidebarButtons, SidebarSide, ToggleSidebarItem}; use dock::{Dock, PanelButtons, DockPosition, ToggleDockItem};
use status_bar::StatusBar; use status_bar::StatusBar;
pub use status_bar::StatusItemView; pub use status_bar::StatusItemView;
use theme::{Theme, ThemeRegistry}; use theme::{Theme, ThemeRegistry};
@ -114,7 +114,7 @@ actions!(
ActivatePreviousPane, ActivatePreviousPane,
ActivateNextPane, ActivateNextPane,
FollowNextCollaborator, FollowNextCollaborator,
ToggleLeftSidebar, ToggleLeftDock,
NewTerminal, NewTerminal,
NewSearch, NewSearch,
Feedback, Feedback,
@ -229,7 +229,7 @@ pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
workspace.save_active_item(true, cx).detach_and_log_err(cx); workspace.save_active_item(true, cx).detach_and_log_err(cx);
}, },
); );
cx.add_action(Workspace::toggle_sidebar_item); cx.add_action(Workspace::toggle_panel);
cx.add_action(Workspace::focus_center); cx.add_action(Workspace::focus_center);
cx.add_action(|workspace: &mut Workspace, _: &ActivatePreviousPane, cx| { cx.add_action(|workspace: &mut Workspace, _: &ActivatePreviousPane, cx| {
workspace.activate_previous_pane(cx) workspace.activate_previous_pane(cx)
@ -237,8 +237,8 @@ pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
cx.add_action(|workspace: &mut Workspace, _: &ActivateNextPane, cx| { cx.add_action(|workspace: &mut Workspace, _: &ActivateNextPane, cx| {
workspace.activate_next_pane(cx) workspace.activate_next_pane(cx)
}); });
cx.add_action(|workspace: &mut Workspace, _: &ToggleLeftSidebar, cx| { cx.add_action(|workspace: &mut Workspace, _: &ToggleLeftDock, cx| {
workspace.toggle_sidebar(SidebarSide::Left, cx); workspace.toggle_dock(DockPosition::Left, cx);
}); });
cx.add_action(Workspace::activate_pane_at_index); cx.add_action(Workspace::activate_pane_at_index);
@ -442,8 +442,8 @@ pub struct Workspace {
remote_entity_subscription: Option<client::Subscription>, remote_entity_subscription: Option<client::Subscription>,
modal: Option<AnyViewHandle>, modal: Option<AnyViewHandle>,
center: PaneGroup, center: PaneGroup,
left_sidebar: ViewHandle<Sidebar>, left_dock: ViewHandle<Dock>,
right_sidebar: ViewHandle<Sidebar>, right_dock: ViewHandle<Dock>,
panes: Vec<ViewHandle<Pane>>, panes: Vec<ViewHandle<Pane>>,
panes_by_item: HashMap<usize, WeakViewHandle<Pane>>, panes_by_item: HashMap<usize, WeakViewHandle<Pane>>,
active_pane: ViewHandle<Pane>, active_pane: ViewHandle<Pane>,
@ -562,16 +562,16 @@ impl Workspace {
cx.emit_global(WorkspaceCreated(weak_handle.clone())); cx.emit_global(WorkspaceCreated(weak_handle.clone()));
let left_sidebar = cx.add_view(|_| Sidebar::new(SidebarSide::Left)); let left_dock = cx.add_view(|_| Dock::new(DockPosition::Left));
let right_sidebar = cx.add_view(|_| Sidebar::new(SidebarSide::Right)); let right_dock = cx.add_view(|_| Dock::new(DockPosition::Right));
let left_sidebar_buttons = let left_dock_buttons =
cx.add_view(|cx| SidebarButtons::new(left_sidebar.clone(), weak_handle.clone(), cx)); cx.add_view(|cx| PanelButtons::new(left_dock.clone(), weak_handle.clone(), cx));
let right_sidebar_buttons = let right_dock_buttons =
cx.add_view(|cx| SidebarButtons::new(right_sidebar.clone(), weak_handle.clone(), cx)); cx.add_view(|cx| PanelButtons::new(right_dock.clone(), weak_handle.clone(), cx));
let status_bar = cx.add_view(|cx| { let status_bar = cx.add_view(|cx| {
let mut status_bar = StatusBar::new(&center_pane.clone(), cx); let mut status_bar = StatusBar::new(&center_pane.clone(), cx);
status_bar.add_left_item(left_sidebar_buttons, cx); status_bar.add_left_item(left_dock_buttons, cx);
status_bar.add_right_item(right_sidebar_buttons, cx); status_bar.add_right_item(right_dock_buttons, cx);
status_bar status_bar
}); });
@ -621,8 +621,8 @@ impl Workspace {
titlebar_item: None, titlebar_item: None,
notifications: Default::default(), notifications: Default::default(),
remote_entity_subscription: None, remote_entity_subscription: None,
left_sidebar, left_dock: left_dock,
right_sidebar, right_dock: right_dock,
project: project.clone(), project: project.clone(),
leader_state: Default::default(), leader_state: Default::default(),
follower_states_by_leader: Default::default(), follower_states_by_leader: Default::default(),
@ -813,12 +813,12 @@ impl Workspace {
self.weak_self.clone() self.weak_self.clone()
} }
pub fn left_sidebar(&self) -> &ViewHandle<Sidebar> { pub fn left_dock(&self) -> &ViewHandle<Dock> {
&self.left_sidebar &self.left_dock
} }
pub fn right_sidebar(&self) -> &ViewHandle<Sidebar> { pub fn right_dock(&self) -> &ViewHandle<Dock> {
&self.right_sidebar &self.right_dock
} }
pub fn status_bar(&self) -> &ViewHandle<StatusBar> { pub fn status_bar(&self) -> &ViewHandle<StatusBar> {
@ -1306,14 +1306,14 @@ impl Workspace {
} }
} }
pub fn toggle_sidebar(&mut self, sidebar_side: SidebarSide, cx: &mut ViewContext<Self>) { pub fn toggle_dock(&mut self, dock_side: DockPosition, cx: &mut ViewContext<Self>) {
let sidebar = match sidebar_side { let dock = match dock_side {
SidebarSide::Left => &mut self.left_sidebar, DockPosition::Left => &mut self.left_dock,
SidebarSide::Right => &mut self.right_sidebar, DockPosition::Right => &mut self.right_dock,
}; };
sidebar.update(cx, |sidebar, cx| { dock.update(cx, |dock, cx| {
let open = !sidebar.is_open(); let open = !dock.is_open();
sidebar.set_open(open, cx); dock.set_open(open, cx);
}); });
self.serialize_workspace(cx); self.serialize_workspace(cx);
@ -1322,19 +1322,19 @@ impl Workspace {
cx.notify(); cx.notify();
} }
pub fn toggle_sidebar_item(&mut self, action: &ToggleSidebarItem, cx: &mut ViewContext<Self>) { pub fn toggle_panel(&mut self, action: &ToggleDockItem, cx: &mut ViewContext<Self>) {
let sidebar = match action.sidebar_side { let dock = match action.dock_position {
SidebarSide::Left => &mut self.left_sidebar, DockPosition::Left => &mut self.left_dock,
SidebarSide::Right => &mut self.right_sidebar, DockPosition::Right => &mut self.right_dock,
}; };
let active_item = sidebar.update(cx, move |sidebar, cx| { let active_item = dock.update(cx, move |dock, cx| {
if sidebar.is_open() && sidebar.active_item_ix() == action.item_index { if dock.is_open() && dock.active_item_ix() == action.item_index {
sidebar.set_open(false, cx); dock.set_open(false, cx);
None None
} else { } else {
sidebar.set_open(true, cx); dock.set_open(true, cx);
sidebar.activate_item(action.item_index, cx); dock.activate_item(action.item_index, cx);
sidebar.active_item().cloned() dock.active_item().cloned()
} }
}); });
@ -1353,20 +1353,20 @@ impl Workspace {
cx.notify(); cx.notify();
} }
pub fn toggle_sidebar_item_focus( pub fn toggle_panel_focus(
&mut self, &mut self,
sidebar_side: SidebarSide, dock_position: DockPosition,
item_index: usize, panel_index: usize,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) { ) {
let sidebar = match sidebar_side { let dock = match dock_position {
SidebarSide::Left => &mut self.left_sidebar, DockPosition::Left => &mut self.left_dock,
SidebarSide::Right => &mut self.right_sidebar, DockPosition::Right => &mut self.right_dock,
}; };
let active_item = sidebar.update(cx, |sidebar, cx| { let active_item = dock.update(cx, |dock, cx| {
sidebar.set_open(true, cx); dock.set_open(true, cx);
sidebar.activate_item(item_index, cx); dock.activate_item(panel_index, cx);
sidebar.active_item().cloned() dock.active_item().cloned()
}); });
if let Some(active_item) = active_item { if let Some(active_item) = active_item {
if active_item.is_focused(cx) { if active_item.is_focused(cx) {
@ -2452,7 +2452,7 @@ impl Workspace {
id: self.database_id, id: self.database_id,
location, location,
center_group, center_group,
left_sidebar_open: self.left_sidebar.read(cx).is_open(), left_sidebar_open: self.left_dock.read(cx).is_open(),
bounds: Default::default(), bounds: Default::default(),
display: Default::default(), display: Default::default(),
}; };
@ -2509,10 +2509,10 @@ impl Workspace {
} }
} }
if workspace.left_sidebar().read(cx).is_open() if workspace.left_dock().read(cx).is_open()
!= serialized_workspace.left_sidebar_open != serialized_workspace.left_sidebar_open
{ {
workspace.toggle_sidebar(SidebarSide::Left, cx); workspace.toggle_dock(DockPosition::Left, cx);
} }
cx.notify(); cx.notify();
@ -2596,9 +2596,9 @@ impl View for Workspace {
let project = self.project.clone(); let project = self.project.clone();
Flex::row() Flex::row()
.with_children( .with_children(
if self.left_sidebar.read(cx).active_item().is_some() { if self.left_dock.read(cx).active_item().is_some() {
Some( Some(
ChildView::new(&self.left_sidebar, cx) ChildView::new(&self.left_dock, cx)
.constrained() .constrained()
.dynamically(|constraint, _, cx| { .dynamically(|constraint, _, cx| {
SizeConstraint::new( SizeConstraint::new(
@ -2633,9 +2633,9 @@ impl View for Workspace {
.flex(1., true), .flex(1., true),
) )
.with_children( .with_children(
if self.right_sidebar.read(cx).active_item().is_some() { if self.right_dock.read(cx).active_item().is_some() {
Some( Some(
ChildView::new(&self.right_sidebar, cx) ChildView::new(&self.right_dock, cx)
.constrained() .constrained()
.dynamically(|constraint, _, cx| { .dynamically(|constraint, _, cx| {
SizeConstraint::new( SizeConstraint::new(
@ -2803,7 +2803,7 @@ pub fn open_paths(
workspace.update(&mut cx, |workspace, cx| { workspace.update(&mut cx, |workspace, cx| {
if contains_directory { if contains_directory {
workspace.toggle_sidebar(SidebarSide::Left, cx); workspace.toggle_dock(DockPosition::Left, cx);
} }
})?; })?;

View file

@ -89,7 +89,7 @@ pub fn menus() -> Vec<Menu<'static>> {
MenuItem::action("Zoom Out", super::DecreaseBufferFontSize), MenuItem::action("Zoom Out", super::DecreaseBufferFontSize),
MenuItem::action("Reset Zoom", super::ResetBufferFontSize), MenuItem::action("Reset Zoom", super::ResetBufferFontSize),
MenuItem::separator(), MenuItem::separator(),
MenuItem::action("Toggle Left Sidebar", workspace::ToggleLeftSidebar), MenuItem::action("Toggle Left Dock", workspace::ToggleLeftDock),
MenuItem::submenu(Menu { MenuItem::submenu(Menu {
name: "Editor Layout", name: "Editor Layout",
items: vec![ items: vec![

View file

@ -36,7 +36,7 @@ use util::{channel::ReleaseChannel, paths, ResultExt};
use uuid::Uuid; use uuid::Uuid;
pub use workspace; pub use workspace;
use workspace::{ use workspace::{
create_and_open_local_file, open_new, sidebar::SidebarSide, AppState, NewFile, NewWindow, create_and_open_local_file, open_new, dock::DockPosition, AppState, NewFile, NewWindow,
Workspace, Workspace,
}; };
@ -242,7 +242,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::AppContext) {
|workspace: &mut Workspace, |workspace: &mut Workspace,
_: &project_panel::ToggleFocus, _: &project_panel::ToggleFocus,
cx: &mut ViewContext<Workspace>| { cx: &mut ViewContext<Workspace>| {
workspace.toggle_sidebar_item_focus(SidebarSide::Left, 0, cx); workspace.toggle_panel_focus(DockPosition::Left, 0, cx);
}, },
); );
cx.add_global_action({ cx.add_global_action({
@ -312,8 +312,8 @@ pub fn initialize_workspace(
workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx); workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx);
let project_panel = ProjectPanel::new(workspace, cx); let project_panel = ProjectPanel::new(workspace, cx);
workspace.left_sidebar().update(cx, |sidebar, cx| { workspace.left_dock().update(cx, |dock, cx| {
sidebar.add_item( dock.add_item(
"icons/folder_tree_16.svg", "icons/folder_tree_16.svg",
"Project Panel".to_string(), "Project Panel".to_string(),
project_panel, project_panel,
@ -658,7 +658,7 @@ mod tests {
.unwrap(); .unwrap();
workspace_1.update(cx, |workspace, cx| { workspace_1.update(cx, |workspace, cx| {
assert_eq!(workspace.worktrees(cx).count(), 2); assert_eq!(workspace.worktrees(cx).count(), 2);
assert!(workspace.left_sidebar().read(cx).is_open()); assert!(workspace.left_dock().read(cx).is_open());
assert!(workspace.active_pane().is_focused(cx)); assert!(workspace.active_pane().is_focused(cx));
}); });
@ -701,7 +701,7 @@ mod tests {
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
&[Path::new("/root/c").into(), Path::new("/root/d").into()] &[Path::new("/root/c").into(), Path::new("/root/d").into()]
); );
assert!(workspace.left_sidebar().read(cx).is_open()); assert!(workspace.left_dock().read(cx).is_open());
assert!(workspace.active_pane().is_focused(cx)); assert!(workspace.active_pane().is_focused(cx));
}); });
} }

View file

@ -93,7 +93,7 @@ export default function statusBar(colorScheme: ColorScheme) {
}, },
}, },
}, },
sidebarButtons: { panelButtons: {
groupLeft: {}, groupLeft: {},
groupRight: {}, groupRight: {},
item: { item: {

View file

@ -118,7 +118,7 @@ export default function workspace(colorScheme: ColorScheme) {
}, },
cursor: "Arrow", cursor: "Arrow",
}, },
sidebar: { dock: {
initialSize: 240, initialSize: 240,
border: border(layer, { left: true, right: true }), border: border(layer, { left: true, right: true }),
}, },
@ -310,19 +310,6 @@ export default function workspace(colorScheme: ColorScheme) {
width: 400, width: 400,
margin: { right: 10, bottom: 10 }, margin: { right: 10, bottom: 10 },
}, },
dock: {
initialSizeRight: 640,
initialSizeBottom: 304,
wash_color: withOpacity(background(colorScheme.highest), 0.5),
panel: {
border: border(colorScheme.middle),
},
maximized: {
margin: 32,
border: border(colorScheme.highest, { overlay: true }),
shadow: colorScheme.modalShadow,
},
},
dropTargetOverlayColor: withOpacity(foreground(layer, "variant"), 0.5), dropTargetOverlayColor: withOpacity(foreground(layer, "variant"), 0.5),
} }
} }