From 5ecc54f01526117ee020533c8cc0d31972ff7af8 Mon Sep 17 00:00:00 2001 From: sedax90 <5001801+sedax90@users.noreply.github.com> Date: Sun, 8 Nov 2026 12:14:27 +0100 Subject: [PATCH 1/8] feat(linux-grid): mark a field's key, edit and type in the row details --- .../app/src/ui/data_grid/row_detail/fields.rs | 77 +++++++++++++++---- .../app/src/ui/data_grid/row_detail/tests.rs | 28 +++++++ linux/crates/app/src/ui/icons.rs | 2 + linux/data/resources/style.css | 9 +++ 4 files changed, 99 insertions(+), 17 deletions(-) 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 b698999b09..0e076261f2 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 @@ -11,6 +11,7 @@ use crate::services::grid::{GridColumn, auto_filled_sentinel, display_text}; use crate::ui::data_grid::tracked_values::cell_description; use crate::ui::data_grid::{DataGrid, GridRow, ServerValue, TrackedValues}; use crate::ui::handler_guard::HandlerGuard; +use crate::ui::icons; /// The data columns in the order the fields list shows them: the ones on /// screen as the grid shows them, then the hidden ones. @@ -63,20 +64,38 @@ pub fn field_value(tracked: &TrackedValues, row: &GridRow, column: &GridColumn) } /// A field's row: its name and type on one line, its value on the next. +/// One field: its name with a key for a primary key column, a pencil +/// while it holds an edit and the type as a badge, over its value. fn field_row() -> gtk::Box { + let key = gtk::Image::builder() + .icon_name(icons::DIALOG_PASSWORD) + .pixel_size(12) + .visible(false) + .build(); + key.add_css_class("warning"); + key.set_accessible_role(gtk::AccessibleRole::Presentation); let name = gtk::Label::builder() .xalign(0.0) .hexpand(true) - .ellipsize(pango::EllipsizeMode::End) + .ellipsize(pango::EllipsizeMode::Middle) .build(); + name.add_css_class("dimmed"); + let edited = gtk::Image::builder() + .icon_name(icons::DOCUMENT_EDIT) + .pixel_size(12) + .visible(false) + .build(); + edited.add_css_class("accent"); + edited.set_accessible_role(gtk::AccessibleRole::Presentation); let kind = gtk::Label::builder() - .xalign(1.0) + .xalign(0.5) .ellipsize(pango::EllipsizeMode::End) .build(); - kind.add_css_class("caption"); - kind.add_css_class("dimmed"); + kind.add_css_class("field-type"); let top = gtk::Box::new(gtk::Orientation::Horizontal, 6); + top.append(&key); top.append(&name); + top.append(&edited); top.append(&kind); let value = gtk::Inscription::builder() .hexpand(true) @@ -85,9 +104,9 @@ fn field_row() -> gtk::Box { .build(); let row = gtk::Box::builder() .orientation(gtk::Orientation::Vertical) - .spacing(2) - .margin_top(6) - .margin_bottom(6) + .spacing(3) + .margin_top(7) + .margin_bottom(7) .margin_start(12) .margin_end(12) .build(); @@ -96,6 +115,30 @@ fn field_row() -> gtk::Box { row } +/// The widgets of a field row, in the order `field_row` makes them. +struct FieldParts { + key: gtk::Image, + name: gtk::Label, + edited: gtk::Image, + kind: gtk::Label, + value: gtk::Inscription, +} + +fn field_parts(row: >k::Widget) -> Option { + let top = row.first_child()?; + let key = top.first_child()?; + let name = key.next_sibling()?; + let edited = name.next_sibling()?; + let kind = edited.next_sibling()?; + Some(FieldParts { + key: key.downcast().ok()?, + name: name.downcast().ok()?, + edited: edited.downcast().ok()?, + kind: kind.downcast().ok()?, + value: row.last_child()?.downcast().ok()?, + }) +} + fn set_class(widget: &impl IsA, class: &str, on: bool) { match on { true => widget.as_ref().add_css_class(class), @@ -192,18 +235,17 @@ impl RowDetailPane { let Some(row_box) = item.child() else { return; }; - let top = row_box.first_child(); - let (Some(name), Some(kind), Some(shown)) = ( - top.as_ref() - .and_then(|top| top.first_child()) - .and_downcast::(), - top.as_ref() - .and_then(|top| top.last_child()) - .and_downcast::(), - row_box.last_child().and_downcast::(), - ) else { + let Some(FieldParts { + key, + name, + edited, + kind, + value: shown, + }) = field_parts(&row_box) + else { return; }; + key.set_visible(column.catalog.as_ref().is_some_and(|catalog| catalog.primary_key)); name.set_label(&column.name); kind.set_label(&column.value_type().name); item.set_accessible_label(&column.name); @@ -212,6 +254,7 @@ impl RowDetailPane { return; }; let value = field_value(&grid.tracked(), &row, &column); + edited.set_visible(value.modified); shown.set_text(Some(&value.text)); shown.set_attributes(Some(&value_attributes(&value))); set_class(&shown, "dimmed", value.placeholder || value.deleted); 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 831c4f96df..116a5b5936 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 @@ -1424,3 +1424,31 @@ fn a_page_that_takes_the_row_closes_its_clock_and_writes_nothing() { ); assert!(!pane.imp().clock_popover.is_visible()); } + +/// A primary key column's field carries a key, and a field holding an +/// edit a pencil, so each reads without opening the field. +#[gtk4::test] +fn the_fields_mark_the_primary_key_and_a_pending_edit() { + let (grid, pane) = opened(two_text_columns(), two_text_values()); + grid.focus(0, 1); + let marked = |icon: &str| { + descendants(&pane.imp().field_list.get()) + .into_iter() + .filter_map(|widget| widget.downcast::().ok()) + .filter(|image| image.is_visible() && image.icon_name().as_deref() == Some(icon)) + .count() + }; + assert_eq!(marked(crate::ui::icons::DIALOG_PASSWORD), 1, "the id column is the key"); + assert_eq!(marked(crate::ui::icons::DOCUMENT_EDIT), 0); + + let delta = grid.tracker.apply(TrackerEdit::Cell { + row_key: key(1), + col: 1, + original: Value::Text("A".into()), + value: CellInput::Value(Value::Text("changed".into())), + }); + grid.grid.apply_delta(&delta); + drain_main_context(); + + assert_eq!(marked(crate::ui::icons::DOCUMENT_EDIT), 1); +} diff --git a/linux/crates/app/src/ui/icons.rs b/linux/crates/app/src/ui/icons.rs index aa2c179ddf..81aba06ea3 100644 --- a/linux/crates/app/src/ui/icons.rs +++ b/linux/crates/app/src/ui/icons.rs @@ -9,6 +9,8 @@ pub const APPLICATIONS_SCIENCE: &str = "applications-science-symbolic"; pub const ASSISTANT: &str = "assistant-symbolic"; pub const CHANGES_PREVENT: &str = "changes-prevent-symbolic"; pub const COMPUTER: &str = "computer-symbolic"; +/// A key, for a primary key column. +pub const DIALOG_PASSWORD: &str = "dialog-password-symbolic"; pub const DIALOG_ERROR: &str = "dialog-error-symbolic"; pub const DIALOG_WARNING: &str = "dialog-warning-symbolic"; pub const DOCUMENT_EDIT: &str = "document-edit-symbolic"; diff --git a/linux/data/resources/style.css b/linux/data/resources/style.css index 4c92a7f3e9..37eab09f2f 100644 --- a/linux/data/resources/style.css +++ b/linux/data/resources/style.css @@ -219,3 +219,12 @@ tp-diagram-canvas > .tp-diagram-border { tp-diagram-canvas > .tp-diagram-accent { color: var(--accent-color); } + +/* A field's type in the row details, as a badge beside its name. */ +.field-type { + font-size: smaller; + padding: 1px 6px; + border-radius: 6px; + background-color: color-mix(in srgb, currentColor 10%, transparent); + opacity: 0.8; +} From d0f125b1beca3ac95cbc16ca6cdefa4a3e99428d Mon Sep 17 00:00:00 2001 From: sedax90 <5001801+sedax90@users.noreply.github.com> Date: Sun, 8 Nov 2026 12:16:43 +0100 Subject: [PATCH 2/8] docs(linux-grid): add the changelog entry --- linux/changelog.d/4112.added.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 linux/changelog.d/4112.added.md diff --git a/linux/changelog.d/4112.added.md b/linux/changelog.d/4112.added.md new file mode 100644 index 0000000000..25afe55cce --- /dev/null +++ b/linux/changelog.d/4112.added.md @@ -0,0 +1 @@ +A field in the row details names its type in a badge and marks a primary key and a pending edit. From f743a96db2fe4cfab77c8b6ca28299fe3304d3d6 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Sun, 8 Nov 2026 19:38:18 +0700 Subject: [PATCH 3/8] fix(linux-grid): name a field's key and type to screen readers and drop the badge style --- linux/changelog.d/4112.added.md | 2 +- .../app/src/ui/data_grid/row_detail/fields.rs | 63 ++++++++++-------- .../app/src/ui/data_grid/row_detail/tests.rs | 64 +++++++++++++++---- linux/crates/app/src/ui/icons.rs | 5 +- linux/data/resources/style.css | 9 --- 5 files changed, 92 insertions(+), 51 deletions(-) diff --git a/linux/changelog.d/4112.added.md b/linux/changelog.d/4112.added.md index 25afe55cce..95b486e939 100644 --- a/linux/changelog.d/4112.added.md +++ b/linux/changelog.d/4112.added.md @@ -1 +1 @@ -A field in the row details names its type in a badge and marks a primary key and a pending edit. +Row Details marks a primary key field with a key, and a field holding an unsaved edit with a pencil. 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 0e076261f2..fc38047a6c 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 @@ -6,6 +6,7 @@ use gtk4::{self as gtk, glib, pango}; use tablepro_core::Value; use super::RowDetailPane; +use crate::i18n::gettext; use crate::services::change_tracker::CellState; use crate::services::grid::{GridColumn, auto_filled_sentinel, display_text}; use crate::ui::data_grid::tracked_values::cell_description; @@ -63,35 +64,47 @@ pub fn field_value(tracked: &TrackedValues, row: &GridRow, column: &GridColumn) } } -/// A field's row: its name and type on one line, its value on the next. -/// One field: its name with a key for a primary key column, a pencil -/// while it holds an edit and the type as a badge, over its value. +fn is_primary_key(column: &GridColumn) -> bool { + column.catalog.as_ref().is_some_and(|catalog| catalog.primary_key) +} + +// The key has no role of its own, so the label is where a screen reader hears it. +pub(super) fn field_label(column: &GridColumn) -> String { + let mut parts = vec![column.name.clone()]; + let type_name = &column.value_type().name; + if !type_name.is_empty() { + parts.push(type_name.clone()); + } + if is_primary_key(column) { + parts.push(gettext("primary key")); + } + parts.join(", ") +} + +fn marker(icon: &str) -> gtk::Image { + let image = gtk::Image::builder().icon_name(icon).visible(false).build(); + image.set_accessible_role(gtk::AccessibleRole::Presentation); + image +} + fn field_row() -> gtk::Box { - let key = gtk::Image::builder() - .icon_name(icons::DIALOG_PASSWORD) - .pixel_size(12) - .visible(false) - .build(); - key.add_css_class("warning"); - key.set_accessible_role(gtk::AccessibleRole::Presentation); + let key = marker(icons::PRIMARY_KEY); + // Dimmed as a libadwaita property row's title, so the eye lands on the value. let name = gtk::Label::builder() .xalign(0.0) .hexpand(true) .ellipsize(pango::EllipsizeMode::Middle) .build(); name.add_css_class("dimmed"); - let edited = gtk::Image::builder() - .icon_name(icons::DOCUMENT_EDIT) - .pixel_size(12) - .visible(false) - .build(); - edited.add_css_class("accent"); - edited.set_accessible_role(gtk::AccessibleRole::Presentation); + let edited = marker(icons::DOCUMENT_EDIT); + // The colour the grid and the value below give a pending value. + edited.add_css_class("warning"); let kind = gtk::Label::builder() - .xalign(0.5) + .xalign(1.0) .ellipsize(pango::EllipsizeMode::End) .build(); - kind.add_css_class("field-type"); + kind.add_css_class("caption"); + kind.add_css_class("dimmed"); let top = gtk::Box::new(gtk::Orientation::Horizontal, 6); top.append(&key); top.append(&name); @@ -104,9 +117,9 @@ fn field_row() -> gtk::Box { .build(); let row = gtk::Box::builder() .orientation(gtk::Orientation::Vertical) - .spacing(3) - .margin_top(7) - .margin_bottom(7) + .spacing(2) + .margin_top(6) + .margin_bottom(6) .margin_start(12) .margin_end(12) .build(); @@ -115,7 +128,6 @@ fn field_row() -> gtk::Box { row } -/// The widgets of a field row, in the order `field_row` makes them. struct FieldParts { key: gtk::Image, name: gtk::Label, @@ -245,11 +257,12 @@ impl RowDetailPane { else { return; }; - key.set_visible(column.catalog.as_ref().is_some_and(|catalog| catalog.primary_key)); + key.set_visible(is_primary_key(&column)); name.set_label(&column.name); kind.set_label(&column.value_type().name); - item.set_accessible_label(&column.name); + item.set_accessible_label(&field_label(&column)); let Some(row) = self.current_row() else { + edited.set_visible(false); shown.set_text(None); return; }; 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 116a5b5936..8d0a213f14 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 @@ -14,7 +14,7 @@ use tablepro_core::{ColumnInfo, Value}; use super::RowDetailPane; use super::calendar::{day_of, day_start_offset, with_day}; use super::clock::{ClockField, time_of, with_time}; -use super::fields::field_order; +use super::fields::{field_label, field_order}; use super::value_editor::value_content; use crate::services::change_tracker::RowKey; use crate::services::grid::{CellLock, GridColumn, GridRowId, grid_columns}; @@ -1425,21 +1425,38 @@ fn a_page_that_takes_the_row_closes_its_clock_and_writes_nothing() { assert!(!pane.imp().clock_popover.is_visible()); } -/// A primary key column's field carries a key, and a field holding an -/// edit a pencil, so each reads without opening the field. +fn drawn_field(pane: &RowDetailPane, column: usize) -> gtk::ListItem { + pane.imp() + .bound + .borrow() + .iter() + .find(|item| { + item.item() + .and_downcast::() + .is_some_and(|boxed| *boxed.borrow::() == column) + }) + .cloned() + .expect("the field is drawn") +} + +fn marks(pane: &RowDetailPane, column: usize, icon: &str) -> bool { + let row = drawn_field(pane, column).child().expect("the field's row"); + descendants(&row) + .into_iter() + .filter_map(|widget| widget.downcast::().ok()) + .any(|image| image.is_visible() && image.icon_name().as_deref() == Some(icon)) +} + #[gtk4::test] -fn the_fields_mark_the_primary_key_and_a_pending_edit() { +fn a_field_marks_its_primary_key_and_a_pending_edit() { let (grid, pane) = opened(two_text_columns(), two_text_values()); grid.focus(0, 1); - let marked = |icon: &str| { - descendants(&pane.imp().field_list.get()) - .into_iter() - .filter_map(|widget| widget.downcast::().ok()) - .filter(|image| image.is_visible() && image.icon_name().as_deref() == Some(icon)) - .count() - }; - assert_eq!(marked(crate::ui::icons::DIALOG_PASSWORD), 1, "the id column is the key"); - assert_eq!(marked(crate::ui::icons::DOCUMENT_EDIT), 0); + drain_main_context(); + let key_mark = crate::ui::icons::PRIMARY_KEY; + let edit_mark = crate::ui::icons::DOCUMENT_EDIT; + assert!(marks(&pane, 0, key_mark)); + assert!(!marks(&pane, 1, key_mark)); + assert!(!marks(&pane, 1, edit_mark)); let delta = grid.tracker.apply(TrackerEdit::Cell { row_key: key(1), @@ -1449,6 +1466,25 @@ fn the_fields_mark_the_primary_key_and_a_pending_edit() { }); grid.grid.apply_delta(&delta); drain_main_context(); + assert!(marks(&pane, 1, edit_mark)); + assert!(!marks(&pane, 0, edit_mark)); + + grid.grid.undo(); + drain_main_context(); + assert!(!marks(&pane, 1, edit_mark), "the pencil outlived the undo"); +} + +#[gtk4::test] +fn a_field_names_its_type_and_its_key_to_a_screen_reader() { + let (grid, pane) = opened(two_text_columns(), two_text_values()); + grid.focus(0, 1); + drain_main_context(); - assert_eq!(marked(crate::ui::icons::DOCUMENT_EDIT), 1); + assert_eq!(drawn_field(&pane, 0).accessible_label().as_deref(), Some("id, integer, primary key")); + assert_eq!(drawn_field(&pane, 1).accessible_label().as_deref(), Some("name, text")); + let result_column = GridColumn { + catalog: None, + ..column_of(named("id", "integer", true)) + }; + assert_eq!(field_label(&result_column), "id, integer"); } diff --git a/linux/crates/app/src/ui/icons.rs b/linux/crates/app/src/ui/icons.rs index 81aba06ea3..d27cdb630c 100644 --- a/linux/crates/app/src/ui/icons.rs +++ b/linux/crates/app/src/ui/icons.rs @@ -9,8 +9,6 @@ pub const APPLICATIONS_SCIENCE: &str = "applications-science-symbolic"; pub const ASSISTANT: &str = "assistant-symbolic"; pub const CHANGES_PREVENT: &str = "changes-prevent-symbolic"; pub const COMPUTER: &str = "computer-symbolic"; -/// A key, for a primary key column. -pub const DIALOG_PASSWORD: &str = "dialog-password-symbolic"; pub const DIALOG_ERROR: &str = "dialog-error-symbolic"; pub const DIALOG_WARNING: &str = "dialog-warning-symbolic"; pub const DOCUMENT_EDIT: &str = "document-edit-symbolic"; @@ -42,6 +40,8 @@ pub const PACKAGE: &str = "package-x-generic-symbolic"; pub const PAN_DOWN: &str = "pan-down-symbolic"; pub const PREFERENCES_SYSTEM: &str = "preferences-system-symbolic"; pub const PREFERENCES_SYSTEM_TIME: &str = "preferences-system-time-symbolic"; +// Adwaita's only key glyph. +pub const PRIMARY_KEY: &str = "dialog-password-symbolic"; pub const PROCESS_STOP: &str = "process-stop-symbolic"; pub const SECURITY_HIGH: &str = "security-high-symbolic"; pub const STARRED: &str = "starred-symbolic"; @@ -122,6 +122,7 @@ pub const ALL: &[&str] = &[ PAN_DOWN, PREFERENCES_SYSTEM, PREFERENCES_SYSTEM_TIME, + PRIMARY_KEY, PROCESS_STOP, SECURITY_HIGH, SIDEBAR_SHOW, diff --git a/linux/data/resources/style.css b/linux/data/resources/style.css index 37eab09f2f..4c92a7f3e9 100644 --- a/linux/data/resources/style.css +++ b/linux/data/resources/style.css @@ -219,12 +219,3 @@ tp-diagram-canvas > .tp-diagram-border { tp-diagram-canvas > .tp-diagram-accent { color: var(--accent-color); } - -/* A field's type in the row details, as a badge beside its name. */ -.field-type { - font-size: smaller; - padding: 1px 6px; - border-radius: 6px; - background-color: color-mix(in srgb, currentColor 10%, transparent); - opacity: 0.8; -} From d83d8ba0c076ac994ba82c7439cdc93eebc25ba8 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Sun, 8 Nov 2026 20:14:05 +0700 Subject: [PATCH 4/8] fix(linux-grid): add a symbolic type marker to row details --- .../crates/app/src/ui/data_grid/row_detail/fields.rs | 12 +++++++++--- .../crates/app/src/ui/data_grid/row_detail/tests.rs | 12 +++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) 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 fc38047a6c..b2b4b16a2e 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 @@ -97,7 +97,7 @@ fn field_row() -> gtk::Box { .build(); name.add_css_class("dimmed"); let edited = marker(icons::DOCUMENT_EDIT); - // The colour the grid and the value below give a pending value. + // Match the pending value beneath the marker. edited.add_css_class("warning"); let kind = gtk::Label::builder() .xalign(1.0) @@ -105,11 +105,17 @@ fn field_row() -> gtk::Box { .build(); kind.add_css_class("caption"); kind.add_css_class("dimmed"); + let type_icon = marker(icons::TEXT_X_GENERIC); + type_icon.set_visible(true); + type_icon.add_css_class("dimmed"); + let type_box = gtk::Box::new(gtk::Orientation::Horizontal, 3); + type_box.append(&type_icon); + type_box.append(&kind); let top = gtk::Box::new(gtk::Orientation::Horizontal, 6); top.append(&key); top.append(&name); top.append(&edited); - top.append(&kind); + top.append(&type_box); let value = gtk::Inscription::builder() .hexpand(true) .min_chars(1) @@ -141,7 +147,7 @@ fn field_parts(row: >k::Widget) -> Option { let key = top.first_child()?; let name = key.next_sibling()?; let edited = name.next_sibling()?; - let kind = edited.next_sibling()?; + let kind = edited.next_sibling()?.last_child()?; Some(FieldParts { key: key.downcast().ok()?, name: name.downcast().ok()?, 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 8d0a213f14..fec52081c0 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 @@ -1457,6 +1457,8 @@ fn a_field_marks_its_primary_key_and_a_pending_edit() { assert!(marks(&pane, 0, key_mark)); assert!(!marks(&pane, 1, key_mark)); assert!(!marks(&pane, 1, edit_mark)); + assert!(marks(&pane, 0, crate::ui::icons::TEXT_X_GENERIC)); + assert!(marks(&pane, 1, crate::ui::icons::TEXT_X_GENERIC)); let delta = grid.tracker.apply(TrackerEdit::Cell { row_key: key(1), @@ -1468,10 +1470,15 @@ fn a_field_marks_its_primary_key_and_a_pending_edit() { drain_main_context(); assert!(marks(&pane, 1, edit_mark)); assert!(!marks(&pane, 0, edit_mark)); + assert_eq!( + drawn_field(&pane, 1).accessible_description().as_deref(), + Some("changed, Modified") + ); grid.grid.undo(); drain_main_context(); assert!(!marks(&pane, 1, edit_mark), "the pencil outlived the undo"); + assert_eq!(drawn_field(&pane, 1).accessible_description().as_deref(), Some("A")); } #[gtk4::test] @@ -1480,7 +1487,10 @@ fn a_field_names_its_type_and_its_key_to_a_screen_reader() { grid.focus(0, 1); drain_main_context(); - assert_eq!(drawn_field(&pane, 0).accessible_label().as_deref(), Some("id, integer, primary key")); + assert_eq!( + drawn_field(&pane, 0).accessible_label().as_deref(), + Some("id, integer, primary key") + ); assert_eq!(drawn_field(&pane, 1).accessible_label().as_deref(), Some("name, text")); let result_column = GridColumn { catalog: None, From 6508ba16d2bde21deefbafc15a3b1599d73fcbe2 Mon Sep 17 00:00:00 2001 From: sedax90 <5001801+sedax90@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:38:28 +0100 Subject: [PATCH 5/8] feat(linux-grid): mark a foreign key field in the row details --- .../app/src/ui/data_grid/references/mod.rs | 15 +++++ .../app/src/ui/data_grid/row_detail/fields.rs | 13 ++++- .../app/src/ui/data_grid/row_detail/tests.rs | 55 +++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/linux/crates/app/src/ui/data_grid/references/mod.rs b/linux/crates/app/src/ui/data_grid/references/mod.rs index a5203f1b90..6d54d5017c 100644 --- a/linux/crates/app/src/ui/data_grid/references/mod.rs +++ b/linux/crates/app/src/ui/data_grid/references/mod.rs @@ -201,6 +201,21 @@ fn add_choice(grid: &DataGrid, name: &str, act: impl Fn(&DataGrid, usize) + 'sta grid.actions().add_action(&action); } +impl DataGrid { + /// Whether the column named `name` is part of a foreign key of the + /// table, under the keys read so far. + pub(crate) fn is_foreign_key_column(&self, name: &str) -> bool { + self.config() + .and_then(|config| config.references.as_ref()) + .map(KeysHandle::get) + .is_some_and(|keys| { + keys.outbound + .iter() + .any(|outbound| outbound.key.columns.iter().any(|column| column == name)) + }) + } +} + /// What `row` offers from `column`, under the keys read so far. A grid /// that was given no keys offers nothing. fn offers(grid: &DataGrid, row: &GridRow, column: usize) -> Offers { 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 0e076261f2..1881095f79 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 @@ -245,7 +245,18 @@ impl RowDetailPane { else { return; }; - key.set_visible(column.catalog.as_ref().is_some_and(|catalog| catalog.primary_key)); + // A primary key shows a key, and a column that only points at another + // table an arrow; a key that is also a foreign key shows the key. + let primary = column.catalog.as_ref().is_some_and(|catalog| catalog.primary_key); + let foreign = grid.is_foreign_key_column(&column.name); + key.set_visible(primary || foreign); + key.set_icon_name(Some(if primary { icons::DIALOG_PASSWORD } else { icons::GO_UP })); + set_class(&key, "warning", primary); + key.set_tooltip_text(Some(&if primary { + crate::i18n::gettext("Primary key") + } else { + crate::i18n::gettext("Foreign key") + })); name.set_label(&column.name); kind.set_label(&column.value_type().name); item.set_accessible_label(&column.name); 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 116a5b5936..5bd4d7b014 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 @@ -1452,3 +1452,58 @@ fn the_fields_mark_the_primary_key_and_a_pending_edit() { assert_eq!(marked(crate::ui::icons::DOCUMENT_EDIT), 1); } + +/// A column that points at another table shows an arrow, and a primary key +/// its key, so a field says what it is without opening it. +#[gtk4::test] +fn a_foreign_key_field_carries_an_arrow_and_a_primary_key_a_key() { + use tablepro_core::ForeignKeyInfo; + use tablepro_core::ddl::OutboundForeignKey; + use tablepro_core::meta::TableRef; + + use crate::ui::data_grid::{KeysHandle, TableKeys}; + + let table = TableRef::unqualified("orders"); + let handle = KeysHandle::new(table.clone()); + handle.set(TableKeys { + table, + outbound: vec![OutboundForeignKey { + key: ForeignKeyInfo { + name: "customer_fkey".to_owned(), + columns: vec!["customer_id".to_owned()], + ref_schema: None, + ref_table: "customers".to_owned(), + ref_columns: vec!["id".to_owned()], + on_delete: None, + on_update: None, + }, + parent_compares_alike: true, + }], + inbound: Vec::new(), + }); + let grid = Grid::build( + GridSpec { + references: Some(handle), + ..GridSpec::table(vec![ + named("id", "integer", true), + named("customer_id", "integer", false), + named("note", "text", false), + ]) + }, + persisted(&[vec![Value::Int(1), Value::Int(42), Value::Text("x".into())]]), + ); + grid.activate("show-details"); + let pane = pane_of(&grid); + grid.focus(0, 1); + drain_main_context(); + + let marks = |icon: &str| { + descendants(&pane.imp().field_list.get()) + .into_iter() + .filter_map(|widget| widget.downcast::().ok()) + .filter(|image| image.is_visible() && image.icon_name().as_deref() == Some(icon)) + .count() + }; + assert_eq!(marks(crate::ui::icons::DIALOG_PASSWORD), 1, "the primary key"); + assert_eq!(marks(crate::ui::icons::GO_UP), 1, "the foreign key"); +} From dba81f22f91c3bb457394626f1170fa51206dd74 Mon Sep 17 00:00:00 2001 From: sedax90 <5001801+sedax90@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:39:33 +0100 Subject: [PATCH 6/8] docs(linux-grid): add the changelog entry --- linux/changelog.d/4131.added.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 linux/changelog.d/4131.added.md diff --git a/linux/changelog.d/4131.added.md b/linux/changelog.d/4131.added.md new file mode 100644 index 0000000000..97b709ac34 --- /dev/null +++ b/linux/changelog.d/4131.added.md @@ -0,0 +1 @@ +A foreign key field in the row details carries an arrow. From 9e863bd690af4ac8705e63f386aba85314529295 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Sun, 8 Nov 2026 21:34:06 +0700 Subject: [PATCH 7/8] fix(linux-grid): compare accessible field text as strings --- .../crates/app/src/ui/data_grid/row_detail/tests.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 fec52081c0..f6dc3be7e4 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 @@ -1471,14 +1471,14 @@ fn a_field_marks_its_primary_key_and_a_pending_edit() { assert!(marks(&pane, 1, edit_mark)); assert!(!marks(&pane, 0, edit_mark)); assert_eq!( - drawn_field(&pane, 1).accessible_description().as_deref(), - Some("changed, Modified") + drawn_field(&pane, 1).accessible_description().as_str(), + "changed, Modified" ); grid.grid.undo(); drain_main_context(); assert!(!marks(&pane, 1, edit_mark), "the pencil outlived the undo"); - assert_eq!(drawn_field(&pane, 1).accessible_description().as_deref(), Some("A")); + assert_eq!(drawn_field(&pane, 1).accessible_description().as_str(), "A"); } #[gtk4::test] @@ -1488,10 +1488,10 @@ fn a_field_names_its_type_and_its_key_to_a_screen_reader() { drain_main_context(); assert_eq!( - drawn_field(&pane, 0).accessible_label().as_deref(), - Some("id, integer, primary key") + drawn_field(&pane, 0).accessible_label().as_str(), + "id, integer, primary key" ); - assert_eq!(drawn_field(&pane, 1).accessible_label().as_deref(), Some("name, text")); + assert_eq!(drawn_field(&pane, 1).accessible_label().as_str(), "name, text"); let result_column = GridColumn { catalog: None, ..column_of(named("id", "integer", true)) From bab21be0f41c13cd028c46a00ab3f6810f2dd643 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Mon, 9 Nov 2026 01:17:35 +0700 Subject: [PATCH 8/8] fix(linux-grid): refresh and announce foreign key markers --- linux/changelog.d/4131.added.md | 2 +- .../app/src/ui/data_grid/references/mod.rs | 5 +- .../app/src/ui/data_grid/row_detail/fields.rs | 23 ++-- .../app/src/ui/data_grid/row_detail/tests.rs | 127 ++++++++++++++---- 4 files changed, 118 insertions(+), 39 deletions(-) diff --git a/linux/changelog.d/4131.added.md b/linux/changelog.d/4131.added.md index 97b709ac34..1ddb1e1b3c 100644 --- a/linux/changelog.d/4131.added.md +++ b/linux/changelog.d/4131.added.md @@ -1 +1 @@ -A foreign key field in the row details carries an arrow. +Row Details marks foreign key fields and announces their key roles to screen readers. diff --git a/linux/crates/app/src/ui/data_grid/references/mod.rs b/linux/crates/app/src/ui/data_grid/references/mod.rs index 6d54d5017c..8b8cb14a99 100644 --- a/linux/crates/app/src/ui/data_grid/references/mod.rs +++ b/linux/crates/app/src/ui/data_grid/references/mod.rs @@ -90,10 +90,9 @@ pub fn refresh_actions(grid: &DataGrid, target: Option<&Resolved>) { } impl DataGrid { - /// The table's foreign keys were read: Ctrl+J follows what they - /// offer now. pub(crate) fn keys_changed(&self) { self.refresh_actions(); + self.imp().detail_pane.redraw_fields(); } /// Fill the cell menu's key items for `cell` as the menu opens; a row @@ -202,8 +201,6 @@ fn add_choice(grid: &DataGrid, name: &str, act: impl Fn(&DataGrid, usize) + 'sta } impl DataGrid { - /// Whether the column named `name` is part of a foreign key of the - /// table, under the keys read so far. pub(crate) fn is_foreign_key_column(&self, name: &str) -> bool { self.config() .and_then(|config| config.references.as_ref()) 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 96e9168b94..84847a32d0 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 @@ -68,8 +68,8 @@ fn is_primary_key(column: &GridColumn) -> bool { column.catalog.as_ref().is_some_and(|catalog| catalog.primary_key) } -// The key has no role of its own, so the label is where a screen reader hears it. -pub(super) fn field_label(column: &GridColumn) -> String { +// Markers have no role of their own, so the label names both key roles. +pub(super) fn field_label(column: &GridColumn, foreign: bool) -> String { let mut parts = vec![column.name.clone()]; let type_name = &column.value_type().name; if !type_name.is_empty() { @@ -78,6 +78,9 @@ pub(super) fn field_label(column: &GridColumn) -> String { if is_primary_key(column) { parts.push(gettext("primary key")); } + if foreign { + parts.push(gettext("foreign key")); + } parts.join(", ") } @@ -236,7 +239,7 @@ impl RowDetailPane { factory } - pub(super) fn redraw_fields(&self) { + pub(in crate::ui::data_grid) fn redraw_fields(&self) { let bound: Vec = self.imp().bound.borrow().clone(); for item in &bound { self.draw_field(item); @@ -267,14 +270,16 @@ impl RowDetailPane { let foreign = grid.is_foreign_key_column(&column.name); key.set_visible(primary || foreign); key.set_icon_name(Some(if primary { icons::PRIMARY_KEY } else { icons::GO_UP })); - key.set_tooltip_text(Some(&if primary { - gettext("Primary key") - } else { - gettext("Foreign key") - })); + let key_tip = match (primary, foreign) { + (true, true) => Some(gettext("Primary and foreign key")), + (true, false) => Some(gettext("Primary key")), + (false, true) => Some(gettext("Foreign key")), + (false, false) => None, + }; + key.set_tooltip_text(key_tip.as_deref()); name.set_label(&column.name); kind.set_label(&column.value_type().name); - item.set_accessible_label(&field_label(&column)); + item.set_accessible_label(&field_label(&column, foreign)); let Some(row) = self.current_row() else { edited.set_visible(false); shown.set_text(None); 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 87a530c0e1..0249fed41b 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 @@ -1496,60 +1496,137 @@ fn a_field_names_its_type_and_its_key_to_a_screen_reader() { catalog: None, ..column_of(named("id", "integer", true)) }; - assert_eq!(field_label(&result_column), "id, integer"); + assert_eq!(field_label(&result_column, false), "id, integer"); } -/// A column that points at another table shows an arrow, and a primary key -/// its key, so a field says what it is without opening it. -#[gtk4::test] -fn a_foreign_key_field_carries_an_arrow_and_a_primary_key_a_key() { +fn composite_foreign_keys() -> crate::ui::data_grid::TableKeys { use tablepro_core::ForeignKeyInfo; use tablepro_core::ddl::OutboundForeignKey; use tablepro_core::meta::TableRef; - use crate::ui::data_grid::{KeysHandle, TableKeys}; - - let table = TableRef::unqualified("orders"); - let handle = KeysHandle::new(table.clone()); - handle.set(TableKeys { - table, + crate::ui::data_grid::TableKeys { + table: TableRef::unqualified("orders"), outbound: vec![OutboundForeignKey { key: ForeignKeyInfo { name: "customer_fkey".to_owned(), - columns: vec!["customer_id".to_owned()], + columns: vec!["id".to_owned(), "tenant_id".to_owned(), "customer_id".to_owned()], ref_schema: None, ref_table: "customers".to_owned(), - ref_columns: vec!["id".to_owned()], + ref_columns: vec!["id".to_owned(), "tenant_id".to_owned(), "customer_id".to_owned()], on_delete: None, on_update: None, }, parent_compares_alike: true, }], inbound: Vec::new(), - }); + } +} + +fn foreign_key_grid(keys: crate::ui::data_grid::TableKeys) -> (Grid, RowDetailPane, crate::ui::data_grid::KeysHandle) { + let handle = crate::ui::data_grid::KeysHandle::new(keys.table.clone()); + handle.set(keys); let grid = Grid::build( GridSpec { - references: Some(handle), + references: Some(handle.clone()), ..GridSpec::table(vec![ named("id", "integer", true), + named("tenant_id", "integer", false), named("customer_id", "integer", false), named("note", "text", false), ]) }, - persisted(&[vec![Value::Int(1), Value::Int(42), Value::Text("x".into())]]), + persisted(&[vec![ + Value::Int(1), + Value::Int(7), + Value::Int(42), + Value::Text("x".into()), + ]]), ); grid.activate("show-details"); let pane = pane_of(&grid); grid.focus(0, 1); drain_main_context(); + (grid, pane, handle) +} - let marks = |icon: &str| { - descendants(&pane.imp().field_list.get()) - .into_iter() - .filter_map(|widget| widget.downcast::().ok()) - .filter(|image| image.is_visible() && image.icon_name().as_deref() == Some(icon)) - .count() - }; - assert_eq!(marks(crate::ui::icons::PRIMARY_KEY), 1, "the primary key"); - assert_eq!(marks(crate::ui::icons::GO_UP), 1, "the foreign key"); +#[gtk4::test] +fn foreign_key_fields_announce_each_role_and_keep_the_primary_key_icon() { + let (_grid, pane, _handle) = foreign_key_grid(composite_foreign_keys()); + let primary = crate::ui::icons::PRIMARY_KEY; + let foreign = crate::ui::icons::GO_UP; + assert!(marks(&pane, 0, primary)); + assert!(!marks(&pane, 0, foreign)); + assert_eq!( + drawn_field(&pane, 0).accessible_label().as_str(), + "id, integer, primary key, foreign key" + ); + for (column, label) in [ + (1, "tenant_id, integer, foreign key"), + (2, "customer_id, integer, foreign key"), + ] { + assert!(marks(&pane, column, foreign)); + assert!(!marks(&pane, column, primary)); + assert_eq!(drawn_field(&pane, column).accessible_label().as_str(), label); + } + assert!(!marks(&pane, 3, primary)); + assert!(!marks(&pane, 3, foreign)); + assert_eq!(drawn_field(&pane, 3).accessible_label().as_str(), "note, text"); + for column in 0..4 { + assert!(marks(&pane, column, crate::ui::icons::TEXT_X_GENERIC)); + } +} + +#[gtk4::test] +fn foreign_key_markers_follow_metadata_changes_without_disturbing_an_edit() { + let keys = composite_foreign_keys(); + let empty = crate::ui::data_grid::TableKeys::none(keys.table.clone()); + let (grid, pane, handle) = foreign_key_grid(empty.clone()); + let primary = crate::ui::icons::PRIMARY_KEY; + let foreign = crate::ui::icons::GO_UP; + assert!(!marks(&pane, 1, foreign)); + assert!(!marks(&pane, 2, foreign)); + edit_field(&grid, &pane, 0, 3); + type_value(&pane, "still typing"); + let focused = gtk::prelude::GtkWindowExt::focus(&grid.window); + let pending_before = grid.tracker.pending_count(); + + handle.set(keys); + grid.grid.keys_changed(); + drain_main_context(); + + assert!(marks(&pane, 1, foreign)); + assert!(marks(&pane, 2, foreign)); + assert!(marks(&pane, 0, primary)); + assert_eq!( + drawn_field(&pane, 0).accessible_label().as_str(), + "id, integer, primary key, foreign key" + ); + assert_eq!( + drawn_field(&pane, 2).accessible_label().as_str(), + "customer_id, integer, foreign key" + ); + assert_eq!(selected_field(&pane), Some(3)); + assert_eq!(pane.typed_text(), "still typing"); + assert_eq!(gtk::prelude::GtkWindowExt::focus(&grid.window), focused); + assert_eq!(grid.tracker.pending_count(), pending_before); + + handle.set(empty); + grid.grid.keys_changed(); + drain_main_context(); + + assert!(!marks(&pane, 1, foreign)); + assert!(!marks(&pane, 2, foreign)); + assert!(marks(&pane, 0, primary)); + assert_eq!( + drawn_field(&pane, 0).accessible_label().as_str(), + "id, integer, primary key" + ); + assert_eq!( + drawn_field(&pane, 2).accessible_label().as_str(), + "customer_id, integer" + ); + assert_eq!(selected_field(&pane), Some(3)); + assert_eq!(pane.typed_text(), "still typing"); + assert_eq!(gtk::prelude::GtkWindowExt::focus(&grid.window), focused); + assert_eq!(grid.tracker.pending_count(), pending_before); }