diff --git a/linux/changelog.d/4137.added.md b/linux/changelog.d/4137.added.md new file mode 100644 index 0000000000..b498d0b520 --- /dev/null +++ b/linux/changelog.d/4137.added.md @@ -0,0 +1 @@ +Preferences can set the format Copy writes when several rows are selected, as TSV, JSON, CSV or Markdown. diff --git a/linux/changelog.d/4138.added.md b/linux/changelog.d/4138.added.md new file mode 100644 index 0000000000..023ae1adcd --- /dev/null +++ b/linux/changelog.d/4138.added.md @@ -0,0 +1 @@ +Preferences can open the row details pane whenever a row is selected. diff --git a/linux/crates/app/src/ui/data_grid/copy/mod.rs b/linux/crates/app/src/ui/data_grid/copy/mod.rs index 222b60e39f..decb23cc3f 100644 --- a/linux/crates/app/src/ui/data_grid/copy/mod.rs +++ b/linux/crates/app/src/ui/data_grid/copy/mod.rs @@ -5,6 +5,7 @@ use gtk4::{self as gtk, glib}; use tablepro_core::column::{ColumnInfo, ResultColumn}; use tablepro_core::edit::CellInput; use tablepro_core::{FilterRule, Value}; +use tablepro_linux_platform::settings::RowCopyFormat; use super::grid_actions::{add, add_for_column, enable}; use super::selection::Resolved; @@ -165,7 +166,6 @@ impl ShownColumns { } } -/// Copy: the target cell's value when one row is in play, else the rows. fn copy(grid: &DataGrid) { let Some(target) = grid.target() else { return; @@ -173,7 +173,22 @@ fn copy(grid: &DataGrid) { let column = target.cell.as_ref().map(|(_, column)| *column); match (copy_scope(target.rows.len(), column), &target.cell) { (CopyScope::Value(column), Some((row, _))) => copy_value(grid, row, column), - _ => copy_rows(grid, &target.rows, CopyKind::Rows), + _ => copy_rows(grid, &target.rows, preferred_format(grid)), + } +} + +fn preferred_format(grid: &DataGrid) -> CopyKind { + match grid + .config() + .map(|config| config.settings.row_copy_format()) + .unwrap_or_default() + { + RowCopyFormat::Rows => CopyKind::Rows, + RowCopyFormat::RowsWithHeaders => CopyKind::RowsWithHeaders, + RowCopyFormat::Json => CopyKind::Json, + RowCopyFormat::Csv => CopyKind::Csv, + RowCopyFormat::CsvWithHeaders => CopyKind::CsvWithHeaders, + RowCopyFormat::Markdown => CopyKind::Markdown, } } diff --git a/linux/crates/app/src/ui/data_grid/copy/tests.rs b/linux/crates/app/src/ui/data_grid/copy/tests.rs index 8a46da5545..afab86f749 100644 --- a/linux/crates/app/src/ui/data_grid/copy/tests.rs +++ b/linux/crates/app/src/ui/data_grid/copy/tests.rs @@ -25,6 +25,7 @@ use crate::ui::data_grid::{DataGrid, GridCell, GridRequest}; use crate::ui::export::ExportSource; const BEFORE: &str = "nothing copied yet"; +const TWO_TEXT_ROWS_JSON: &str = "[\n{\"id\":1,\"name\":\"A\"},\n{\"id\":2,\"name\":\"B\"}\n]"; /// What a copy test drives: a grid and the requests it made. trait Copies { @@ -747,3 +748,49 @@ fn the_text_copies_take_the_columns_on_screen() { assert_eq!(lines, "{\"id\":1,\"name\":\"Ada\"}\n{\"id\":2,\"name\":\"Grace\"}\n"); assert_eq!(one_row, "1, 'Ada', 2, 'Grace'"); } + +#[gtk4::test] +fn copy_writes_several_rows_in_the_preferred_format() { + use tablepro_linux_platform::settings::RowCopyFormat; + + let grid = Grid::open(two_text_columns(), two_text_values()); + select_all(&grid); + let settings = &grid.grid.config().expect("a configured grid").settings; + for format in RowCopyFormat::ALL { + settings.set_row_copy_format(format.nick()).expect("store the format"); + + let text = copied(&grid, || activate(&grid.grid, "copy")); + + match format { + RowCopyFormat::Rows => assert_eq!(text, "1\tA\n2\tB\n"), + RowCopyFormat::RowsWithHeaders => assert_eq!(text, "id\tname\n1\tA\n2\tB\n"), + RowCopyFormat::Csv => assert_eq!(text, "1,A\n2,B\n"), + RowCopyFormat::CsvWithHeaders => assert_eq!(text, "id,name\n1,A\n2,B\n"), + RowCopyFormat::Markdown => assert_eq!(text, "| id | name |\n| --- | --- |\n| 1 | A |\n| 2 | B |"), + RowCopyFormat::Json => assert_eq!(text, TWO_TEXT_ROWS_JSON), + } + } +} + +#[gtk4::test] +fn preferred_row_format_preserves_single_cell_copy_and_explicit_formats() { + let grid = Grid::open(two_text_columns(), two_text_values()); + grid.grid + .config() + .expect("a configured grid") + .settings + .set_row_copy_format("json") + .expect("store the format"); + grid.grid.selection().select_item(0, true); + grid.focus(0, 1); + + assert_eq!(copied(&grid, || activate(&grid.grid, "copy")), "A"); + + select_all(&grid); + assert_eq!( + copied(&grid, || activate(&grid.grid, "copy-csv-headers")), + "id,name\n1,A\n2,B\n" + ); + let text = copied(&grid, || activate(&grid.grid, "copy")); + assert_eq!(text, TWO_TEXT_ROWS_JSON); +} diff --git a/linux/crates/app/src/ui/data_grid/edit/tests/rows.rs b/linux/crates/app/src/ui/data_grid/edit/tests/rows.rs index 1dc09f2a7a..900d3d92d9 100644 --- a/linux/crates/app/src/ui/data_grid/edit/tests/rows.rs +++ b/linux/crates/app/src/ui/data_grid/edit/tests/rows.rs @@ -6,7 +6,7 @@ use libadwaita::prelude::*; use tablepro_core::Value; use tablepro_core::edit::CellInput; -use super::{editing, none, pending, press, two_text_rows}; +use super::{details_shown, editing, none, pending, press, two_text_rows}; use crate::services::change_tracker::RowState; use crate::services::grid::edit_policy; use crate::test_support::{drain_main_context, respond, wait_until}; @@ -526,3 +526,97 @@ fn a_deleted_focus_does_not_disable_presets_for_other_selected_rows() { assert_eq!(pending(&grid, 2, 1), Some(CellInput::Value(Value::Null))); assert_eq!(grid.tracker.row_state(&key(1)), RowState::PendingDelete); } + +#[gtk4::test] +fn selecting_a_row_opens_the_details_only_when_preferences_ask() { + let grid = two_text_rows(); + let settings = grid.grid.config().expect("a configured grid").settings.clone(); + + grid.focus(0, 1); + grid.grid.selection().select_item(0, true); + assert!(!details_shown(&grid), "off by default"); + + settings.set_auto_show_inspector(true).expect("store the flag"); + drain_main_context(); + assert!(!details_shown(&grid), "the preference waits for a new selection"); + grid.focus(0, 0); + assert!(!details_shown(&grid), "focus alone does not select a row"); + grid.grid.selection().select_item(1, true); + drain_main_context(); + assert!(details_shown(&grid)); + + settings + .set_auto_show_inspector(false) + .expect("turn automatic opening off"); + drain_main_context(); + assert!(details_shown(&grid), "turning the preference off leaves the pane open"); + grid.activate("show-details"); + grid.grid.selection().select_item(0, true); + drain_main_context(); + assert!(!details_shown(&grid)); +} + +#[gtk4::test] +fn closing_details_keeps_it_closed_through_focus_moves_and_escape() { + let grid = two_text_rows(); + let settings = grid.grid.config().expect("a configured grid").settings.clone(); + settings + .set_auto_show_inspector(true) + .expect("enable automatic opening"); + select_all_from(&grid, 0, 1); + assert!(details_shown(&grid)); + + assert!(press(&grid, gdk::Key::Return, gdk::ModifierType::ALT_MASK)); + assert!(!details_shown(&grid)); + grid.focus(1, 0); + assert!( + !details_shown(&grid), + "moving focus with the same selection keeps it closed" + ); + assert!(press(&grid, gdk::Key::Escape, none())); + drain_main_context(); + assert!(grid.grid.selection().selection().is_empty()); + assert!( + grid.grid.focused_cell().is_some(), + "the action target still has a focused row" + ); + assert!(!details_shown(&grid), "clearing the selection must not reopen details"); + grid.focus(0, 1); + assert!( + !details_shown(&grid), + "a focused cell without a selection keeps it closed" + ); + + grid.grid.selection().select_item(0, true); + drain_main_context(); + assert!(details_shown(&grid), "a new selection opens details again"); +} + +#[gtk4::test] +fn open_grids_use_the_shared_auto_details_preference_on_their_next_selection() { + let first = two_text_rows(); + let settings = first.grid.config().expect("a configured grid").settings.clone(); + let second = Grid::build( + GridSpec { + settings: Some(settings.clone()), + ..GridSpec::table(two_text_columns()) + }, + page(1..3), + ); + let isolated = two_text_rows(); + for grid in [&first, &second, &isolated] { + grid.grid.selection().unselect_all(); + assert!(!details_shown(grid)); + } + + settings + .set_auto_show_inspector(true) + .expect("enable automatic opening"); + for grid in [&first, &second, &isolated] { + grid.grid.selection().select_item(0, true); + } + drain_main_context(); + assert!(details_shown(&first)); + assert!(details_shown(&second)); + assert!(!details_shown(&isolated)); +} diff --git a/linux/crates/app/src/ui/data_grid/grid_actions.rs b/linux/crates/app/src/ui/data_grid/grid_actions.rs index 1b7e5e095c..7acbc5abf3 100644 --- a/linux/crates/app/src/ui/data_grid/grid_actions.rs +++ b/linux/crates/app/src/ui/data_grid/grid_actions.rs @@ -152,6 +152,20 @@ impl DataGrid { self.target()?.cell.map(|(_, column)| column) } + pub(super) fn open_details_for_selection(&self) { + let wanted = self + .config() + .is_some_and(|config| config.settings.auto_show_inspector()); + // Action targets include a focused row after Escape clears the selection. + let selected = !self.selection().selection().is_empty(); + if wanted + && selected + && let Some(details) = self.imp().actions.lookup_action("show-details") + { + details.change_state(&true.to_variant()); + } + } + /// Open the detail pane on the focused row, with `column`'s field. pub(crate) fn show_details_for(&self, column: usize) { self.imp().detail_pane.select_field(column); diff --git a/linux/crates/app/src/ui/data_grid/mod.rs b/linux/crates/app/src/ui/data_grid/mod.rs index 8fbf4b920e..0b664e0d0d 100644 --- a/linux/crates/app/src/ui/data_grid/mod.rs +++ b/linux/crates/app/src/ui/data_grid/mod.rs @@ -417,6 +417,7 @@ impl DataGrid { fn selection_moved(&self) { self.refresh_actions(); self.imp().detail_pane.follow_focus(); + self.open_details_for_selection(); self.emit_by_name::<()>("selection-changed", &[]); } 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 cbecb66443..024d47f75c 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 @@ -1968,3 +1968,24 @@ fn search_keys_and_tab_order_reach_the_filter_list_and_value() { .expect("Escape"); wait_until(WAIT, || !grid.grid.imp().split_view.shows_sidebar()).expect("Escape closes the empty overlay search"); } + +#[gtk4::test] +fn changing_automatic_details_opening_keeps_an_active_value_draft() { + let (grid, pane) = opened(two_text_columns(), two_text_values()); + edit_field(&grid, &pane, 0, 1); + type_value(&pane, "unfinished"); + let settings = grid.grid.config().expect("a configured grid").settings.clone(); + + settings + .set_auto_show_inspector(true) + .expect("enable automatic opening"); + settings + .set_auto_show_inspector(false) + .expect("disable automatic opening"); + drain_main_context(); + + assert!(pane.is_open()); + assert!(pane.is_editing_value()); + assert_eq!(pane.typed_text(), "unfinished"); + 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 56c18441f8..4e6e1936de 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 @@ -247,7 +247,7 @@ impl RowDetailPane { } } - fn is_editing_value(&self) -> bool { + pub(super) fn is_editing_value(&self) -> bool { self.imp().edit.borrow().is_some() } 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 b811995241..17c3916449 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 @@ -4,7 +4,7 @@ use gtk4::prelude::*; use gtk4::subclass::prelude::*; use libadwaita as adw; use tablepro_linux_platform::AppSettings; -use tablepro_linux_platform::settings::{GridRowHeight, keys}; +use tablepro_linux_platform::settings::{GridRowHeight, RowCopyFormat, keys}; mod imp { use libadwaita::prelude::*; @@ -30,6 +30,10 @@ mod imp { #[template_child] pub row_numbers_row: TemplateChild, #[template_child] + pub auto_inspector_row: TemplateChild, + #[template_child] + pub row_copy_format_row: TemplateChild, + #[template_child] pub row_height_row: TemplateChild, #[template_child] pub null_display_row: TemplateChild, @@ -113,22 +117,43 @@ impl DataBrowserGroup { }) .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()) - }) + .bind(keys::AUTO_SHOW_INSPECTOR, &imp.auto_inspector_row.get(), "active") .build(); + bind_choice( + &imp.row_height_row.get(), + gio_settings, + keys::GRID_ROW_HEIGHT, + GridRowHeight::ALL.map(GridRowHeight::nick), + ); + bind_choice( + &imp.row_copy_format_row.get(), + gio_settings, + keys::ROW_COPY_FORMAT, + RowCopyFormat::ALL.map(RowCopyFormat::nick), + ); } } +fn bind_choice( + row: &adw::ComboRow, + settings: &gio::Settings, + key: &'static str, + words: [&'static str; N], +) { + settings + .bind(key, row, "selected") + .mapping(move |variant, _| { + let word = variant.str()?; + let index = words.iter().position(|candidate| *candidate == word)?; + Some((index as u32).to_value()) + }) + .set_mapping(move |value, _| { + let index = value.get::().ok()?; + Some(words.get(index as usize)?.to_variant()) + }) + .build(); +} + #[cfg(test)] mod tests { use libadwaita::prelude::*; @@ -169,6 +194,21 @@ mod tests { assert!(settings.get().show_alternate_rows()); } + #[gtk4::test] + fn automatic_details_switches_stay_in_sync() { + let settings = MemorySettings::new(); + let first = bound_group(&settings); + let second = bound_group(&settings); + assert!(!first.imp().auto_inspector_row.is_active()); + + first.imp().auto_inspector_row.set_active(true); + assert!(settings.get().auto_show_inspector()); + assert!(second.imp().auto_inspector_row.is_active()); + settings.get().set_auto_show_inspector(false).expect("store the flag"); + assert!(!first.imp().auto_inspector_row.is_active()); + assert!(!second.imp().auto_inspector_row.is_active()); + } + #[gtk4::test] fn the_group_is_titled_for_the_data_browser() { let settings = MemorySettings::new(); @@ -258,4 +298,28 @@ mod tests { assert!(first.imp().grid_system_font_row.is_active()); assert!(!second.imp().grid_font_row.is_sensitive()); } + + #[gtk4::test] + fn copy_format_rows_follow_every_choice_from_both_windows() { + let settings = MemorySettings::new(); + let first = bound_group(&settings); + let second = bound_group(&settings); + + for (index, format) in RowCopyFormat::ALL.into_iter().enumerate() { + first.imp().row_copy_format_row.set_selected(index as u32); + assert_eq!(settings.get().row_copy_format(), format); + assert_eq!(second.imp().row_copy_format_row.selected(), index as u32); + } + for (index, format) in RowCopyFormat::ALL.into_iter().enumerate().rev() { + settings + .get() + .set_row_copy_format(format.nick()) + .expect("store copy format"); + assert_eq!(first.imp().row_copy_format_row.selected(), index as u32); + assert_eq!(second.imp().row_copy_format_row.selected(), index as u32); + } + second.imp().row_copy_format_row.set_selected(2); + assert_eq!(first.imp().row_copy_format_row.selected(), 2); + assert_eq!(settings.get().row_copy_format(), RowCopyFormat::Json); + } } diff --git a/linux/crates/platform/src/settings/grid_preferences.rs b/linux/crates/platform/src/settings/grid_preferences.rs index f23cbb69dc..65a184bfd5 100644 --- a/linux/crates/platform/src/settings/grid_preferences.rs +++ b/linux/crates/platform/src/settings/grid_preferences.rs @@ -47,6 +47,50 @@ impl GridRowHeight { } } +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] +pub enum RowCopyFormat { + #[default] + Rows, + RowsWithHeaders, + Json, + Csv, + CsvWithHeaders, + Markdown, +} + +impl RowCopyFormat { + pub const ALL: [Self; 6] = [ + Self::Rows, + Self::RowsWithHeaders, + Self::Json, + Self::Csv, + Self::CsvWithHeaders, + Self::Markdown, + ]; + + pub fn from_nick(nick: &str) -> Self { + match nick { + "rows-headers" => Self::RowsWithHeaders, + "json" => Self::Json, + "csv" => Self::Csv, + "csv-headers" => Self::CsvWithHeaders, + "markdown" => Self::Markdown, + _ => Self::Rows, + } + } + + pub fn nick(self) -> &'static str { + match self { + Self::Rows => "rows", + Self::RowsWithHeaders => "rows-headers", + Self::Json => "json", + Self::Csv => "csv", + Self::CsvWithHeaders => "csv-headers", + Self::Markdown => "markdown", + } + } +} + #[derive(Debug, Clone, PartialEq, Eq)] pub struct GridPreferenceValues { pub show_row_numbers: bool, @@ -54,6 +98,8 @@ pub struct GridPreferenceValues { pub row_height: GridRowHeight, pub null_display: String, pub font: EditorFont, + pub row_copy_format: RowCopyFormat, + pub auto_show_inspector: bool, } impl Default for GridPreferenceValues { @@ -64,6 +110,8 @@ impl Default for GridPreferenceValues { row_height: GridRowHeight::Normal, null_display: "NULL".to_owned(), font: EditorFont::System, + row_copy_format: RowCopyFormat::Rows, + auto_show_inspector: false, } } } @@ -71,6 +119,8 @@ impl Default for GridPreferenceValues { impl GridPreferenceValues { fn read(settings: &gio::Settings) -> Self { Self { + row_copy_format: RowCopyFormat::from_nick(&settings.string(keys::ROW_COPY_FORMAT)), + auto_show_inspector: settings.boolean(keys::AUTO_SHOW_INSPECTOR), 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)), @@ -148,6 +198,8 @@ impl GridPreferences { | keys::NULL_DISPLAY | keys::GRID_USE_SYSTEM_FONT | keys::GRID_FONT + | keys::ROW_COPY_FORMAT + | keys::AUTO_SHOW_INSPECTOR ) && let Some(preferences) = weak.upgrade() { preferences.update(GridPreferenceValues::read(settings)); diff --git a/linux/crates/platform/src/settings/keys.rs b/linux/crates/platform/src/settings/keys.rs index fd4fe976b9..ad5c2b195a 100644 --- a/linux/crates/platform/src/settings/keys.rs +++ b/linux/crates/platform/src/settings/keys.rs @@ -11,6 +11,8 @@ pub const USE_SYSTEM_FONT: &str = "use-system-font"; pub const CUSTOM_FONT: &str = "custom-font"; pub const GRID_USE_SYSTEM_FONT: &str = "grid-use-system-font"; pub const GRID_FONT: &str = "grid-font"; +pub const AUTO_SHOW_INSPECTOR: &str = "auto-show-inspector"; +pub const ROW_COPY_FORMAT: &str = "row-copy-format"; pub const STYLE_SCHEME: &str = "style-scheme"; pub const VIM_KEYBINDINGS: &str = "vim-keybindings"; pub const CONNECT_DIALOG_DRIVER: &str = "connect-dialog-driver"; diff --git a/linux/crates/platform/src/settings/mod.rs b/linux/crates/platform/src/settings/mod.rs index 2ececf6c1d..2f60f4292b 100644 --- a/linux/crates/platform/src/settings/mod.rs +++ b/linux/crates/platform/src/settings/mod.rs @@ -14,7 +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 grid_preferences::{GridPreferenceValues, GridPreferences, GridRowHeight, RowCopyFormat}; pub use window_geometry::WindowGeometry; /// The provider setting's value while the assistant is off. @@ -115,6 +115,22 @@ impl AppSettings { self.set_string(keys::GRID_ROW_HEIGHT, height) } + pub fn auto_show_inspector(&self) -> bool { + self.grid_preferences().snapshot().auto_show_inspector + } + + pub fn set_auto_show_inspector(&self, show: bool) -> Result<(), SettingsError> { + self.set_boolean(keys::AUTO_SHOW_INSPECTOR, show) + } + + pub fn row_copy_format(&self) -> RowCopyFormat { + self.grid_preferences().snapshot().row_copy_format + } + + pub fn set_row_copy_format(&self, format: &str) -> Result<(), SettingsError> { + self.set_string(keys::ROW_COPY_FORMAT, format) + } + pub fn null_display(&self) -> String { self.grid_preferences().snapshot().null_display.clone() } diff --git a/linux/crates/platform/tests/settings.rs b/linux/crates/platform/tests/settings.rs index b30491b437..7a1ed43ba6 100644 --- a/linux/crates/platform/tests/settings.rs +++ b/linux/crates/platform/tests/settings.rs @@ -533,3 +533,54 @@ async fn grid_font_uses_the_shared_snapshot_and_preserves_the_editor_font() -> T assert_eq!(calls.get(), 3); Ok(()) } + +#[glib::async_test] +async fn row_copy_format_publishes_every_format_through_the_shared_model() -> TestResult { + use std::cell::RefCell; + use std::rc::Rc; + use tablepro_linux_platform::settings::RowCopyFormat; + + let fixture = Fixture::new()?; + let preferences = fixture.settings.grid_preferences(); + let original = preferences.snapshot(); + let observed = Rc::new(RefCell::new(Vec::new())); + let updates = observed.clone(); + preferences.connect_changed(move |preferences| updates.borrow_mut().push(preferences.snapshot().row_copy_format)); + + assert_eq!(fixture.settings.row_copy_format(), RowCopyFormat::Rows); + for format in RowCopyFormat::ALL { + fixture.settings.set_row_copy_format(format.nick())?; + assert_eq!(fixture.settings.row_copy_format(), format); + assert_eq!(preferences.snapshot().row_copy_format, format); + assert_eq!(RowCopyFormat::from_nick(format.nick()), format); + } + assert_eq!(observed.borrow().as_slice(), &RowCopyFormat::ALL[1..]); + assert_eq!(original.row_copy_format, RowCopyFormat::Rows); + assert_eq!(RowCopyFormat::from_nick("unknown"), RowCopyFormat::Rows); + Ok(()) +} + +#[glib::async_test] +async fn automatic_details_preference_is_published_in_the_shared_snapshot() -> TestResult { + use gio::prelude::SettingsExt; + use std::cell::RefCell; + use std::rc::Rc; + + let fixture = Fixture::new()?; + let preferences = fixture.settings.grid_preferences(); + let original = preferences.snapshot(); + let observed = Rc::new(RefCell::new(Vec::new())); + let changes = observed.clone(); + preferences.connect_changed(move |preferences| { + changes.borrow_mut().push(preferences.snapshot().auto_show_inspector); + }); + assert!(!fixture.settings.auto_show_inspector()); + + fixture.settings.set_auto_show_inspector(true)?; + assert!(fixture.settings.auto_show_inspector()); + fixture.settings.gio().set_boolean(keys::AUTO_SHOW_INSPECTOR, false)?; + assert!(!fixture.settings.auto_show_inspector()); + assert_eq!(observed.borrow().as_slice(), &[true, false]); + assert!(!original.auto_show_inspector); + Ok(()) +} diff --git a/linux/data/app.tablepro.TablePro.gschema.xml.in b/linux/data/app.tablepro.TablePro.gschema.xml.in index c82785d5ae..6ff41fa29c 100644 --- a/linux/data/app.tablepro.TablePro.gschema.xml.in +++ b/linux/data/app.tablepro.TablePro.gschema.xml.in @@ -89,6 +89,26 @@ How much room a data grid row takes around its text. + + + + + + + + + + "rows" + Format of copied rows + The format Copy writes when several rows are selected. + + + + false + Open row details when a row is selected + Whether selecting a row in a data grid opens its row details pane. + + "NULL" Text for a NULL value diff --git a/linux/data/resources/ui/preferences-data-browser-group.ui b/linux/data/resources/ui/preferences-data-browser-group.ui index 40c40db731..7d26c09c52 100644 --- a/linux/data/resources/ui/preferences-data-browser-group.ui +++ b/linux/data/resources/ui/preferences-data-browser-group.ui @@ -43,6 +43,30 @@ + + + Open Row Details on Selection + Selecting a row opens its details pane + + + + + Copy Rows As + The format Copy writes when several rows are selected + + + + TSV + TSV with Headers + JSON + CSV + CSV with Headers + Markdown + + + + + Text for NULL diff --git a/linux/docs/state-management.md b/linux/docs/state-management.md index 5aca04ebab..bb615ebec6 100644 --- a/linux/docs/state-management.md +++ b/linux/docs/state-management.md @@ -93,7 +93,7 @@ A tab belongs to its session, and a session to one window ([decisions/0028-sessi ## 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. Each grid owns its font CSS provider, scoped to that grid and removed when the grid closes. Its custom font description supplies both the rendered font and column width measurement. +`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. Each grid owns its font CSS provider, scoped to that grid and removed when the grid closes. Its custom font description supplies both the rendered font and column width measurement. Automatic Row Details opening reads the same snapshot when the selection changes and opens only for a nonempty selection. Closing it keeps it closed through focus changes and clearing the selection. Turning the preference off leaves an open pane alone. Copy reads the row format from the shared snapshot when it runs; a single focused cell keeps its value format, and Copy As keeps the requested format. 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. diff --git a/linux/docs/storage.md b/linux/docs/storage.md index d70a66a716..6af98de356 100644 --- a/linux/docs/storage.md +++ b/linux/docs/storage.md @@ -345,6 +345,8 @@ The schema id is the application id and the path follows it: `app.tablepro.Table | `show-row-numbers` | `b` | `true` | | | `grid-use-system-font` | `b` | `true` | | | `grid-font` | `s` | `Monospace 10` | | +| `auto-show-inspector` | `b` | `false` | | +| `row-copy-format` | `s` | `rows` | rows, rows-headers, json, csv, csv-headers, markdown | | `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` | |