Rename DockItem to Panel
This commit is contained in:
parent
03f8c1206a
commit
1ddbda5095
9 changed files with 25 additions and 24 deletions
|
@ -65,7 +65,7 @@ impl View for CopilotButton {
|
||||||
.workspace
|
.workspace
|
||||||
.status_bar
|
.status_bar
|
||||||
.panel_buttons
|
.panel_buttons
|
||||||
.item
|
.button
|
||||||
.style_for(state, active);
|
.style_for(state, active);
|
||||||
|
|
||||||
Flex::row()
|
Flex::row()
|
||||||
|
|
|
@ -41,7 +41,7 @@ impl View for DeployFeedbackButton {
|
||||||
.workspace
|
.workspace
|
||||||
.status_bar
|
.status_bar
|
||||||
.panel_buttons
|
.panel_buttons
|
||||||
.item
|
.button
|
||||||
.style_for(state, active);
|
.style_for(state, active);
|
||||||
|
|
||||||
Svg::new("icons/feedback_16.svg")
|
Svg::new("icons/feedback_16.svg")
|
||||||
|
|
|
@ -1327,7 +1327,7 @@ impl Entity for ProjectPanel {
|
||||||
type Event = Event;
|
type Event = Event;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl workspace::dock::DockItem for ProjectPanel {
|
impl workspace::dock::Panel for ProjectPanel {
|
||||||
fn should_show_badge(&self, _: &AppContext) -> bool {
|
fn should_show_badge(&self, _: &AppContext) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl View for TerminalButton {
|
||||||
.workspace
|
.workspace
|
||||||
.status_bar
|
.status_bar
|
||||||
.panel_buttons
|
.panel_buttons
|
||||||
.item
|
.button
|
||||||
.style_for(state, active);
|
.style_for(state, active);
|
||||||
|
|
||||||
Flex::row()
|
Flex::row()
|
||||||
|
|
|
@ -344,7 +344,7 @@ pub struct StatusBar {
|
||||||
pub struct StatusBarPanelButtons {
|
pub struct StatusBarPanelButtons {
|
||||||
pub group_left: ContainerStyle,
|
pub group_left: ContainerStyle,
|
||||||
pub group_right: ContainerStyle,
|
pub group_right: ContainerStyle,
|
||||||
pub item: Interactive<DockItem>,
|
pub button: Interactive<PanelButton>,
|
||||||
pub badge: ContainerStyle,
|
pub badge: ContainerStyle,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,7 +382,7 @@ pub struct Dock {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Default)]
|
#[derive(Clone, Deserialize, Default)]
|
||||||
pub struct DockItem {
|
pub struct PanelButton {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub container: ContainerStyle,
|
pub container: ContainerStyle,
|
||||||
pub icon_color: Color,
|
pub icon_color: Color,
|
||||||
|
|
|
@ -7,7 +7,7 @@ use serde::Deserialize;
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
pub trait DockItem: View {
|
pub trait Panel: 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,17 @@ pub trait DockItem: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait DockItemHandle {
|
pub trait PanelHandle {
|
||||||
|
|
||||||
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> DockItemHandle for ViewHandle<T>
|
impl<T> PanelHandle for ViewHandle<T>
|
||||||
where
|
where
|
||||||
T: DockItem,
|
T: Panel,
|
||||||
{
|
{
|
||||||
fn id(&self) -> usize {
|
fn id(&self) -> usize {
|
||||||
self.id()
|
self.id()
|
||||||
|
@ -47,8 +48,8 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&dyn DockItemHandle> for AnyViewHandle {
|
impl From<&dyn PanelHandle> for AnyViewHandle {
|
||||||
fn from(val: &dyn DockItemHandle) -> Self {
|
fn from(val: &dyn PanelHandle) -> Self {
|
||||||
val.as_any().clone()
|
val.as_any().clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +79,7 @@ impl DockPosition {
|
||||||
struct Item {
|
struct Item {
|
||||||
icon_path: &'static str,
|
icon_path: &'static str,
|
||||||
tooltip: String,
|
tooltip: String,
|
||||||
view: Rc<dyn DockItemHandle>,
|
view: Rc<dyn PanelHandle>,
|
||||||
_subscriptions: [Subscription; 2],
|
_subscriptions: [Subscription; 2],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,12 +89,12 @@ pub struct PanelButtons {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
||||||
pub struct ToggleDockItem {
|
pub struct TogglePanel {
|
||||||
pub dock_position: DockPosition,
|
pub dock_position: DockPosition,
|
||||||
pub item_index: usize,
|
pub item_index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_actions!(workspace, [ToggleDockItem]);
|
impl_actions!(workspace, [TogglePanel]);
|
||||||
|
|
||||||
impl Dock {
|
impl Dock {
|
||||||
pub fn new(position: DockPosition) -> Self {
|
pub fn new(position: DockPosition) -> Self {
|
||||||
|
@ -126,7 +127,7 @@ impl Dock {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_item<T: DockItem>(
|
pub fn add_item<T: Panel>(
|
||||||
&mut self,
|
&mut self,
|
||||||
icon_path: &'static str,
|
icon_path: &'static str,
|
||||||
tooltip: String,
|
tooltip: String,
|
||||||
|
@ -171,7 +172,7 @@ impl Dock {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn active_item(&self) -> Option<&Rc<dyn DockItemHandle>> {
|
pub fn active_item(&self) -> Option<&Rc<dyn PanelHandle>> {
|
||||||
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 {
|
||||||
|
@ -235,7 +236,7 @@ impl View for PanelButtons {
|
||||||
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 dock = self.dock.read(cx);
|
let dock = self.dock.read(cx);
|
||||||
let item_style = theme.item.clone();
|
let item_style = theme.button.clone();
|
||||||
let badge_style = theme.badge;
|
let badge_style = theme.badge;
|
||||||
let active_ix = dock.active_item_ix;
|
let active_ix = dock.active_item_ix;
|
||||||
let is_open = dock.is_open;
|
let is_open = dock.is_open;
|
||||||
|
@ -255,7 +256,7 @@ impl View for PanelButtons {
|
||||||
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 = ToggleDockItem {
|
let action = TogglePanel {
|
||||||
dock_position,
|
dock_position,
|
||||||
item_index: ix,
|
item_index: ix,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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::{dock::DockItem, ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
|
use crate::{dock::Panel, 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 DockItem for TestItem {}
|
impl Panel for TestItem {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 dock::{Dock, PanelButtons, DockPosition, ToggleDockItem};
|
use dock::{Dock, PanelButtons, DockPosition, TogglePanel};
|
||||||
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};
|
||||||
|
@ -1322,7 +1322,7 @@ impl Workspace {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_panel(&mut self, action: &ToggleDockItem, cx: &mut ViewContext<Self>) {
|
pub fn toggle_panel(&mut self, action: &TogglePanel, cx: &mut ViewContext<Self>) {
|
||||||
let dock = match action.dock_position {
|
let dock = match action.dock_position {
|
||||||
DockPosition::Left => &mut self.left_dock,
|
DockPosition::Left => &mut self.left_dock,
|
||||||
DockPosition::Right => &mut self.right_dock,
|
DockPosition::Right => &mut self.right_dock,
|
||||||
|
|
|
@ -96,7 +96,7 @@ export default function statusBar(colorScheme: ColorScheme) {
|
||||||
panelButtons: {
|
panelButtons: {
|
||||||
groupLeft: {},
|
groupLeft: {},
|
||||||
groupRight: {},
|
groupRight: {},
|
||||||
item: {
|
button: {
|
||||||
...statusContainer,
|
...statusContainer,
|
||||||
iconSize: 16,
|
iconSize: 16,
|
||||||
iconColor: foreground(layer, "variant"),
|
iconColor: foreground(layer, "variant"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue