2023-11-17 21:28:52 +00:00
|
|
|
use crate::ProjectDiagnosticsEditor;
|
2023-11-20 16:58:05 +00:00
|
|
|
use gpui::{div, Div, EventEmitter, ParentElement, Render, ViewContext, WeakView};
|
2023-11-29 22:41:44 +00:00
|
|
|
use ui::prelude::*;
|
2023-11-17 21:28:52 +00:00
|
|
|
use ui::{Icon, IconButton, Tooltip};
|
2023-11-15 00:25:55 +00:00
|
|
|
use workspace::{item::ItemHandle, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView};
|
|
|
|
|
|
|
|
pub struct ToolbarControls {
|
|
|
|
editor: Option<WeakView<ProjectDiagnosticsEditor>>,
|
|
|
|
}
|
|
|
|
|
2023-11-20 22:46:01 +00:00
|
|
|
impl Render for ToolbarControls {
|
|
|
|
type Element = Div;
|
2023-11-15 00:25:55 +00:00
|
|
|
|
|
|
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
2023-11-17 17:54:34 +00:00
|
|
|
let include_warnings = self
|
|
|
|
.editor
|
|
|
|
.as_ref()
|
|
|
|
.and_then(|editor| editor.upgrade())
|
|
|
|
.map(|editor| editor.read(cx).include_warnings)
|
|
|
|
.unwrap_or(false);
|
|
|
|
|
|
|
|
let tooltip = if include_warnings {
|
|
|
|
"Exclude Warnings"
|
|
|
|
} else {
|
|
|
|
"Include Warnings"
|
|
|
|
};
|
|
|
|
|
|
|
|
div().child(
|
|
|
|
IconButton::new("toggle-warnings", Icon::ExclamationTriangle)
|
2023-11-20 22:46:01 +00:00
|
|
|
.tooltip(move |cx| Tooltip::text(tooltip, cx))
|
|
|
|
.on_click(cx.listener(|this, _, cx| {
|
2023-11-17 17:54:34 +00:00
|
|
|
if let Some(editor) = this.editor.as_ref().and_then(|editor| editor.upgrade()) {
|
|
|
|
editor.update(cx, |editor, cx| {
|
|
|
|
editor.toggle_warnings(&Default::default(), cx);
|
|
|
|
});
|
|
|
|
}
|
2023-11-20 22:46:01 +00:00
|
|
|
})),
|
2023-11-17 17:54:34 +00:00
|
|
|
)
|
2023-11-15 00:25:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl EventEmitter<ToolbarItemEvent> for ToolbarControls {}
|
|
|
|
|
|
|
|
impl ToolbarItemView for ToolbarControls {
|
|
|
|
fn set_active_pane_item(
|
|
|
|
&mut self,
|
|
|
|
active_pane_item: Option<&dyn ItemHandle>,
|
|
|
|
_: &mut ViewContext<Self>,
|
|
|
|
) -> ToolbarItemLocation {
|
|
|
|
if let Some(pane_item) = active_pane_item.as_ref() {
|
|
|
|
if let Some(editor) = pane_item.downcast::<ProjectDiagnosticsEditor>() {
|
|
|
|
self.editor = Some(editor.downgrade());
|
2023-11-20 17:42:15 +00:00
|
|
|
ToolbarItemLocation::PrimaryRight
|
2023-11-15 00:25:55 +00:00
|
|
|
} else {
|
|
|
|
ToolbarItemLocation::Hidden
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ToolbarItemLocation::Hidden
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToolbarControls {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
ToolbarControls { editor: None }
|
|
|
|
}
|
|
|
|
}
|