diff --git a/linux/changelog.d/4157.changed.md b/linux/changelog.d/4157.changed.md new file mode 100644 index 0000000000..5f37bcca59 --- /dev/null +++ b/linux/changelog.d/4157.changed.md @@ -0,0 +1 @@ +Row details edit a field in its own row instead of in an editor under the list. 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 fc8aea1527..6bae619fb4 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 @@ -143,22 +143,30 @@ fn field_row() -> gtk::Box { .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(); + 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); + // 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(©); + let line = gtk::Box::new(gtk::Orientation::Horizontal, 6); + line.append(&content); + line.append(&suffix); + // The value editor, in place of the value, while this is the picked field. + let slot = gtk::Box::builder().visible(false).build(); let row = gtk::Box::builder() + .orientation(gtk::Orientation::Vertical) .spacing(6) .margin_top(6) .margin_bottom(6) .margin_start(12) .margin_end(12) .build(); - row.append(&content); - row.append(©); + row.append(&line); + row.append(&slot); row } @@ -168,26 +176,45 @@ struct FieldParts { edited: gtk::Image, kind: gtk::Label, value: gtk::Inscription, + tools: gtk::Box, copy: gtk::Button, + slot: gtk::Box, } fn field_parts(row: >k::Widget) -> Option { - let content = row.first_child()?; + let line = row.first_child()?; + let content = line.first_child()?; let top = content.first_child()?; let key = top.first_child()?; let name = key.next_sibling()?; let edited = name.next_sibling()?; let kind = edited.next_sibling()?.last_child()?; + let tools = content.next_sibling()?.first_child()?; + let copy = tools.next_sibling()?; Some(FieldParts { key: key.downcast().ok()?, name: name.downcast().ok()?, edited: edited.downcast().ok()?, kind: kind.downcast().ok()?, value: top.next_sibling()?.downcast().ok()?, - copy: content.next_sibling()?.downcast().ok()?, + tools: tools.downcast().ok()?, + copy: copy.downcast().ok()?, + slot: line.next_sibling()?.downcast().ok()?, }) } +/// Move `widget` into `home`, unless it is there already: taking it out +/// would drop the keyboard it holds. +fn move_into(widget: >k::Box, home: >k::Box) { + if widget.parent().as_ref() == Some(home.upcast_ref()) { + return; + } + if let Some(parent) = widget.parent().and_downcast::() { + parent.remove(widget); + } + home.append(widget); +} + fn set_class(widget: &impl IsA, class: &str, on: bool) { match on { true => widget.as_ref().add_css_class(class), @@ -318,17 +345,20 @@ impl RowDetailPane { if let Some(item) = item.downcast_ref::() { pane.imp().bound.borrow_mut().push(item.clone()); pane.draw_field(item); + pane.place_editor(); } } )); factory.connect_unbind(glib::clone!( #[weak(rename_to = pane)] self, - move |_, item| pane - .imp() - .bound - .borrow_mut() - .retain(|bound| bound.upcast_ref::() != item) + move |_, item| { + pane.imp() + .bound + .borrow_mut() + .retain(|bound| bound.upcast_ref::() != item); + pane.place_editor(); + } )); factory } @@ -343,6 +373,7 @@ impl RowDetailPane { pub(super) fn refilter_fields(&self) { let imp = self.imp(); + let editor_had_keyboard = self.editor_holds_focus(); let has_edits = self.grid().zip(self.current_row()).is_some_and(|(grid, row)| { grid.grid_columns().iter().any(|column| { let mark = grid.tracked().mark(&row, column.index); @@ -360,6 +391,8 @@ impl RowDetailPane { 0 => "empty", _ => "fields", }); + self.place_editor(); + self.keep_keyboard(editor_had_keyboard); } fn field_shown(&self, column: Option) -> bool { @@ -477,6 +510,7 @@ impl RowDetailPane { return; }; self.take_field(column); + self.place_editor(); self.load_value(); self.move_grid_focus(column); } @@ -484,10 +518,23 @@ impl RowDetailPane { /// Show `column`'s field, selected in the list, as the grid asks. pub(super) fn set_field(&self, column: usize) { self.take_field(column); + self.list_field(column); self.select_in_list(Some(column)); + self.place_editor(); self.load_value(); } + // The editor sits only in a listed field's row. + fn list_field(&self, column: usize) { + let imp = self.imp(); + if self.current_row().is_none() || self.field_shown(Some(column)) { + return; + } + imp.field_search.set_text(""); + imp.edited_toggle.set_active(false); + self.refilter_fields(); + } + /// Make `column` the selected field. What was typed in another field /// is committed first. pub(super) fn take_field(&self, column: usize) { @@ -510,11 +557,62 @@ impl RowDetailPane { let syncing = imp.syncing.replace(true); imp.selection.set_selected(position); imp.syncing.set(syncing); + self.place_editor(); if position != gtk::INVALID_LIST_POSITION { imp.field_list.scroll_to(position, gtk::ListScrollFlags::NONE, None); } } + /// Lay the value editor into the picked field's row, in place of its + /// value, and its pickers beside that row's copy button. The list + /// recycles rows as it scrolls and filters, so every bind and unbind + /// lays them again, and with no row for them they go back to the dock. + fn place_editor(&self) { + let imp = self.imp(); + let picked = imp.field.get(); + let bound: Vec = imp.bound.borrow().clone(); + let mut seat = None; + for item in &bound { + let Some(parts) = item.child().as_ref().and_then(field_parts) else { + continue; + }; + let holds = picked.is_some() && item.is_selected() && field_of(item.item()) == picked; + parts.value.set_visible(!holds); + parts.tools.set_visible(holds); + parts.slot.set_visible(holds); + if holds { + seat = Some((parts.tools, parts.slot)); + } + } + let dock = imp.editor_dock.get(); + let (tools_home, editor_home) = seat.unwrap_or_else(|| (dock.clone(), dock)); + move_into(&imp.editor_tools.get(), &tools_home); + move_into(&imp.editor_box.get(), &editor_home); + } + + fn editor_holds_focus(&self) -> bool { + let imp = self.imp(); + crate::ui::a11y::holds_focus(&imp.editor_box.get()) || crate::ui::a11y::holds_focus(&imp.editor_tools.get()) + } + + /// A filter or a new column set can take away the row that held the + /// editor and the keyboard with it, which GTK would hand to the + /// window's first control. + fn keep_keyboard(&self, editor_had_it: bool) { + let imp = self.imp(); + let list = imp.field_list.get(); + if !editor_had_it || self.current_row().is_none() || imp.editor_box.is_ancestor(&list) { + return; + } + if imp.filtered.n_items() == 0 { + imp.field_search.grab_focus(); + return; + } + // The list's focused row was the one taken away. + list.scroll_to(0, gtk::ListScrollFlags::FOCUS, None); + list.grab_focus(); + } + /// Move the grid's focused cell to `column` of the shown row. The /// list holds the keyboard, and `scroll_to` only marks the cell the /// grid focuses next while the grid does not, so the keyboard stays @@ -580,6 +678,7 @@ impl RowDetailPane { return; } let items: Vec = wanted.into_iter().map(glib::BoxedAnyObject::new).collect(); + let editor_had_keyboard = self.editor_holds_focus(); imp.syncing.set(true); store.splice(0, store.n_items(), &items); imp.syncing.set(false); @@ -588,6 +687,8 @@ impl RowDetailPane { imp.field.set(None); } self.select_in_list(imp.field.get()); + self.place_editor(); + self.keep_keyboard(editor_had_keyboard); } fn watch_column_visibility(&self) { 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 7f9b51ba0a..5b15b387ce 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 @@ -47,7 +47,11 @@ pub struct RowDetailPane { #[template_child] pub edited_toggle: TemplateChild, #[template_child] - pub field_label: TemplateChild, + pub editor_dock: TemplateChild, + #[template_child] + pub editor_tools: TemplateChild, + #[template_child] + pub editor_box: TemplateChild, #[template_child] pub choice_button: 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 5dab5cc14b..25b45a5a68 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 @@ -80,15 +80,39 @@ impl RowDetailPane { return; } self.render(); - let view = self.imp().value_view.get(); + if crate::ui::a11y::holds_focus(&self.imp().value_view.get()) { + return; + } + self.reveal_editor(); // The pane may only now be on its way to the screen. - if !view.grab_focus() { - glib::idle_add_local_once(move || { - view.grab_focus(); - }); + if !self.grab_value() { + glib::idle_add_local_once(glib::clone!( + #[weak(rename_to = pane)] + self, + move || { + pane.grab_value(); + } + )); + } + } + + /// A list builds a row only as it lays it out, which a pane opening + /// now has not done yet. Focusing the picked field's row makes the + /// list build it at once, so the editor has its row to sit in. + fn reveal_editor(&self) { + let imp = self.imp(); + let position = imp.selection.selected(); + if position != gtk::INVALID_LIST_POSITION { + imp.field_list.scroll_to(position, gtk::ListScrollFlags::FOCUS, None); } } + /// Only in its field's row: in the dock it would take keys unseen. + fn grab_value(&self) -> bool { + let imp = self.imp(); + imp.editor_box.is_ancestor(&imp.field_list.get()) && imp.value_view.grab_focus() + } + /// Commit what was typed in the value editor before the grid writes /// its rows. A value the column refuses goes, since it was never a /// pending change. 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 682b22aa34..76fc4c77e6 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 @@ -584,6 +584,84 @@ fn tab_leaves_the_field_list_after_the_focused_field() { wait_until(WAIT, || !crate::ui::a11y::holds_focus(&list)).expect("Tab out of the list"); } +fn field_row_of(pane: &RowDetailPane, column: usize) -> gtk::Widget { + drawn_field(pane, column).child().expect("the field's row") +} + +fn shows_value(pane: &RowDetailPane, column: usize) -> bool { + descendants(&field_row_of(pane, column)) + .into_iter() + .filter_map(|widget| widget.downcast::().ok()) + .any(|value| value.is_visible()) +} + +#[gtk4::test] +fn the_value_editor_sits_in_the_picked_fields_row() { + let (grid, pane) = opened(three_text_columns(), three_text_values()); + let imp = pane.imp(); + grid.focus(0, 1); + drain_main_context(); + + assert!( + imp.editor_box.is_ancestor(&field_row_of(&pane, 1)), + "the editor is not in its field's row" + ); + assert!(imp.editor_tools.is_ancestor(&field_row_of(&pane, 1))); + assert!( + !shows_value(&pane, 1), + "the picked field drew its value beside the editor" + ); + assert!(shows_value(&pane, 2)); + + grid.focus(0, 2); + drain_main_context(); + + assert!( + imp.editor_box.is_ancestor(&field_row_of(&pane, 2)), + "the editor did not follow the field" + ); + assert!(!imp.editor_box.is_ancestor(&field_row_of(&pane, 1))); + assert!(shows_value(&pane, 1), "the field left behind lost its value"); + assert_eq!(pane.typed_text(), "x"); +} + +#[gtk4::test] +fn a_field_the_search_drops_while_editing_hands_the_keyboard_to_the_search() { + let (grid, pane) = opened(three_text_columns(), three_text_values()); + edit_field(&grid, &pane, 0, 2); + search_fields(&pane, "x"); + assert_eq!(listed_columns(&pane), vec![2]); + assert!(crate::ui::a11y::holds_focus(&pane.imp().value_view.get())); + + type_value(&pane, "z"); + assert!(press_in_value(&pane, gdk::Key::Return, gdk::ModifierType::CONTROL_MASK)); + drain_main_context(); + + assert_eq!(pending(&grid, 1, 2), Some(text("z"))); + assert!(listed_columns(&pane).is_empty()); + assert!( + crate::ui::a11y::holds_focus(&pane.imp().field_search.get()), + "the keyboard left the pane with the field's row" + ); +} + +#[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()); + let imp = pane.imp(); + grid.focus(0, 1); + search_fields(&pane, "note"); + assert_eq!(listed_columns(&pane), vec![2]); + + grid.grid.show_details_for(1); + wait_until(WAIT, || imp.editor_box.is_ancestor(&imp.field_list.get())).expect("the editor takes a row"); + + assert!(imp.field_search.text().is_empty(), "the search still hides the field"); + assert_eq!(listed_columns(&pane), vec![0, 1, 2]); + assert!(imp.editor_box.is_ancestor(&field_row_of(&pane, 1))); + assert_eq!(pane.typed_text(), "A"); +} + #[gtk4::test] fn every_control_in_the_pane_is_named() { let (grid, pane) = opened(two_text_columns(), two_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 6b7a52de1b..f3823387b2 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 @@ -402,7 +402,6 @@ impl RowDetailPane { buffer.place_cursor(&buffer.start_iter()); let view = imp.value_view.get(); view.set_editable(content.message.is_none()); - imp.field_label.set_label(name); view.update_property(&[gtk::accessible::Property::Label(name)]); self.show_message(content.message.as_deref(), false); imp.calendar_button.set_visible(content.calendar); diff --git a/linux/data/resources/ui/row-detail-pane.ui b/linux/data/resources/ui/row-detail-pane.ui index 85de2424b4..d11dab7e26 100644 --- a/linux/data/resources/ui/row-detail-pane.ui +++ b/linux/data/resources/ui/row-detail-pane.ui @@ -122,316 +122,308 @@ - + vertical true - false - false - + + - vertical - + 6 + 6 + 6 + 12 + 12 - - 6 - 6 - 6 - 12 - 12 - - - true - Search fields - - Search fields - - - - - - document-edit-symbolic - Show edited fields only - - Show edited fields only - - - + + true + Search fields + + Search fields + - - true - - - fields - - - never - 120 - - - - item - - Fields - - - - - - - - - - empty + + document-edit-symbolic + Show edited fields only + + Show edited fields only + + + + + + + + true + + + fields + + + never + 120 - - No Matching Fields - true - 12 - 12 - + + + item + + Fields + - + - - - - - vertical - - 6 - 6 - 6 - 12 - 6 - - - true - 0 - end - - - - - - - false - Pick a Value - - Pick a Value - + + empty + + + No Matching Fields + true + 12 + 12 - - - - x-office-calendar-symbolic - false - Pick a Date - - Pick a Date - - - - - - - - Pick a Date - - - + + + + + + + + + + + false + + + + + + false + Pick a Value + + Pick a Value + + + + + + + x-office-calendar-symbolic + false + Pick a Date + + Pick a Date + + + + + + + + Pick a Date + - - - - preferences-system-time-symbolic - false - Pick a Time - - Pick a Time - - - - - clock_set - - - 6 - 6 - 6 - 6 - 6 - - - vertical - true - true - 0.5 - true - - - 23 - 1 - 6 - - - - Hour - - - - - - : - - - - - vertical - true - true - 0.5 - true - - - 59 - 1 - 10 - - - - Minute - - - - - - : + + + + + + preferences-system-time-symbolic + false + Pick a Time + + Pick a Time + + + + + clock_set + + + 6 + 6 + 6 + 6 + 6 + + + vertical + true + true + 0.5 + true + + + 23 + 1 + 6 - - - - vertical - true - true - 0.5 - true - - - 59 - 1 - 10 - - - - Second - + + + Hour + + + + + + : + + + + + vertical + true + true + 0.5 + true + + + 59 + 1 + 10 - - - - Set - center - 6 - + + + Minute + + + + + + : + + + + + vertical + true + true + 0.5 + true + + + 59 + 1 + 10 - + + + Second + - + + + + Set + center + 6 + + + - - - - view-more-symbolic - value_menu - More Actions - - More Actions - - - - + + + + view-more-symbolic + value_menu + More Actions + + More Actions + + + + + + + + + vertical + 6 false scale-down - 6 - 12 - 12 Image preview - - - true + + + hidden - - never - 120 + + - - true - word-char - true - 6 - 6 - 12 - 12 - - + + never + + true + 320 + + + true + word-char + true + 6 + 6 + 12 + 12 + + + + + + + start + start + 6 + 12 + false + false + presentation + + + + + + - - - start - start - 6 - 12 - false - false - presentation - - - - - - @@ -440,17 +432,13 @@ true word-char false - 6 - 6 - 12 - 12 - +