| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | use gpui::{ClipboardItem, Context, Entity, ParentElement, Styled, Window}; |
| 7 | use gpuikit::elements::button::button; |
| 8 | use gpuikit::elements::input::text_area; |
| 9 | use gpuikit::elements::typography::{h3, small}; |
| 10 | use gpuikit::layout::{h_stack, v_stack}; |
| 11 | |
| 12 | use crate::ui::app::AppRoot; |
| 13 | |
| 14 | pub fn render( |
| 15 | app: &mut AppRoot, |
| 16 | view: &Entity<AppRoot>, |
| 17 | _window: &mut Window, |
| 18 | cx: &mut Context<AppRoot>, |
| 19 | ) -> gpui::Div { |
| 20 | |
| 21 | let joined = app.state.log.iter().cloned().collect::<Vec<_>>().join("\n"); |
| 22 | if app.log_input.read(cx).content() != joined { |
| 23 | app.log_input |
| 24 | .update(cx, |input, cx| input.set_content_silent(joined, cx)); |
| 25 | } |
| 26 | |
| 27 | v_stack() |
| 28 | .size_full() |
| 29 | .gap_2() |
| 30 | .p_4() |
| 31 | .child( |
| 32 | h_stack() |
| 33 | .items_center() |
| 34 | .gap_3() |
| 35 | .child(h3("Log")) |
| 36 | .child(small(format!( |
| 37 | "{} lines — click, drag, Ctrl-A/Ctrl-C to copy", |
| 38 | app.state.log.len() |
| 39 | ))) |
| 40 | .child(gpui::div().flex_1()) |
| 41 | .child(button("btn-copy-log", "Copy log").on_click({ |
| 42 | let view = view.clone(); |
| 43 | move |_, _window, cx| { |
| 44 | let joined = view |
| 45 | .read(cx) |
| 46 | .state |
| 47 | .log |
| 48 | .iter() |
| 49 | .cloned() |
| 50 | .collect::<Vec<_>>() |
| 51 | .join("\n"); |
| 52 | cx.write_to_clipboard(ClipboardItem::new_string(joined)); |
| 53 | view.update(cx, |app, cx| { |
| 54 | app.state.push_log("log copied to clipboard"); |
| 55 | cx.notify(); |
| 56 | }); |
| 57 | } |
| 58 | })), |
| 59 | ) |
| 60 | .child( |
| 61 | gpui::div() |
| 62 | .flex_1() |
| 63 | .min_h_0() |
| 64 | .child(text_area(&app.log_input, cx)), |
| 65 | ) |
| 66 | } |