1use gpui::{
2 elements::*, platform::CursorStyle, Entity, ModelHandle, RenderContext, View, ViewContext,
3};
4use postage::watch;
5use project::Project;
6use workspace::{Settings, StatusItemView};
7
8pub struct DiagnosticSummary {
9 settings: watch::Receiver<Settings>,
10 summary: project::DiagnosticSummary,
11}
12
13impl DiagnosticSummary {
14 pub fn new(
15 project: &ModelHandle<Project>,
16 settings: watch::Receiver<Settings>,
17 cx: &mut ViewContext<Self>,
18 ) -> Self {
19 cx.subscribe(project, |this, project, event, cx| {
20 if let project::Event::DiskBasedDiagnosticsUpdated { .. } = event {
21 this.summary = project.read(cx).diagnostic_summary(cx);
22 cx.notify();
23 }
24 })
25 .detach();
26 Self {
27 settings,
28 summary: project.read(cx).diagnostic_summary(cx),
29 }
30 }
31}
32
33impl Entity for DiagnosticSummary {
34 type Event = ();
35}
36
37impl View for DiagnosticSummary {
38 fn ui_name() -> &'static str {
39 "DiagnosticSummary"
40 }
41
42 fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
43 enum Tag {}
44
45 let theme = &self.settings.borrow().theme.project_diagnostics;
46 MouseEventHandler::new::<Tag, _, _, _>(0, cx, |_, _| {
47 Label::new(
48 format!(
49 "Errors: {}, Warnings: {}",
50 self.summary.error_count, self.summary.warning_count
51 ),
52 theme.status_bar_item.text.clone(),
53 )
54 .contained()
55 .with_style(theme.status_bar_item.container)
56 .boxed()
57 })
58 .with_cursor_style(CursorStyle::PointingHand)
59 .on_click(|cx| cx.dispatch_action(crate::Deploy))
60 .boxed()
61 }
62}
63
64impl StatusItemView for DiagnosticSummary {
65 fn set_active_pane_item(
66 &mut self,
67 _: Option<&dyn workspace::ItemViewHandle>,
68 _: &mut ViewContext<Self>,
69 ) {
70 }
71}