Rename Sidebar to Dock
This commit is contained in:
parent
1919a826f9
commit
03f8c1206a
18 changed files with 133 additions and 146 deletions
|
@ -7,7 +7,7 @@ use serde::Deserialize;
|
|||
use settings::Settings;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub trait SidebarItem: View {
|
||||
pub trait DockItem: View {
|
||||
fn should_activate_item_on_event(&self, _: &Self::Event, _: &AppContext) -> bool {
|
||||
false
|
||||
}
|
||||
|
@ -19,16 +19,16 @@ pub trait SidebarItem: View {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait SidebarItemHandle {
|
||||
pub trait DockItemHandle {
|
||||
fn id(&self) -> usize;
|
||||
fn should_show_badge(&self, cx: &WindowContext) -> bool;
|
||||
fn is_focused(&self, cx: &WindowContext) -> bool;
|
||||
fn as_any(&self) -> &AnyViewHandle;
|
||||
}
|
||||
|
||||
impl<T> SidebarItemHandle for ViewHandle<T>
|
||||
impl<T> DockItemHandle for ViewHandle<T>
|
||||
where
|
||||
T: SidebarItem,
|
||||
T: DockItem,
|
||||
{
|
||||
fn id(&self) -> usize {
|
||||
self.id()
|
||||
|
@ -47,26 +47,26 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl From<&dyn SidebarItemHandle> for AnyViewHandle {
|
||||
fn from(val: &dyn SidebarItemHandle) -> Self {
|
||||
impl From<&dyn DockItemHandle> for AnyViewHandle {
|
||||
fn from(val: &dyn DockItemHandle) -> Self {
|
||||
val.as_any().clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Sidebar {
|
||||
sidebar_side: SidebarSide,
|
||||
pub struct Dock {
|
||||
position: DockPosition,
|
||||
items: Vec<Item>,
|
||||
is_open: bool,
|
||||
active_item_ix: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
|
||||
pub enum SidebarSide {
|
||||
pub enum DockPosition {
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
|
||||
impl SidebarSide {
|
||||
impl DockPosition {
|
||||
fn to_resizable_side(self) -> Side {
|
||||
match self {
|
||||
Self::Left => Side::Right,
|
||||
|
@ -78,27 +78,27 @@ impl SidebarSide {
|
|||
struct Item {
|
||||
icon_path: &'static str,
|
||||
tooltip: String,
|
||||
view: Rc<dyn SidebarItemHandle>,
|
||||
view: Rc<dyn DockItemHandle>,
|
||||
_subscriptions: [Subscription; 2],
|
||||
}
|
||||
|
||||
pub struct SidebarButtons {
|
||||
sidebar: ViewHandle<Sidebar>,
|
||||
pub struct PanelButtons {
|
||||
dock: ViewHandle<Dock>,
|
||||
workspace: WeakViewHandle<Workspace>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
||||
pub struct ToggleSidebarItem {
|
||||
pub sidebar_side: SidebarSide,
|
||||
pub struct ToggleDockItem {
|
||||
pub dock_position: DockPosition,
|
||||
pub item_index: usize,
|
||||
}
|
||||
|
||||
impl_actions!(workspace, [ToggleSidebarItem]);
|
||||
impl_actions!(workspace, [ToggleDockItem]);
|
||||
|
||||
impl Sidebar {
|
||||
pub fn new(sidebar_side: SidebarSide) -> Self {
|
||||
impl Dock {
|
||||
pub fn new(position: DockPosition) -> Self {
|
||||
Self {
|
||||
sidebar_side,
|
||||
position,
|
||||
items: Default::default(),
|
||||
active_item_ix: 0,
|
||||
is_open: false,
|
||||
|
@ -126,7 +126,7 @@ impl Sidebar {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn add_item<T: SidebarItem>(
|
||||
pub fn add_item<T: DockItem>(
|
||||
&mut self,
|
||||
icon_path: &'static str,
|
||||
tooltip: String,
|
||||
|
@ -171,7 +171,7 @@ impl Sidebar {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn active_item(&self) -> Option<&Rc<dyn SidebarItemHandle>> {
|
||||
pub fn active_item(&self) -> Option<&Rc<dyn DockItemHandle>> {
|
||||
if self.is_open {
|
||||
self.items.get(self.active_item_ix).map(|item| &item.view)
|
||||
} else {
|
||||
|
@ -180,25 +180,25 @@ impl Sidebar {
|
|||
}
|
||||
}
|
||||
|
||||
impl Entity for Sidebar {
|
||||
impl Entity for Dock {
|
||||
type Event = ();
|
||||
}
|
||||
|
||||
impl View for Sidebar {
|
||||
impl View for Dock {
|
||||
fn ui_name() -> &'static str {
|
||||
"Sidebar"
|
||||
"Dock"
|
||||
}
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
||||
if let Some(active_item) = self.active_item() {
|
||||
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)
|
||||
.contained()
|
||||
.with_style(style.container)
|
||||
.with_resize_handle::<ResizeHandleTag>(
|
||||
self.sidebar_side as usize,
|
||||
self.sidebar_side.to_resizable_side(),
|
||||
self.position as usize,
|
||||
self.position.to_resizable_side(),
|
||||
4.,
|
||||
style.initial_size,
|
||||
cx,
|
||||
|
@ -210,43 +210,43 @@ impl View for Sidebar {
|
|||
}
|
||||
}
|
||||
|
||||
impl SidebarButtons {
|
||||
impl PanelButtons {
|
||||
pub fn new(
|
||||
sidebar: ViewHandle<Sidebar>,
|
||||
dock: ViewHandle<Dock>,
|
||||
workspace: WeakViewHandle<Workspace>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
cx.observe(&sidebar, |_, _, cx| cx.notify()).detach();
|
||||
Self { sidebar, workspace }
|
||||
cx.observe(&dock, |_, _, cx| cx.notify()).detach();
|
||||
Self { dock, workspace }
|
||||
}
|
||||
}
|
||||
|
||||
impl Entity for SidebarButtons {
|
||||
impl Entity for PanelButtons {
|
||||
type Event = ();
|
||||
}
|
||||
|
||||
impl View for SidebarButtons {
|
||||
impl View for PanelButtons {
|
||||
fn ui_name() -> &'static str {
|
||||
"SidebarToggleButton"
|
||||
"DockToggleButton"
|
||||
}
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
||||
let theme = &cx.global::<Settings>().theme;
|
||||
let tooltip_style = theme.tooltip.clone();
|
||||
let theme = &theme.workspace.status_bar.sidebar_buttons;
|
||||
let sidebar = self.sidebar.read(cx);
|
||||
let theme = &theme.workspace.status_bar.panel_buttons;
|
||||
let dock = self.dock.read(cx);
|
||||
let item_style = theme.item.clone();
|
||||
let badge_style = theme.badge;
|
||||
let active_ix = sidebar.active_item_ix;
|
||||
let is_open = sidebar.is_open;
|
||||
let sidebar_side = sidebar.sidebar_side;
|
||||
let group_style = match sidebar_side {
|
||||
SidebarSide::Left => theme.group_left,
|
||||
SidebarSide::Right => theme.group_right,
|
||||
let active_ix = dock.active_item_ix;
|
||||
let is_open = dock.is_open;
|
||||
let dock_position = dock.position;
|
||||
let group_style = match dock_position {
|
||||
DockPosition::Left => theme.group_left,
|
||||
DockPosition::Right => theme.group_right,
|
||||
};
|
||||
|
||||
#[allow(clippy::needless_collect)]
|
||||
let items = sidebar
|
||||
let items = dock
|
||||
.items
|
||||
.iter()
|
||||
.map(|item| (item.icon_path, item.tooltip.clone(), item.view.clone()))
|
||||
|
@ -255,8 +255,8 @@ impl View for SidebarButtons {
|
|||
Flex::row()
|
||||
.with_children(items.into_iter().enumerate().map(
|
||||
|(ix, (icon_path, tooltip, item_view))| {
|
||||
let action = ToggleSidebarItem {
|
||||
sidebar_side,
|
||||
let action = ToggleDockItem {
|
||||
dock_position,
|
||||
item_index: ix,
|
||||
};
|
||||
MouseEventHandler::<Self, _>::new(ix, cx, |state, cx| {
|
||||
|
@ -291,7 +291,7 @@ impl View for SidebarButtons {
|
|||
let action = action.clone();
|
||||
cx.window_context().defer(move |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(
|
||||
&mut self,
|
||||
_: Option<&dyn crate::ItemHandle>,
|
|
@ -766,7 +766,7 @@ impl<T: FollowableItem> FollowableItemHandle for ViewHandle<T> {
|
|||
#[cfg(test)]
|
||||
pub(crate) mod test {
|
||||
use super::{Item, ItemEvent};
|
||||
use crate::{sidebar::SidebarItem, ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
|
||||
use crate::{dock::DockItem, ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
|
||||
use gpui::{
|
||||
elements::Empty, AnyElement, AppContext, Element, Entity, ModelHandle, Task, View,
|
||||
ViewContext, ViewHandle, WeakViewHandle,
|
||||
|
@ -1060,5 +1060,5 @@ pub(crate) mod test {
|
|||
}
|
||||
}
|
||||
|
||||
impl SidebarItem for TestItem {}
|
||||
impl DockItem for TestItem {}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ pub mod pane_group;
|
|||
mod persistence;
|
||||
pub mod searchable;
|
||||
pub mod shared_screen;
|
||||
pub mod sidebar;
|
||||
pub mod dock;
|
||||
mod status_bar;
|
||||
mod toolbar;
|
||||
|
||||
|
@ -74,7 +74,7 @@ use project::{Project, ProjectEntryId, ProjectPath, Worktree, WorktreeId};
|
|||
use serde::Deserialize;
|
||||
use settings::{Autosave, Settings};
|
||||
use shared_screen::SharedScreen;
|
||||
use sidebar::{Sidebar, SidebarButtons, SidebarSide, ToggleSidebarItem};
|
||||
use dock::{Dock, PanelButtons, DockPosition, ToggleDockItem};
|
||||
use status_bar::StatusBar;
|
||||
pub use status_bar::StatusItemView;
|
||||
use theme::{Theme, ThemeRegistry};
|
||||
|
@ -114,7 +114,7 @@ actions!(
|
|||
ActivatePreviousPane,
|
||||
ActivateNextPane,
|
||||
FollowNextCollaborator,
|
||||
ToggleLeftSidebar,
|
||||
ToggleLeftDock,
|
||||
NewTerminal,
|
||||
NewSearch,
|
||||
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);
|
||||
},
|
||||
);
|
||||
cx.add_action(Workspace::toggle_sidebar_item);
|
||||
cx.add_action(Workspace::toggle_panel);
|
||||
cx.add_action(Workspace::focus_center);
|
||||
cx.add_action(|workspace: &mut Workspace, _: &ActivatePreviousPane, 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| {
|
||||
workspace.activate_next_pane(cx)
|
||||
});
|
||||
cx.add_action(|workspace: &mut Workspace, _: &ToggleLeftSidebar, cx| {
|
||||
workspace.toggle_sidebar(SidebarSide::Left, cx);
|
||||
cx.add_action(|workspace: &mut Workspace, _: &ToggleLeftDock, cx| {
|
||||
workspace.toggle_dock(DockPosition::Left, cx);
|
||||
});
|
||||
cx.add_action(Workspace::activate_pane_at_index);
|
||||
|
||||
|
@ -442,8 +442,8 @@ pub struct Workspace {
|
|||
remote_entity_subscription: Option<client::Subscription>,
|
||||
modal: Option<AnyViewHandle>,
|
||||
center: PaneGroup,
|
||||
left_sidebar: ViewHandle<Sidebar>,
|
||||
right_sidebar: ViewHandle<Sidebar>,
|
||||
left_dock: ViewHandle<Dock>,
|
||||
right_dock: ViewHandle<Dock>,
|
||||
panes: Vec<ViewHandle<Pane>>,
|
||||
panes_by_item: HashMap<usize, WeakViewHandle<Pane>>,
|
||||
active_pane: ViewHandle<Pane>,
|
||||
|
@ -562,16 +562,16 @@ impl Workspace {
|
|||
|
||||
cx.emit_global(WorkspaceCreated(weak_handle.clone()));
|
||||
|
||||
let left_sidebar = cx.add_view(|_| Sidebar::new(SidebarSide::Left));
|
||||
let right_sidebar = cx.add_view(|_| Sidebar::new(SidebarSide::Right));
|
||||
let left_sidebar_buttons =
|
||||
cx.add_view(|cx| SidebarButtons::new(left_sidebar.clone(), weak_handle.clone(), cx));
|
||||
let right_sidebar_buttons =
|
||||
cx.add_view(|cx| SidebarButtons::new(right_sidebar.clone(), weak_handle.clone(), cx));
|
||||
let left_dock = cx.add_view(|_| Dock::new(DockPosition::Left));
|
||||
let right_dock = cx.add_view(|_| Dock::new(DockPosition::Right));
|
||||
let left_dock_buttons =
|
||||
cx.add_view(|cx| PanelButtons::new(left_dock.clone(), weak_handle.clone(), cx));
|
||||
let right_dock_buttons =
|
||||
cx.add_view(|cx| PanelButtons::new(right_dock.clone(), weak_handle.clone(), cx));
|
||||
let status_bar = cx.add_view(|cx| {
|
||||
let mut status_bar = StatusBar::new(¢er_pane.clone(), cx);
|
||||
status_bar.add_left_item(left_sidebar_buttons, cx);
|
||||
status_bar.add_right_item(right_sidebar_buttons, cx);
|
||||
status_bar.add_left_item(left_dock_buttons, cx);
|
||||
status_bar.add_right_item(right_dock_buttons, cx);
|
||||
status_bar
|
||||
});
|
||||
|
||||
|
@ -621,8 +621,8 @@ impl Workspace {
|
|||
titlebar_item: None,
|
||||
notifications: Default::default(),
|
||||
remote_entity_subscription: None,
|
||||
left_sidebar,
|
||||
right_sidebar,
|
||||
left_dock: left_dock,
|
||||
right_dock: right_dock,
|
||||
project: project.clone(),
|
||||
leader_state: Default::default(),
|
||||
follower_states_by_leader: Default::default(),
|
||||
|
@ -813,12 +813,12 @@ impl Workspace {
|
|||
self.weak_self.clone()
|
||||
}
|
||||
|
||||
pub fn left_sidebar(&self) -> &ViewHandle<Sidebar> {
|
||||
&self.left_sidebar
|
||||
pub fn left_dock(&self) -> &ViewHandle<Dock> {
|
||||
&self.left_dock
|
||||
}
|
||||
|
||||
pub fn right_sidebar(&self) -> &ViewHandle<Sidebar> {
|
||||
&self.right_sidebar
|
||||
pub fn right_dock(&self) -> &ViewHandle<Dock> {
|
||||
&self.right_dock
|
||||
}
|
||||
|
||||
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>) {
|
||||
let sidebar = match sidebar_side {
|
||||
SidebarSide::Left => &mut self.left_sidebar,
|
||||
SidebarSide::Right => &mut self.right_sidebar,
|
||||
pub fn toggle_dock(&mut self, dock_side: DockPosition, cx: &mut ViewContext<Self>) {
|
||||
let dock = match dock_side {
|
||||
DockPosition::Left => &mut self.left_dock,
|
||||
DockPosition::Right => &mut self.right_dock,
|
||||
};
|
||||
sidebar.update(cx, |sidebar, cx| {
|
||||
let open = !sidebar.is_open();
|
||||
sidebar.set_open(open, cx);
|
||||
dock.update(cx, |dock, cx| {
|
||||
let open = !dock.is_open();
|
||||
dock.set_open(open, cx);
|
||||
});
|
||||
|
||||
self.serialize_workspace(cx);
|
||||
|
@ -1322,19 +1322,19 @@ impl Workspace {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn toggle_sidebar_item(&mut self, action: &ToggleSidebarItem, cx: &mut ViewContext<Self>) {
|
||||
let sidebar = match action.sidebar_side {
|
||||
SidebarSide::Left => &mut self.left_sidebar,
|
||||
SidebarSide::Right => &mut self.right_sidebar,
|
||||
pub fn toggle_panel(&mut self, action: &ToggleDockItem, cx: &mut ViewContext<Self>) {
|
||||
let dock = match action.dock_position {
|
||||
DockPosition::Left => &mut self.left_dock,
|
||||
DockPosition::Right => &mut self.right_dock,
|
||||
};
|
||||
let active_item = sidebar.update(cx, move |sidebar, cx| {
|
||||
if sidebar.is_open() && sidebar.active_item_ix() == action.item_index {
|
||||
sidebar.set_open(false, cx);
|
||||
let active_item = dock.update(cx, move |dock, cx| {
|
||||
if dock.is_open() && dock.active_item_ix() == action.item_index {
|
||||
dock.set_open(false, cx);
|
||||
None
|
||||
} else {
|
||||
sidebar.set_open(true, cx);
|
||||
sidebar.activate_item(action.item_index, cx);
|
||||
sidebar.active_item().cloned()
|
||||
dock.set_open(true, cx);
|
||||
dock.activate_item(action.item_index, cx);
|
||||
dock.active_item().cloned()
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1353,20 +1353,20 @@ impl Workspace {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn toggle_sidebar_item_focus(
|
||||
pub fn toggle_panel_focus(
|
||||
&mut self,
|
||||
sidebar_side: SidebarSide,
|
||||
item_index: usize,
|
||||
dock_position: DockPosition,
|
||||
panel_index: usize,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
let sidebar = match sidebar_side {
|
||||
SidebarSide::Left => &mut self.left_sidebar,
|
||||
SidebarSide::Right => &mut self.right_sidebar,
|
||||
let dock = match dock_position {
|
||||
DockPosition::Left => &mut self.left_dock,
|
||||
DockPosition::Right => &mut self.right_dock,
|
||||
};
|
||||
let active_item = sidebar.update(cx, |sidebar, cx| {
|
||||
sidebar.set_open(true, cx);
|
||||
sidebar.activate_item(item_index, cx);
|
||||
sidebar.active_item().cloned()
|
||||
let active_item = dock.update(cx, |dock, cx| {
|
||||
dock.set_open(true, cx);
|
||||
dock.activate_item(panel_index, cx);
|
||||
dock.active_item().cloned()
|
||||
});
|
||||
if let Some(active_item) = active_item {
|
||||
if active_item.is_focused(cx) {
|
||||
|
@ -2452,7 +2452,7 @@ impl Workspace {
|
|||
id: self.database_id,
|
||||
location,
|
||||
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(),
|
||||
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
|
||||
{
|
||||
workspace.toggle_sidebar(SidebarSide::Left, cx);
|
||||
workspace.toggle_dock(DockPosition::Left, cx);
|
||||
}
|
||||
|
||||
cx.notify();
|
||||
|
@ -2596,9 +2596,9 @@ impl View for Workspace {
|
|||
let project = self.project.clone();
|
||||
Flex::row()
|
||||
.with_children(
|
||||
if self.left_sidebar.read(cx).active_item().is_some() {
|
||||
if self.left_dock.read(cx).active_item().is_some() {
|
||||
Some(
|
||||
ChildView::new(&self.left_sidebar, cx)
|
||||
ChildView::new(&self.left_dock, cx)
|
||||
.constrained()
|
||||
.dynamically(|constraint, _, cx| {
|
||||
SizeConstraint::new(
|
||||
|
@ -2633,9 +2633,9 @@ impl View for Workspace {
|
|||
.flex(1., true),
|
||||
)
|
||||
.with_children(
|
||||
if self.right_sidebar.read(cx).active_item().is_some() {
|
||||
if self.right_dock.read(cx).active_item().is_some() {
|
||||
Some(
|
||||
ChildView::new(&self.right_sidebar, cx)
|
||||
ChildView::new(&self.right_dock, cx)
|
||||
.constrained()
|
||||
.dynamically(|constraint, _, cx| {
|
||||
SizeConstraint::new(
|
||||
|
@ -2803,7 +2803,7 @@ pub fn open_paths(
|
|||
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
if contains_directory {
|
||||
workspace.toggle_sidebar(SidebarSide::Left, cx);
|
||||
workspace.toggle_dock(DockPosition::Left, cx);
|
||||
}
|
||||
})?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue