add copy function
This commit is contained in:
@@ -28,7 +28,7 @@ impl NewMessage {
|
|||||||
/// Trash message.
|
/// Trash message.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct FailedMessage {
|
pub struct FailedMessage {
|
||||||
pub raw_event: String,
|
pub raw_event: SharedString,
|
||||||
pub reason: SharedString,
|
pub reason: SharedString,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ impl FailedMessage {
|
|||||||
T: Into<SharedString>,
|
T: Into<SharedString>,
|
||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
raw_event: event.as_json(),
|
raw_event: SharedString::from(event.as_json()),
|
||||||
reason: reason.into(),
|
reason: reason.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,11 +84,6 @@ impl BackupPanel {
|
|||||||
fn copy_secret(&mut self, cx: &mut Context<Self>) {
|
fn copy_secret(&mut self, cx: &mut Context<Self>) {
|
||||||
let value = self.nsec_input.read(cx).value();
|
let value = self.nsec_input.read(cx).value();
|
||||||
let item = ClipboardItem::new_string(value.to_string());
|
let item = ClipboardItem::new_string(value.to_string());
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
cx.write_to_primary(item);
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
|
||||||
cx.write_to_clipboard(item);
|
cx.write_to_clipboard(item);
|
||||||
|
|
||||||
// Set the copied status to true
|
// Set the copied status to true
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
use chat::ChatRegistry;
|
use chat::ChatRegistry;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable,
|
AnyElement, App, AppContext, ClipboardItem, Context, Entity, EventEmitter, FocusHandle,
|
||||||
InteractiveElement, IntoElement, ListAlignment, ListState, ParentElement, Render, SharedString,
|
Focusable, InteractiveElement, IntoElement, ListAlignment, ListState, ParentElement, Render,
|
||||||
Styled, Window, div, list, px,
|
SharedString, Styled, Window, div, list, px, relative,
|
||||||
};
|
};
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
|
use ui::button::{Button, ButtonVariants};
|
||||||
use ui::dock::{Panel, PanelEvent};
|
use ui::dock::{Panel, PanelEvent};
|
||||||
use ui::scroll::Scrollbar;
|
use ui::scroll::Scrollbar;
|
||||||
use ui::v_flex;
|
use ui::{Icon, IconName, Sizable, h_flex, v_flex};
|
||||||
|
|
||||||
pub fn init(window: &mut Window, cx: &mut App) -> Entity<TrashPanel> {
|
pub fn init(window: &mut Window, cx: &mut App) -> Entity<TrashPanel> {
|
||||||
cx.new(|cx| TrashPanel::new(window, cx))
|
cx.new(|cx| TrashPanel::new(window, cx))
|
||||||
@@ -34,6 +35,16 @@ impl TrashPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn copy(&self, ix: usize, cx: &App) {
|
||||||
|
let chat = ChatRegistry::global(cx);
|
||||||
|
let trashes = chat.read(cx).trashes();
|
||||||
|
|
||||||
|
if let Some(message) = trashes.read(cx).iter().nth(ix) {
|
||||||
|
let item = ClipboardItem::new_string(message.raw_event.to_string());
|
||||||
|
cx.write_to_clipboard(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn render_list_item(
|
fn render_list_item(
|
||||||
&mut self,
|
&mut self,
|
||||||
ix: usize,
|
ix: usize,
|
||||||
@@ -47,22 +58,49 @@ impl TrashPanel {
|
|||||||
v_flex()
|
v_flex()
|
||||||
.id(ix)
|
.id(ix)
|
||||||
.p_2()
|
.p_2()
|
||||||
.rounded(cx.theme().radius)
|
.w_full()
|
||||||
.bg(cx.theme().elevated_surface_background)
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.p_2()
|
||||||
|
.w_full()
|
||||||
|
.gap_1()
|
||||||
|
.rounded(cx.theme().radius_lg)
|
||||||
|
.bg(cx.theme().surface_background)
|
||||||
.text_sm()
|
.text_sm()
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.text_color(cx.theme().text_danger)
|
.text_color(cx.theme().text_danger)
|
||||||
.child(message.reason.clone()),
|
.child(message.reason.clone()),
|
||||||
)
|
)
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.h_10()
|
||||||
|
.w_full()
|
||||||
|
.px_2()
|
||||||
|
.justify_between()
|
||||||
|
.bg(cx.theme().elevated_surface_background)
|
||||||
|
.border_1()
|
||||||
|
.border_color(cx.theme().border)
|
||||||
|
.rounded(cx.theme().radius)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.line_clamp(1)
|
.truncate()
|
||||||
.text_ellipsis()
|
.text_ellipsis()
|
||||||
.text_xs()
|
.text_xs()
|
||||||
.overflow_hidden()
|
.line_height(relative(1.))
|
||||||
.child(message.raw_event.clone()),
|
.child(message.raw_event.clone()),
|
||||||
)
|
)
|
||||||
|
.child(
|
||||||
|
Button::new(format!("copy-{ix}"))
|
||||||
|
.icon(IconName::Copy)
|
||||||
|
.ghost()
|
||||||
|
.small()
|
||||||
|
.on_click(cx.listener(move |this, _ev, _window, cx| {
|
||||||
|
this.copy(ix, cx);
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
} else {
|
} else {
|
||||||
div().id(ix).into_any_element()
|
div().id(ix).into_any_element()
|
||||||
@@ -76,7 +114,12 @@ impl Panel for TrashPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn title(&self, _cx: &App) -> AnyElement {
|
fn title(&self, _cx: &App) -> AnyElement {
|
||||||
self.name.clone().into_any_element()
|
h_flex()
|
||||||
|
.gap_1()
|
||||||
|
.text_sm()
|
||||||
|
.child(Icon::new(IconName::Warning).small())
|
||||||
|
.child("Errors")
|
||||||
|
.into_any_element()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user