From a08448514283da4fbcc75850f2291aef3eb288aa Mon Sep 17 00:00:00 2001 From: ozacod Date: Fri, 1 May 2026 18:49:13 +0300 Subject: [PATCH 1/2] Make error notifications copyable --- crates/project_panel/src/undo.rs | 8 +++++-- crates/workspace/src/notifications.rs | 30 +++++++++++++++++++++++++++ crates/workspace/src/workspace.rs | 1 + crates/zed/src/zed.rs | 4 ++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/crates/project_panel/src/undo.rs b/crates/project_panel/src/undo.rs index ca4fc9ed375..787d71b9f42 100644 --- a/crates/project_panel/src/undo.rs +++ b/crates/project_panel/src/undo.rs @@ -138,7 +138,7 @@ use gpui::{AppContext, AsyncApp, SharedString, Task, WeakEntity}; use project::{ProjectPath, WorktreeId}; use std::sync::atomic::{AtomicBool, Ordering}; use std::{collections::VecDeque, sync::Arc}; -use ui::App; +use ui::{App, Severity}; use workspace::{ Workspace, notifications::{NotificationId, simple_message_notification::MessageNotification}, @@ -550,7 +550,11 @@ impl Inner { NotificationId::Named(SharedString::new_static("project_panel_undo")); workspace.show_notification(notification_id, cx, move |cx| { - cx.new(|cx| MessageNotification::new(error, cx).with_title(title)) + cx.new(|cx| { + MessageNotification::new(error, cx) + .severity(Severity::Error) + .with_title(title) + }) }) }) .ok(); diff --git a/crates/workspace/src/notifications.rs b/crates/workspace/src/notifications.rs index ce54765e3ff..aa848c6681e 100644 --- a/crates/workspace/src/notifications.rs +++ b/crates/workspace/src/notifications.rs @@ -728,6 +728,8 @@ pub mod simple_message_notification { show_suppress_button: bool, title: Option, scroll_handle: ScrollHandle, + copyable_text: Option, + severity: Severity, } impl Focusable for MessageNotification { @@ -747,9 +749,11 @@ pub mod simple_message_notification { S: Into, { let message = message.into(); + let copyable = message.clone(); Self::new_from_builder(cx, move |_, _| { Label::new(message.clone()).into_any_element() }) + .copyable_text(copyable) } pub fn new_from_builder(cx: &mut App, content: F) -> MessageNotification @@ -773,9 +777,24 @@ pub mod simple_message_notification { title: None, focus_handle: cx.focus_handle(), scroll_handle: ScrollHandle::new(), + copyable_text: None, + severity: Severity::Info, } } + pub fn severity(mut self, severity: Severity) -> Self { + self.severity = severity; + self + } + + pub fn copyable_text(mut self, text: S) -> Self + where + S: Into, + { + self.copyable_text = Some(text.into()); + self + } + pub fn primary_message(mut self, message: S) -> Self where S: Into, @@ -913,6 +932,17 @@ pub mod simple_message_notification { .with_suffix( h_flex() .gap_1() + .when_some( + matches!(self.severity, Severity::Error | Severity::Warning) + .then(|| self.copyable_text.clone()) + .flatten(), + |this, text| { + this.child( + ui::CopyButton::new("copy-notification-message", text) + .tooltip_label("Copy Message"), + ) + }, + ) .children(self.primary_message.iter().map(|message| { let mut button = Button::new(message.clone(), message.clone()) .label_size(LabelSize::Small) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index b0c5d3cb97d..35a75ec7c21 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -8137,6 +8137,7 @@ fn notify_if_database_failed(window: WindowHandle, cx: &mut Asyn |cx| { cx.new(|cx| { MessageNotification::new("Failed to load the database file.", cx) + .severity(Severity::Error) .primary_message("File an Issue") .primary_icon(IconName::Plus) .primary_on_click(|window, cx| { diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 6d1a9c176f1..51dd156f685 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -1720,6 +1720,7 @@ fn open_log_file(workspace: &mut Workspace, window: &mut Window, cx: &mut Contex ), cx, ) + .severity(Severity::Error) }) }, ); @@ -1797,6 +1798,7 @@ fn notify_settings_errors(result: settings::SettingsParseResult, is_user: bool, show_app_notification(id, cx, move |cx| { cx.new(|cx| { MessageNotification::new(format!("Invalid user settings file\n{error}"), cx) + .severity(Severity::Error) .primary_message("Open Settings File") .primary_icon(IconName::Settings) .primary_on_click(|window, cx| { @@ -1833,6 +1835,7 @@ fn notify_settings_errors(result: settings::SettingsParseResult, is_user: bool, ), cx, ) + .severity(Severity::Error) .primary_message("Open Settings File") .primary_icon(IconName::Settings) .primary_on_click(|window, cx| { @@ -1991,6 +1994,7 @@ fn show_keymap_file_json_error( show_app_notification(notification_id, cx, move |cx| { cx.new(|cx| { MessageNotification::new(message.clone(), cx) + .severity(Severity::Error) .primary_message("Open Keymap File") .primary_icon(IconName::Settings) .primary_on_click(|window, cx| { From 3e4613e47750f499f97c54b257126065ad928a41 Mon Sep 17 00:00:00 2001 From: ozacod Date: Fri, 1 May 2026 21:20:11 +0300 Subject: [PATCH 2/2] replace copyable with text_to_copy --- crates/workspace/src/notifications.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/workspace/src/notifications.rs b/crates/workspace/src/notifications.rs index aa848c6681e..97b5aac0b6f 100644 --- a/crates/workspace/src/notifications.rs +++ b/crates/workspace/src/notifications.rs @@ -728,7 +728,7 @@ pub mod simple_message_notification { show_suppress_button: bool, title: Option, scroll_handle: ScrollHandle, - copyable_text: Option, + text_to_copy: Option, severity: Severity, } @@ -749,11 +749,11 @@ pub mod simple_message_notification { S: Into, { let message = message.into(); - let copyable = message.clone(); + let text_to_copy = message.clone(); Self::new_from_builder(cx, move |_, _| { Label::new(message.clone()).into_any_element() }) - .copyable_text(copyable) + .text_to_copy(text_to_copy) } pub fn new_from_builder(cx: &mut App, content: F) -> MessageNotification @@ -777,7 +777,7 @@ pub mod simple_message_notification { title: None, focus_handle: cx.focus_handle(), scroll_handle: ScrollHandle::new(), - copyable_text: None, + text_to_copy: None, severity: Severity::Info, } } @@ -787,11 +787,11 @@ pub mod simple_message_notification { self } - pub fn copyable_text(mut self, text: S) -> Self + pub fn text_to_copy(mut self, text: S) -> Self where S: Into, { - self.copyable_text = Some(text.into()); + self.text_to_copy = Some(text.into()); self } @@ -934,7 +934,7 @@ pub mod simple_message_notification { .gap_1() .when_some( matches!(self.severity, Severity::Error | Severity::Warning) - .then(|| self.copyable_text.clone()) + .then(|| self.text_to_copy.clone()) .flatten(), |this, text| { this.child(