Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Rename item to panel in various locations
Nathan Sobocc21421ea869
diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rsindex 74132098744..82d8d404259 100644--- a/crates/workspace/src/dock.rs+++ b/crates/workspace/src/dock.rs@@ -83,9 +83,9 @@ impl From<&dyn PanelHandle> for AnyViewHandle {pub struct Dock {position: DockPosition,- panels: Vec<PanelEntry>,+ panel_entries: Vec<PanelEntry>,is_open: bool,- active_item_ix: usize,+ active_panel_index: usize,}#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]@@ -127,7 +127,7 @@ pub struct PanelButtons {#[derive(Clone, Debug, Deserialize, PartialEq)]pub struct TogglePanel {pub dock_position: DockPosition,- pub item_index: usize,+ pub panel_index: usize,}impl_actions!(workspace, [TogglePanel]);@@ -136,8 +136,8 @@ impl Dock {pub fn new(position: DockPosition) -> Self {Self {position,- panels: Default::default(),- active_item_ix: 0,+ panel_entries: Default::default(),+ active_panel_index: 0,is_open: false,}}@@ -146,8 +146,8 @@ impl Dock {self.is_open}- pub fn active_item_ix(&self) -> usize {- self.active_item_ix+ pub fn active_panel_index(&self) -> usize {+ self.active_panel_index}pub fn set_open(&mut self, open: bool, cx: &mut ViewContext<Self>) {@@ -168,11 +168,11 @@ impl Dock {cx.subscribe(&panel, |this, view, event, cx| {if view.read(cx).should_activate_on_event(event, cx) {if let Some(ix) = this- .panels+ .panel_entries.iter()- .position(|item| item.panel.id() == view.id())+ .position(|entry| entry.panel.id() == view.id()){- this.activate_item(ix, cx);+ this.activate_panel(ix, cx);}} else if view.read(cx).should_close_on_event(event, cx) {this.set_open(false, cx);@@ -181,7 +181,7 @@ impl Dock {];let dock_view_id = cx.view_id();- self.panels.push(PanelEntry {+ self.panel_entries.push(PanelEntry {panel: Rc::new(panel),context_menu: cx.add_view(|cx| {let mut menu = ContextMenu::new(dock_view_id, cx);@@ -195,40 +195,40 @@ impl Dock {pub fn remove_panel<T: Panel>(&mut self, panel: &ViewHandle<T>, cx: &mut ViewContext<Self>) {if let Some(panel_ix) = self- .panels+ .panel_entries.iter()- .position(|item| item.panel.id() == panel.id())+ .position(|entry| entry.panel.id() == panel.id()){- if panel_ix == self.active_item_ix {- self.active_item_ix = 0;+ if panel_ix == self.active_panel_index {+ self.active_panel_index = 0;self.set_open(false, cx);}- self.panels.remove(panel_ix);+ self.panel_entries.remove(panel_ix);cx.notify();}}pub fn panels_len(&self) -> usize {- self.panels.len()+ self.panel_entries.len()}- pub fn activate_item(&mut self, item_ix: usize, cx: &mut ViewContext<Self>) {- self.active_item_ix = item_ix;+ pub fn activate_panel(&mut self, panel_ix: usize, cx: &mut ViewContext<Self>) {+ self.active_panel_index = panel_ix;cx.notify();}- pub fn toggle_item(&mut self, item_ix: usize, cx: &mut ViewContext<Self>) {- if self.active_item_ix == item_ix {+ pub fn toggle_panel(&mut self, panel_ix: usize, cx: &mut ViewContext<Self>) {+ if self.active_panel_index == panel_ix {self.is_open = false;} else {- self.active_item_ix = item_ix;+ self.active_panel_index = panel_ix;}cx.notify();}- pub fn active_item(&self) -> Option<&Rc<dyn PanelHandle>> {+ pub fn active_panel(&self) -> Option<&Rc<dyn PanelHandle>> {if self.is_open {- self.panels.get(self.active_item_ix).map(|item| &item.panel)+ self.panel_entries.get(self.active_panel_index).map(|entry| &entry.panel)} else {None}@@ -245,10 +245,10 @@ impl View for Dock {}fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {- if let Some(active_item) = self.active_item() {+ if let Some(active_panel) = self.active_panel() {enum ResizeHandleTag {}let style = &cx.global::<Settings>().theme.workspace.dock;- ChildView::new(active_item.as_any(), cx)+ ChildView::new(active_panel.as_any(), cx).contained().with_style(style.container).with_resize_handle::<ResizeHandleTag>(@@ -289,9 +289,9 @@ impl View for PanelButtons {let theme = &cx.global::<Settings>().theme;let tooltip_style = theme.tooltip.clone();let theme = &theme.workspace.status_bar.panel_buttons;- let item_style = theme.button.clone();+ let button_style = theme.button.clone();let dock = self.dock.read(cx);- let active_ix = dock.active_item_ix;+ let active_ix = dock.active_panel_index;let is_open = dock.is_open;let dock_position = dock.position;let group_style = match dock_position {@@ -304,27 +304,27 @@ impl View for PanelButtons {DockPosition::Bottom | DockPosition::Right => AnchorCorner::BottomRight,};- let items = dock- .panels+ let panels = dock+ .panel_entries.iter().map(|item| (item.panel.clone(), item.context_menu.clone())).collect::<Vec<_>>();Flex::row().with_children(- items+ panels.into_iter().enumerate().map(|(ix, (view, context_menu))| {let action = TogglePanel {dock_position,- item_index: ix,+ panel_index: ix,};Stack::new().with_child(MouseEventHandler::<Self, _>::new(ix, cx, |state, cx| {let is_active = is_open && ix == active_ix;- let style = item_style.style_for(state, is_active);+ let style = button_style.style_for(state, is_active);Flex::row().with_child(Svg::new(view.icon_path(cx))diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex 497b28cff10..cf89ed43c75 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -858,7 +858,7 @@ impl Workspace {dock.update(cx, |dock, cx| {was_visible = dock.is_open()&& dock- .active_item()+ .active_panel().map_or(false, |item| item.as_any().is::<T>());dock.remove_panel(&panel, cx);});@@ -872,7 +872,7 @@ impl Workspace {dock.add_panel(panel, cx);if was_visible {dock.set_open(true, cx);- dock.activate_item(dock.panels_len() - 1, cx);+ dock.activate_panel(dock.panels_len() - 1, cx);}});}@@ -1392,13 +1392,13 @@ impl Workspace {DockPosition::Right => &mut self.right_dock,};let active_item = dock.update(cx, move |dock, cx| {- if dock.is_open() && dock.active_item_ix() == action.item_index {+ if dock.is_open() && dock.active_panel_index() == action.panel_index {dock.set_open(false, cx);None} else {dock.set_open(true, cx);- dock.activate_item(action.item_index, cx);- dock.active_item().cloned()+ dock.activate_panel(action.panel_index, cx);+ dock.active_panel().cloned()}});@@ -1430,8 +1430,8 @@ impl Workspace {};let active_item = dock.update(cx, |dock, cx| {dock.set_open(true, cx);- dock.activate_item(panel_index, cx);- dock.active_item().cloned()+ dock.activate_panel(panel_index, cx);+ dock.active_panel().cloned()});if let Some(active_item) = active_item {if active_item.is_focused(cx) {@@ -2655,7 +2655,7 @@ impl View for Workspace {let project = self.project.clone();Flex::row().with_children(- if self.left_dock.read(cx).active_item().is_some() {+ if self.left_dock.read(cx).active_panel().is_some() {Some(ChildView::new(&self.left_dock, cx).constrained()@@ -2688,7 +2688,7 @@ impl View for Workspace {.flex(1., true),).with_children(- if self.bottom_dock.read(cx).active_item().is_some()+ if self.bottom_dock.read(cx).active_panel().is_some(){Some(ChildView::new(&self.bottom_dock, cx))} else {@@ -2698,7 +2698,7 @@ impl View for Workspace {.flex(1., true),).with_children(- if self.right_dock.read(cx).active_item().is_some() {+ if self.right_dock.read(cx).active_panel().is_some() {Some(ChildView::new(&self.right_dock, cx).constrained()