Merge branch 'main' into theme-improvements
This commit is contained in:
commit
bcc554a3db
76 changed files with 4053 additions and 1557 deletions
|
@ -13,8 +13,9 @@ use gpui::{
|
|||
},
|
||||
impl_actions, impl_internal_actions,
|
||||
platform::{CursorStyle, NavigationDirection},
|
||||
AppContext, AsyncAppContext, Entity, ModelHandle, MutableAppContext, PromptLevel, Quad,
|
||||
RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
AppContext, AsyncAppContext, Entity, ModelHandle, MouseButton, MouseButtonEvent,
|
||||
MutableAppContext, PromptLevel, Quad, RenderContext, Task, View, ViewContext, ViewHandle,
|
||||
WeakViewHandle,
|
||||
};
|
||||
use project::{Project, ProjectEntryId, ProjectPath};
|
||||
use serde::Deserialize;
|
||||
|
@ -71,10 +72,10 @@ const MAX_NAVIGATION_HISTORY_LEN: usize = 1024;
|
|||
|
||||
pub fn init(cx: &mut MutableAppContext) {
|
||||
cx.add_action(|pane: &mut Pane, action: &ActivateItem, cx| {
|
||||
pane.activate_item(action.0, true, true, cx);
|
||||
pane.activate_item(action.0, true, true, false, cx);
|
||||
});
|
||||
cx.add_action(|pane: &mut Pane, _: &ActivateLastItem, cx| {
|
||||
pane.activate_item(pane.items.len() - 1, true, true, cx);
|
||||
pane.activate_item(pane.items.len() - 1, true, true, false, cx);
|
||||
});
|
||||
cx.add_action(|pane: &mut Pane, _: &ActivatePrevItem, cx| {
|
||||
pane.activate_prev_item(cx);
|
||||
|
@ -288,7 +289,7 @@ impl Pane {
|
|||
{
|
||||
let prev_active_item_index = pane.active_item_index;
|
||||
pane.nav_history.borrow_mut().set_mode(mode);
|
||||
pane.activate_item(index, true, true, cx);
|
||||
pane.activate_item(index, true, true, false, cx);
|
||||
pane.nav_history
|
||||
.borrow_mut()
|
||||
.set_mode(NavigationMode::Normal);
|
||||
|
@ -380,7 +381,7 @@ impl Pane {
|
|||
&& item.project_entry_ids(cx).as_slice() == &[project_entry_id]
|
||||
{
|
||||
let item = item.boxed_clone();
|
||||
pane.activate_item(ix, true, focus_item, cx);
|
||||
pane.activate_item(ix, true, focus_item, true, cx);
|
||||
return Some(item);
|
||||
}
|
||||
}
|
||||
|
@ -404,9 +405,11 @@ impl Pane {
|
|||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
// Prevent adding the same item to the pane more than once.
|
||||
// If there is already an active item, reorder the desired item to be after it
|
||||
// and activate it.
|
||||
if let Some(item_ix) = pane.read(cx).items.iter().position(|i| i.id() == item.id()) {
|
||||
pane.update(cx, |pane, cx| {
|
||||
pane.activate_item(item_ix, activate_pane, focus_item, cx)
|
||||
pane.activate_item(item_ix, activate_pane, focus_item, true, cx)
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -426,7 +429,7 @@ impl Pane {
|
|||
};
|
||||
|
||||
pane.items.insert(item_ix, item);
|
||||
pane.activate_item(item_ix, activate_pane, focus_item, cx);
|
||||
pane.activate_item(item_ix, activate_pane, focus_item, false, cx);
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
|
@ -465,13 +468,31 @@ impl Pane {
|
|||
|
||||
pub fn activate_item(
|
||||
&mut self,
|
||||
index: usize,
|
||||
mut index: usize,
|
||||
activate_pane: bool,
|
||||
focus_item: bool,
|
||||
move_after_current_active: bool,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
use NavigationMode::{GoingBack, GoingForward};
|
||||
if index < self.items.len() {
|
||||
if move_after_current_active {
|
||||
// If there is already an active item, reorder the desired item to be after it
|
||||
// and activate it.
|
||||
if self.active_item_index != index && self.active_item_index < self.items.len() {
|
||||
let pane_to_activate = self.items.remove(index);
|
||||
if self.active_item_index < index {
|
||||
index = self.active_item_index + 1;
|
||||
} else if self.active_item_index < self.items.len() + 1 {
|
||||
index = self.active_item_index;
|
||||
// Index is less than active_item_index. Reordering will decrement the
|
||||
// active_item_index, so adjust it accordingly
|
||||
self.active_item_index = index - 1;
|
||||
}
|
||||
self.items.insert(index, pane_to_activate);
|
||||
}
|
||||
}
|
||||
|
||||
let prev_active_item_ix = mem::replace(&mut self.active_item_index, index);
|
||||
if prev_active_item_ix != self.active_item_index
|
||||
|| matches!(self.nav_history.borrow().mode, GoingBack | GoingForward)
|
||||
|
@ -502,7 +523,7 @@ impl Pane {
|
|||
} else if self.items.len() > 0 {
|
||||
index = self.items.len() - 1;
|
||||
}
|
||||
self.activate_item(index, true, true, cx);
|
||||
self.activate_item(index, true, true, false, cx);
|
||||
}
|
||||
|
||||
pub fn activate_next_item(&mut self, cx: &mut ViewContext<Self>) {
|
||||
|
@ -512,7 +533,7 @@ impl Pane {
|
|||
} else {
|
||||
index = 0;
|
||||
}
|
||||
self.activate_item(index, true, true, cx);
|
||||
self.activate_item(index, true, true, false, cx);
|
||||
}
|
||||
|
||||
pub fn close_active_item(
|
||||
|
@ -641,10 +662,13 @@ impl Pane {
|
|||
pane.update(&mut cx, |pane, cx| {
|
||||
if let Some(item_ix) = pane.items.iter().position(|i| i.id() == item.id()) {
|
||||
if item_ix == pane.active_item_index {
|
||||
if item_ix + 1 < pane.items.len() {
|
||||
pane.activate_next_item(cx);
|
||||
} else if item_ix > 0 {
|
||||
// Activate the previous item if possible.
|
||||
// This returns the user to the previously opened tab if they closed
|
||||
// a ne item they just navigated to.
|
||||
if item_ix > 0 {
|
||||
pane.activate_prev_item(cx);
|
||||
} else if item_ix + 1 < pane.items.len() {
|
||||
pane.activate_next_item(cx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -712,7 +736,7 @@ impl Pane {
|
|||
|
||||
if has_conflict && can_save {
|
||||
let mut answer = pane.update(cx, |pane, cx| {
|
||||
pane.activate_item(item_ix, true, true, cx);
|
||||
pane.activate_item(item_ix, true, true, false, cx);
|
||||
cx.prompt(
|
||||
PromptLevel::Warning,
|
||||
CONFLICT_MESSAGE,
|
||||
|
@ -733,7 +757,7 @@ impl Pane {
|
|||
});
|
||||
let should_save = if should_prompt_for_save && !will_autosave {
|
||||
let mut answer = pane.update(cx, |pane, cx| {
|
||||
pane.activate_item(item_ix, true, true, cx);
|
||||
pane.activate_item(item_ix, true, true, false, cx);
|
||||
cx.prompt(
|
||||
PromptLevel::Warning,
|
||||
DIRTY_MESSAGE,
|
||||
|
@ -840,8 +864,10 @@ impl Pane {
|
|||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let mut row = Flex::row().scrollable::<Tabs, _>(1, autoscroll, cx);
|
||||
for (ix, item) in self.items.iter().enumerate() {
|
||||
for (ix, (item, detail)) in self.items.iter().zip(self.tab_details(cx)).enumerate() {
|
||||
let detail = if detail == 0 { None } else { Some(detail) };
|
||||
let is_active = ix == self.active_item_index;
|
||||
|
||||
row.add_child({
|
||||
|
@ -850,7 +876,7 @@ impl Pane {
|
|||
} else {
|
||||
theme.workspace.tab.clone()
|
||||
};
|
||||
let title = item.tab_content(&tab_style, cx);
|
||||
let title = item.tab_content(detail, &tab_style, cx);
|
||||
|
||||
let mut style = if is_active {
|
||||
theme.workspace.active_tab.clone()
|
||||
|
@ -930,9 +956,9 @@ impl Pane {
|
|||
)
|
||||
.with_padding(Padding::uniform(4.))
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click({
|
||||
.on_click(MouseButton::Left, {
|
||||
let pane = pane.clone();
|
||||
move |_, _, cx| {
|
||||
move |_, cx| {
|
||||
cx.dispatch_action(CloseItem {
|
||||
item_id,
|
||||
pane: pane.clone(),
|
||||
|
@ -953,7 +979,7 @@ impl Pane {
|
|||
.with_style(style.container)
|
||||
.boxed()
|
||||
})
|
||||
.on_mouse_down(move |_, cx| {
|
||||
.on_mouse_down(MouseButton::Left, move |_, cx| {
|
||||
cx.dispatch_action(ActivateItem(ix));
|
||||
})
|
||||
.boxed()
|
||||
|
@ -971,6 +997,43 @@ impl Pane {
|
|||
row.boxed()
|
||||
})
|
||||
}
|
||||
|
||||
fn tab_details(&self, cx: &AppContext) -> Vec<usize> {
|
||||
let mut tab_details = (0..self.items.len()).map(|_| 0).collect::<Vec<_>>();
|
||||
|
||||
let mut tab_descriptions = HashMap::default();
|
||||
let mut done = false;
|
||||
while !done {
|
||||
done = true;
|
||||
|
||||
// Store item indices by their tab description.
|
||||
for (ix, (item, detail)) in self.items.iter().zip(&tab_details).enumerate() {
|
||||
if let Some(description) = item.tab_description(*detail, cx) {
|
||||
if *detail == 0
|
||||
|| Some(&description) != item.tab_description(detail - 1, cx).as_ref()
|
||||
{
|
||||
tab_descriptions
|
||||
.entry(description)
|
||||
.or_insert(Vec::new())
|
||||
.push(ix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If two or more items have the same tab description, increase their level
|
||||
// of detail and try again.
|
||||
for (_, item_ixs) in tab_descriptions.drain() {
|
||||
if item_ixs.len() > 1 {
|
||||
done = false;
|
||||
for ix in item_ixs {
|
||||
tab_details[ix] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tab_details
|
||||
}
|
||||
}
|
||||
|
||||
impl Entity for Pane {
|
||||
|
@ -1017,9 +1080,12 @@ impl View for Pane {
|
|||
},
|
||||
)
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_mouse_down(|position, cx| {
|
||||
cx.dispatch_action(DeploySplitMenu { position });
|
||||
})
|
||||
.on_mouse_down(
|
||||
MouseButton::Left,
|
||||
|MouseButtonEvent { position, .. }, cx| {
|
||||
cx.dispatch_action(DeploySplitMenu { position });
|
||||
},
|
||||
)
|
||||
.boxed(),
|
||||
)
|
||||
.constrained()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::StatusItemView;
|
||||
use gpui::{
|
||||
elements::*, impl_actions, platform::CursorStyle, AnyViewHandle, AppContext, Entity,
|
||||
RenderContext, Subscription, View, ViewContext, ViewHandle,
|
||||
MouseButton, MouseMovedEvent, RenderContext, Subscription, View, ViewContext, ViewHandle,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use settings::Settings;
|
||||
|
@ -187,19 +187,27 @@ impl Sidebar {
|
|||
..Default::default()
|
||||
})
|
||||
.with_cursor_style(CursorStyle::ResizeLeftRight)
|
||||
.on_mouse_down(|_, _| {}) // This prevents the mouse down event from being propagated elsewhere
|
||||
.on_drag(move |old_position, new_position, cx| {
|
||||
let delta = new_position.x() - old_position.x();
|
||||
let prev_width = *actual_width.borrow();
|
||||
*custom_width.borrow_mut() = 0f32
|
||||
.max(match side {
|
||||
Side::Left => prev_width + delta,
|
||||
Side::Right => prev_width - delta,
|
||||
})
|
||||
.round();
|
||||
.on_mouse_down(MouseButton::Left, |_, _| {}) // This prevents the mouse down event from being propagated elsewhere
|
||||
.on_drag(
|
||||
MouseButton::Left,
|
||||
move |old_position,
|
||||
MouseMovedEvent {
|
||||
position: new_position,
|
||||
..
|
||||
},
|
||||
cx| {
|
||||
let delta = new_position.x() - old_position.x();
|
||||
let prev_width = *actual_width.borrow();
|
||||
*custom_width.borrow_mut() = 0f32
|
||||
.max(match side {
|
||||
Side::Left => prev_width + delta,
|
||||
Side::Right => prev_width - delta,
|
||||
})
|
||||
.round();
|
||||
|
||||
cx.notify();
|
||||
})
|
||||
cx.notify();
|
||||
},
|
||||
)
|
||||
.boxed()
|
||||
}
|
||||
}
|
||||
|
@ -314,9 +322,9 @@ impl View for SidebarButtons {
|
|||
.boxed()
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click({
|
||||
.on_click(MouseButton::Left, {
|
||||
let action = action.clone();
|
||||
move |_, _, cx| cx.dispatch_action(action.clone())
|
||||
move |_, cx| cx.dispatch_action(action.clone())
|
||||
})
|
||||
.with_tooltip::<Self, _>(
|
||||
ix,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{ItemHandle, Pane};
|
||||
use gpui::{
|
||||
elements::*, platform::CursorStyle, Action, AnyViewHandle, AppContext, ElementBox, Entity,
|
||||
MutableAppContext, RenderContext, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
MouseButton, MutableAppContext, RenderContext, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
};
|
||||
use settings::Settings;
|
||||
|
||||
|
@ -191,7 +191,9 @@ fn nav_button<A: Action + Clone>(
|
|||
} else {
|
||||
CursorStyle::default()
|
||||
})
|
||||
.on_click(move |_, _, cx| cx.dispatch_action(action.clone()))
|
||||
.on_click(MouseButton::Left, move |_, cx| {
|
||||
cx.dispatch_action(action.clone())
|
||||
})
|
||||
.with_tooltip::<A, _>(
|
||||
0,
|
||||
action_name.to_string(),
|
||||
|
|
|
@ -21,8 +21,8 @@ use gpui::{
|
|||
json::{self, ToJson},
|
||||
platform::{CursorStyle, WindowOptions},
|
||||
AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, Border, Entity, ImageData,
|
||||
ModelContext, ModelHandle, MutableAppContext, PathPromptOptions, PromptLevel, RenderContext,
|
||||
Task, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
ModelContext, ModelHandle, MouseButton, MutableAppContext, PathPromptOptions, PromptLevel,
|
||||
RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
};
|
||||
use language::LanguageRegistry;
|
||||
use log::error;
|
||||
|
@ -256,7 +256,11 @@ pub trait Item: View {
|
|||
fn navigate(&mut self, _: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool {
|
||||
false
|
||||
}
|
||||
fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox;
|
||||
fn tab_description<'a>(&'a self, _: usize, _: &'a AppContext) -> Option<Cow<'a, str>> {
|
||||
None
|
||||
}
|
||||
fn tab_content(&self, detail: Option<usize>, style: &theme::Tab, cx: &AppContext)
|
||||
-> ElementBox;
|
||||
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
|
||||
fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]>;
|
||||
fn is_singleton(&self, cx: &AppContext) -> bool;
|
||||
|
@ -409,7 +413,9 @@ impl<T: FollowableItem> FollowableItemHandle for ViewHandle<T> {
|
|||
}
|
||||
|
||||
pub trait ItemHandle: 'static + fmt::Debug {
|
||||
fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox;
|
||||
fn tab_description<'a>(&self, detail: usize, cx: &'a AppContext) -> Option<Cow<'a, str>>;
|
||||
fn tab_content(&self, detail: Option<usize>, style: &theme::Tab, cx: &AppContext)
|
||||
-> ElementBox;
|
||||
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
|
||||
fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]>;
|
||||
fn is_singleton(&self, cx: &AppContext) -> bool;
|
||||
|
@ -463,8 +469,17 @@ impl dyn ItemHandle {
|
|||
}
|
||||
|
||||
impl<T: Item> ItemHandle for ViewHandle<T> {
|
||||
fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox {
|
||||
self.read(cx).tab_content(style, cx)
|
||||
fn tab_description<'a>(&self, detail: usize, cx: &'a AppContext) -> Option<Cow<'a, str>> {
|
||||
self.read(cx).tab_description(detail, cx)
|
||||
}
|
||||
|
||||
fn tab_content(
|
||||
&self,
|
||||
detail: Option<usize>,
|
||||
style: &theme::Tab,
|
||||
cx: &AppContext,
|
||||
) -> ElementBox {
|
||||
self.read(cx).tab_content(detail, style, cx)
|
||||
}
|
||||
|
||||
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath> {
|
||||
|
@ -562,7 +577,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
|||
if T::should_activate_item_on_event(event) {
|
||||
pane.update(cx, |pane, cx| {
|
||||
if let Some(ix) = pane.index_for_item(&item) {
|
||||
pane.activate_item(ix, true, true, cx);
|
||||
pane.activate_item(ix, true, true, false, cx);
|
||||
pane.activate(cx);
|
||||
}
|
||||
});
|
||||
|
@ -1507,7 +1522,7 @@ impl Workspace {
|
|||
});
|
||||
if let Some((pane, ix)) = result {
|
||||
self.activate_pane(pane.clone(), cx);
|
||||
pane.update(cx, |pane, cx| pane.activate_item(ix, true, true, cx));
|
||||
pane.update(cx, |pane, cx| pane.activate_item(ix, true, true, false, cx));
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
@ -1965,7 +1980,7 @@ impl Workspace {
|
|||
.with_style(style.container)
|
||||
.boxed()
|
||||
})
|
||||
.on_click(|_, _, cx| cx.dispatch_action(Authenticate))
|
||||
.on_click(MouseButton::Left, |_, cx| cx.dispatch_action(Authenticate))
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.aligned()
|
||||
.boxed(),
|
||||
|
@ -2016,7 +2031,9 @@ impl Workspace {
|
|||
if let Some((peer_id, peer_github_login)) = peer {
|
||||
MouseEventHandler::new::<ToggleFollow, _, _>(replica_id.into(), cx, move |_, _| content)
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(move |_, _, cx| cx.dispatch_action(ToggleFollow(peer_id)))
|
||||
.on_click(MouseButton::Left, move |_, cx| {
|
||||
cx.dispatch_action(ToggleFollow(peer_id))
|
||||
})
|
||||
.with_tooltip::<ToggleFollow, _>(
|
||||
peer_id.0 as usize,
|
||||
if is_followed {
|
||||
|
@ -2686,11 +2703,62 @@ fn open_new(app_state: &Arc<AppState>, cx: &mut MutableAppContext) {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::cell::Cell;
|
||||
|
||||
use super::*;
|
||||
use gpui::{executor::Deterministic, ModelHandle, TestAppContext, ViewContext};
|
||||
use project::{FakeFs, Project, ProjectEntryId};
|
||||
use serde_json::json;
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_tab_disambiguation(cx: &mut TestAppContext) {
|
||||
cx.foreground().forbid_parking();
|
||||
Settings::test_async(cx);
|
||||
|
||||
let fs = FakeFs::new(cx.background());
|
||||
let project = Project::test(fs, [], cx).await;
|
||||
let (window_id, workspace) = cx.add_window(|cx| Workspace::new(project.clone(), cx));
|
||||
|
||||
// Adding an item with no ambiguity renders the tab without detail.
|
||||
let item1 = cx.add_view(window_id, |_| {
|
||||
let mut item = TestItem::new();
|
||||
item.tab_descriptions = Some(vec!["c", "b1/c", "a/b1/c"]);
|
||||
item
|
||||
});
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
workspace.add_item(Box::new(item1.clone()), cx);
|
||||
});
|
||||
item1.read_with(cx, |item, _| assert_eq!(item.tab_detail.get(), None));
|
||||
|
||||
// Adding an item that creates ambiguity increases the level of detail on
|
||||
// both tabs.
|
||||
let item2 = cx.add_view(window_id, |_| {
|
||||
let mut item = TestItem::new();
|
||||
item.tab_descriptions = Some(vec!["c", "b2/c", "a/b2/c"]);
|
||||
item
|
||||
});
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
workspace.add_item(Box::new(item2.clone()), cx);
|
||||
});
|
||||
item1.read_with(cx, |item, _| assert_eq!(item.tab_detail.get(), Some(1)));
|
||||
item2.read_with(cx, |item, _| assert_eq!(item.tab_detail.get(), Some(1)));
|
||||
|
||||
// Adding an item that creates ambiguity increases the level of detail only
|
||||
// on the ambiguous tabs. In this case, the ambiguity can't be resolved so
|
||||
// we stop at the highest detail available.
|
||||
let item3 = cx.add_view(window_id, |_| {
|
||||
let mut item = TestItem::new();
|
||||
item.tab_descriptions = Some(vec!["c", "b2/c", "a/b2/c"]);
|
||||
item
|
||||
});
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
workspace.add_item(Box::new(item3.clone()), cx);
|
||||
});
|
||||
item1.read_with(cx, |item, _| assert_eq!(item.tab_detail.get(), Some(1)));
|
||||
item2.read_with(cx, |item, _| assert_eq!(item.tab_detail.get(), Some(3)));
|
||||
item3.read_with(cx, |item, _| assert_eq!(item.tab_detail.get(), Some(3)));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_tracking_active_path(cx: &mut TestAppContext) {
|
||||
cx.foreground().forbid_parking();
|
||||
|
@ -2880,7 +2948,7 @@ mod tests {
|
|||
|
||||
let close_items = workspace.update(cx, |workspace, cx| {
|
||||
pane.update(cx, |pane, cx| {
|
||||
pane.activate_item(1, true, true, cx);
|
||||
pane.activate_item(1, true, true, false, cx);
|
||||
assert_eq!(pane.active_item().unwrap().id(), item2.id());
|
||||
});
|
||||
|
||||
|
@ -3211,6 +3279,8 @@ mod tests {
|
|||
project_entry_ids: Vec<ProjectEntryId>,
|
||||
project_path: Option<ProjectPath>,
|
||||
nav_history: Option<ItemNavHistory>,
|
||||
tab_descriptions: Option<Vec<&'static str>>,
|
||||
tab_detail: Cell<Option<usize>>,
|
||||
}
|
||||
|
||||
enum TestItemEvent {
|
||||
|
@ -3230,6 +3300,8 @@ mod tests {
|
|||
project_entry_ids: self.project_entry_ids.clone(),
|
||||
project_path: self.project_path.clone(),
|
||||
nav_history: None,
|
||||
tab_descriptions: None,
|
||||
tab_detail: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3247,6 +3319,8 @@ mod tests {
|
|||
project_path: None,
|
||||
is_singleton: true,
|
||||
nav_history: None,
|
||||
tab_descriptions: None,
|
||||
tab_detail: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3277,7 +3351,15 @@ mod tests {
|
|||
}
|
||||
|
||||
impl Item for TestItem {
|
||||
fn tab_content(&self, _: &theme::Tab, _: &AppContext) -> ElementBox {
|
||||
fn tab_description<'a>(&'a self, detail: usize, _: &'a AppContext) -> Option<Cow<'a, str>> {
|
||||
self.tab_descriptions.as_ref().and_then(|descriptions| {
|
||||
let description = *descriptions.get(detail).or(descriptions.last())?;
|
||||
Some(description.into())
|
||||
})
|
||||
}
|
||||
|
||||
fn tab_content(&self, detail: Option<usize>, _: &theme::Tab, _: &AppContext) -> ElementBox {
|
||||
self.tab_detail.set(detail);
|
||||
Empty::new().boxed()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue