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