diff --git a/linux/changelog.d/4158.added.md b/linux/changelog.d/4158.added.md new file mode 100644 index 0000000000..d5118ad18f --- /dev/null +++ b/linux/changelog.d/4158.added.md @@ -0,0 +1 @@ +Each field in the row details has its own menu to set it to NULL, DEFAULT or empty, or copy it. 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 6bae619fb4..df3871a313 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 @@ -146,12 +146,16 @@ fn field_row() -> gtk::Box { let copy = gtk::Button::from_icon_name(icons::EDIT_COPY); copy.add_css_class("flat"); crate::ui::a11y::describe_icon_button(©, &gettext("Copy Value"), None); + let menu = gtk::MenuButton::builder().icon_name(icons::VIEW_MORE).build(); + menu.add_css_class("flat"); + crate::ui::a11y::describe_icon_button(&menu, &gettext("More Actions"), None); // The value editor's pickers, while this is the picked field. let tools = gtk::Box::builder().visible(false).build(); // Suffixes of the row, as on a libadwaita property row. let suffix = gtk::Box::builder().valign(gtk::Align::Center).build(); suffix.append(&tools); suffix.append(©); + suffix.append(&menu); let line = gtk::Box::new(gtk::Orientation::Horizontal, 6); line.append(&content); line.append(&suffix); @@ -178,6 +182,7 @@ struct FieldParts { value: gtk::Inscription, tools: gtk::Box, copy: gtk::Button, + menu: gtk::MenuButton, slot: gtk::Box, } @@ -198,6 +203,7 @@ fn field_parts(row: >k::Widget) -> Option { kind: kind.downcast().ok()?, value: top.next_sibling()?.downcast().ok()?, tools: tools.downcast().ok()?, + menu: copy.next_sibling()?.downcast().ok()?, copy: copy.downcast().ok()?, slot: line.next_sibling()?.downcast().ok()?, }) @@ -334,6 +340,7 @@ impl RowDetailPane { } } )); + pane.connect_field_menu(&parts.menu, item); } item.set_child(Some(&row)); } @@ -631,19 +638,52 @@ 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; - }; + /// Hold the shown row's `column` as the target of the grid's actions, + /// whichever field the editor holds, as a cell menu holds its cell. + fn hold_field(&self, column: usize) -> Option { + let (grid, row) = (self.grid()?, self.current_pin()?); 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(); + Some(grid) + } + + fn act_on_field(&self, column: usize, action: &str) { + if let Some(grid) = self.hold_field(column) { + grid.actions().activate_action(action, None); + grid.release_menu_target_soon(); + } + } + + /// The menu's items are the grid's own cell actions, held on the + /// row's field until it closes, so they act on that field while the + /// grid has no focus and the editor stays on its own. + fn connect_field_menu(&self, menu: >k::MenuButton, item: >k::ListItem) { + menu.set_menu_model(Some(&*self.imp().value_menu)); + menu.set_create_popup_func(glib::clone!( + #[weak(rename_to = pane)] + self, + #[weak] + item, + move |_| { + if let Some(column) = field_of(item.item()) { + pane.hold_field(column); + } + } + )); + if let Some(popover) = menu.popover() { + popover.connect_closed(glib::clone!( + #[weak(rename_to = pane)] + self, + move |_| { + if let Some(grid) = pane.grid() { + grid.release_menu_target_soon(); + } + } + )); + } } /// A header drag, a hidden column or a new column set reorders the diff --git a/linux/crates/app/src/ui/data_grid/row_detail/imp.rs b/linux/crates/app/src/ui/data_grid/row_detail/imp.rs index 5b15b387ce..6102f1e0aa 100644 --- a/linux/crates/app/src/ui/data_grid/row_detail/imp.rs +++ b/linux/crates/app/src/ui/data_grid/row_detail/imp.rs @@ -75,7 +75,7 @@ pub struct RowDetailPane { #[template_child] pub clock_set: TemplateChild, #[template_child] - pub value_menu_button: TemplateChild, + pub value_menu: TemplateChild, #[template_child] pub value_scroller: TemplateChild, #[template_child] diff --git a/linux/crates/app/src/ui/data_grid/row_detail/mod.rs b/linux/crates/app/src/ui/data_grid/row_detail/mod.rs index 25b45a5a68..b49ad6b9ab 100644 --- a/linux/crates/app/src/ui/data_grid/row_detail/mod.rs +++ b/linux/crates/app/src/ui/data_grid/row_detail/mod.rs @@ -41,7 +41,6 @@ impl RowDetailPane { self.imp().grid.set(Some(grid)); self.connect_fields(grid); self.connect_value_editor(grid); - self.connect_value_menu(grid); self.connect_choices(); self.connect_calendar(); self.connect_clock(); 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 76fc4c77e6..a27e3690e7 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 @@ -416,7 +416,7 @@ fn a_locked_cell_is_read_only_with_its_sentence() { message(&pane), Some(CellLock::KeyColumn.explanation(edit_parse_message)) ); - pane.imp().value_menu_button.popup(); + field_menu(&pane, 0).popup(); assert!(!grid.is_enabled("set-null"), "the menu offered to change a locked cell"); assert!(grid.is_enabled("copy")); } @@ -441,7 +441,7 @@ fn set_to_null_writes_null_into_the_field() { take_keyboard(&grid); grid.focus(0, 1); pane.focus_value(); - pane.imp().value_menu_button.popup(); + field_menu(&pane, 1).popup(); assert!(grid.is_enabled("set-null"), "the menu does not act on the field"); assert!(!grid.is_enabled("set-default"), "a saved row offered DEFAULT"); @@ -489,7 +489,7 @@ fn copy_value_copies_the_field() { } }); - pane.imp().value_menu_button.popup(); + field_menu(&pane, 1).popup(); grid.activate("copy"); wait_until(WAIT, || !heard.borrow().is_empty()).expect("the copy lands"); @@ -575,12 +575,20 @@ fn tab_leaves_the_field_list_after_the_focused_field() { .and_downcast::() .is_some_and(|button| button.icon_name().as_deref() == Some(crate::ui::icons::EDIT_COPY)) }; + let on_menu = || { + gtk::prelude::GtkWindowExt::focus(&grid.window) + .and_then(|focus| focus.ancestor(gtk::MenuButton::static_type())) + .and_downcast::() + .is_some_and(|button| button.icon_name().as_deref() == Some(crate::ui::icons::VIEW_MORE)) + }; 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, on_menu).expect("Tab to the field's menu"); + 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"); } @@ -645,6 +653,36 @@ fn a_field_the_search_drops_while_editing_hands_the_keyboard_to_the_search() { ); } +/// The menu button of data column `column`'s row, once the list has drawn +/// it. +fn field_menu(pane: &RowDetailPane, column: usize) -> gtk::MenuButton { + drain_main_context(); + 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::VIEW_MORE)) + .expect("the field's menu") +} + +#[gtk4::test] +fn a_fields_menu_acts_on_that_field_and_leaves_the_editor() { + let (grid, pane) = opened(three_text_columns(), three_text_values()); + grid.focus(0, 1); + let menu = field_menu(&pane, 2); + + menu.popup(); + assert!(grid.is_enabled("set-null"), "the menu does not act on its field"); + grid.activate("set-null"); + menu.popdown(); + drain_main_context(); + + assert_eq!(pending(&grid, 1, 2), Some(CellInput::Value(Value::Null))); + assert_eq!(pending(&grid, 1, 1), None); + assert_eq!(selected_field(&pane), Some(1), "the menu moved the editor"); + assert_eq!(pane.typed_text(), "A"); +} + #[gtk4::test] fn a_field_the_search_hides_lists_again_when_the_grid_shows_it() { let (grid, pane) = opened(three_text_columns(), three_text_values()); diff --git a/linux/crates/app/src/ui/data_grid/row_detail/value_editor.rs b/linux/crates/app/src/ui/data_grid/row_detail/value_editor.rs index f3823387b2..6efe1a28ab 100644 --- a/linux/crates/app/src/ui/data_grid/row_detail/value_editor.rs +++ b/linux/crates/app/src/ui/data_grid/row_detail/value_editor.rs @@ -17,7 +17,6 @@ use crate::services::grid::{ display_text, empty_placeholder, hex_dump, }; use crate::ui::data_grid::edit::CHOICE_ACTIONS; -use crate::ui::data_grid::selection::Target; use crate::ui::data_grid::{DataGrid, GridRow, PinnedRow}; use crate::ui::error_text::edit_parse_message; use crate::ui::handler_guard::HandlerGuard; @@ -449,25 +448,6 @@ impl RowDetailPane { } } - /// The menu's items are the grid's own cell actions, held on the - /// shown row and field until it closes, as the cell menu holds its - /// cell, so they act on the field while the grid has no focus. - pub(super) fn connect_value_menu(&self, grid: &DataGrid) { - let button = self.imp().value_menu_button.get(); - button.set_create_popup_func(glib::clone!( - #[weak(rename_to = pane)] - self, - move |_| pane.arm_value_menu() - )); - if let Some(popover) = button.popover() { - popover.connect_closed(glib::clone!( - #[weak] - grid, - move |_| grid.release_menu_target_soon() - )); - } - } - /// The labels of the field shown, filled as the menu opens so they act /// on that row and field. pub(super) fn connect_choices(&self) { @@ -494,16 +474,6 @@ impl RowDetailPane { } } - fn arm_value_menu(&self) { - let Some(grid) = self.grid() else { - return; - }; - let cell = self.current_pin().zip(self.imp().field.get()); - let rows = cell.iter().map(|(row, _)| row.clone()).collect(); - grid.hold_menu_target(Target { cell, rows }); - grid.refresh_actions(); - } - fn follow_style_scheme(&self, grid: &DataGrid) { let settings = grid.config().map(|config| config.settings.clone()); let paint = { diff --git a/linux/data/resources/ui/row-detail-pane.ui b/linux/data/resources/ui/row-detail-pane.ui index d11dab7e26..b1a793c458 100644 --- a/linux/data/resources/ui/row-detail-pane.ui +++ b/linux/data/resources/ui/row-detail-pane.ui @@ -346,19 +346,6 @@ - - - view-more-symbolic - value_menu - More Actions - - More Actions - - - -