From 03e7ef4132ddda4c56eafb658db448c4a726d7ad Mon Sep 17 00:00:00 2001 From: sedax90 <5001801+sedax90@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:53:08 +0100 Subject: [PATCH 01/10] feat(linux-grid): add row numbers, row height and NULL text preferences --- linux/changelog.d/4134.added.md | 1 + .../app/src/services/grid/display_text.rs | 18 ++++- .../app/src/ui/data_grid/display_settings.rs | 65 +++++++++++++++++++ linux/crates/app/src/ui/data_grid/imp.rs | 1 + linux/crates/app/src/ui/data_grid/mod.rs | 3 + .../app/src/ui/data_grid/tests/cells.rs | 21 ++++++ .../preferences_dialog/data_browser_group.rs | 33 +++++++++- linux/crates/platform/src/settings/keys.rs | 3 + linux/crates/platform/src/settings/mod.rs | 26 ++++++++ .../data/app.tablepro.TablePro.gschema.xml.in | 24 +++++++ linux/data/resources/style.css | 14 ++++ .../ui/preferences-data-browser-group.ui | 25 +++++++ linux/po/POTFILES.in | 1 + 13 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 linux/changelog.d/4134.added.md create mode 100644 linux/crates/app/src/ui/data_grid/display_settings.rs diff --git a/linux/changelog.d/4134.added.md b/linux/changelog.d/4134.added.md new file mode 100644 index 0000000000..3aef7231ad --- /dev/null +++ b/linux/changelog.d/4134.added.md @@ -0,0 +1 @@ +Data grid preferences set whether rows are numbered, how tall a row is and what a NULL shows. diff --git a/linux/crates/app/src/services/grid/display_text.rs b/linux/crates/app/src/services/grid/display_text.rs index a6a3f1d70c..fe6f0f895b 100644 --- a/linux/crates/app/src/services/grid/display_text.rs +++ b/linux/crates/app/src/services/grid/display_text.rs @@ -39,6 +39,19 @@ pub fn editable_null_sentinel() -> String { /// A technical term, so it is not translated. const READONLY_NULL: &str = "NULL"; +thread_local! { + static NULL_DISPLAY: std::cell::RefCell = std::cell::RefCell::new(READONLY_NULL.to_owned()); +} + +/// The text a cell shows for NULL, which Preferences set. +pub fn null_display() -> String { + NULL_DISPLAY.with(|text| text.borrow().clone()) +} + +pub fn set_null_display(text: &str) { + NULL_DISPLAY.with(|slot| *slot.borrow_mut() = text.to_owned()); +} + /// For a column the server fills in on INSERT, so a new draft row does /// not read as if its id were stored as NULL. pub fn auto_filled_sentinel() -> String { @@ -51,7 +64,10 @@ pub fn auto_filled_sentinel() -> String { pub fn display_text<'a>(value: &'a Value, column: &ColumnType, scratch: &'a mut String) -> DisplayText<'a> { scratch.clear(); match value { - Value::Null => DisplayText::placeholder(READONLY_NULL), + Value::Null => { + scratch.push_str(&null_display()); + DisplayText::placeholder(scratch.as_str()) + } Value::Text(text) => shown(text, scratch), // The server's own text, never parsed and written out again. Value::Json(json) => shown(json.as_str(), scratch), diff --git a/linux/crates/app/src/ui/data_grid/display_settings.rs b/linux/crates/app/src/ui/data_grid/display_settings.rs new file mode 100644 index 0000000000..d1dc361540 --- /dev/null +++ b/linux/crates/app/src/ui/data_grid/display_settings.rs @@ -0,0 +1,65 @@ +//! The preferences that shape how a grid reads, as the macOS data grid +//! settings do: whether rows are numbered, how much room a row takes, and +//! what a NULL shows. + +use gtk4::prelude::*; +use gtk4::subclass::prelude::*; +use tablepro_linux_platform::settings::keys; + +use super::DataGrid; +use super::grid_cell::set_class; +use crate::services::grid::display_text::set_null_display; +use crate::ui::handler_guard::HandlerGuard; + +/// The classes a row height takes, one for each word the setting holds. +const HEIGHT_CLASSES: [(&str, &str); 4] = [ + ("compact", "row-compact"), + ("normal", "row-normal"), + ("comfortable", "row-comfortable"), + ("spacious", "row-spacious"), +]; + +impl DataGrid { + /// Follow the row numbers, the row height and the NULL text the + /// preferences name, now and when one changes. + pub(super) fn watch_display_settings(&self) { + let Some(settings) = self.config().map(|config| config.settings.clone()) else { + return; + }; + let weak = self.downgrade(); + // Connected before the reads: GSettings emits `changed` only for a + // key read while a handler was connected. + let handler = settings.gio().connect_changed(None, move |_, key| { + if matches!(key, keys::SHOW_ROW_NUMBERS | keys::GRID_ROW_HEIGHT | keys::NULL_DISPLAY) + && let Some(grid) = weak.upgrade() + { + grid.apply_display_settings(); + } + }); + self.imp() + .display_watch + .replace(Some(HandlerGuard::new(settings.gio(), handler))); + self.apply_display_settings(); + } + + /// Read the three settings again and draw the grid by them. + pub(super) fn apply_display_settings(&self) { + let Some(settings) = self.config().map(|config| config.settings.clone()) else { + return; + }; + let view = self.column_view(); + let height = settings.grid_row_height(); + for (word, class) in HEIGHT_CLASSES { + set_class(&view, class, word == height); + } + if let Some(numbers) = self.row_numbers_column() { + numbers.set_visible(settings.show_row_numbers()); + } + // The text is the app's to show, so every grid reads the same one. + let null = settings.null_display(); + if crate::services::grid::display_text::null_display() != null { + set_null_display(&null); + self.redraw(); + } + } +} diff --git a/linux/crates/app/src/ui/data_grid/imp.rs b/linux/crates/app/src/ui/data_grid/imp.rs index 1b043907fd..521dbe8d4a 100644 --- a/linux/crates/app/src/ui/data_grid/imp.rs +++ b/linux/crates/app/src/ui/data_grid/imp.rs @@ -87,6 +87,7 @@ pub struct DataGrid { /// The window's focus handler, while the grid is in a window. pub focus_watch: RefCell, glib::SignalHandlerId)>>, pub(super) font_watch: RefCell>, + pub(super) display_watch: RefCell>, pub(super) stripes_watch: RefCell>, } diff --git a/linux/crates/app/src/ui/data_grid/mod.rs b/linux/crates/app/src/ui/data_grid/mod.rs index f1b2db8c4b..40098df398 100644 --- a/linux/crates/app/src/ui/data_grid/mod.rs +++ b/linux/crates/app/src/ui/data_grid/mod.rs @@ -5,6 +5,7 @@ mod client_sorter; mod column_chooser; mod columns; mod copy; +mod display_settings; mod edit; mod find_bar; mod grid_actions; @@ -91,6 +92,7 @@ impl DataGrid { grid.set_columns(columns, sorting, rules); grid.watch_fonts(); grid.watch_stripes(); + grid.watch_display_settings(); grid } @@ -193,6 +195,7 @@ impl DataGrid { self.imp().summary.forget_column(); self.edit().set_rules(self, rules); self.rebuild_columns(columns, sorting); + self.apply_display_settings(); self.show_rows_or_empty(); self.refresh_actions(); } diff --git a/linux/crates/app/src/ui/data_grid/tests/cells.rs b/linux/crates/app/src/ui/data_grid/tests/cells.rs index b828616eda..6f703b35f7 100644 --- a/linux/crates/app/src/ui/data_grid/tests/cells.rs +++ b/linux/crates/app/src/ui/data_grid/tests/cells.rs @@ -204,6 +204,27 @@ fn open_grids_follow_the_stripes_preference() { assert!(striped()); } +#[gtk4::test] +fn open_grids_follow_the_display_preferences() { + let grid = two_text_rows(); + let settings = grid.grid.config().expect("a configured grid").settings.clone(); + let view = grid.grid.column_view(); + let numbers = grid.grid.row_numbers_column().expect("a row number column"); + + settings.set_show_row_numbers(false).expect("store the flag"); + settings.set_grid_row_height("compact").expect("store the height"); + drain_main_context(); + assert!(!numbers.is_visible()); + assert!(view.has_css_class("row-compact")); + + settings.set_grid_row_height("spacious").expect("store the height"); + settings.set_show_row_numbers(true).expect("store the flag"); + drain_main_context(); + assert!(numbers.is_visible()); + assert!(view.has_css_class("row-spacious") && !view.has_css_class("row-compact")); + crate::services::grid::display_text::set_null_display("NULL"); +} + #[gtk4::test] fn column_view_carries_data_table_class() { let grid = two_text_rows(); diff --git a/linux/crates/app/src/ui/preferences_dialog/data_browser_group.rs b/linux/crates/app/src/ui/preferences_dialog/data_browser_group.rs index 9fd59b7397..a29ba9c4d0 100644 --- a/linux/crates/app/src/ui/preferences_dialog/data_browser_group.rs +++ b/linux/crates/app/src/ui/preferences_dialog/data_browser_group.rs @@ -1,10 +1,14 @@ -use gio::prelude::SettingsExtManual; +use gio::prelude::{SettingsExt, SettingsExtManual}; use gtk4::glib; use gtk4::subclass::prelude::*; use libadwaita as adw; +use libadwaita::prelude::ComboRowExt; use tablepro_linux_platform::AppSettings; use tablepro_linux_platform::settings::keys; +/// The words the row height setting holds, in the combo's order. +const ROW_HEIGHTS: [&str; 4] = ["compact", "normal", "comfortable", "spacious"]; + mod imp { use libadwaita::prelude::*; use libadwaita::subclass::prelude::*; @@ -20,6 +24,12 @@ mod imp { pub alternate_rows_row: TemplateChild, #[template_child] pub confirm_row: TemplateChild, + #[template_child] + pub row_numbers_row: TemplateChild, + #[template_child] + pub row_height_row: TemplateChild, + #[template_child] + pub null_display_row: TemplateChild, } #[glib::object_subclass] @@ -80,6 +90,27 @@ impl DataBrowserGroup { gio_settings .bind(keys::CONFIRM_BULK_DELETE, &imp.confirm_row.get(), "active") .build(); + gio_settings + .bind(keys::SHOW_ROW_NUMBERS, &imp.row_numbers_row.get(), "active") + .build(); + gio_settings + .bind(keys::NULL_DISPLAY, &imp.null_display_row.get(), "text") + .build(); + // The combo holds a position and the setting a word. + let row = imp.row_height_row.get(); + let current = settings.grid_row_height(); + row.set_selected( + ROW_HEIGHTS + .iter() + .position(|height| *height == current) + .map_or(1, |at| at as u32), + ); + let stored = gio_settings.clone(); + row.connect_selected_notify(move |row| { + if let Some(height) = ROW_HEIGHTS.get(row.selected() as usize) { + let _ = stored.set_string(keys::GRID_ROW_HEIGHT, height); + } + }); } } diff --git a/linux/crates/platform/src/settings/keys.rs b/linux/crates/platform/src/settings/keys.rs index 7e3cd2fc79..0b9d74d3ef 100644 --- a/linux/crates/platform/src/settings/keys.rs +++ b/linux/crates/platform/src/settings/keys.rs @@ -1,6 +1,9 @@ pub const DEFAULT_PAGE_SIZE: &str = "default-page-size"; pub const CONFIRM_BULK_DELETE: &str = "confirm-bulk-delete"; pub const SHOW_ALTERNATE_ROWS: &str = "show-alternate-rows"; +pub const SHOW_ROW_NUMBERS: &str = "show-row-numbers"; +pub const GRID_ROW_HEIGHT: &str = "grid-row-height"; +pub const NULL_DISPLAY: &str = "null-display"; pub const SAVE_QUERY_HISTORY: &str = "save-query-history"; pub const HISTORY_RETENTION_DAYS: &str = "history-retention-days"; pub const QUERY_TIMEOUT_SECS: &str = "query-timeout-secs"; diff --git a/linux/crates/platform/src/settings/mod.rs b/linux/crates/platform/src/settings/mod.rs index 45998d1b79..85a11212b4 100644 --- a/linux/crates/platform/src/settings/mod.rs +++ b/linux/crates/platform/src/settings/mod.rs @@ -88,6 +88,32 @@ impl AppSettings { self.set_boolean(keys::SHOW_ALTERNATE_ROWS, show) } + pub fn show_row_numbers(&self) -> bool { + self.settings.boolean(keys::SHOW_ROW_NUMBERS) + } + + pub fn set_show_row_numbers(&self, show: bool) -> Result<(), SettingsError> { + self.set_boolean(keys::SHOW_ROW_NUMBERS, show) + } + + /// The grid's row height: `compact`, `normal`, `comfortable` or `spacious`. + pub fn grid_row_height(&self) -> String { + self.settings.string(keys::GRID_ROW_HEIGHT).into() + } + + pub fn set_grid_row_height(&self, height: &str) -> Result<(), SettingsError> { + self.set_string(keys::GRID_ROW_HEIGHT, height) + } + + /// What a cell shows for NULL. + pub fn null_display(&self) -> String { + self.settings.string(keys::NULL_DISPLAY).into() + } + + pub fn set_null_display(&self, text: &str) -> Result<(), SettingsError> { + self.set_string(keys::NULL_DISPLAY, text) + } + /// Whether runs go into the query history. Off records nothing and /// leaves the entries already there. pub fn save_query_history(&self) -> bool { diff --git a/linux/data/app.tablepro.TablePro.gschema.xml.in b/linux/data/app.tablepro.TablePro.gschema.xml.in index 5e82ecfe29..9df7a6c758 100644 --- a/linux/data/app.tablepro.TablePro.gschema.xml.in +++ b/linux/data/app.tablepro.TablePro.gschema.xml.in @@ -71,6 +71,30 @@ Shade every other row of a data grid so a row reads across its columns. + + true + Show row numbers + Show each row's number in the first column of a data grid. + + + + + + + + + + "normal" + Data grid row height + How much room a data grid row takes around its text. + + + + "NULL" + Text for a NULL value + What a data grid cell shows for a value that is NULL. + + true Save query history diff --git a/linux/data/resources/style.css b/linux/data/resources/style.css index 4c92a7f3e9..6fb81af21d 100644 --- a/linux/data/resources/style.css +++ b/linux/data/resources/style.css @@ -219,3 +219,17 @@ tp-diagram-canvas > .tp-diagram-border { tp-diagram-canvas > .tp-diagram-accent { color: var(--accent-color); } + +/* How much room a data grid row takes around its text, from Preferences. + Normal is the default padding above. */ +columnview.data-table.row-compact > listview > row > cell > * { + padding: 0 6px; +} + +columnview.data-table.row-comfortable > listview > row > cell > * { + padding: 4px 6px; +} + +columnview.data-table.row-spacious > listview > row > cell > * { + padding: 6px 6px; +} diff --git a/linux/data/resources/ui/preferences-data-browser-group.ui b/linux/data/resources/ui/preferences-data-browser-group.ui index 330633f43a..1f52211557 100644 --- a/linux/data/resources/ui/preferences-data-browser-group.ui +++ b/linux/data/resources/ui/preferences-data-browser-group.ui @@ -23,6 +23,31 @@ Show Alternate Row Backgrounds + + + Show Row Numbers + + + + + Row Height + + + + Compact + Normal + Comfortable + Spacious + + + + + + + + Text for NULL + + Confirm Before Deleting Rows diff --git a/linux/po/POTFILES.in b/linux/po/POTFILES.in index 23a2291ef9..7f37312b2d 100644 --- a/linux/po/POTFILES.in +++ b/linux/po/POTFILES.in @@ -250,6 +250,7 @@ crates/app/src/ui/data_grid/column_chooser.rs crates/app/src/ui/data_grid/columns.rs crates/app/src/ui/data_grid/copy/mod.rs crates/app/src/ui/data_grid/copy/tests.rs +crates/app/src/ui/data_grid/display_settings.rs crates/app/src/ui/data_grid/edit/actions.rs crates/app/src/ui/data_grid/edit/cell_editor.rs crates/app/src/ui/data_grid/edit/choice_menu.rs From ff5eae335ae9eeb0aa3ed14c2a08134db6e067f6 Mon Sep 17 00:00:00 2001 From: sedax90 <5001801+sedax90@users.noreply.github.com> Date: Sun, 8 Nov 2026 16:53:43 +0100 Subject: [PATCH 02/10] fix(linux-grid): show the chosen NULL text in editable cells too --- .../app/src/services/grid/display_text.rs | 33 +++++++++++++++++-- .../crates/app/src/ui/data_grid/grid_cell.rs | 10 +++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/linux/crates/app/src/services/grid/display_text.rs b/linux/crates/app/src/services/grid/display_text.rs index fe6f0f895b..2ee4b4c975 100644 --- a/linux/crates/app/src/services/grid/display_text.rs +++ b/linux/crates/app/src/services/grid/display_text.rs @@ -30,9 +30,22 @@ impl<'a> DisplayText<'a> { } } -/// The brackets keep it apart from a literal `NULL` text value. +/// The brackets keep it apart from a literal `NULL` text value. A text the +/// user chose for NULL is shown as it is, since they picked it. pub fn editable_null_sentinel() -> String { - crate::i18n::gettext("") + // Spelled once, since every bind of a NULL cell asks. + EDITABLE_NULL.with(|slot| { + slot.borrow_mut() + .get_or_insert_with(|| { + let text = null_display(); + if text == READONLY_NULL { + crate::i18n::gettext("") + } else { + text + } + }) + .clone() + }) } /// A read-only cell dims its NULL instead, so it needs no brackets. @@ -41,6 +54,7 @@ const READONLY_NULL: &str = "NULL"; thread_local! { static NULL_DISPLAY: std::cell::RefCell = std::cell::RefCell::new(READONLY_NULL.to_owned()); + static EDITABLE_NULL: std::cell::RefCell> = const { std::cell::RefCell::new(None) }; } /// The text a cell shows for NULL, which Preferences set. @@ -50,6 +64,7 @@ pub fn null_display() -> String { pub fn set_null_display(text: &str) { NULL_DISPLAY.with(|slot| *slot.borrow_mut() = text.to_owned()); + EDITABLE_NULL.with(|slot| *slot.borrow_mut() = None); } /// For a column the server fills in on INSERT, so a new draft row does @@ -222,7 +237,7 @@ mod tests { use tablepro_core::column::{BoolStorage, ColumnKind, ColumnType}; use tablepro_core::value::{JsonText, OffsetTimestamp, SqlTime, Temporal, UndecodableReason, UndecodedValue}; - use super::{DISPLAY_MAX_CHARS, DisplayText, display_text}; + use super::{DISPLAY_MAX_CHARS, DisplayText, display_text, editable_null_sentinel, set_null_display}; fn text_column() -> ColumnType { ColumnType::untyped_text("text") @@ -233,6 +248,18 @@ mod tests { display_text(value, &text_column(), &mut scratch).text.to_owned() } + #[test] + fn a_chosen_null_text_reaches_editable_cells_and_the_default_keeps_its_brackets() { + assert_eq!(editable_null_sentinel(), ""); + + set_null_display("(none)"); + assert_eq!(editable_null_sentinel(), "(none)"); + assert_eq!(shown(&Value::Null), "(none)"); + + set_null_display("NULL"); + assert_eq!(editable_null_sentinel(), ""); + } + #[test] fn display_text_borrows_text_without_allocating() { let value = Value::Text("hello".into()); diff --git a/linux/crates/app/src/ui/data_grid/grid_cell.rs b/linux/crates/app/src/ui/data_grid/grid_cell.rs index dd0b69b1b0..f8790e9497 100644 --- a/linux/crates/app/src/ui/data_grid/grid_cell.rs +++ b/linux/crates/app/src/ui/data_grid/grid_cell.rs @@ -36,8 +36,7 @@ pub struct TextAttributes { deleted: pango::AttrList, deleted_placeholder: pango::AttrList, placeholder: pango::AttrList, - /// The stand-in texts, translated once rather than on every bind. - editable_null: String, + /// The stand-in text, translated once rather than on every bind. auto_filled: String, } @@ -61,7 +60,6 @@ impl TextAttributes { deleted: list(TextMark::Deleted, false), deleted_placeholder: list(TextMark::Deleted, true), placeholder: list(TextMark::Plain, true), - editable_null: editable_null_sentinel(), auto_filled: auto_filled_sentinel(), } } @@ -344,7 +342,11 @@ fn shown_text<'a>( } (Some(ServerValue::Default), _) => DisplayText::placeholder("DEFAULT"), (Some(ServerValue::Expression(expression)), _) => DisplayText::placeholder(expression.sql), - (None, Value::Null) if editable => DisplayText::placeholder(&paint.attributes.editable_null), + (None, Value::Null) if editable => { + scratch.clear(); + scratch.push_str(&editable_null_sentinel()); + DisplayText::placeholder(scratch.as_str()) + } (None, value) => display_text(value, &paint.column.column_type, scratch), } } From ab70c2d05d00a3a9b789801f71ecfe4b6a84945d Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Sun, 8 Nov 2026 22:55:55 +0700 Subject: [PATCH 03/10] fix(linux-grid): share live display preferences across grids --- .../app/src/services/grid/display_text.rs | 18 +- linux/crates/app/src/ui/a11y/tests.rs | 1 + linux/crates/app/src/ui/data_grid/columns.rs | 14 +- .../app/src/ui/data_grid/display_settings.rs | 50 ++---- .../crates/app/src/ui/data_grid/grid_cell.rs | 15 +- linux/crates/app/src/ui/data_grid/imp.rs | 3 +- linux/crates/app/src/ui/data_grid/mod.rs | 1 - .../app/src/ui/data_grid/row_detail/fields.rs | 10 +- .../app/src/ui/data_grid/row_detail/tests.rs | 29 +++ .../ui/data_grid/row_detail/value_editor.rs | 7 +- linux/crates/app/src/ui/data_grid/stripes.rs | 30 +--- .../crates/app/src/ui/data_grid/test_grid.rs | 4 +- .../app/src/ui/data_grid/tests/cells.rs | 81 ++++++++- .../app/src/ui/data_grid/tests/columns.rs | 31 ++++ .../preferences_dialog/data_browser_group.rs | 81 ++++++--- .../src/ui/preferences_dialog/general_page.rs | 20 +-- .../src/ui/preferences_dialog/grid_page.rs | 79 ++++++++ .../app/src/ui/preferences_dialog/imp.rs | 4 + .../app/src/ui/preferences_dialog/mod.rs | 62 +++---- .../platform/src/settings/grid_preferences.rs | 168 ++++++++++++++++++ linux/crates/platform/src/settings/mod.rs | 21 ++- linux/crates/platform/tests/settings.rs | 128 +++++++++++++ linux/data/resources/resources.gresource.xml | 1 + .../ui/preferences-data-browser-group.ui | 2 + linux/data/resources/ui/preferences-dialog.ui | 3 + .../resources/ui/preferences-general-page.ui | 3 - .../resources/ui/preferences-grid-page.ui | 12 ++ linux/docs/state-management.md | 6 + linux/docs/storage.md | 6 +- linux/po/POTFILES.in | 2 + 30 files changed, 717 insertions(+), 175 deletions(-) create mode 100644 linux/crates/app/src/ui/preferences_dialog/grid_page.rs create mode 100644 linux/crates/platform/src/settings/grid_preferences.rs create mode 100644 linux/data/resources/ui/preferences-grid-page.ui diff --git a/linux/crates/app/src/services/grid/display_text.rs b/linux/crates/app/src/services/grid/display_text.rs index fe6f0f895b..a6a3f1d70c 100644 --- a/linux/crates/app/src/services/grid/display_text.rs +++ b/linux/crates/app/src/services/grid/display_text.rs @@ -39,19 +39,6 @@ pub fn editable_null_sentinel() -> String { /// A technical term, so it is not translated. const READONLY_NULL: &str = "NULL"; -thread_local! { - static NULL_DISPLAY: std::cell::RefCell = std::cell::RefCell::new(READONLY_NULL.to_owned()); -} - -/// The text a cell shows for NULL, which Preferences set. -pub fn null_display() -> String { - NULL_DISPLAY.with(|text| text.borrow().clone()) -} - -pub fn set_null_display(text: &str) { - NULL_DISPLAY.with(|slot| *slot.borrow_mut() = text.to_owned()); -} - /// For a column the server fills in on INSERT, so a new draft row does /// not read as if its id were stored as NULL. pub fn auto_filled_sentinel() -> String { @@ -64,10 +51,7 @@ pub fn auto_filled_sentinel() -> String { pub fn display_text<'a>(value: &'a Value, column: &ColumnType, scratch: &'a mut String) -> DisplayText<'a> { scratch.clear(); match value { - Value::Null => { - scratch.push_str(&null_display()); - DisplayText::placeholder(scratch.as_str()) - } + Value::Null => DisplayText::placeholder(READONLY_NULL), Value::Text(text) => shown(text, scratch), // The server's own text, never parsed and written out again. Value::Json(json) => shown(json.as_str(), scratch), diff --git a/linux/crates/app/src/ui/a11y/tests.rs b/linux/crates/app/src/ui/a11y/tests.rs index 70f3cc15f7..c7ce7a5277 100644 --- a/linux/crates/app/src/ui/a11y/tests.rs +++ b/linux/crates/app/src/ui/a11y/tests.rs @@ -40,6 +40,7 @@ fn template_classes() -> Vec { preferences_dialog::DataBrowserGroup::static_type(), preferences_dialog::EditorPage::static_type(), preferences_dialog::GeneralPage::static_type(), + preferences_dialog::GridPage::static_type(), preferences_dialog::HistoryGroup::static_type(), saved_queries_dialog::SavedQueriesDialog::static_type(), saved_queries_dialog::SavedQueryRow::static_type(), diff --git a/linux/crates/app/src/ui/data_grid/columns.rs b/linux/crates/app/src/ui/data_grid/columns.rs index 4a7ffe816d..12c443aec7 100644 --- a/linux/crates/app/src/ui/data_grid/columns.rs +++ b/linux/crates/app/src/ui/data_grid/columns.rs @@ -11,12 +11,12 @@ use tablepro_core::Value; use super::grid_cell::{GridCell, TextAttributes}; use super::server_sorter::ServerSorter; use super::{DataGrid, GridRow, GridSorting, TrackedValues, client_sorter, grid_menu, row_number_column}; -use crate::services::grid::display_text::editable_null_sentinel; use crate::services::grid::{ CellDisplay, ColumnLayout, GridColumn, LayoutSlot, Placement, default_width_chars, header_text, merge_order, number_width_chars, sampled_texts, typical_texts, typical_width_chars, }; use crate::ui::handler_guard::HandlerGuard; +use tablepro_linux_platform::settings::GridPreferences; /// Rows sampled for a column's opening width. const WIDTH_SAMPLE: usize = 200; @@ -49,6 +49,7 @@ pub struct ColumnPaint { pub column: GridColumn, pub tracked: TrackedValues, pub attributes: Rc, + pub preferences: GridPreferences, /// The column lines its values up on the last digit. An untyped column /// does once every value it holds is a number. pub numbers: Cell, @@ -159,6 +160,10 @@ impl DataGrid { column: column.clone(), tracked: tracked.clone(), attributes: attributes.clone(), + preferences: self + .config() + .map(|config| config.settings.grid_preferences().clone()) + .unwrap_or_default(), numbers: Cell::new(column.display() == CellDisplay::Number), }); built.view_columns.push(self.build_column(&paint, sorting)); @@ -303,7 +308,6 @@ impl DataGrid { let font = value_font(&context); let metrics = context.metrics(Some(&font), None); let char_px = pango::units_to_double(metrics.approximate_char_width()); - let null = editable_null_sentinel(); let mut widths = Vec::new(); for (paint, view_column) in set.paints.iter().zip(&set.view_columns) { let index = paint.column.index; @@ -348,9 +352,9 @@ impl DataGrid { None => 0, }; let header = header_width(&context, header_text(column)) + indicator; - // A NULL the user can replace draws as ``, wider than the - // fewest cells a column takes. - let placeholder = match paint.tracked.tracks_changes() && values.iter().any(|value| value.is_null()) { + let preferences = paint.preferences.snapshot(); + let null = super::grid_cell::null_text(&preferences.null_display, paint.tracked.tracks_changes()); + let placeholder = match values.iter().any(|value| value.is_null()) { true => drawn_width(&context, &font, &null), false => 0, }; diff --git a/linux/crates/app/src/ui/data_grid/display_settings.rs b/linux/crates/app/src/ui/data_grid/display_settings.rs index d1dc361540..70fbf7b1e5 100644 --- a/linux/crates/app/src/ui/data_grid/display_settings.rs +++ b/linux/crates/app/src/ui/data_grid/display_settings.rs @@ -1,65 +1,47 @@ -//! The preferences that shape how a grid reads, as the macOS data grid -//! settings do: whether rows are numbered, how much room a row takes, and -//! what a NULL shows. - use gtk4::prelude::*; use gtk4::subclass::prelude::*; -use tablepro_linux_platform::settings::keys; +use tablepro_linux_platform::settings::GridRowHeight; use super::DataGrid; use super::grid_cell::set_class; -use crate::services::grid::display_text::set_null_display; use crate::ui::handler_guard::HandlerGuard; -/// The classes a row height takes, one for each word the setting holds. -const HEIGHT_CLASSES: [(&str, &str); 4] = [ - ("compact", "row-compact"), - ("normal", "row-normal"), - ("comfortable", "row-comfortable"), - ("spacious", "row-spacious"), -]; - impl DataGrid { - /// Follow the row numbers, the row height and the NULL text the - /// preferences name, now and when one changes. pub(super) fn watch_display_settings(&self) { - let Some(settings) = self.config().map(|config| config.settings.clone()) else { + let Some(config) = self.config() else { return; }; + let preferences = config.settings.grid_preferences(); let weak = self.downgrade(); - // Connected before the reads: GSettings emits `changed` only for a - // key read while a handler was connected. - let handler = settings.gio().connect_changed(None, move |_, key| { - if matches!(key, keys::SHOW_ROW_NUMBERS | keys::GRID_ROW_HEIGHT | keys::NULL_DISPLAY) - && let Some(grid) = weak.upgrade() - { + let handler = preferences.connect_changed(move |_| { + if let Some(grid) = weak.upgrade() { grid.apply_display_settings(); } }); self.imp() .display_watch - .replace(Some(HandlerGuard::new(settings.gio(), handler))); + .replace(Some(HandlerGuard::new(preferences, handler))); self.apply_display_settings(); } - /// Read the three settings again and draw the grid by them. pub(super) fn apply_display_settings(&self) { - let Some(settings) = self.config().map(|config| config.settings.clone()) else { + let Some(config) = self.config() else { return; }; + let values = config.settings.grid_preferences().snapshot(); let view = self.column_view(); - let height = settings.grid_row_height(); - for (word, class) in HEIGHT_CLASSES { - set_class(&view, class, word == height); + for height in GridRowHeight::ALL { + set_class(&view, height.css_class(), height == values.row_height); } + set_class(&view, "tp-striped", values.show_alternate_rows); if let Some(numbers) = self.row_numbers_column() { - numbers.set_visible(settings.show_row_numbers()); + numbers.set_visible(values.show_row_numbers); } - // The text is the app's to show, so every grid reads the same one. - let null = settings.null_display(); - if crate::services::grid::display_text::null_display() != null { - set_null_display(&null); + let changed = self.imp().applied_null.borrow().as_deref() != Some(&values.null_display); + if changed { + self.imp().applied_null.replace(Some(values.null_display.clone())); self.redraw(); + self.fonts_changed(); } } } diff --git a/linux/crates/app/src/ui/data_grid/grid_cell.rs b/linux/crates/app/src/ui/data_grid/grid_cell.rs index dd0b69b1b0..cd8a745e24 100644 --- a/linux/crates/app/src/ui/data_grid/grid_cell.rs +++ b/linux/crates/app/src/ui/data_grid/grid_cell.rs @@ -37,7 +37,6 @@ pub struct TextAttributes { deleted_placeholder: pango::AttrList, placeholder: pango::AttrList, /// The stand-in texts, translated once rather than on every bind. - editable_null: String, auto_filled: String, } @@ -61,7 +60,6 @@ impl TextAttributes { deleted: list(TextMark::Deleted, false), deleted_placeholder: list(TextMark::Deleted, true), placeholder: list(TextMark::Plain, true), - editable_null: editable_null_sentinel(), auto_filled: auto_filled_sentinel(), } } @@ -344,11 +342,22 @@ fn shown_text<'a>( } (Some(ServerValue::Default), _) => DisplayText::placeholder("DEFAULT"), (Some(ServerValue::Expression(expression)), _) => DisplayText::placeholder(expression.sql), - (None, Value::Null) if editable => DisplayText::placeholder(&paint.attributes.editable_null), + (None, Value::Null) => { + *scratch = null_text(&paint.preferences.snapshot().null_display, editable); + DisplayText::placeholder(scratch) + } (None, value) => display_text(value, &paint.column.column_type, scratch), } } +pub(super) fn null_text(text: &str, editable: bool) -> String { + match (editable, text) { + (true, "NULL") => editable_null_sentinel(), + (true, _) => format!("<{text}>"), + (false, _) => text.to_owned(), + } +} + pub(super) fn set_class(widget: &impl IsA, class: &str, on: bool) { match on { true => widget.as_ref().add_css_class(class), diff --git a/linux/crates/app/src/ui/data_grid/imp.rs b/linux/crates/app/src/ui/data_grid/imp.rs index 521dbe8d4a..92e08c2e2a 100644 --- a/linux/crates/app/src/ui/data_grid/imp.rs +++ b/linux/crates/app/src/ui/data_grid/imp.rs @@ -88,7 +88,7 @@ pub struct DataGrid { pub focus_watch: RefCell, glib::SignalHandlerId)>>, pub(super) font_watch: RefCell>, pub(super) display_watch: RefCell>, - pub(super) stripes_watch: RefCell>, + pub(super) applied_null: RefCell>, } #[glib::object_subclass] @@ -127,6 +127,7 @@ impl ObjectImpl for DataGrid { self.summary.stop(); self.obj().stop_watching_focus(); drop(self.font_watch.take()); + drop(self.display_watch.take()); if let Some(menus) = self.menus.get() { menus.unparent(); } diff --git a/linux/crates/app/src/ui/data_grid/mod.rs b/linux/crates/app/src/ui/data_grid/mod.rs index 40098df398..9c4f407fba 100644 --- a/linux/crates/app/src/ui/data_grid/mod.rs +++ b/linux/crates/app/src/ui/data_grid/mod.rs @@ -91,7 +91,6 @@ impl DataGrid { imp.detail_pane.attach(&grid); grid.set_columns(columns, sorting, rules); grid.watch_fonts(); - grid.watch_stripes(); grid.watch_display_settings(); grid } 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..325669e934 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 @@ -40,13 +40,13 @@ pub struct FieldValue { pub deleted: bool, } -pub fn field_value(tracked: &TrackedValues, row: &GridRow, column: &GridColumn) -> FieldValue { +pub fn field_value(tracked: &TrackedValues, row: &GridRow, column: &GridColumn, null_display: &str) -> FieldValue { let mark = tracked.mark(row, column.index); let (text, placeholder, null) = tracked.with_value(row, column.index, |value, computed| match (computed, value) { (Some(ServerValue::Default), _) if column.auto_filled() => (auto_filled_sentinel(), true, false), (Some(ServerValue::Default), _) => ("DEFAULT".to_owned(), true, false), (Some(ServerValue::Expression(expression)), _) => (expression.sql.to_owned(), true, false), - (None, Value::Null) => ("NULL".to_owned(), true, true), + (None, Value::Null) => (null_display.to_owned(), true, true), (None, value) => { let mut scratch = String::new(); let shown = display_text(value, &column.column_type, &mut scratch); @@ -211,7 +211,11 @@ impl RowDetailPane { shown.set_text(None); return; }; - let value = field_value(&grid.tracked(), &row, &column); + let Some(config) = grid.config() else { + return; + }; + let preferences = config.settings.grid_preferences().snapshot(); + let value = field_value(&grid.tracked(), &row, &column, &preferences.null_display); 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..aa84c89847 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,32 @@ fn a_page_that_takes_the_row_closes_its_clock_and_writes_nothing() { ); assert!(!pane.imp().clock_popover.is_visible()); } + +#[gtk4::test] +fn null_preferences_update_details_without_replacing_a_draft() { + let (grid, pane) = opened(two_text_columns(), vec![vec![Value::Int(1), Value::Null]]); + grid.focus(0, 1); + let settings = grid.grid.config().expect("configured grid").settings.clone(); + settings.set_null_display("missing").expect("store placeholder"); + drain_main_context(); + + assert_eq!(pane.imp().placeholder_label.label(), "missing"); + let shown: Vec = descendants(&pane.imp().field_list.get()) + .into_iter() + .filter_map(|widget| widget.downcast::().ok()) + .filter_map(|inscription| inscription.text().map(|text| text.to_string())) + .collect(); + assert!(shown.contains(&"missing".to_owned()), "field list showed {shown:?}"); + + edit_field(&grid, &pane, 0, 1); + type_value(&pane, "unfinished"); + assert!(grid.grid.is_editing()); + settings + .set_null_display("absent") + .expect("change placeholder while editing"); + drain_main_context(); + + assert_eq!(pane.typed_text(), "unfinished"); + assert!(grid.grid.is_editing()); + assert_eq!(pending(&grid, 1, 1), None); +} 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 326e4dea53..df1174a1e2 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 @@ -350,7 +350,12 @@ impl RowDetailPane { } let tracked = grid.tracked(); let input = tracked.edit_input(&row, column.index); - let content = value_content(&column, &row.id(), tracked.lock(&column, &row), &input); + let mut content = value_content(&column, &row.id(), tracked.lock(&column, &row), &input); + if matches!(input, CellInput::Value(Value::Null)) + && let Some(config) = grid.config() + { + content.open_placeholder = Some(config.settings.grid_preferences().snapshot().null_display.clone()); + } self.show_value(&column.name, &content); self.show_picture(match input { CellInput::Value(Value::Bytes(bytes)) => Some(bytes), diff --git a/linux/crates/app/src/ui/data_grid/stripes.rs b/linux/crates/app/src/ui/data_grid/stripes.rs index b190b95f60..54db9bf583 100644 --- a/linux/crates/app/src/ui/data_grid/stripes.rs +++ b/linux/crates/app/src/ui/data_grid/stripes.rs @@ -1,14 +1,9 @@ +use gtk4 as gtk; use gtk4::prelude::*; -use gtk4::subclass::prelude::*; -use gtk4::{self as gtk, glib}; -use tablepro_linux_platform::settings::keys; -use super::DataGrid; use super::grid_cell::set_class; -use crate::ui::handler_guard::HandlerGuard; const STRIPE: &str = "tp-stripe"; -const STRIPED: &str = "tp-striped"; // Rows are recycled, so `:nth-child` cannot stripe them and GTK has no API // to class a row: each cell's child follows its row's position instead. @@ -21,26 +16,3 @@ pub(super) fn follow(cell: >k::ColumnViewCell) { } }); } - -impl DataGrid { - pub(super) fn watch_stripes(&self) { - let Some(settings) = self.config().map(|config| config.settings.clone()) else { - return; - }; - let view = self.column_view(); - // Connected before the read: GSettings emits `changed` only for a key - // read while a handler was connected. - let handler = settings.gio().connect_changed( - Some(keys::SHOW_ALTERNATE_ROWS), - glib::clone!( - #[weak] - view, - move |settings, key| set_class(&view, STRIPED, settings.boolean(key)) - ), - ); - self.imp() - .stripes_watch - .replace(Some(HandlerGuard::new(settings.gio(), handler))); - set_class(&view, STRIPED, settings.show_alternate_rows()); - } -} diff --git a/linux/crates/app/src/ui/data_grid/test_grid.rs b/linux/crates/app/src/ui/data_grid/test_grid.rs index 8393abd3de..5573b1ea11 100644 --- a/linux/crates/app/src/ui/data_grid/test_grid.rs +++ b/linux/crates/app/src/ui/data_grid/test_grid.rs @@ -105,6 +105,7 @@ pub(crate) fn text(value: &str) -> CellInput { /// How a test grid is built: an editing table grid by default. pub(crate) struct GridSpec { pub columns: Vec, + pub settings: Option>, pub editable: bool, pub sorting: GridSorting, pub layout: Option, @@ -123,6 +124,7 @@ impl GridSpec { pub(crate) fn table(columns: Vec) -> Self { Self { columns, + settings: None, editable: true, sorting: GridSorting::Server { initial: None }, layout: None, @@ -187,7 +189,7 @@ impl Grid { }), tracker: spec.editable.then(|| tracker.clone()), result_lock: None, - settings: settings.get().clone(), + settings: spec.settings.unwrap_or_else(|| settings.get().clone()), layout: spec.layout, references: spec.references, dialect: spec.dialect, diff --git a/linux/crates/app/src/ui/data_grid/tests/cells.rs b/linux/crates/app/src/ui/data_grid/tests/cells.rs index 6f703b35f7..3aaa42d8f6 100644 --- a/linux/crates/app/src/ui/data_grid/tests/cells.rs +++ b/linux/crates/app/src/ui/data_grid/tests/cells.rs @@ -29,6 +29,7 @@ fn paint() -> Rc { column: columns[0].clone(), tracked: TrackedValues::untracked(), attributes: Rc::new(TextAttributes::new()), + preferences: Default::default(), numbers: Cell::new(false), }) } @@ -222,7 +223,6 @@ fn open_grids_follow_the_display_preferences() { drain_main_context(); assert!(numbers.is_visible()); assert!(view.has_css_class("row-spacious") && !view.has_css_class("row-compact")); - crate::services::grid::display_text::set_null_display("NULL"); } #[gtk4::test] @@ -522,3 +522,82 @@ fn cells_are_freed_with_the_grid() { let alive = freed.iter().filter(|cell| cell.upgrade().is_some()).count(); assert_eq!(alive, 0, "cells outlived their grid"); } + +#[gtk4::test] +fn null_text_reaches_every_grid_and_stays_with_its_settings() { + let editable = Grid::open(two_text_columns(), vec![vec![Value::Int(1), Value::Null]]); + let settings = editable.grid.config().expect("configured grid").settings.clone(); + let readonly = Grid::build( + GridSpec { + settings: Some(settings.clone()), + ..GridSpec::results(two_text_columns()) + }, + results(&[vec![Value::Int(1), Value::Null]]), + ); + let isolated = Grid::build( + GridSpec::results(two_text_columns()), + results(&[vec![Value::Int(1), Value::Null]]), + ); + let editable_cell = editable.cell_of(1, 1); + let readonly_cell = readonly.cell_at(0, 1); + assert_eq!(Grid::display_text(&editable_cell), editable_null_sentinel()); + assert_eq!(Grid::display_text(&readonly_cell), "NULL"); + + settings.set_null_display("missing").expect("store placeholder"); + drain_main_context(); + + assert_eq!(Grid::display_text(&editable_cell), ""); + assert_eq!(Grid::display_text(&readonly_cell), "missing"); + assert_eq!(Grid::display_text(&isolated.cell_at(0, 1)), "NULL"); + assert!(described(&editable_cell)); + assert!(described(&readonly_cell)); + let reopened = Grid::build( + GridSpec { + settings: Some(settings), + ..GridSpec::results(two_text_columns()) + }, + results(&[vec![Value::Int(1), Value::Null]]), + ); + assert_eq!(Grid::display_text(&reopened.cell_at(0, 1)), "missing"); +} + +#[gtk4::test] +fn display_preferences_preserve_the_inline_draft_and_selected_rows() { + let grid = two_text_rows(); + let cell = grid.focus(0, 1); + grid.grid.selection().select_range(0, 2, true); + assert!(grid.grid.edit().edit_cell(&cell)); + let editor = grid.grid.edit().open_text().expect("inline editor"); + editor.set_text("unfinished"); + let selected = super::selected_ids(&grid); + let settings = grid.grid.config().expect("configured grid").settings.clone(); + + settings.set_null_display("missing").expect("store placeholder"); + settings.set_grid_row_height("spacious").expect("store height"); + settings.set_show_row_numbers(false).expect("hide numbers"); + drain_main_context(); + + assert_eq!(grid.grid.edit().open_text().as_ref(), Some(&editor)); + assert_eq!(editor.text(), "unfinished"); + assert_eq!(grid.grid.edit().editing_cell(), Some(cell)); + assert_eq!(super::selected_ids(&grid), selected); + assert_eq!(grid.tracker.cell_overlay(&key(1), 1).pending, None); +} + +#[gtk4::test] +fn row_height_preferences_change_the_allocated_row_height() { + let grid = two_text_rows(); + let settings = grid.grid.config().expect("configured grid").settings.clone(); + let cell = grid.cell_of(1, 1); + settings.set_grid_row_height("compact").expect("compact height"); + crate::test_support::after_next_frame(&grid.grid); + let row = row_widget(&cell); + wait_until(WAIT, || row.height() > 0).expect("row laid out"); + let compact = row.measure(gtk::Orientation::Vertical, -1).1; + + settings.set_grid_row_height("spacious").expect("spacious height"); + wait_until(WAIT, || row.measure(gtk::Orientation::Vertical, -1).1 > compact) + .expect("the larger padding makes a taller row"); + let spacious = row.measure(gtk::Orientation::Vertical, -1).1; + wait_until(WAIT, || row.height() >= spacious).expect("row uses its larger height"); +} diff --git a/linux/crates/app/src/ui/data_grid/tests/columns.rs b/linux/crates/app/src/ui/data_grid/tests/columns.rs index 887d76ac09..6858622954 100644 --- a/linux/crates/app/src/ui/data_grid/tests/columns.rs +++ b/linux/crates/app/src/ui/data_grid/tests/columns.rs @@ -831,3 +831,34 @@ mod real_keys { assert_eq!(layouts.saved("t").widths.get("name"), None); } } + +#[gtk4::test] +fn null_text_resizes_automatic_columns_and_preserves_manual_widths() { + for editable in [false, true] { + let columns = two_text_columns(); + let spec = if editable { + GridSpec::table(columns) + } else { + GridSpec::results(columns) + }; + let values = vec![vec![Value::Int(1), Value::Null]]; + let rows = if editable { persisted(&values) } else { results(&values) }; + let grid = Grid::build(spec, rows); + let settings = grid.grid.config().expect("configured grid").settings.clone(); + let column = data_column(&grid, 1); + let original = column.fixed_width(); + + settings + .set_null_display("value is unavailable") + .expect("store long placeholder"); + wait_until(WAIT, || column.fixed_width() > original).expect("automatic column grows"); + wait_until(WAIT, || { + shows_whole(grid.cell_at(0, 1).display().expect("cell display")) + }) + .expect("the whole placeholder fits"); + column.set_fixed_width(260); + settings.set_null_display("none").expect("store short placeholder"); + drain_main_context(); + assert_eq!(column.fixed_width(), 260, "the chosen width stays"); + } +} diff --git a/linux/crates/app/src/ui/preferences_dialog/data_browser_group.rs b/linux/crates/app/src/ui/preferences_dialog/data_browser_group.rs index a29ba9c4d0..611b65ca31 100644 --- a/linux/crates/app/src/ui/preferences_dialog/data_browser_group.rs +++ b/linux/crates/app/src/ui/preferences_dialog/data_browser_group.rs @@ -1,13 +1,10 @@ -use gio::prelude::{SettingsExt, SettingsExtManual}; +use gio::prelude::SettingsExtManual; use gtk4::glib; +use gtk4::prelude::*; use gtk4::subclass::prelude::*; use libadwaita as adw; -use libadwaita::prelude::ComboRowExt; use tablepro_linux_platform::AppSettings; -use tablepro_linux_platform::settings::keys; - -/// The words the row height setting holds, in the combo's order. -const ROW_HEIGHTS: [&str; 4] = ["compact", "normal", "comfortable", "spacious"]; +use tablepro_linux_platform::settings::{GridRowHeight, keys}; mod imp { use libadwaita::prelude::*; @@ -64,8 +61,6 @@ mod imp { } glib::wrapper! { - /// The General page's rows for the row paginator and the delete - /// confirmation. pub struct DataBrowserGroup(ObjectSubclass) @extends adw::PreferencesGroup, gtk4::Widget, @implements gtk4::Accessible, gtk4::Buildable, gtk4::ConstraintTarget; @@ -96,21 +91,20 @@ impl DataBrowserGroup { gio_settings .bind(keys::NULL_DISPLAY, &imp.null_display_row.get(), "text") .build(); - // The combo holds a position and the setting a word. - let row = imp.row_height_row.get(); - let current = settings.grid_row_height(); - row.set_selected( - ROW_HEIGHTS - .iter() - .position(|height| *height == current) - .map_or(1, |at| at as u32), - ); - let stored = gio_settings.clone(); - row.connect_selected_notify(move |row| { - if let Some(height) = ROW_HEIGHTS.get(row.selected() as usize) { - let _ = stored.set_string(keys::GRID_ROW_HEIGHT, height); - } - }); + gio_settings + .bind(keys::GRID_ROW_HEIGHT, &imp.row_height_row.get(), "selected") + .mapping(|variant, _| { + let height = variant.str()?; + let index = GridRowHeight::ALL + .iter() + .position(|candidate| candidate.nick() == height)?; + Some((index as u32).to_value()) + }) + .set_mapping(|value, _| { + let index = value.get::().ok()?; + Some(GridRowHeight::ALL.get(index as usize)?.nick().to_variant()) + }) + .build(); } } @@ -173,4 +167,45 @@ mod tests { Some("Ask before deleting 10 or more rows at once") ); } + + #[gtk4::test] + fn display_preferences_follow_changes_from_another_window() { + let settings = MemorySettings::new(); + let first = bound_group(&settings); + let second = bound_group(&settings); + + first.imp().row_height_row.set_selected(3); + first.imp().row_numbers_row.set_active(false); + first.imp().null_display_row.set_text("empty"); + + assert_eq!(settings.get().grid_row_height(), "spacious"); + assert_eq!(second.imp().row_height_row.selected(), 3); + assert!(!second.imp().row_numbers_row.is_active()); + assert_eq!(second.imp().null_display_row.text(), "empty"); + + settings.get().set_grid_row_height("compact").expect("store the height"); + settings.get().set_show_row_numbers(true).expect("store the flag"); + settings.get().set_null_display("missing").expect("store the text"); + + for group in [&first, &second] { + assert_eq!(group.imp().row_height_row.selected(), 0); + assert!(group.imp().row_numbers_row.is_active()); + assert_eq!(group.imp().null_display_row.text(), "missing"); + } + second.imp().row_height_row.set_selected(1); + assert_eq!(first.imp().row_height_row.selected(), 1); + assert_eq!(settings.get().grid_row_height(), "normal"); + } + + #[gtk4::test] + fn null_text_entry_limits_characters_without_cutting_unicode() { + let settings = MemorySettings::new(); + let group = bound_group(&settings); + let text = "界".repeat(21); + + group.imp().null_display_row.set_text(&text); + + assert_eq!(group.imp().null_display_row.text(), "界".repeat(20)); + assert_eq!(settings.get().null_display(), "界".repeat(20)); + } } diff --git a/linux/crates/app/src/ui/preferences_dialog/general_page.rs b/linux/crates/app/src/ui/preferences_dialog/general_page.rs index 299e3f0cfc..ed143127a7 100644 --- a/linux/crates/app/src/ui/preferences_dialog/general_page.rs +++ b/linux/crates/app/src/ui/preferences_dialog/general_page.rs @@ -9,7 +9,6 @@ use tablepro_linux_platform::AppSettings; use tablepro_linux_platform::settings::keys; use tablepro_session::runtime::Tasks; -use super::data_browser_group::DataBrowserGroup; use super::history_group::HistoryGroup; use crate::ui::file_reveal::FileRevealer; @@ -24,8 +23,6 @@ mod imp { #[template_child] pub restore_session_row: TemplateChild, #[template_child] - pub data_browser_group: TemplateChild, - #[template_child] pub history_group: TemplateChild, #[template_child] pub privacy_group: TemplateChild, @@ -40,7 +37,6 @@ mod imp { type ParentType = adw::PreferencesPage; fn class_init(klass: &mut Self::Class) { - DataBrowserGroup::ensure_type(); HistoryGroup::ensure_type(); klass.bind_template(); } @@ -56,7 +52,6 @@ mod imp { } glib::wrapper! { - /// The General page: startup, the data browser and the query history. pub struct GeneralPage(ObjectSubclass) @extends adw::PreferencesPage, gtk4::Widget, @implements gtk4::Accessible, gtk4::Buildable, gtk4::ConstraintTarget; @@ -89,7 +84,6 @@ impl GeneralPage { .gio() .bind(keys::SHARE_USAGE_DATA, &imp.share_usage_data_row.get(), "active") .build(); - imp.data_browser_group.bind(settings); imp.history_group.bind(settings, storage, history, tasks, revealer); } @@ -136,7 +130,6 @@ mod tests { page } - /// The page's groups, in the order it shows them. fn groups(page: &GeneralPage) -> Vec { crate::test_support::descendants(page) .into_iter() @@ -178,11 +171,11 @@ mod tests { let page = bound_page(&settings, &storage, &root, &runtime.tasks()); let titles: Vec = groups(&page).iter().map(|group| group.title().to_string()).collect(); - assert_eq!(titles, ["Startup", "Data Browser", "Query History"]); + assert_eq!(titles, ["Startup", "Query History"]); } #[gtk4::test] - fn general_page_contains_the_data_browser_and_history_groups() { + fn general_page_contains_startup_and_history_groups() { let settings = MemorySettings::new(); let runtime = test_runtime(); let storage = test_storage(&runtime.tasks()); @@ -193,9 +186,8 @@ mod tests { let titles: Vec = groups.iter().map(|group| group.title().to_string()).collect(); assert_eq!(page.title(), "General"); - assert_eq!(titles, ["Startup", "Data Browser", "Query History"]); - assert!(groups[1].is::()); - assert!(groups[2].is::()); + assert_eq!(titles, ["Startup", "Query History"]); + assert!(groups[1].is::()); } #[gtk4::test] @@ -216,7 +208,7 @@ mod tests { } #[gtk4::test] - fn the_page_binds_both_of_its_groups() { + fn the_page_binds_its_history_group() { let settings = MemorySettings::new(); let runtime = test_runtime(); let storage = test_storage(&runtime.tasks()); @@ -224,10 +216,8 @@ mod tests { let page = bound_page(&settings, &storage, &root, &runtime.tasks()); let imp = page.imp(); - imp.data_browser_group.imp().confirm_row.set_active(false); imp.history_group.imp().save_history_row.set_active(false); - assert!(!settings.get().confirm_bulk_delete()); assert!(!settings.get().save_query_history()); } } diff --git a/linux/crates/app/src/ui/preferences_dialog/grid_page.rs b/linux/crates/app/src/ui/preferences_dialog/grid_page.rs new file mode 100644 index 0000000000..4044a2ba52 --- /dev/null +++ b/linux/crates/app/src/ui/preferences_dialog/grid_page.rs @@ -0,0 +1,79 @@ +use gtk4::glib; +use gtk4::prelude::*; +use gtk4::subclass::prelude::*; +use libadwaita as adw; +use tablepro_linux_platform::AppSettings; + +use super::data_browser_group::DataBrowserGroup; + +mod imp { + use libadwaita::subclass::prelude::*; + + use super::*; + + #[derive(Default, gtk4::CompositeTemplate)] + #[template(resource = "/app/tablepro/TablePro/ui/preferences-grid-page.ui")] + pub struct GridPage { + #[template_child] + pub data_browser_group: TemplateChild, + } + + #[glib::object_subclass] + impl ObjectSubclass for GridPage { + const NAME: &'static str = "TableProGridPage"; + type Type = super::GridPage; + type ParentType = adw::PreferencesPage; + + fn class_init(klass: &mut Self::Class) { + DataBrowserGroup::ensure_type(); + klass.bind_template(); + } + + fn instance_init(object: &glib::subclass::InitializingObject) { + object.init_template(); + } + } + + impl ObjectImpl for GridPage {} + impl WidgetImpl for GridPage {} + impl PreferencesPageImpl for GridPage {} +} + +glib::wrapper! { + pub struct GridPage(ObjectSubclass) + @extends adw::PreferencesPage, gtk4::Widget, + @implements gtk4::Accessible, gtk4::Buildable, gtk4::ConstraintTarget; +} + +impl Default for GridPage { + fn default() -> Self { + glib::Object::new() + } +} + +impl GridPage { + pub(super) fn bind(&self, settings: &AppSettings) { + self.imp().data_browser_group.bind(settings); + } +} + +#[cfg(test)] +mod tests { + use libadwaita::prelude::*; + + use super::*; + use crate::test_support::MemorySettings; + + #[gtk4::test] + fn the_grid_page_binds_its_data_browser_group() { + crate::register_test_resources(); + let settings = MemorySettings::new(); + let page = GridPage::default(); + page.bind(settings.get()); + + page.imp().data_browser_group.imp().confirm_row.set_active(false); + + assert_eq!(page.title(), "Data Grid"); + assert!(!settings.get().confirm_bulk_delete()); + } +} diff --git a/linux/crates/app/src/ui/preferences_dialog/imp.rs b/linux/crates/app/src/ui/preferences_dialog/imp.rs index a726595628..ee14ce46a7 100644 --- a/linux/crates/app/src/ui/preferences_dialog/imp.rs +++ b/linux/crates/app/src/ui/preferences_dialog/imp.rs @@ -12,6 +12,7 @@ use super::account_page::AccountPage; use super::ai_page::AiPage; use super::editor_page::EditorPage; use super::general_page::GeneralPage; +use super::grid_page::GridPage; use super::mcp_page::McpPage; #[derive(Default, gtk4::CompositeTemplate)] @@ -20,6 +21,8 @@ pub struct PreferencesDialog { #[template_child] pub general_page: TemplateChild, #[template_child] + pub grid_page: TemplateChild, + #[template_child] pub editor_page: TemplateChild, #[template_child] pub mcp_page: TemplateChild, @@ -38,6 +41,7 @@ impl ObjectSubclass for PreferencesDialog { fn class_init(klass: &mut Self::Class) { GeneralPage::ensure_type(); + GridPage::ensure_type(); EditorPage::ensure_type(); McpPage::ensure_type(); AiPage::ensure_type(); diff --git a/linux/crates/app/src/ui/preferences_dialog/mod.rs b/linux/crates/app/src/ui/preferences_dialog/mod.rs index 567b5f661b..d9035c9094 100644 --- a/linux/crates/app/src/ui/preferences_dialog/mod.rs +++ b/linux/crates/app/src/ui/preferences_dialog/mod.rs @@ -5,6 +5,7 @@ mod data_browser_group; mod device_limit_dialog; mod editor_page; mod general_page; +mod grid_page; mod history_group; mod imp; mod mcp_page; @@ -26,7 +27,7 @@ use crate::ui::file_reveal::FileRevealer; #[cfg(test)] pub(super) use self::{ - data_browser_group::DataBrowserGroup, editor_page::EditorPage, general_page::GeneralPage, + data_browser_group::DataBrowserGroup, editor_page::EditorPage, general_page::GeneralPage, grid_page::GridPage, history_group::HistoryGroup, }; @@ -65,6 +66,7 @@ impl PreferencesDialog { revealer.clone(), telemetry.has_project_key(), ); + imp.grid_page.bind(settings); imp.editor_page.bind( settings, editor_page::SnippetsFolder { @@ -110,8 +112,6 @@ impl PreferencesDialog { } } -/// A query history of its own under `root`, opening in the background -/// as the app's does. #[cfg(test)] fn test_history(root: &tempfile::TempDir, tasks: &Tasks) -> HistoryService { let paths = tablepro_storage::StoragePaths::under(root.path(), "tablepro-test", "app.tablepro.TablePro.Devel"); @@ -122,8 +122,8 @@ fn test_history(root: &tempfile::TempDir, tasks: &Tasks) -> HistoryService { HistoryService::start(paths, preferences, tasks) } -/// A storage under a temporary root, so the dialog's storage row and -/// history actions stay away from the developer's own files. +// A storage under a temporary root, so the dialog's storage row and +// history actions stay away from the developer's own files. #[cfg(test)] fn test_storage(tasks: &Tasks) -> crate::storage::SharedStorage { let root = std::env::temp_dir().join(format!("tablepro-prefs-{}", std::process::id())); @@ -141,9 +141,9 @@ mod tests { use crate::test_support::{MemorySettings, assert_labelled, descendants, test_runtime, unlabelled_icon_buttons}; use crate::ui::file_reveal::RecordingRevealer; - /// The template lives in the embedded resources, so a test that - /// builds the dialog has to register them first. Test order is not - /// fixed, so it cannot rely on another test having done it. + // The template lives in the embedded resources, so a test that + // builds the dialog has to register them first. Test order is not + // fixed, so it cannot rely on another test having done it. fn new_dialog( settings: &MemorySettings, storage: &crate::storage::SharedStorage, @@ -164,13 +164,12 @@ mod tests { ) } - /// The dialog's pages, in the order it shows them. They are not in - /// its widget tree until it is presented, so they come from the - /// template. - fn pages(dialog: &PreferencesDialog) -> [adw::PreferencesPage; 5] { + // Pages are not in the widget tree until the dialog is presented. + fn pages(dialog: &PreferencesDialog) -> [adw::PreferencesPage; 6] { let imp = dialog.imp(); [ imp.general_page.get().upcast(), + imp.grid_page.get().upcast(), imp.editor_page.get().upcast(), imp.ai_page.get().upcast(), imp.mcp_page.get().upcast(), @@ -190,9 +189,10 @@ mod tests { test_history(&root, &runtime.tasks()), &runtime.tasks(), ); - let [general, editor, ai, mcp, account] = pages(&dialog); + let [general, grid, editor, ai, mcp, account] = pages(&dialog); assert_eq!(general.title(), "General"); + assert_eq!(grid.title(), "Data Grid"); assert_eq!(editor.title(), "Editor"); assert_eq!(ai.title(), "AI"); assert_eq!(mcp.title(), "MCP"); @@ -303,18 +303,18 @@ mod tests { dialog.imp().general_page.history_group().imp().clear_button.get() } - /// How long a test waits for work that crosses a thread. Long - /// enough that a loaded machine cannot decide the outcome; a - /// passing test returns as soon as its condition holds and never - /// spends it. + // How long a test waits for work that crosses a thread. Long + // enough that a loaded machine cannot decide the outcome; a + // passing test returns as soon as its condition holds and never + // spends it. const WAIT: std::time::Duration = std::time::Duration::from_secs(30); - /// An AdwDialog needs a real window to present into before its - /// toast overlay renders anything. This one opens at a session - /// window's size (session-window.ui). A window left at its 360 px - /// floor gives its content 350 px under Xvfb, which has no - /// compositor, and libadwaita warns that the dialog's bottom sheet, - /// which needs 360, does not fit. + // An AdwDialog needs a real window to present into before its + // toast overlay renders anything. This one opens at a session + // window's size (session-window.ui). A window left at its 360 px + // floor gives its content 350 px under Xvfb, which has no + // compositor, and libadwaita warns that the dialog's bottom sheet, + // which needs 360, does not fit. fn present_on_a_window(dialog: &PreferencesDialog) -> crate::test_support::OwnedWindow { let window = crate::test_support::OwnedWindow::presented( adw::Window::builder().default_width(1200).default_height(760).build(), @@ -347,9 +347,9 @@ mod tests { assert!(clear_button(&dialog).is_mapped()); } - /// What the dialog's toast says, read off the label the overlay - /// renders. AdwPreferencesDialog owns the overlay itself and does - /// not hand it out. + // What the dialog's toast says, read off the label the overlay + // renders. AdwPreferencesDialog owns the overlay itself and does + // not hand it out. fn toast_text(window: &adw::Window) -> Option { crate::test_support::drain_main_context(); crate::test_support::descendants(window) @@ -386,8 +386,8 @@ mod tests { .len() } - /// The test drives the runtime from outside it, which is the one - /// place blocking on it cannot deadlock. + // The test drives the runtime from outside it, which is the one + // place blocking on it cannot deadlock. #[expect( clippy::disallowed_methods, reason = "a GTK test has no runtime of its own, so it drives the app's from outside" @@ -396,9 +396,9 @@ mod tests { runtime.tasks().handle().block_on(future) } - /// Press Clear on the confirmation alert the button raised. The - /// alert presents into the window's dialog host, not into the - /// preferences dialog, so that is where it is. + // Press Clear on the confirmation alert the button raised. The + // alert presents into the window's dialog host, not into the + // preferences dialog, so that is where it is. fn confirm_the_alert(window: &adw::Window) { crate::test_support::drain_main_context(); let alert = diff --git a/linux/crates/platform/src/settings/grid_preferences.rs b/linux/crates/platform/src/settings/grid_preferences.rs new file mode 100644 index 0000000000..6889059db9 --- /dev/null +++ b/linux/crates/platform/src/settings/grid_preferences.rs @@ -0,0 +1,168 @@ +use std::cell::{OnceCell, RefCell}; +use std::rc::Rc; +use std::sync::OnceLock; + +use gio::prelude::*; +use glib::subclass::prelude::*; + +use super::keys; + +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] +pub enum GridRowHeight { + Compact, + #[default] + Normal, + Comfortable, + Spacious, +} + +impl GridRowHeight { + pub const ALL: [Self; 4] = [Self::Compact, Self::Normal, Self::Comfortable, Self::Spacious]; + + pub fn from_nick(nick: &str) -> Self { + match nick { + "compact" => Self::Compact, + "comfortable" => Self::Comfortable, + "spacious" => Self::Spacious, + _ => Self::Normal, + } + } + + pub fn nick(self) -> &'static str { + match self { + Self::Compact => "compact", + Self::Normal => "normal", + Self::Comfortable => "comfortable", + Self::Spacious => "spacious", + } + } + + pub fn css_class(self) -> &'static str { + match self { + Self::Compact => "row-compact", + Self::Normal => "row-normal", + Self::Comfortable => "row-comfortable", + Self::Spacious => "row-spacious", + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct GridPreferenceValues { + pub show_row_numbers: bool, + pub show_alternate_rows: bool, + pub row_height: GridRowHeight, + pub null_display: String, +} + +impl Default for GridPreferenceValues { + fn default() -> Self { + Self { + show_row_numbers: true, + show_alternate_rows: true, + row_height: GridRowHeight::Normal, + null_display: "NULL".to_owned(), + } + } +} + +impl GridPreferenceValues { + fn read(settings: &gio::Settings) -> Self { + Self { + show_row_numbers: settings.boolean(keys::SHOW_ROW_NUMBERS), + show_alternate_rows: settings.boolean(keys::SHOW_ALTERNATE_ROWS), + row_height: GridRowHeight::from_nick(&settings.string(keys::GRID_ROW_HEIGHT)), + null_display: null_display_text(&settings.string(keys::NULL_DISPLAY)), + } + } +} + +fn null_display_text(text: &str) -> String { + let text: String = text.chars().filter(|ch| !ch.is_control()).take(20).collect(); + if text.trim().is_empty() { + "NULL".to_owned() + } else { + text + } +} + +mod imp { + use super::*; + + #[derive(Default)] + pub struct GridPreferences { + pub(super) settings: OnceCell, + pub(super) handler: RefCell>, + pub(super) values: RefCell>, + } + + #[glib::object_subclass] + impl ObjectSubclass for GridPreferences { + const NAME: &'static str = "TableProGridPreferences"; + type Type = super::GridPreferences; + } + + impl ObjectImpl for GridPreferences { + fn signals() -> &'static [glib::subclass::Signal] { + static SIGNALS: OnceLock> = OnceLock::new(); + SIGNALS.get_or_init(|| vec![glib::subclass::Signal::builder("changed").build()]) + } + + fn dispose(&self) { + if let (Some(settings), Some(handler)) = (self.settings.get(), self.handler.take()) { + settings.disconnect(handler); + } + } + } +} + +glib::wrapper! { + pub struct GridPreferences(ObjectSubclass); +} + +impl Default for GridPreferences { + fn default() -> Self { + glib::Object::new() + } +} + +impl GridPreferences { + pub(super) fn new(settings: &gio::Settings) -> Self { + let preferences = Self::default(); + let _ = preferences.imp().settings.set(settings.clone()); + let weak = preferences.downgrade(); + // GSettings only announces keys read after a handler was connected. + let handler = settings.connect_changed(None, move |settings, key| { + if matches!( + key, + keys::SHOW_ROW_NUMBERS | keys::SHOW_ALTERNATE_ROWS | keys::GRID_ROW_HEIGHT | keys::NULL_DISPLAY + ) && let Some(preferences) = weak.upgrade() + { + preferences.update(GridPreferenceValues::read(settings)); + } + }); + preferences.imp().handler.replace(Some(handler)); + preferences.update(GridPreferenceValues::read(settings)); + preferences + } + + pub fn snapshot(&self) -> Rc { + self.imp().values.borrow().clone() + } + + pub fn connect_changed(&self, callback: impl Fn(&Self) + 'static) -> glib::SignalHandlerId { + self.connect_closure( + "changed", + false, + glib::closure_local!(move |preferences: Self| callback(&preferences)), + ) + } + + fn update(&self, values: GridPreferenceValues) { + if *self.imp().values.borrow().as_ref() == values { + return; + } + self.imp().values.replace(Rc::new(values)); + self.emit_by_name::<()>("changed", &[]); + } +} diff --git a/linux/crates/platform/src/settings/mod.rs b/linux/crates/platform/src/settings/mod.rs index 85a11212b4..df83a22e82 100644 --- a/linux/crates/platform/src/settings/mod.rs +++ b/linux/crates/platform/src/settings/mod.rs @@ -1,8 +1,10 @@ mod editor_font; mod error; +mod grid_preferences; pub mod keys; mod window_geometry; +use std::cell::OnceCell; use std::path::Path; use std::time::Duration; @@ -12,6 +14,7 @@ use tablepro_core::export::{CsvDecimal, CsvDelimiter, CsvLineBreak, CsvOptions, pub use editor_font::EditorFont; pub use error::SettingsError; +pub use grid_preferences::{GridPreferenceValues, GridPreferences, GridRowHeight}; pub use window_geometry::WindowGeometry; /// The provider setting's value while the assistant is off. @@ -19,6 +22,7 @@ pub const AI_PROVIDER_NONE: &str = "none"; pub struct AppSettings { settings: gio::Settings, + grid_preferences: OnceCell, } impl AppSettings { @@ -33,6 +37,7 @@ impl AppSettings { .ok_or_else(|| SettingsError::SchemaNotFound(schema_id.to_owned()))?; Ok(Self { settings: gio::Settings::new_full(&schema, gio::SettingsBackend::NONE, None), + grid_preferences: OnceCell::new(), }) } @@ -55,6 +60,7 @@ impl AppSettings { .ok_or_else(|| SettingsError::SchemaNotFound(schema_id.to_owned()))?; Ok(Self { settings: gio::Settings::new_full(&schema, Some(backend), None), + grid_preferences: OnceCell::new(), }) } @@ -63,6 +69,11 @@ impl AppSettings { &self.settings } + pub fn grid_preferences(&self) -> &GridPreferences { + self.grid_preferences + .get_or_init(|| GridPreferences::new(&self.settings)) + } + pub fn default_page_size(&self) -> u32 { self.settings.uint(keys::DEFAULT_PAGE_SIZE) } @@ -81,7 +92,7 @@ impl AppSettings { } pub fn show_alternate_rows(&self) -> bool { - self.settings.boolean(keys::SHOW_ALTERNATE_ROWS) + self.grid_preferences().snapshot().show_alternate_rows } pub fn set_show_alternate_rows(&self, show: bool) -> Result<(), SettingsError> { @@ -89,25 +100,23 @@ impl AppSettings { } pub fn show_row_numbers(&self) -> bool { - self.settings.boolean(keys::SHOW_ROW_NUMBERS) + self.grid_preferences().snapshot().show_row_numbers } pub fn set_show_row_numbers(&self, show: bool) -> Result<(), SettingsError> { self.set_boolean(keys::SHOW_ROW_NUMBERS, show) } - /// The grid's row height: `compact`, `normal`, `comfortable` or `spacious`. pub fn grid_row_height(&self) -> String { - self.settings.string(keys::GRID_ROW_HEIGHT).into() + self.grid_preferences().snapshot().row_height.nick().to_owned() } pub fn set_grid_row_height(&self, height: &str) -> Result<(), SettingsError> { self.set_string(keys::GRID_ROW_HEIGHT, height) } - /// What a cell shows for NULL. pub fn null_display(&self) -> String { - self.settings.string(keys::NULL_DISPLAY).into() + self.grid_preferences().snapshot().null_display.clone() } pub fn set_null_display(&self, text: &str) -> Result<(), SettingsError> { diff --git a/linux/crates/platform/tests/settings.rs b/linux/crates/platform/tests/settings.rs index 5e50a60ee0..170aa87c07 100644 --- a/linux/crates/platform/tests/settings.rs +++ b/linux/crates/platform/tests/settings.rs @@ -330,3 +330,131 @@ fn nonexistent_dir_is_schema_directory() -> TestResult { assert!(matches!(error, SettingsError::SchemaDirectory { path, .. } if path == missing)); Ok(()) } + +#[test] +fn grid_preferences_start_from_schema_and_keep_one_model() -> TestResult { + use tablepro_linux_platform::settings::{GridPreferenceValues, GridPreferences}; + + let fixture = Fixture::new()?; + let preferences = fixture.settings.grid_preferences(); + assert_eq!(preferences.snapshot().as_ref(), &GridPreferenceValues::default()); + assert_eq!(preferences, fixture.settings.grid_preferences()); + assert_eq!(GridPreferences::default().snapshot(), preferences.snapshot()); + Ok(()) +} + +#[test] +fn every_grid_preference_observer_reads_the_updated_snapshot() -> TestResult { + use std::cell::RefCell; + use std::rc::Rc; + + use tablepro_linux_platform::settings::GridRowHeight; + + let fixture = Fixture::new()?; + let preferences = fixture.settings.grid_preferences(); + let original = preferences.snapshot(); + let first = Rc::new(RefCell::new(Vec::new())); + let second = Rc::new(RefCell::new(Vec::new())); + for observed in [&first, &second] { + let observed = observed.clone(); + preferences.connect_changed(move |preferences| observed.borrow_mut().push(preferences.snapshot())); + } + + fixture.settings.set_show_row_numbers(false)?; + fixture.settings.set_show_alternate_rows(false)?; + fixture.settings.set_grid_row_height("spacious")?; + fixture.settings.set_null_display("Missing")?; + + assert_eq!(first.borrow().len(), 4); + assert_eq!(*first.borrow(), *second.borrow()); + let current = preferences.snapshot(); + assert!(!current.show_row_numbers); + assert!(!current.show_alternate_rows); + assert_eq!(current.row_height, GridRowHeight::Spacious); + assert_eq!(current.null_display, "Missing"); + assert!(original.show_row_numbers); + assert_eq!(original.null_display, "NULL"); + Ok(()) +} + +#[test] +fn grid_preference_backends_stay_independent() -> TestResult { + let first = Fixture::new()?; + let second = Fixture::new()?; + let first_preferences = first.settings.grid_preferences(); + let second_preferences = second.settings.grid_preferences(); + + first.settings.set_null_display("Missing")?; + second.settings.set_grid_row_height("compact")?; + + assert_eq!(first_preferences.snapshot().null_display, "Missing"); + assert_eq!(second_preferences.snapshot().null_display, "NULL"); + assert_eq!(first_preferences.snapshot().row_height.nick(), "normal"); + assert_eq!(second_preferences.snapshot().row_height.nick(), "compact"); + Ok(()) +} + +#[test] +fn null_display_is_bounded_even_for_external_settings_writes() -> TestResult { + use gio::prelude::SettingsExt; + + let fixture = Fixture::new()?; + let preferences = fixture.settings.grid_preferences(); + fixture.settings.gio().set_string(keys::NULL_DISPLAY, "\n\t\r")?; + assert_eq!(preferences.snapshot().null_display, "NULL"); + fixture.settings.gio().set_string(keys::NULL_DISPLAY, " ")?; + assert_eq!(preferences.snapshot().null_display, "NULL"); + fixture.settings.gio().set_string(keys::NULL_DISPLAY, "no\nvalue\t")?; + assert_eq!(preferences.snapshot().null_display, "novalue"); + fixture + .settings + .gio() + .set_string(keys::NULL_DISPLAY, &"界".repeat(25))?; + assert_eq!(preferences.snapshot().null_display, "界".repeat(20)); + Ok(()) +} + +#[test] +fn grid_preference_changes_ignore_unrelated_and_equivalent_values() -> TestResult { + use std::cell::Cell; + use std::rc::Rc; + + let fixture = Fixture::new()?; + let calls = Rc::new(Cell::new(0)); + let observed = calls.clone(); + fixture + .settings + .grid_preferences() + .connect_changed(move |_| observed.set(observed.get() + 1)); + + fixture.settings.set_default_page_size(500)?; + fixture.settings.set_null_display("")?; + fixture.settings.set_null_display("NULL")?; + + assert_eq!(calls.get(), 0); + assert!(fixture.settings.set_grid_row_height("unknown").is_err()); + assert_eq!(fixture.settings.grid_row_height(), "normal"); + Ok(()) +} + +#[test] +fn dropping_grid_preferences_disconnects_the_settings_handler() -> TestResult { + use gio::prelude::*; + + let fixture = Fixture::new()?; + let settings = fixture.settings.gio().clone(); + let preferences = fixture.settings.grid_preferences().downgrade(); + let changed = glib::subclass::SignalId::lookup("changed", gio::Settings::static_type()).expect("changed signal"); + assert!(glib::signal::signal_has_handler_pending( + &settings, changed, None, false + )); + + drop(fixture); + + assert!(preferences.upgrade().is_none()); + assert!(!glib::signal::signal_has_handler_pending( + &settings, changed, None, false + )); + settings.set_boolean(keys::SHOW_ROW_NUMBERS, false)?; + Ok(()) +} diff --git a/linux/data/resources/resources.gresource.xml b/linux/data/resources/resources.gresource.xml index 35964baac2..bf12eb901c 100644 --- a/linux/data/resources/resources.gresource.xml +++ b/linux/data/resources/resources.gresource.xml @@ -33,6 +33,7 @@ ui/preferences-dialog.ui ui/preferences-editor-page.ui ui/preferences-general-page.ui + ui/preferences-grid-page.ui ui/preferences-history-group.ui ui/preferences-ai-page.ui ui/preferences-mcp-page.ui diff --git a/linux/data/resources/ui/preferences-data-browser-group.ui b/linux/data/resources/ui/preferences-data-browser-group.ui index 1f52211557..bb541a71b6 100644 --- a/linux/data/resources/ui/preferences-data-browser-group.ui +++ b/linux/data/resources/ui/preferences-data-browser-group.ui @@ -46,6 +46,8 @@ Text for NULL + 20 + Up to 20 characters. Empty text uses NULL. diff --git a/linux/data/resources/ui/preferences-dialog.ui b/linux/data/resources/ui/preferences-dialog.ui index a3a3429e32..4905d01ac7 100644 --- a/linux/data/resources/ui/preferences-dialog.ui +++ b/linux/data/resources/ui/preferences-dialog.ui @@ -8,6 +8,9 @@ + + + diff --git a/linux/data/resources/ui/preferences-general-page.ui b/linux/data/resources/ui/preferences-general-page.ui index 116c7f3fe4..78724d223f 100644 --- a/linux/data/resources/ui/preferences-general-page.ui +++ b/linux/data/resources/ui/preferences-general-page.ui @@ -16,9 +16,6 @@ - - - diff --git a/linux/data/resources/ui/preferences-grid-page.ui b/linux/data/resources/ui/preferences-grid-page.ui new file mode 100644 index 0000000000..39efcde3a2 --- /dev/null +++ b/linux/data/resources/ui/preferences-grid-page.ui @@ -0,0 +1,12 @@ + + + + + + diff --git a/linux/docs/state-management.md b/linux/docs/state-management.md index 8550e8077c..e7825026c2 100644 --- a/linux/docs/state-management.md +++ b/linux/docs/state-management.md @@ -87,6 +87,12 @@ A tab belongs to its session, and a session to one window ([decisions/0028-sessi - Dropped outside every window, `create-window` declines a new window and the tab goes back to that position ([toolkit-workarounds.md](toolkit-workarounds.md#a-tab-dropped-outside-every-window)). - `ReturnTab` runs from the window's queue, after libadwaita finishes attaching the page. A tab whose session closed while it was out closes where it is; the session's close already asked about it, and its view no longer holds the page to close it. +## Grid preferences + +`AppSettings` owns one `GridPreferences` object. It reads the grid keys from GSettings and announces each changed snapshot. Every grid holds that object through its settings and follows its change signal. Preferences rows bind directly to GSettings, including both directions for choices stored as strings. + +The snapshot belongs to its settings backend, so isolated test settings cannot change another grid. A display change redraws the existing row slots and resizes automatic columns. It keeps row selection, user column widths and active editor drafts. The formatting helpers receive display choices explicitly and keep no global preference state. + ## The SQL editor `SqlEditor` (`crates/app/src/ui/editor/`) runs SQL on a connection of its own and lists what each statement returned. diff --git a/linux/docs/storage.md b/linux/docs/storage.md index d21106bf82..ce4fb3d80f 100644 --- a/linux/docs/storage.md +++ b/linux/docs/storage.md @@ -319,6 +319,10 @@ The schema id is the application id and the path follows it: `app.tablepro.Table | `window-height` | `i` | `760` | 294 to 32767 | | `is-maximized` | `b` | `false` | | | `default-page-size` | `u` | `1000` | 100 to 100000 | +| `show-alternate-rows` | `b` | `true` | | +| `show-row-numbers` | `b` | `true` | | +| `grid-row-height` | `s` | `normal` | compact, normal, comfortable, spacious | +| `null-display` | `s` | `NULL` | Displayed as at most 20 characters, without control characters; blank uses NULL | | `confirm-bulk-delete` | `b` | `true` | | | `restore-session` | `b` | `true` | | | `last-seen-version` | `s` | empty | | @@ -351,7 +355,7 @@ The schema id is the application id and the path follows it: `app.tablepro.Table | `csv-line-break` | enum | `lf` | lf, crlf, cr | | `csv-decimal` | enum | `period` | period, comma | -`tablepro_storage::AppSettings` wraps it in typed accessors: +`tablepro_linux_platform::AppSettings` wraps it in typed accessors: ```rust pub fn open(schema_id: &str) -> Result; diff --git a/linux/po/POTFILES.in b/linux/po/POTFILES.in index 7f37312b2d..c7305f6abd 100644 --- a/linux/po/POTFILES.in +++ b/linux/po/POTFILES.in @@ -490,6 +490,7 @@ crates/app/src/ui/preferences_dialog/data_browser_group.rs crates/app/src/ui/preferences_dialog/device_limit_dialog.rs crates/app/src/ui/preferences_dialog/editor_page.rs crates/app/src/ui/preferences_dialog/general_page.rs +crates/app/src/ui/preferences_dialog/grid_page.rs crates/app/src/ui/preferences_dialog/history_group.rs crates/app/src/ui/preferences_dialog/imp.rs crates/app/src/ui/preferences_dialog/mcp_page.rs @@ -766,6 +767,7 @@ data/resources/ui/preferences-data-browser-group.ui data/resources/ui/preferences-dialog.ui data/resources/ui/preferences-editor-page.ui data/resources/ui/preferences-general-page.ui +data/resources/ui/preferences-grid-page.ui data/resources/ui/preferences-history-group.ui data/resources/ui/preferences-mcp-page.ui data/resources/ui/results-pane.ui From c0da2cff3f543faaabbe21ce76ba914f2e5710fb Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Sun, 8 Nov 2026 23:34:33 +0700 Subject: [PATCH 04/10] fix(linux-grid): keep display preferences when resetting columns --- linux/crates/app/src/ui/data_grid/columns.rs | 1 + linux/crates/app/src/ui/data_grid/mod.rs | 3 --- .../crates/app/src/ui/data_grid/tests/layout.rs | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/linux/crates/app/src/ui/data_grid/columns.rs b/linux/crates/app/src/ui/data_grid/columns.rs index e8ab39e933..df2f4c1701 100644 --- a/linux/crates/app/src/ui/data_grid/columns.rs +++ b/linux/crates/app/src/ui/data_grid/columns.rs @@ -194,6 +194,7 @@ impl DataGrid { self.size_unsized_columns(); self.watch_layout_changes(); self.wire_sorting(sorting); + self.apply_display_settings(); } fn build_column(&self, paint: &Rc, sorting: GridSorting) -> gtk::ColumnViewColumn { diff --git a/linux/crates/app/src/ui/data_grid/mod.rs b/linux/crates/app/src/ui/data_grid/mod.rs index 9c4f407fba..44213b9528 100644 --- a/linux/crates/app/src/ui/data_grid/mod.rs +++ b/linux/crates/app/src/ui/data_grid/mod.rs @@ -186,15 +186,12 @@ impl DataGrid { self.imp().columns.borrow().columns() } - /// Build the columns for another column set, with what may change in - /// its rows. The rows go, since they were read under the old columns. pub fn set_columns(&self, columns: Arc<[GridColumn]>, sorting: GridSorting, rules: Option) { self.commit_editors(); self.store().clear(); self.imp().summary.forget_column(); self.edit().set_rules(self, rules); self.rebuild_columns(columns, sorting); - self.apply_display_settings(); self.show_rows_or_empty(); self.refresh_actions(); } diff --git a/linux/crates/app/src/ui/data_grid/tests/layout.rs b/linux/crates/app/src/ui/data_grid/tests/layout.rs index 78470730b6..17606d4f34 100644 --- a/linux/crates/app/src/ui/data_grid/tests/layout.rs +++ b/linux/crates/app/src/ui/data_grid/tests/layout.rs @@ -338,3 +338,19 @@ mod real_keys { wait_until(WAIT, || grid.grid.shown_columns() == [0, 1, 2]).expect("the column to move back"); } } + +#[gtk4::test] +fn resetting_the_column_layout_keeps_row_numbers_hidden() { + let grid = Grid::open(two_text_columns(), two_text_values()); + let settings = grid.grid.config().expect("configured grid").settings.clone(); + settings.set_show_row_numbers(false).expect("hide row numbers"); + assert!(!grid.grid.row_numbers_column().expect("row numbers").is_visible()); + + grid.grid.reset_layout(); + + let numbers = grid.grid.row_numbers_column().expect("rebuilt row numbers"); + assert!(!numbers.is_visible()); + assert!(!settings.show_row_numbers()); + settings.set_show_row_numbers(true).expect("show row numbers"); + assert!(numbers.is_visible()); +} From c03b4eb3bcbcc9680fe3c5fdbbcd4fb75ccc3fd9 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Sun, 8 Nov 2026 23:39:10 +0700 Subject: [PATCH 05/10] test(linux-grid): load native styles for row height checks --- .../crates/app/src/ui/data_grid/test_grid.rs | 28 +++++++++++++++++-- .../app/src/ui/data_grid/tests/cells.rs | 18 ++++++++---- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/linux/crates/app/src/ui/data_grid/test_grid.rs b/linux/crates/app/src/ui/data_grid/test_grid.rs index 5573b1ea11..5925213135 100644 --- a/linux/crates/app/src/ui/data_grid/test_grid.rs +++ b/linux/crates/app/src/ui/data_grid/test_grid.rs @@ -149,7 +149,6 @@ impl GridSpec { } } -/// A grid in a shown window, with the requests it made. pub(crate) struct Grid { pub window: gtk::Window, pub grid: DataGrid, @@ -158,6 +157,28 @@ pub(crate) struct Grid { requests: Rc>>, _settings: MemorySettings, _runtime: AppRuntime, + _style: GridStyle, +} + +struct GridStyle { + display: gtk::gdk::Display, + provider: gtk::CssProvider, +} + +impl GridStyle { + fn new() -> Self { + let display = gtk::gdk::Display::default().expect("test display"); + let provider = gtk::CssProvider::new(); + provider.load_from_resource(&format!("{}/style.css", crate::config::RESOURCE_BASE_PATH)); + gtk::style_context_add_provider_for_display(&display, &provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION); + Self { display, provider } + } +} + +impl Drop for GridStyle { + fn drop(&mut self) { + gtk::style_context_remove_provider_for_display(&self.display, &self.provider); + } } impl Grid { @@ -168,9 +189,9 @@ impl Grid { pub(crate) fn build(spec: GridSpec, rows: Vec) -> Self { crate::register_test_resources(); - // The stylesheet the app draws the grid with, cell padding and the - // monospace font included. libadwaita::init().expect("libadwaita initialises under the test backend"); + // This fixture has no AdwApplication startup to load its resource stylesheet. + let style = GridStyle::new(); let runtime = crate::test_support::test_runtime(); let settings = MemorySettings::new(); let tracker = TabTrackerHandle::default(); @@ -217,6 +238,7 @@ impl Grid { requests, _settings: settings, _runtime: runtime, + _style: style, }; // A saved layout can hide columns, which draw no cells. let width = opened.grid.shown_columns().len(); diff --git a/linux/crates/app/src/ui/data_grid/tests/cells.rs b/linux/crates/app/src/ui/data_grid/tests/cells.rs index 9c358336ed..0e32c1c01d 100644 --- a/linux/crates/app/src/ui/data_grid/tests/cells.rs +++ b/linux/crates/app/src/ui/data_grid/tests/cells.rs @@ -589,15 +589,21 @@ fn row_height_preferences_change_the_allocated_row_height() { let grid = two_text_rows(); let settings = grid.grid.config().expect("configured grid").settings.clone(); let cell = grid.cell_of(1, 1); - settings.set_grid_row_height("compact").expect("compact height"); crate::test_support::after_next_frame(&grid.grid); let row = row_widget(&cell); wait_until(WAIT, || row.height() > 0).expect("row laid out"); - let compact = row.measure(gtk::Orientation::Vertical, -1).1; + let normal = row.height(); + + settings.set_grid_row_height("compact").expect("compact height"); + wait_until(WAIT, || row.height() < normal).expect("compact rows allocate less height than normal rows"); + let compact = row.height(); settings.set_grid_row_height("spacious").expect("spacious height"); - wait_until(WAIT, || row.measure(gtk::Orientation::Vertical, -1).1 > compact) - .expect("the larger padding makes a taller row"); - let spacious = row.measure(gtk::Orientation::Vertical, -1).1; - wait_until(WAIT, || row.height() >= spacious).expect("row uses its larger height"); + wait_until(WAIT, || row.height() > normal).expect("spacious rows allocate more height than normal rows"); + assert!(row.height() > compact); + + settings.set_grid_row_height("normal").expect("normal height"); + wait_until(WAIT, || row.height() == normal).expect("normal rows restore their original height"); + assert_eq!(row_widget(&cell), row); + assert_eq!(grid.cell_of(1, 1), cell); } From f0b307019572c81d6e27cfda848a9220cfd0942f Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Mon, 9 Nov 2026 01:11:17 +0700 Subject: [PATCH 06/10] test(linux-grid): isolate settings notification contexts --- linux/crates/platform/tests/settings.rs | 135 +++++++++++++++--------- 1 file changed, 85 insertions(+), 50 deletions(-) diff --git a/linux/crates/platform/tests/settings.rs b/linux/crates/platform/tests/settings.rs index 170aa87c07..7036f72749 100644 --- a/linux/crates/platform/tests/settings.rs +++ b/linux/crates/platform/tests/settings.rs @@ -12,6 +12,7 @@ type TestResult = Result<(), Box>; const SCHEMA_ID: &str = "app.tablepro.TablePro"; +// GSettings captures the thread-default context, so every test owns one through glib::async_test. struct Fixture { _dir: tempfile::TempDir, settings: AppSettings, @@ -39,8 +40,8 @@ fn compile_schemas() -> Result> { Ok(dir) } -#[test] -fn defaults_match_schema() -> TestResult { +#[glib::async_test] +async fn defaults_match_schema() -> TestResult { let fixture = Fixture::new()?; assert_eq!(fixture.settings.default_page_size(), 1_000); @@ -61,8 +62,8 @@ fn defaults_match_schema() -> TestResult { Ok(()) } -#[test] -fn usage_data_turns_off_and_on_again() -> TestResult { +#[glib::async_test] +async fn usage_data_turns_off_and_on_again() -> TestResult { let fixture = Fixture::new()?; fixture.settings.set_share_usage_data(false)?; @@ -74,8 +75,8 @@ fn usage_data_turns_off_and_on_again() -> TestResult { Ok(()) } -#[test] -fn a_day_of_use_counts_once() -> TestResult { +#[glib::async_test] +async fn a_day_of_use_counts_once() -> TestResult { let fixture = Fixture::new()?; fixture.settings.record_usage_day("2026-11-05")?; @@ -89,8 +90,8 @@ fn a_day_of_use_counts_once() -> TestResult { Ok(()) } -#[test] -fn vim_keybindings_round_trip() -> TestResult { +#[glib::async_test] +async fn vim_keybindings_round_trip() -> TestResult { let fixture = Fixture::new()?; fixture.settings.set_vim_keybindings(true)?; @@ -100,8 +101,8 @@ fn vim_keybindings_round_trip() -> TestResult { Ok(()) } -#[test] -fn mcp_server_round_trip_and_port_range() -> TestResult { +#[glib::async_test] +async fn mcp_server_round_trip_and_port_range() -> TestResult { let fixture = Fixture::new()?; fixture.settings.set_mcp_server_enabled(true)?; @@ -115,8 +116,8 @@ fn mcp_server_round_trip_and_port_range() -> TestResult { Ok(()) } -#[test] -fn the_assistant_starts_off_and_keeps_each_providers_model() -> TestResult { +#[glib::async_test] +async fn the_assistant_starts_off_and_keeps_each_providers_model() -> TestResult { let fixture = Fixture::new()?; assert_eq!(fixture.settings.ai_provider(), None); assert!(!fixture.settings.ai_inline_suggestions()); @@ -152,8 +153,8 @@ fn the_assistant_starts_off_and_keeps_each_providers_model() -> TestResult { Ok(()) } -#[test] -fn restore_session_round_trip() -> TestResult { +#[glib::async_test] +async fn restore_session_round_trip() -> TestResult { let fixture = Fixture::new()?; fixture.settings.set_restore_session(false)?; @@ -162,8 +163,8 @@ fn restore_session_round_trip() -> TestResult { Ok(()) } -#[test] -fn last_seen_version_starts_empty_and_round_trips() -> TestResult { +#[glib::async_test] +async fn last_seen_version_starts_empty_and_round_trips() -> TestResult { let fixture = Fixture::new()?; assert_eq!(fixture.settings.last_seen_version(), ""); @@ -173,8 +174,8 @@ fn last_seen_version_starts_empty_and_round_trips() -> TestResult { Ok(()) } -#[test] -fn confirm_bulk_delete_round_trip() -> TestResult { +#[glib::async_test] +async fn confirm_bulk_delete_round_trip() -> TestResult { let fixture = Fixture::new()?; fixture.settings.set_confirm_bulk_delete(false)?; @@ -184,8 +185,8 @@ fn confirm_bulk_delete_round_trip() -> TestResult { Ok(()) } -#[test] -fn show_alternate_rows_round_trip() -> TestResult { +#[glib::async_test] +async fn show_alternate_rows_round_trip() -> TestResult { let fixture = Fixture::new()?; fixture.settings.set_show_alternate_rows(false)?; @@ -195,8 +196,8 @@ fn show_alternate_rows_round_trip() -> TestResult { Ok(()) } -#[test] -fn save_query_history_round_trip() -> TestResult { +#[glib::async_test] +async fn save_query_history_round_trip() -> TestResult { let fixture = Fixture::new()?; fixture.settings.set_save_query_history(false)?; @@ -205,8 +206,8 @@ fn save_query_history_round_trip() -> TestResult { Ok(()) } -#[test] -fn csv_options_round_trip() -> TestResult { +#[glib::async_test] +async fn csv_options_round_trip() -> TestResult { let fixture = Fixture::new()?; let options = CsvOptions { null_to_empty: false, @@ -225,8 +226,8 @@ fn csv_options_round_trip() -> TestResult { Ok(()) } -#[test] -fn reset_csv_options_restores_defaults() -> TestResult { +#[glib::async_test] +async fn reset_csv_options_restores_defaults() -> TestResult { let fixture = Fixture::new()?; fixture.settings.set_csv_options(&CsvOptions { delimiter: CsvDelimiter::Tab, @@ -240,8 +241,8 @@ fn reset_csv_options_restores_defaults() -> TestResult { Ok(()) } -#[test] -fn window_geometry_round_trip() -> TestResult { +#[glib::async_test] +async fn window_geometry_round_trip() -> TestResult { let fixture = Fixture::new()?; let geometry = WindowGeometry { width: 1440, @@ -255,8 +256,8 @@ fn window_geometry_round_trip() -> TestResult { Ok(()) } -#[test] -fn range_rejects_out_of_bounds() -> TestResult { +#[glib::async_test] +async fn range_rejects_out_of_bounds() -> TestResult { let fixture = Fixture::new()?; for (key, result) in [ @@ -278,8 +279,8 @@ fn range_rejects_out_of_bounds() -> TestResult { Ok(()) } -#[test] -fn query_timeout_zero_is_none() -> TestResult { +#[glib::async_test] +async fn query_timeout_zero_is_none() -> TestResult { let fixture = Fixture::new()?; fixture.settings.set_query_timeout_secs(0)?; @@ -288,8 +289,8 @@ fn query_timeout_zero_is_none() -> TestResult { Ok(()) } -#[test] -fn editor_font_defaults_to_system() -> TestResult { +#[glib::async_test] +async fn editor_font_defaults_to_system() -> TestResult { let fixture = Fixture::new()?; assert_eq!(fixture.settings.editor_font(), EditorFont::System); @@ -304,8 +305,8 @@ fn editor_font_defaults_to_system() -> TestResult { Ok(()) } -#[test] -fn missing_schema_is_schema_not_found() -> TestResult { +#[glib::async_test] +async fn missing_schema_is_schema_not_found() -> TestResult { let dir = compile_schemas()?; let result = AppSettings::with_backend("app.tablepro.Absent", dir.path(), &gio::memory_settings_backend_new()); @@ -317,8 +318,8 @@ fn missing_schema_is_schema_not_found() -> TestResult { Ok(()) } -#[test] -fn nonexistent_dir_is_schema_directory() -> TestResult { +#[glib::async_test] +async fn nonexistent_dir_is_schema_directory() -> TestResult { let dir = tempfile::tempdir()?; let missing = dir.path().join("absent"); @@ -331,8 +332,8 @@ fn nonexistent_dir_is_schema_directory() -> TestResult { Ok(()) } -#[test] -fn grid_preferences_start_from_schema_and_keep_one_model() -> TestResult { +#[glib::async_test] +async fn grid_preferences_start_from_schema_and_keep_one_model() -> TestResult { use tablepro_linux_platform::settings::{GridPreferenceValues, GridPreferences}; let fixture = Fixture::new()?; @@ -343,8 +344,8 @@ fn grid_preferences_start_from_schema_and_keep_one_model() -> TestResult { Ok(()) } -#[test] -fn every_grid_preference_observer_reads_the_updated_snapshot() -> TestResult { +#[glib::async_test] +async fn every_grid_preference_observer_reads_the_updated_snapshot() -> TestResult { use std::cell::RefCell; use std::rc::Rc; @@ -377,8 +378,8 @@ fn every_grid_preference_observer_reads_the_updated_snapshot() -> TestResult { Ok(()) } -#[test] -fn grid_preference_backends_stay_independent() -> TestResult { +#[glib::async_test] +async fn grid_preference_backends_stay_independent() -> TestResult { let first = Fixture::new()?; let second = Fixture::new()?; let first_preferences = first.settings.grid_preferences(); @@ -394,8 +395,8 @@ fn grid_preference_backends_stay_independent() -> TestResult { Ok(()) } -#[test] -fn null_display_is_bounded_even_for_external_settings_writes() -> TestResult { +#[glib::async_test] +async fn null_display_is_bounded_even_for_external_settings_writes() -> TestResult { use gio::prelude::SettingsExt; let fixture = Fixture::new()?; @@ -414,8 +415,8 @@ fn null_display_is_bounded_even_for_external_settings_writes() -> TestResult { Ok(()) } -#[test] -fn grid_preference_changes_ignore_unrelated_and_equivalent_values() -> TestResult { +#[glib::async_test] +async fn grid_preference_changes_ignore_unrelated_and_equivalent_values() -> TestResult { use std::cell::Cell; use std::rc::Rc; @@ -437,8 +438,8 @@ fn grid_preference_changes_ignore_unrelated_and_equivalent_values() -> TestResul Ok(()) } -#[test] -fn dropping_grid_preferences_disconnects_the_settings_handler() -> TestResult { +#[glib::async_test] +async fn dropping_grid_preferences_disconnects_the_settings_handler() -> TestResult { use gio::prelude::*; let fixture = Fixture::new()?; @@ -458,3 +459,37 @@ fn dropping_grid_preferences_disconnects_the_settings_handler() -> TestResult { settings.set_boolean(keys::SHOW_ROW_NUMBERS, false)?; Ok(()) } + +#[glib::async_test] +async fn settings_observers_run_while_another_thread_owns_the_global_context() -> TestResult { + use std::cell::Cell; + use std::rc::Rc; + use std::sync::mpsc; + + let fixture = Fixture::new()?; + let preferences = fixture.settings.grid_preferences(); + let calls = Rc::new(Cell::new(0)); + let observed = calls.clone(); + preferences.connect_changed(move |_| observed.set(observed.get() + 1)); + + let (ready, started) = mpsc::sync_channel(0); + let (release, released) = mpsc::channel(); + let owner = std::thread::spawn(move || { + let context = glib::MainContext::default(); + let _guard = context.acquire().expect("only this worker uses the global context"); + ready.send(()).expect("the test waits for context ownership"); + let _ = released.recv(); + }); + started.recv()?; + + let changed = fixture.settings.set_show_row_numbers(false); + let notifications = calls.get(); + let snapshot = preferences.snapshot(); + drop(release); + owner.join().expect("the context owner exits"); + changed?; + + assert_eq!(notifications, 1); + assert!(!snapshot.show_row_numbers); + Ok(()) +} From 65b6a7ffd406e02fd20aa0d747a42a2552f5c8e0 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Mon, 9 Nov 2026 02:19:53 +0700 Subject: [PATCH 07/10] fix(linux-grid): type the settings test shutdown channel --- linux/crates/platform/tests/settings.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/crates/platform/tests/settings.rs b/linux/crates/platform/tests/settings.rs index 7036f72749..8840f0316f 100644 --- a/linux/crates/platform/tests/settings.rs +++ b/linux/crates/platform/tests/settings.rs @@ -473,7 +473,7 @@ async fn settings_observers_run_while_another_thread_owns_the_global_context() - preferences.connect_changed(move |_| observed.set(observed.get() + 1)); let (ready, started) = mpsc::sync_channel(0); - let (release, released) = mpsc::channel(); + let (release, released) = mpsc::channel::<()>(); let owner = std::thread::spawn(move || { let context = glib::MainContext::default(); let _guard = context.acquire().expect("only this worker uses the global context"); From 2f99c47e7b073f7280b2b5f3bdac4b09d32aca26 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Mon, 9 Nov 2026 16:22:46 +0700 Subject: [PATCH 08/10] fix(linux-grid): hide the pinned row number gutter with the row numbers --- .../app/src/ui/data_grid/display_settings.rs | 1 + .../app/src/ui/data_grid/pinned_numbers.rs | 14 +++++++++---- .../app/src/ui/data_grid/tests/gutter.rs | 21 +++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/linux/crates/app/src/ui/data_grid/display_settings.rs b/linux/crates/app/src/ui/data_grid/display_settings.rs index 70fbf7b1e5..dbbb524862 100644 --- a/linux/crates/app/src/ui/data_grid/display_settings.rs +++ b/linux/crates/app/src/ui/data_grid/display_settings.rs @@ -36,6 +36,7 @@ impl DataGrid { set_class(&view, "tp-striped", values.show_alternate_rows); if let Some(numbers) = self.row_numbers_column() { numbers.set_visible(values.show_row_numbers); + super::pinned_numbers::sync(self); } let changed = self.imp().applied_null.borrow().as_deref() != Some(&values.null_display); if changed { diff --git a/linux/crates/app/src/ui/data_grid/pinned_numbers.rs b/linux/crates/app/src/ui/data_grid/pinned_numbers.rs index f056782c04..deade15d75 100644 --- a/linux/crates/app/src/ui/data_grid/pinned_numbers.rs +++ b/linux/crates/app/src/ui/data_grid/pinned_numbers.rs @@ -169,7 +169,7 @@ pub(super) fn install(grid: &DataGrid) { return None; } let area = header(&grid.column_view()).and_then(|header| header.compute_bounds(overlay)); - let Some((area, column)) = area.zip(grid.row_numbers_column()) else { + let Some((area, column)) = area.zip(shown_numbers(&grid)) else { return Some(gtk::gdk::Rectangle::new(0, 0, 0, 0)); }; let width = column.fixed_width(); @@ -196,15 +196,21 @@ pub(super) fn install(grid: &DataGrid) { )); } +// The row numbers preference hides the column without taking it out of the view. +fn shown_numbers(grid: &DataGrid) -> Option { + grid.row_numbers_column().filter(|column| column.is_visible()) +} + pub(super) fn sync(grid: &DataGrid) { let imp = grid.imp(); - if let Some(column) = grid.row_numbers_column() { + let numbers = shown_numbers(grid); + if let Some(column) = &numbers { imp.gutter_backing.set_width_request(column.fixed_width()); } - let visible = imp.scrolled.hadjustment().value() > 0.0; + let visible = numbers.is_some() && imp.scrolled.hadjustment().value() > 0.0; imp.gutter_backing.set_visible(visible); // Keep one pointer target while scrolling schedules a new native header allocation. - imp.gutter_header.set_visible(grid.row_numbers_column().is_some()); + imp.gutter_header.set_visible(numbers.is_some()); imp.viewport.queue_draw(); grid.edit().queue_editor_allocate(); } diff --git a/linux/crates/app/src/ui/data_grid/tests/gutter.rs b/linux/crates/app/src/ui/data_grid/tests/gutter.rs index da126f2346..13483a45b7 100644 --- a/linux/crates/app/src/ui/data_grid/tests/gutter.rs +++ b/linux/crates/app/src/ui/data_grid/tests/gutter.rs @@ -406,6 +406,27 @@ fn the_row_numbers_stay_in_view_when_the_columns_scroll_sideways() { assert!(!projection(&grid).is_visible()); } +#[gtk4::test] +fn hidden_row_numbers_leave_no_pinned_gutter() { + use gtk::subclass::prelude::*; + let grid = wide_rows(20); + scroll(&grid).set_overlay_scrolling(false); + sideways(&grid); + assert!(projection(&grid).is_visible()); + let settings = grid.grid.config().expect("configured grid").settings.clone(); + + settings.set_show_row_numbers(false).expect("hide row numbers"); + after_next_frame(&grid.window); + assert!(scroll(&grid).hadjustment().value() > 0.0); + assert!(!projection(&grid).is_visible()); + assert!(!grid.grid.imp().gutter_header.is_visible()); + + settings.set_show_row_numbers(true).expect("show row numbers"); + after_next_frame(&grid.window); + assert!(projection(&grid).is_visible()); + assert!(grid.grid.imp().gutter_header.is_visible()); +} + #[gtk4::test] fn scrolling_over_the_gutter_uses_the_grid_in_both_axes() { use crate::test_support::{KeyInjector, wait_until}; From 64ad079be47c7b1c06adc3d76f4f0f2426fb4e4a Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Mon, 9 Nov 2026 16:54:23 +0700 Subject: [PATCH 09/10] fix(linux-workspace): drop the too_many_lines expectation update no longer meets --- linux/crates/app/src/ui/workspace/mod.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/linux/crates/app/src/ui/workspace/mod.rs b/linux/crates/app/src/ui/workspace/mod.rs index 97905d18c9..1546b9b017 100644 --- a/linux/crates/app/src/ui/workspace/mod.rs +++ b/linux/crates/app/src/ui/workspace/mod.rs @@ -1330,10 +1330,6 @@ impl WorkspaceModel { } } - #[expect( - clippy::too_many_lines, - reason = "Each workspace input dispatches to its own handler" - )] fn update(&mut self, msg: WorkspaceInput) { match msg { WorkspaceInput::HealthChanged(health) => self.refresh_health_banner(&health), From 0dd52296e7138a63545cf1dacd5c942582847cc7 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Mon, 9 Nov 2026 17:19:45 +0700 Subject: [PATCH 10/10] ci: rerun the checks GitHub dropped for the last push