Show terminal count in panel button

This commit is contained in:
Antonio Scandurra 2023-05-09 12:21:35 +02:00
parent 02066afb0e
commit e6be35c9a5
4 changed files with 33 additions and 25 deletions

View file

@ -16,7 +16,7 @@ pub struct TerminalPanel {
project: ModelHandle<Project>,
pane: ViewHandle<Pane>,
workspace: WeakViewHandle<Workspace>,
_subscription: Subscription,
_subscriptions: Vec<Subscription>,
}
impl TerminalPanel {
@ -37,12 +37,15 @@ impl TerminalPanel {
});
pane
});
let subscription = cx.subscribe(&pane, Self::handle_pane_event);
let subscriptions = vec![
cx.observe(&pane, |_, _, cx| cx.notify()),
cx.subscribe(&pane, Self::handle_pane_event),
];
Self {
project: workspace.project().clone(),
pane,
workspace: workspace.weak_handle(),
_subscription: subscription,
_subscriptions: subscriptions,
}
}
@ -108,4 +111,13 @@ impl Panel for TerminalPanel {
fn should_close_on_event(&self, event: &Event, _: &AppContext) -> bool {
matches!(event, Event::Close)
}
fn label(&self, cx: &AppContext) -> Option<String> {
let count = self.pane.read(cx).items_len();
if count == 0 {
None
} else {
Some(count.to_string())
}
}
}