Add tab tooltips
This commit is contained in:
parent
e655a6c767
commit
ebe57254e0
10 changed files with 119 additions and 39 deletions
|
@ -44,6 +44,9 @@ pub trait Item: View {
|
|||
fn navigate(&mut self, _: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool {
|
||||
false
|
||||
}
|
||||
fn tab_tooltip_text<'a>(&'a self, _: &'a AppContext) -> Option<Cow<'a, str>> {
|
||||
None
|
||||
}
|
||||
fn tab_description<'a>(&'a self, _: usize, _: &'a AppContext) -> Option<Cow<'a, str>> {
|
||||
None
|
||||
}
|
||||
|
@ -162,6 +165,7 @@ pub trait ItemHandle: 'static + fmt::Debug {
|
|||
cx: &mut AppContext,
|
||||
handler: Box<dyn Fn(ItemEvent, &mut AppContext)>,
|
||||
) -> gpui::Subscription;
|
||||
fn tab_tooltip_text<'a>(&self, cx: &'a AppContext) -> Option<Cow<'a, str>>;
|
||||
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;
|
||||
|
@ -248,6 +252,10 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
|||
})
|
||||
}
|
||||
|
||||
fn tab_tooltip_text<'a>(&self, cx: &'a AppContext) -> Option<Cow<'a, str>> {
|
||||
self.read(cx).tab_tooltip_text(cx)
|
||||
}
|
||||
|
||||
fn tab_description<'a>(&self, detail: usize, cx: &'a AppContext) -> Option<Cow<'a, str>> {
|
||||
self.read(cx).tab_description(detail, cx)
|
||||
}
|
||||
|
|
|
@ -1386,6 +1386,9 @@ impl Pane {
|
|||
let detail = detail.clone();
|
||||
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
let mut tooltip_theme = theme.tooltip.clone();
|
||||
tooltip_theme.max_text_width = None;
|
||||
let tab_tooltip_text = item.tab_tooltip_text(cx).map(|a| a.to_string());
|
||||
|
||||
move |mouse_state, cx| {
|
||||
let tab_style =
|
||||
|
@ -1393,39 +1396,56 @@ impl Pane {
|
|||
let hovered = mouse_state.hovered();
|
||||
|
||||
enum Tab {}
|
||||
MouseEventHandler::<Tab>::new(ix, cx, |_, cx| {
|
||||
Self::render_tab(
|
||||
&item,
|
||||
pane.clone(),
|
||||
ix == 0,
|
||||
detail,
|
||||
hovered,
|
||||
tab_style,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.on_down(MouseButton::Left, move |_, cx| {
|
||||
cx.dispatch_action(ActivateItem(ix));
|
||||
})
|
||||
.on_click(MouseButton::Middle, {
|
||||
let item = item.clone();
|
||||
let pane = pane.clone();
|
||||
move |_, cx: &mut EventContext| {
|
||||
cx.dispatch_action(CloseItemById {
|
||||
item_id: item.id(),
|
||||
pane: pane.clone(),
|
||||
})
|
||||
}
|
||||
})
|
||||
.on_down(MouseButton::Right, move |e, cx| {
|
||||
let item = item.clone();
|
||||
cx.dispatch_action(DeployTabContextMenu {
|
||||
position: e.position,
|
||||
item_id: item.id(),
|
||||
pane: pane.clone(),
|
||||
});
|
||||
})
|
||||
.boxed()
|
||||
let mouse_event_handler =
|
||||
MouseEventHandler::<Tab>::new(ix, cx, |_, cx| {
|
||||
Self::render_tab(
|
||||
&item,
|
||||
pane.clone(),
|
||||
ix == 0,
|
||||
detail,
|
||||
hovered,
|
||||
tab_style,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.on_down(MouseButton::Left, move |_, cx| {
|
||||
cx.dispatch_action(ActivateItem(ix));
|
||||
})
|
||||
.on_click(MouseButton::Middle, {
|
||||
let item = item.clone();
|
||||
let pane = pane.clone();
|
||||
move |_, cx: &mut EventContext| {
|
||||
cx.dispatch_action(CloseItemById {
|
||||
item_id: item.id(),
|
||||
pane: pane.clone(),
|
||||
})
|
||||
}
|
||||
})
|
||||
.on_down(
|
||||
MouseButton::Right,
|
||||
move |e, cx| {
|
||||
let item = item.clone();
|
||||
cx.dispatch_action(DeployTabContextMenu {
|
||||
position: e.position,
|
||||
item_id: item.id(),
|
||||
pane: pane.clone(),
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
if let Some(tab_tooltip_text) = tab_tooltip_text {
|
||||
return mouse_event_handler
|
||||
.with_tooltip::<Self, _>(
|
||||
ix,
|
||||
tab_tooltip_text,
|
||||
None,
|
||||
tooltip_theme,
|
||||
cx,
|
||||
)
|
||||
.boxed();
|
||||
}
|
||||
|
||||
mouse_event_handler.boxed()
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -13,7 +13,10 @@ use gpui::{
|
|||
};
|
||||
use settings::Settings;
|
||||
use smallvec::SmallVec;
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
sync::{Arc, Weak},
|
||||
};
|
||||
|
||||
pub enum Event {
|
||||
Close,
|
||||
|
@ -92,6 +95,9 @@ impl View for SharedScreen {
|
|||
}
|
||||
|
||||
impl Item for SharedScreen {
|
||||
fn tab_tooltip_text<'a>(&'a self, _: &'a AppContext) -> Option<Cow<'a, str>> {
|
||||
Some(format!("{}'s screen", self.user.github_login).into())
|
||||
}
|
||||
fn deactivated(&mut self, cx: &mut ViewContext<Self>) {
|
||||
if let Some(nav_history) = self.nav_history.as_ref() {
|
||||
nav_history.push::<()>(None, cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue