diff --git a/linux/changelog.d/4156.added.md b/linux/changelog.d/4156.added.md new file mode 100644 index 0000000000..d528d5a272 --- /dev/null +++ b/linux/changelog.d/4156.added.md @@ -0,0 +1 @@ +Each field in the row details has a button that copies its whole value. diff --git a/linux/crates/app/src/ui/data_grid/row_detail/fields.rs b/linux/crates/app/src/ui/data_grid/row_detail/fields.rs index a4da790526..fc8aea1527 100644 --- a/linux/crates/app/src/ui/data_grid/row_detail/fields.rs +++ b/linux/crates/app/src/ui/data_grid/row_detail/fields.rs @@ -133,16 +133,32 @@ fn field_row() -> gtk::Box { .min_chars(1) .text_overflow(gtk::InscriptionOverflow::EllipsizeEnd) .build(); - let row = gtk::Box::builder() + // As the grid's cells and the value editor draw a value. + value.add_css_class("monospace"); + let content = gtk::Box::builder() .orientation(gtk::Orientation::Vertical) .spacing(2) + .hexpand(true) + .valign(gtk::Align::Center) + .build(); + content.append(&top); + content.append(&value); + // A suffix of the row, as on a libadwaita property row. + let copy = gtk::Button::builder() + .icon_name(icons::EDIT_COPY) + .valign(gtk::Align::Center) + .build(); + copy.add_css_class("flat"); + crate::ui::a11y::describe_icon_button(©, &gettext("Copy Value"), None); + let row = gtk::Box::builder() + .spacing(6) .margin_top(6) .margin_bottom(6) .margin_start(12) .margin_end(12) .build(); - row.append(&top); - row.append(&value); + row.append(&content); + row.append(©); row } @@ -152,10 +168,12 @@ struct FieldParts { edited: gtk::Image, kind: gtk::Label, value: gtk::Inscription, + copy: gtk::Button, } fn field_parts(row: >k::Widget) -> Option { - let top = row.first_child()?; + let content = row.first_child()?; + let top = content.first_child()?; let key = top.first_child()?; let name = key.next_sibling()?; let edited = name.next_sibling()?; @@ -165,7 +183,8 @@ fn field_parts(row: >k::Widget) -> Option { name: name.downcast().ok()?, edited: edited.downcast().ok()?, kind: kind.downcast().ok()?, - value: row.last_child()?.downcast().ok()?, + value: top.next_sibling()?.downcast().ok()?, + copy: content.next_sibling()?.downcast().ok()?, }) } @@ -266,11 +285,32 @@ impl RowDetailPane { fn field_factory(&self) -> gtk::SignalListItemFactory { let factory = gtk::SignalListItemFactory::new(); - factory.connect_setup(|_, item| { - if let Some(item) = item.downcast_ref::() { - item.set_child(Some(&field_row())); + factory.connect_setup(glib::clone!( + #[weak(rename_to = pane)] + self, + move |_, item| { + let Some(item) = item.downcast_ref::() else { + return; + }; + let row = field_row(); + if let Some(parts) = field_parts(row.upcast_ref()) { + // The grid's Copy, so the whole value goes rather than + // the text the field draws, which cuts a long one. + parts.copy.connect_clicked(glib::clone!( + #[weak] + pane, + #[weak] + item, + move |_| { + if let Some(column) = field_of(item.item()) { + pane.act_on_field(column, "copy"); + } + } + )); + } + item.set_child(Some(&row)); } - }); + )); factory.connect_bind(glib::clone!( #[weak(rename_to = pane)] self, @@ -370,6 +410,7 @@ impl RowDetailPane { edited, kind, value: shown, + .. }) = field_parts(&row_box) else { return; @@ -492,6 +533,21 @@ impl RowDetailPane { .scroll_to(position, Some(&view_column), gtk::ListScrollFlags::FOCUS, None); } + /// Run the grid's `action` on the shown row's `column`, whichever + /// field the editor holds, as a cell menu runs it on its cell. + fn act_on_field(&self, column: usize, action: &str) { + let (Some(grid), Some(row)) = (self.grid(), self.current_pin()) else { + return; + }; + grid.hold_menu_target(crate::ui::data_grid::selection::Target { + cell: Some((row.clone(), column)), + rows: vec![row], + }); + grid.refresh_actions(); + grid.actions().activate_action(action, None); + grid.release_menu_target_soon(); + } + /// A header drag, a hidden column or a new column set reorders the /// fields once the grid has finished changing its columns. fn schedule_field_sync(&self) { diff --git a/linux/crates/app/src/ui/data_grid/row_detail/tests.rs b/linux/crates/app/src/ui/data_grid/row_detail/tests.rs index 1747ca4d97..682b22aa34 100644 --- a/linux/crates/app/src/ui/data_grid/row_detail/tests.rs +++ b/linux/crates/app/src/ui/data_grid/row_detail/tests.rs @@ -18,6 +18,7 @@ use super::clock::{ClockField, time_of, with_time}; use super::fields::{field_label, field_order}; use super::value_editor::value_content; use crate::services::change_tracker::RowKey; +use crate::services::grid::display_text::DISPLAY_MAX_CHARS; use crate::services::grid::{CellLock, GridColumn, GridRowId, grid_columns}; use crate::services::tracker_edit::TrackerEdit; use crate::test_support::{ @@ -511,6 +512,78 @@ fn the_fields_follow_the_grid_column_order() { assert_eq!(fields(&pane), [1, 2, 0], "a hidden column's field did not go last"); } +fn copy_button(pane: &RowDetailPane, column: usize) -> gtk::Button { + let row = drawn_field(pane, column).child().expect("the field's row"); + descendants(&row) + .into_iter() + .filter_map(|widget| widget.downcast::().ok()) + .find(|button| button.icon_name().as_deref() == Some(crate::ui::icons::EDIT_COPY)) + .expect("the field's copy button") +} + +#[gtk4::test] +fn a_fields_copy_button_copies_its_whole_value_and_leaves_the_editor() { + let long = "x".repeat(DISPLAY_MAX_CHARS + 500); + let (grid, pane) = opened( + three_text_columns(), + vec![vec![Value::Int(1), Value::Text("A".into()), Value::Text(long.clone())]], + ); + grid.focus(0, 1); + drain_main_context(); + let heard: Rc>> = Rc::default(); + let log = heard.clone(); + grid.grid.connect_request(move |_, request| { + if let GridRequest::Toast(text) = request { + log.borrow_mut().push(text); + } + }); + + copy_button(&pane, 2).emit_clicked(); + wait_until(WAIT, || !heard.borrow().is_empty()).expect("the copy lands"); + + let clipboard = grid.grid.clipboard(); + let copied = finish_on_main(WAIT, async move { clipboard.read_text_future().await }) + .expect("the clipboard to answer") + .expect("text on the clipboard"); + assert_eq!( + copied.as_deref().map(str::len), + Some(long.len()), + "the copy took the text the field draws" + ); + assert_eq!(selected_field(&pane), Some(1), "the copy moved the editor"); + assert_eq!(pane.typed_text(), "A"); +} + +/// The arrows go from field to field, so Tab leaves the list once past +/// the focused field's own buttons rather than through every field. +#[gtk4::test] +fn tab_leaves_the_field_list_after_the_focused_field() { + let (grid, pane) = opened(two_text_columns(), two_text_values()); + crate::test_support::KeyInjector::focus_only(&grid.window); + take_keyboard(&grid); + grid.focus(0, 1); + let list = pane.imp().field_list.get(); + wait_until(WAIT, || { + pane.imp().field_search.is_mapped() && list.width() > 0 && list.height() > 0 + }) + .expect("the fields are laid out"); + crate::test_support::after_next_frame(&grid.window); + assert!(pane.imp().field_search.grab_focus()); + let keys = crate::test_support::KeyInjector::connect().expect("an X11 display"); + let on_copy = || { + gtk::prelude::GtkWindowExt::focus(&grid.window) + .and_downcast::() + .is_some_and(|button| button.icon_name().as_deref() == Some(crate::ui::icons::EDIT_COPY)) + }; + + keys.press(gdk::Key::Tab, gdk::ModifierType::empty()).expect("Tab"); + wait_until(WAIT, || crate::ui::a11y::holds_focus(&list)).expect("Tab to the list"); + keys.press(gdk::Key::Tab, gdk::ModifierType::empty()).expect("Tab"); + wait_until(WAIT, on_copy).expect("Tab to the field's copy button"); + keys.press(gdk::Key::Tab, gdk::ModifierType::empty()).expect("Tab"); + wait_until(WAIT, || !crate::ui::a11y::holds_focus(&list)).expect("Tab out of the list"); +} + #[gtk4::test] fn every_control_in_the_pane_is_named() { let (grid, pane) = opened(two_text_columns(), two_text_values()); diff --git a/linux/data/resources/ui/row-detail-pane.ui b/linux/data/resources/ui/row-detail-pane.ui index 133dfbeccd..85de2424b4 100644 --- a/linux/data/resources/ui/row-detail-pane.ui +++ b/linux/data/resources/ui/row-detail-pane.ui @@ -170,6 +170,10 @@ 120 + + item Fields