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..71c2accb87 100644 --- a/linux/crates/app/src/services/grid/display_text.rs +++ b/linux/crates/app/src/services/grid/display_text.rs @@ -35,6 +35,13 @@ pub fn editable_null_sentinel() -> String { crate::i18n::gettext("") } +pub fn null_text(text: &str, editable: bool) -> String { + match (editable, text) { + (true, "NULL") => editable_null_sentinel(), + _ => text.to_owned(), + } +} + /// A read-only cell dims its NULL instead, so it needs no brackets. /// A technical term, so it is not translated. const READONLY_NULL: &str = "NULL"; @@ -206,7 +213,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, null_text}; fn text_column() -> ColumnType { ColumnType::untyped_text("text") @@ -217,6 +224,14 @@ 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!(null_text("NULL", true), ""); + assert_eq!(null_text("(none)", true), "(none)"); + assert_eq!(null_text("(none)", false), "(none)"); + assert_eq!(null_text("NULL", false), "NULL"); + } + #[test] fn display_text_borrows_text_without_allocating() { let value = Value::Text("hello".into()); 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 1825de79d9..5c416d7fba 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)); @@ -192,6 +197,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 { @@ -306,7 +312,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; @@ -351,9 +356,12 @@ 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 = crate::services::grid::display_text::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 new file mode 100644 index 0000000000..dbbb524862 --- /dev/null +++ b/linux/crates/app/src/ui/data_grid/display_settings.rs @@ -0,0 +1,48 @@ +use gtk4::prelude::*; +use gtk4::subclass::prelude::*; +use tablepro_linux_platform::settings::GridRowHeight; + +use super::DataGrid; +use super::grid_cell::set_class; +use crate::ui::handler_guard::HandlerGuard; + +impl DataGrid { + pub(super) fn watch_display_settings(&self) { + let Some(config) = self.config() else { + return; + }; + let preferences = config.settings.grid_preferences(); + let weak = self.downgrade(); + let handler = preferences.connect_changed(move |_| { + if let Some(grid) = weak.upgrade() { + grid.apply_display_settings(); + } + }); + self.imp() + .display_watch + .replace(Some(HandlerGuard::new(preferences, handler))); + self.apply_display_settings(); + } + + pub(super) fn apply_display_settings(&self) { + let Some(config) = self.config() else { + return; + }; + let values = config.settings.grid_preferences().snapshot(); + let view = self.column_view(); + 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(values.show_row_numbers); + super::pinned_numbers::sync(self); + } + 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 b5e3b57db4..5fc03a2827 100644 --- a/linux/crates/app/src/ui/data_grid/grid_cell.rs +++ b/linux/crates/app/src/ui/data_grid/grid_cell.rs @@ -10,7 +10,7 @@ use super::columns::ColumnPaint; use super::tracked_values::cell_description; use super::{DataGrid, GridRow, ServerValue}; use crate::services::change_tracker::CellState; -use crate::services::grid::display_text::{DisplayText, auto_filled_sentinel, display_text, editable_null_sentinel}; +use crate::services::grid::display_text::{DisplayText, auto_filled_sentinel, display_text, null_text}; use crate::services::grid::{CellLock, GridColumn}; /// Enough for any number, date or short text. @@ -36,8 +36,6 @@ 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, auto_filled: String, } @@ -61,7 +59,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(), } } @@ -403,7 +400,10 @@ 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), } } diff --git a/linux/crates/app/src/ui/data_grid/imp.rs b/linux/crates/app/src/ui/data_grid/imp.rs index cdf684bc73..10275e0d52 100644 --- a/linux/crates/app/src/ui/data_grid/imp.rs +++ b/linux/crates/app/src/ui/data_grid/imp.rs @@ -93,7 +93,8 @@ 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) stripes_watch: RefCell>, + pub(super) display_watch: RefCell>, + pub(super) applied_null: RefCell>, } #[glib::object_subclass] @@ -133,6 +134,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 233d573213..70d3a25ddd 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; @@ -92,7 +93,7 @@ impl DataGrid { imp.detail_pane.attach(&grid); grid.set_columns(columns, sorting, rules); grid.watch_fonts(); - grid.watch_stripes(); + grid.watch_display_settings(); grid } @@ -187,8 +188,6 @@ 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(); 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/row_detail/fields.rs b/linux/crates/app/src/ui/data_grid/row_detail/fields.rs index b2b4b16a2e..61d4574474 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 @@ -42,13 +42,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); @@ -272,7 +272,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); edited.set_visible(value.modified); shown.set_text(Some(&value.text)); shown.set_attributes(Some(&value_attributes(&value))); 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 0976385e79..0c112df291 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 @@ -1542,6 +1542,35 @@ 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); +} + fn drawn_field(pane: &RowDetailPane, column: usize) -> gtk::ListItem { pane.imp() .bound 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 9f88684e78..56c18441f8 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 @@ -348,7 +348,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 dbae138e59..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,28 +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 5947359510..8fd9256976 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, @@ -147,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, @@ -194,7 +195,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 b828616eda..0e32c1c01d 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), }) } @@ -204,6 +205,26 @@ 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")); +} + #[gtk4::test] fn column_view_carries_data_table_class() { let grid = two_text_rows(); @@ -501,3 +522,88 @@ 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), "missing"); + 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); + crate::test_support::after_next_frame(&grid.grid); + let row = row_widget(&cell); + wait_until(WAIT, || row.height() > 0).expect("row laid out"); + 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.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); +} 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/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}; 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()); +} 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..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,9 +1,10 @@ use gio::prelude::SettingsExtManual; use gtk4::glib; +use gtk4::prelude::*; use gtk4::subclass::prelude::*; use libadwaita as adw; use tablepro_linux_platform::AppSettings; -use tablepro_linux_platform::settings::keys; +use tablepro_linux_platform::settings::{GridRowHeight, keys}; mod imp { use libadwaita::prelude::*; @@ -20,6 +21,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] @@ -54,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; @@ -80,6 +85,26 @@ 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(); + 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(); } } @@ -142,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/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), 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/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..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,13 +92,37 @@ 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> { self.set_boolean(keys::SHOW_ALTERNATE_ROWS, show) } + pub fn show_row_numbers(&self) -> bool { + 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) + } + + pub fn grid_row_height(&self) -> String { + 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) + } + + pub fn null_display(&self) -> String { + self.grid_preferences().snapshot().null_display.clone() + } + + 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/crates/platform/tests/settings.rs b/linux/crates/platform/tests/settings.rs index b33f9f7d99..35d889ca53 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,170 @@ fn nonexistent_dir_is_schema_directory() -> TestResult { Ok(()) } -#[test] -fn an_explicit_adwaita_choice_is_distinct_from_the_system_default() -> 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()?; + 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(()) +} + +#[glib::async_test] +async 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(()) +} + +#[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(); + 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(()) +} + +#[glib::async_test] +async 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(()) +} + +#[glib::async_test] +async 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(()) +} + +#[glib::async_test] +async 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(()) +} + +#[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(()) +} + +#[glib::async_test] +async fn an_explicit_adwaita_choice_is_distinct_from_the_system_default() -> TestResult { use gio::prelude::SettingsExt; let fixture = Fixture::new()?; diff --git a/linux/data/app.tablepro.TablePro.gschema.xml.in b/linux/data/app.tablepro.TablePro.gschema.xml.in index 61223f041e..53b0cb4554 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/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/style.css b/linux/data/resources/style.css index bddc5b6a42..5bd021dc9e 100644 --- a/linux/data/resources/style.css +++ b/linux/data/resources/style.css @@ -223,3 +223,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..bb541a71b6 100644 --- a/linux/data/resources/ui/preferences-data-browser-group.ui +++ b/linux/data/resources/ui/preferences-data-browser-group.ui @@ -23,6 +23,33 @@ Show Alternate Row Backgrounds + + + Show Row Numbers + + + + + Row Height + + + + Compact + Normal + Comfortable + Spacious + + + + + + + + Text for NULL + 20 + Up to 20 characters. Empty text uses NULL. + + Confirm Before Deleting Rows 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 3c9ab1f113..aab902c3a2 100644 --- a/linux/docs/storage.md +++ b/linux/docs/storage.md @@ -340,6 +340,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 | | @@ -372,7 +376,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 624ca4091b..464cf46144 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 @@ -490,6 +491,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 @@ -767,6 +769,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