mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 18:46:49 +00:00
This PR adds new `Button` and `IconButton` components built on top of our new button abstractions. Both of these buttons are built from the common `ButtonLike` base, and implement the `ButtonCommon` (name TBD) trait in order to provide a common interface. There are still some visual tweaks that we'll need to make to the new buttons, but those should be straightforward to make after we land this. Release Notes: - N/A
67 lines
2.1 KiB
Rust
67 lines
2.1 KiB
Rust
use crate::ProjectDiagnosticsEditor;
|
|
use gpui::{div, Div, EventEmitter, ParentElement, Render, ViewContext, WeakView};
|
|
use ui::prelude::*;
|
|
use ui::{Icon, IconButton, Tooltip};
|
|
use workspace::{item::ItemHandle, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView};
|
|
|
|
pub struct ToolbarControls {
|
|
editor: Option<WeakView<ProjectDiagnosticsEditor>>,
|
|
}
|
|
|
|
impl Render for ToolbarControls {
|
|
type Element = Div;
|
|
|
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
|
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)
|
|
.tooltip(move |cx| Tooltip::text(tooltip, cx))
|
|
.on_click(cx.listener(|this, _, cx| {
|
|
if let Some(editor) = this.editor.as_ref().and_then(|editor| editor.upgrade()) {
|
|
editor.update(cx, |editor, cx| {
|
|
editor.toggle_warnings(&Default::default(), cx);
|
|
});
|
|
}
|
|
})),
|
|
)
|
|
}
|
|
}
|
|
|
|
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());
|
|
ToolbarItemLocation::PrimaryRight
|
|
} else {
|
|
ToolbarItemLocation::Hidden
|
|
}
|
|
} else {
|
|
ToolbarItemLocation::Hidden
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ToolbarControls {
|
|
pub fn new() -> Self {
|
|
ToolbarControls { editor: None }
|
|
}
|
|
}
|