Some checks failed
Update All Top Ranking Issues / update_top_ranking_issues (push) Has been cancelled
Triage Project Sync (#84) / Sync triage project (push) Has been cancelled
release_nightly / notify_on_failure (push) Has been cancelled
release_nightly / check_style (push) Has been cancelled
release_nightly / run_tests_windows (push) Has been cancelled
release_nightly / clippy_windows (push) Has been cancelled
release_nightly / bundle_linux_aarch64 (push) Has been cancelled
release_nightly / bundle_linux_x86_64 (push) Has been cancelled
release_nightly / bundle_mac_aarch64 (push) Has been cancelled
release_nightly / bundle_mac_x86_64 (push) Has been cancelled
release_nightly / bundle_windows_aarch64 (push) Has been cancelled
release_nightly / bundle_windows_x86_64 (push) Has been cancelled
release_nightly / build_nix_linux_x86_64 (push) Has been cancelled
release_nightly / build_nix_mac_aarch64 (push) Has been cancelled
release_nightly / update_nightly_tag (push) Has been cancelled
Hotfix Review Monitor / check-hotfix-reviews (push) Has been cancelled
Stale PR Review Reminder / check-stale-prs (push) Has been cancelled
Update Weekly Top Ranking Issues / update_top_ranking_issues (push) Has been cancelled
Bump collab-staging Tag / update-collab-staging-tag (push) Has been cancelled
compliance_check / scheduled_compliance_check (push) Has been cancelled
Single-commit orphan branch: full zed-industries/zed @ 8c74db0 source tree with a 3-file patch applied (no upstream history). Patch (crates/gpui_linux/src/linux/wayland/): - serial.rs: add SerialKind::KeyboardEnter - client.rs: store wl_keyboard.enter serial; add latest_serial_of() - window.rs: activate() uses keyboard-enter serial (Mutter focus gate) Mutter honors window activation only when the token carries the keyboard- focus serial from wl_keyboard.enter; GPUI used a stale mouse-press serial. See docs/tray-window-focus-wayland.md in logiguard. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
174 lines
6.7 KiB
Rust
174 lines
6.7 KiB
Rust
use crate::{BufferDiagnosticsEditor, ProjectDiagnosticsEditor, ToggleDiagnosticsRefresh};
|
|
use agent_settings::AgentSettings;
|
|
use gpui::{Context, EventEmitter, ParentElement, Render, Window};
|
|
use language::DiagnosticEntry;
|
|
use settings::Settings;
|
|
use text::{Anchor, BufferId};
|
|
use ui::{Tooltip, prelude::*};
|
|
use workspace::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, item::ItemHandle};
|
|
use zed_actions::assistant::InlineAssist;
|
|
use zed_actions::buffer_search;
|
|
|
|
pub struct ToolbarControls {
|
|
editor: Option<Box<dyn DiagnosticsToolbarEditor>>,
|
|
}
|
|
|
|
pub(crate) trait DiagnosticsToolbarEditor: Send + Sync {
|
|
/// Informs the toolbar whether warnings are included in the diagnostics.
|
|
fn include_warnings(&self, cx: &App) -> bool;
|
|
/// Toggles whether warning diagnostics should be displayed by the
|
|
/// diagnostics editor.
|
|
fn toggle_warnings(&self, window: &mut Window, cx: &mut App);
|
|
/// Indicates whether the diagnostics editor is currently updating the
|
|
/// diagnostics.
|
|
fn is_updating(&self, cx: &App) -> bool;
|
|
/// Requests that the diagnostics editor stop updating the diagnostics.
|
|
fn stop_updating(&self, cx: &mut App);
|
|
/// Requests that the diagnostics editor updates the displayed diagnostics
|
|
/// with the latest information.
|
|
fn refresh_diagnostics(&self, window: &mut Window, cx: &mut App);
|
|
/// Returns a list of diagnostics for the provided buffer id.
|
|
fn get_diagnostics_for_buffer(
|
|
&self,
|
|
buffer_id: BufferId,
|
|
cx: &App,
|
|
) -> Vec<DiagnosticEntry<Anchor>>;
|
|
}
|
|
|
|
impl Render for ToolbarControls {
|
|
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
|
let mut include_warnings = false;
|
|
let mut is_updating = false;
|
|
|
|
match &self.editor {
|
|
Some(editor) => {
|
|
include_warnings = editor.include_warnings(cx);
|
|
is_updating = editor.is_updating(cx);
|
|
}
|
|
None => {}
|
|
}
|
|
|
|
let is_agent_enabled = AgentSettings::get_global(cx).enabled(cx);
|
|
|
|
let (warning_tooltip, warning_color) = if include_warnings {
|
|
("Exclude Warnings", Color::Warning)
|
|
} else {
|
|
("Include Warnings", Color::Disabled)
|
|
};
|
|
|
|
h_flex()
|
|
.gap_1()
|
|
.child({
|
|
IconButton::new("toggle_search", IconName::MagnifyingGlass)
|
|
.icon_size(IconSize::Small)
|
|
.tooltip(Tooltip::for_action_title(
|
|
"Buffer Search",
|
|
&buffer_search::Deploy::find(),
|
|
))
|
|
.on_click(|_, window, cx| {
|
|
window.dispatch_action(Box::new(buffer_search::Deploy::find()), cx);
|
|
})
|
|
})
|
|
.when(is_agent_enabled, |this| {
|
|
this.child(
|
|
IconButton::new("inline_assist", IconName::ZedAssistant)
|
|
.icon_size(IconSize::Small)
|
|
.tooltip(Tooltip::for_action_title(
|
|
"Inline Assist",
|
|
&InlineAssist::default(),
|
|
))
|
|
.on_click(|_, window, cx| {
|
|
window.dispatch_action(Box::new(InlineAssist::default()), cx);
|
|
}),
|
|
)
|
|
})
|
|
.map(|div| {
|
|
if is_updating {
|
|
div.child(
|
|
IconButton::new("stop-updating", IconName::Stop)
|
|
.icon_color(Color::Error)
|
|
.icon_size(IconSize::Small)
|
|
.tooltip(Tooltip::for_action_title(
|
|
"Stop Diagnostics Update",
|
|
&ToggleDiagnosticsRefresh,
|
|
))
|
|
.on_click(cx.listener(move |toolbar_controls, _, _, cx| {
|
|
if let Some(editor) = toolbar_controls.editor() {
|
|
editor.stop_updating(cx);
|
|
cx.notify();
|
|
}
|
|
})),
|
|
)
|
|
} else {
|
|
div.child(
|
|
IconButton::new("refresh-diagnostics", IconName::ArrowCircle)
|
|
.icon_size(IconSize::Small)
|
|
.tooltip(Tooltip::for_action_title(
|
|
"Refresh Diagnostics",
|
|
&ToggleDiagnosticsRefresh,
|
|
))
|
|
.on_click(cx.listener({
|
|
move |toolbar_controls, _, window, cx| {
|
|
if let Some(editor) = toolbar_controls.editor() {
|
|
editor.refresh_diagnostics(window, cx)
|
|
}
|
|
}
|
|
})),
|
|
)
|
|
}
|
|
})
|
|
.child(
|
|
IconButton::new("toggle-warnings", IconName::Warning)
|
|
.icon_color(warning_color)
|
|
.icon_size(IconSize::Small)
|
|
.tooltip(Tooltip::text(warning_tooltip))
|
|
.on_click(cx.listener(|this, _, window, cx| {
|
|
if let Some(editor) = &this.editor {
|
|
editor.toggle_warnings(window, cx)
|
|
}
|
|
})),
|
|
)
|
|
}
|
|
}
|
|
|
|
impl EventEmitter<ToolbarItemEvent> for ToolbarControls {}
|
|
|
|
impl ToolbarItemView for ToolbarControls {
|
|
fn set_active_pane_item(
|
|
&mut self,
|
|
active_pane_item: Option<&dyn ItemHandle>,
|
|
_window: &mut Window,
|
|
_: &mut Context<Self>,
|
|
) -> ToolbarItemLocation {
|
|
if let Some(pane_item) = active_pane_item.as_ref() {
|
|
if let Some(editor) = pane_item.downcast::<ProjectDiagnosticsEditor>() {
|
|
self.editor = Some(Box::new(editor.downgrade()));
|
|
ToolbarItemLocation::PrimaryRight
|
|
} else if let Some(editor) = pane_item.downcast::<BufferDiagnosticsEditor>() {
|
|
self.editor = Some(Box::new(editor.downgrade()));
|
|
ToolbarItemLocation::PrimaryRight
|
|
} else {
|
|
ToolbarItemLocation::Hidden
|
|
}
|
|
} else {
|
|
ToolbarItemLocation::Hidden
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for ToolbarControls {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
impl ToolbarControls {
|
|
pub fn new() -> Self {
|
|
ToolbarControls { editor: None }
|
|
}
|
|
|
|
fn editor(&self) -> Option<&dyn DiagnosticsToolbarEditor> {
|
|
self.editor.as_deref()
|
|
}
|
|
}
|