Show error+warning counts in project diagnostics tab

Allow workspace items' tab contents to be arbitrary elements

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-01-11 17:23:11 -08:00
parent 6ad9ff10c1
commit 6865a42df9
13 changed files with 121 additions and 77 deletions

View file

@ -55,8 +55,6 @@ pub enum Event {
Split(SplitDirection),
}
const MAX_TAB_TITLE_LEN: usize = 24;
#[derive(Debug, Eq, PartialEq)]
pub struct State {
pub tabs: Vec<TabState>,
@ -213,15 +211,12 @@ impl Pane {
let is_active = ix == self.active_item;
row.add_child({
let mut title = item_view.title(cx);
if title.len() > MAX_TAB_TITLE_LEN {
let mut truncated_len = MAX_TAB_TITLE_LEN;
while !title.is_char_boundary(truncated_len) {
truncated_len -= 1;
}
title.truncate(truncated_len);
title.push('…');
}
let tab_style = if is_active {
theme.workspace.active_tab.clone()
} else {
theme.workspace.tab.clone()
};
let title = item_view.tab_content(&tab_style, cx);
let mut style = if is_active {
theme.workspace.active_tab.clone()
@ -270,29 +265,16 @@ impl Pane {
.boxed(),
)
.with_child(
Container::new(
Align::new(
Label::new(
title,
if is_active {
theme.workspace.active_tab.label.clone()
} else {
theme.workspace.tab.label.clone()
},
)
.boxed(),
)
.boxed(),
)
.with_style(ContainerStyle {
margin: Margin {
left: style.spacing,
right: style.spacing,
Container::new(Align::new(title).boxed())
.with_style(ContainerStyle {
margin: Margin {
left: style.spacing,
right: style.spacing,
..Default::default()
},
..Default::default()
},
..Default::default()
})
.boxed(),
})
.boxed(),
)
.with_child(
Align::new(

View file

@ -142,7 +142,7 @@ pub trait ItemView: View {
type ItemHandle: ItemHandle;
fn item_handle(&self, cx: &AppContext) -> Self::ItemHandle;
fn title(&self, cx: &AppContext) -> String;
fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox;
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
fn clone_on_split(&self, _: &mut ViewContext<Self>) -> Option<Self>
where
@ -197,7 +197,7 @@ pub trait WeakItemHandle {
pub trait ItemViewHandle {
fn item_handle(&self, cx: &AppContext) -> Box<dyn ItemHandle>;
fn title(&self, cx: &AppContext) -> String;
fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox;
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
fn boxed_clone(&self) -> Box<dyn ItemViewHandle>;
fn clone_on_split(&self, cx: &mut MutableAppContext) -> Option<Box<dyn ItemViewHandle>>;
@ -308,8 +308,8 @@ impl<T: ItemView> ItemViewHandle for ViewHandle<T> {
Box::new(self.read(cx).item_handle(cx))
}
fn title(&self, cx: &AppContext) -> String {
self.read(cx).title(cx)
fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox {
self.read(cx).tab_content(style, cx)
}
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath> {
@ -980,7 +980,11 @@ impl Workspace {
}
pub fn activate_next_pane(&mut self, cx: &mut ViewContext<Self>) {
let ix = self.panes.iter().position(|pane| pane == &self.active_pane).unwrap();
let ix = self
.panes
.iter()
.position(|pane| pane == &self.active_pane)
.unwrap();
let next_ix = (ix + 1) % self.panes.len();
self.activate_pane(self.panes[next_ix].clone(), cx);
}