agent: Add "copy to clipboard" button to error message popups (#29299)
This change makes agent errors copy-able to clipboard:  Release Notes: - N/A
This commit is contained in:
parent
f11c749353
commit
aa161078fb
1 changed files with 22 additions and 4 deletions
|
@ -16,9 +16,9 @@ use client::zed_urls;
|
||||||
use editor::{Anchor, AnchorRangeExt as _, Editor, EditorEvent, MultiBuffer};
|
use editor::{Anchor, AnchorRangeExt as _, Editor, EditorEvent, MultiBuffer};
|
||||||
use fs::Fs;
|
use fs::Fs;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Action, Animation, AnimationExt as _, AnyElement, App, AsyncWindowContext, Corner, Entity,
|
Action, Animation, AnimationExt as _, AnyElement, App, AsyncWindowContext, ClipboardItem,
|
||||||
EventEmitter, FocusHandle, Focusable, FontWeight, KeyContext, Pixels, Subscription, Task,
|
Corner, Entity, EventEmitter, FocusHandle, Focusable, FontWeight, KeyContext, Pixels,
|
||||||
UpdateGlobal, WeakEntity, prelude::*, pulsating_between,
|
Subscription, Task, UpdateGlobal, WeakEntity, prelude::*, pulsating_between,
|
||||||
};
|
};
|
||||||
use language::LanguageRegistry;
|
use language::LanguageRegistry;
|
||||||
use language_model::{LanguageModelProviderTosView, LanguageModelRegistry};
|
use language_model::{LanguageModelProviderTosView, LanguageModelRegistry};
|
||||||
|
@ -1600,6 +1600,8 @@ impl AssistantPanel {
|
||||||
h_flex()
|
h_flex()
|
||||||
.justify_end()
|
.justify_end()
|
||||||
.mt_1()
|
.mt_1()
|
||||||
|
.gap_1()
|
||||||
|
.child(self.create_copy_button(ERROR_MESSAGE))
|
||||||
.child(Button::new("subscribe", "Subscribe").on_click(cx.listener(
|
.child(Button::new("subscribe", "Subscribe").on_click(cx.listener(
|
||||||
|this, _, _, cx| {
|
|this, _, _, cx| {
|
||||||
this.thread.update(cx, |this, _cx| {
|
this.thread.update(cx, |this, _cx| {
|
||||||
|
@ -1646,6 +1648,8 @@ impl AssistantPanel {
|
||||||
h_flex()
|
h_flex()
|
||||||
.justify_end()
|
.justify_end()
|
||||||
.mt_1()
|
.mt_1()
|
||||||
|
.gap_1()
|
||||||
|
.child(self.create_copy_button(ERROR_MESSAGE))
|
||||||
.child(
|
.child(
|
||||||
Button::new("subscribe", "Update Monthly Spend Limit").on_click(
|
Button::new("subscribe", "Update Monthly Spend Limit").on_click(
|
||||||
cx.listener(|this, _, _, cx| {
|
cx.listener(|this, _, _, cx| {
|
||||||
|
@ -1711,6 +1715,8 @@ impl AssistantPanel {
|
||||||
h_flex()
|
h_flex()
|
||||||
.justify_end()
|
.justify_end()
|
||||||
.mt_1()
|
.mt_1()
|
||||||
|
.gap_1()
|
||||||
|
.child(self.create_copy_button(error_message))
|
||||||
.child(
|
.child(
|
||||||
Button::new("subscribe", call_to_action).on_click(cx.listener(
|
Button::new("subscribe", call_to_action).on_click(cx.listener(
|
||||||
|this, _, _, cx| {
|
|this, _, _, cx| {
|
||||||
|
@ -1742,6 +1748,7 @@ impl AssistantPanel {
|
||||||
message: SharedString,
|
message: SharedString,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> AnyElement {
|
) -> AnyElement {
|
||||||
|
let message_with_header = format!("{}\n{}", header, message);
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_0p5()
|
.gap_0p5()
|
||||||
.child(
|
.child(
|
||||||
|
@ -1756,12 +1763,14 @@ impl AssistantPanel {
|
||||||
.id("error-message")
|
.id("error-message")
|
||||||
.max_h_32()
|
.max_h_32()
|
||||||
.overflow_y_scroll()
|
.overflow_y_scroll()
|
||||||
.child(Label::new(message)),
|
.child(Label::new(message.clone())),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.justify_end()
|
.justify_end()
|
||||||
.mt_1()
|
.mt_1()
|
||||||
|
.gap_1()
|
||||||
|
.child(self.create_copy_button(message_with_header))
|
||||||
.child(Button::new("dismiss", "Dismiss").on_click(cx.listener(
|
.child(Button::new("dismiss", "Dismiss").on_click(cx.listener(
|
||||||
|this, _, _, cx| {
|
|this, _, _, cx| {
|
||||||
this.thread.update(cx, |this, _cx| {
|
this.thread.update(cx, |this, _cx| {
|
||||||
|
@ -1775,6 +1784,15 @@ impl AssistantPanel {
|
||||||
.into_any()
|
.into_any()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_copy_button(&self, message: impl Into<String>) -> impl IntoElement {
|
||||||
|
let message = message.into();
|
||||||
|
IconButton::new("copy", IconName::Copy)
|
||||||
|
.on_click(move |_, _, cx| {
|
||||||
|
cx.write_to_clipboard(ClipboardItem::new_string(message.clone()))
|
||||||
|
})
|
||||||
|
.tooltip(Tooltip::text("Copy Error Message"))
|
||||||
|
}
|
||||||
|
|
||||||
fn key_context(&self) -> KeyContext {
|
fn key_context(&self) -> KeyContext {
|
||||||
let mut key_context = KeyContext::new_with_defaults();
|
let mut key_context = KeyContext::new_with_defaults();
|
||||||
key_context.add("AgentPanel");
|
key_context.add("AgentPanel");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue