Rename item to panel in various locations
This commit is contained in:
parent
0ccb4a50e6
commit
cc21421ea8
2 changed files with 43 additions and 43 deletions
|
@ -83,9 +83,9 @@ impl From<&dyn PanelHandle> for AnyViewHandle {
|
||||||
|
|
||||||
pub struct Dock {
|
pub struct Dock {
|
||||||
position: DockPosition,
|
position: DockPosition,
|
||||||
panels: Vec<PanelEntry>,
|
panel_entries: Vec<PanelEntry>,
|
||||||
is_open: bool,
|
is_open: bool,
|
||||||
active_item_ix: usize,
|
active_panel_index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
|
#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
|
||||||
|
@ -127,7 +127,7 @@ pub struct PanelButtons {
|
||||||
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
||||||
pub struct TogglePanel {
|
pub struct TogglePanel {
|
||||||
pub dock_position: DockPosition,
|
pub dock_position: DockPosition,
|
||||||
pub item_index: usize,
|
pub panel_index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_actions!(workspace, [TogglePanel]);
|
impl_actions!(workspace, [TogglePanel]);
|
||||||
|
@ -136,8 +136,8 @@ impl Dock {
|
||||||
pub fn new(position: DockPosition) -> Self {
|
pub fn new(position: DockPosition) -> Self {
|
||||||
Self {
|
Self {
|
||||||
position,
|
position,
|
||||||
panels: Default::default(),
|
panel_entries: Default::default(),
|
||||||
active_item_ix: 0,
|
active_panel_index: 0,
|
||||||
is_open: false,
|
is_open: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,8 +146,8 @@ impl Dock {
|
||||||
self.is_open
|
self.is_open
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn active_item_ix(&self) -> usize {
|
pub fn active_panel_index(&self) -> usize {
|
||||||
self.active_item_ix
|
self.active_panel_index
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_open(&mut self, open: bool, cx: &mut ViewContext<Self>) {
|
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| {
|
cx.subscribe(&panel, |this, view, event, cx| {
|
||||||
if view.read(cx).should_activate_on_event(event, cx) {
|
if view.read(cx).should_activate_on_event(event, cx) {
|
||||||
if let Some(ix) = this
|
if let Some(ix) = this
|
||||||
.panels
|
.panel_entries
|
||||||
.iter()
|
.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) {
|
} else if view.read(cx).should_close_on_event(event, cx) {
|
||||||
this.set_open(false, cx);
|
this.set_open(false, cx);
|
||||||
|
@ -181,7 +181,7 @@ impl Dock {
|
||||||
];
|
];
|
||||||
|
|
||||||
let dock_view_id = cx.view_id();
|
let dock_view_id = cx.view_id();
|
||||||
self.panels.push(PanelEntry {
|
self.panel_entries.push(PanelEntry {
|
||||||
panel: Rc::new(panel),
|
panel: Rc::new(panel),
|
||||||
context_menu: cx.add_view(|cx| {
|
context_menu: cx.add_view(|cx| {
|
||||||
let mut menu = ContextMenu::new(dock_view_id, 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>) {
|
pub fn remove_panel<T: Panel>(&mut self, panel: &ViewHandle<T>, cx: &mut ViewContext<Self>) {
|
||||||
if let Some(panel_ix) = self
|
if let Some(panel_ix) = self
|
||||||
.panels
|
.panel_entries
|
||||||
.iter()
|
.iter()
|
||||||
.position(|item| item.panel.id() == panel.id())
|
.position(|entry| entry.panel.id() == panel.id())
|
||||||
{
|
{
|
||||||
if panel_ix == self.active_item_ix {
|
if panel_ix == self.active_panel_index {
|
||||||
self.active_item_ix = 0;
|
self.active_panel_index = 0;
|
||||||
self.set_open(false, cx);
|
self.set_open(false, cx);
|
||||||
}
|
}
|
||||||
self.panels.remove(panel_ix);
|
self.panel_entries.remove(panel_ix);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn panels_len(&self) -> usize {
|
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>) {
|
pub fn activate_panel(&mut self, panel_ix: usize, cx: &mut ViewContext<Self>) {
|
||||||
self.active_item_ix = item_ix;
|
self.active_panel_index = panel_ix;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_item(&mut self, item_ix: usize, cx: &mut ViewContext<Self>) {
|
pub fn toggle_panel(&mut self, panel_ix: usize, cx: &mut ViewContext<Self>) {
|
||||||
if self.active_item_ix == item_ix {
|
if self.active_panel_index == panel_ix {
|
||||||
self.is_open = false;
|
self.is_open = false;
|
||||||
} else {
|
} else {
|
||||||
self.active_item_ix = item_ix;
|
self.active_panel_index = panel_ix;
|
||||||
}
|
}
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn active_item(&self) -> Option<&Rc<dyn PanelHandle>> {
|
pub fn active_panel(&self) -> Option<&Rc<dyn PanelHandle>> {
|
||||||
if self.is_open {
|
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 {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -245,10 +245,10 @@ impl View for 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_panel) = self.active_panel() {
|
||||||
enum ResizeHandleTag {}
|
enum ResizeHandleTag {}
|
||||||
let style = &cx.global::<Settings>().theme.workspace.dock;
|
let style = &cx.global::<Settings>().theme.workspace.dock;
|
||||||
ChildView::new(active_item.as_any(), cx)
|
ChildView::new(active_panel.as_any(), cx)
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
.with_resize_handle::<ResizeHandleTag>(
|
.with_resize_handle::<ResizeHandleTag>(
|
||||||
|
@ -289,9 +289,9 @@ impl View for PanelButtons {
|
||||||
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.panel_buttons;
|
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 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 is_open = dock.is_open;
|
||||||
let dock_position = dock.position;
|
let dock_position = dock.position;
|
||||||
let group_style = match dock_position {
|
let group_style = match dock_position {
|
||||||
|
@ -304,27 +304,27 @@ impl View for PanelButtons {
|
||||||
DockPosition::Bottom | DockPosition::Right => AnchorCorner::BottomRight,
|
DockPosition::Bottom | DockPosition::Right => AnchorCorner::BottomRight,
|
||||||
};
|
};
|
||||||
|
|
||||||
let items = dock
|
let panels = dock
|
||||||
.panels
|
.panel_entries
|
||||||
.iter()
|
.iter()
|
||||||
.map(|item| (item.panel.clone(), item.context_menu.clone()))
|
.map(|item| (item.panel.clone(), item.context_menu.clone()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_children(
|
.with_children(
|
||||||
items
|
panels
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(ix, (view, context_menu))| {
|
.map(|(ix, (view, context_menu))| {
|
||||||
let action = TogglePanel {
|
let action = TogglePanel {
|
||||||
dock_position,
|
dock_position,
|
||||||
item_index: ix,
|
panel_index: ix,
|
||||||
};
|
};
|
||||||
|
|
||||||
Stack::new()
|
Stack::new()
|
||||||
.with_child(
|
.with_child(
|
||||||
MouseEventHandler::<Self, _>::new(ix, cx, |state, cx| {
|
MouseEventHandler::<Self, _>::new(ix, cx, |state, cx| {
|
||||||
let is_active = is_open && ix == active_ix;
|
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()
|
Flex::row()
|
||||||
.with_child(
|
.with_child(
|
||||||
Svg::new(view.icon_path(cx))
|
Svg::new(view.icon_path(cx))
|
||||||
|
|
|
@ -858,7 +858,7 @@ impl Workspace {
|
||||||
dock.update(cx, |dock, cx| {
|
dock.update(cx, |dock, cx| {
|
||||||
was_visible = dock.is_open()
|
was_visible = dock.is_open()
|
||||||
&& dock
|
&& dock
|
||||||
.active_item()
|
.active_panel()
|
||||||
.map_or(false, |item| item.as_any().is::<T>());
|
.map_or(false, |item| item.as_any().is::<T>());
|
||||||
dock.remove_panel(&panel, cx);
|
dock.remove_panel(&panel, cx);
|
||||||
});
|
});
|
||||||
|
@ -872,7 +872,7 @@ impl Workspace {
|
||||||
dock.add_panel(panel, cx);
|
dock.add_panel(panel, cx);
|
||||||
if was_visible {
|
if was_visible {
|
||||||
dock.set_open(true, cx);
|
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,
|
DockPosition::Right => &mut self.right_dock,
|
||||||
};
|
};
|
||||||
let active_item = dock.update(cx, move |dock, cx| {
|
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);
|
dock.set_open(false, cx);
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
dock.set_open(true, cx);
|
dock.set_open(true, cx);
|
||||||
dock.activate_item(action.item_index, cx);
|
dock.activate_panel(action.panel_index, cx);
|
||||||
dock.active_item().cloned()
|
dock.active_panel().cloned()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1430,8 +1430,8 @@ impl Workspace {
|
||||||
};
|
};
|
||||||
let active_item = dock.update(cx, |dock, cx| {
|
let active_item = dock.update(cx, |dock, cx| {
|
||||||
dock.set_open(true, cx);
|
dock.set_open(true, cx);
|
||||||
dock.activate_item(panel_index, cx);
|
dock.activate_panel(panel_index, cx);
|
||||||
dock.active_item().cloned()
|
dock.active_panel().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) {
|
||||||
|
@ -2655,7 +2655,7 @@ 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_dock.read(cx).active_item().is_some() {
|
if self.left_dock.read(cx).active_panel().is_some() {
|
||||||
Some(
|
Some(
|
||||||
ChildView::new(&self.left_dock, cx)
|
ChildView::new(&self.left_dock, cx)
|
||||||
.constrained()
|
.constrained()
|
||||||
|
@ -2688,7 +2688,7 @@ impl View for Workspace {
|
||||||
.flex(1., true),
|
.flex(1., true),
|
||||||
)
|
)
|
||||||
.with_children(
|
.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))
|
Some(ChildView::new(&self.bottom_dock, cx))
|
||||||
} else {
|
} else {
|
||||||
|
@ -2698,7 +2698,7 @@ impl View for Workspace {
|
||||||
.flex(1., true),
|
.flex(1., true),
|
||||||
)
|
)
|
||||||
.with_children(
|
.with_children(
|
||||||
if self.right_dock.read(cx).active_item().is_some() {
|
if self.right_dock.read(cx).active_panel().is_some() {
|
||||||
Some(
|
Some(
|
||||||
ChildView::new(&self.right_dock, cx)
|
ChildView::new(&self.right_dock, cx)
|
||||||
.constrained()
|
.constrained()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue