diff --git a/linux/ARCHITECTURE.md b/linux/ARCHITECTURE.md index e687edd48e..37a8c70a1b 100644 --- a/linux/ARCHITECTURE.md +++ b/linux/ARCHITECTURE.md @@ -87,7 +87,7 @@ Each window is a `SessionWindow` (`crates/app/src/ui/session_window/`) for its c - When a run, a save or an export ends in a tab the user is not looking at, the window's `WorkNotifier` sends a desktop notification through `GApplication`: one per tab, with no time threshold, as GNOME Console does. A tab counts as looked at while the window is active and the tab is in front. The notification names the tab and the connection only, since it can show on the lock screen, so an editor tab goes by its number rather than its script. Clicking it runs `app.focus-tab`, which brings the tab forward in its window. It is withdrawn once the tab is in front of an active window, when the tab closes, and when the session goes. A save that settles while a close prompt covering its tab decides is not notified: the prompt waited for it in front of the user, and then closes the tab or asks about it again. - The window's content is the page itself, never a wrapper, and is at least 360 by 294 pixels. Each page has its own header bars and its own `AdwToastOverlay`, and the window's toasts go to the page on screen. The menus come from `data/resources/gtk/menus.ui`, which `GtkApplication` loads at startup. Main Menu above the sidebar holds app and connection-library commands. Session Menu in the content header holds commands for the session in front, including Safe Mode. -The `WorkspaceShell` (`crates/app/src/ui/workspace/workspace_shell.rs`) is what a window has once: the connection tree in the sidebar, the one tab view every session's tabs share, the header bars, the assistant's column and the toasts. Its `front` property is the session of the tab in front, or with no tab the newest session or the one last shown, and the session in front speaks for the window: the header bars, the window title, its banners, its assistant pane and the window's actions read it through bindings. The `Workspace` (`crates/app/src/ui/workspace/`) is one session: its sidebar model, which the tree shows as one list per schema and a search as one flat list of what it found, its tabs, its banners and its assistant pane, and the `title`, `subtitle`, `window-title` and `icon-name` properties the shell binds. The shell's template puts the `AdwTabOverview` at the root, as libadwaita expects, around an `AdwBreakpointBin` with an `AdwOverlaySplitView`: the sidebar and the tabs each have their own header bar. Below 600sp the sidebar collapses into an overlay, and below 450sp an `AdwTabButton` takes the tab bar's place. The `show-sidebar` window action and F9 show and hide the sidebar. Below the tree, a bar holds the Add menu the session in front builds from what its engine makes and whether it may write; the Favorites scope hides it. The shell adds the window's workspace actions once, each sent to the session in front, and removes them when it shuts down. A workspace follows its session's health and object list through `WatchForwarder`s and tells the window what it holds through its `dirty-changed`, `saves-in-flight-changed`, `work-completed` and `tabs-changed` signals. Its `WorkspaceHandle` runs the saves and tells the close prompts what closing any part of it would lose. Its `ExportLedger` writes exports off the GTK thread: the rows are encoded on the runtime and GIO writes them. An export takes the rows a grid holds, or every row of a table or an editor statement, streamed through `Connection::stream_read` on a read-only connection of its own with no deadline. `ReplaceFileWriter` removes a file the export made when it stops or fails. An existing regular file gets a temporary file beside it, renamed over it at the end, so a stopped export leaves it as it was. GLib truncates a symbolic link's target, a hard-linked file or a file in a folder that refuses the temporary file when the export opens it, and a stopped export then says that file is incomplete. [Workspace tab system](#workspace-tab-system) covers its tabs, and `../core/ARCHITECTURE.md`, Sessions and health, the `Session` itself. +The `WorkspaceShell` (`crates/app/src/ui/workspace/workspace_shell.rs`) is what a window has once: the connection tree in the sidebar, the one tab view every session's tabs share, the header bars, the assistant's column and the toasts. Its `front` property is the session of the tab in front, or with no tab the newest session or the one last shown, and the session in front speaks for the window: the header bars, the window title, its banners, its assistant pane and the window's actions read it through bindings. The `Workspace` (`crates/app/src/ui/workspace/`) is one session: its sidebar model, which the tree shows as one list per schema and a search as one flat list of what it found, its tabs, its banners and its assistant pane, and the `title`, `subtitle`, `window-title` and `icon-name` properties the shell binds. The shell's template puts the `AdwTabOverview` at the root, as libadwaita expects, around an `AdwBreakpointBin` with an `AdwOverlaySplitView`: the sidebar and the tabs each have their own header bar. Below 600sp the sidebar collapses into an overlay, and below 450sp an `AdwTabButton` takes the tab bar's place. The `show-sidebar` window action and F9 show and hide the sidebar. Below the tree, a bar holds the Add menu the session in front builds from what its engine makes and whether it may write; the Favorites scope hides it. A handle on the sidebar's edge sets the most it takes ([toolkit-workarounds.md](docs/toolkit-workarounds.md#a-sidebar-the-user-can-widen)). The shell adds the window's workspace actions once, each sent to the session in front, and removes them when it shuts down. A workspace follows its session's health and object list through `WatchForwarder`s and tells the window what it holds through its `dirty-changed`, `saves-in-flight-changed`, `work-completed` and `tabs-changed` signals. Its `WorkspaceHandle` runs the saves and tells the close prompts what closing any part of it would lose. Its `ExportLedger` writes exports off the GTK thread: the rows are encoded on the runtime and GIO writes them. An export takes the rows a grid holds, or every row of a table or an editor statement, streamed through `Connection::stream_read` on a read-only connection of its own with no deadline. `ReplaceFileWriter` removes a file the export made when it stops or fails. An existing regular file gets a temporary file beside it, renamed over it at the end, so a stopped export leaves it as it was. GLib truncates a symbolic link's target, a hard-linked file or a file in a folder that refuses the temporary file when the export opens it, and a stopped export then says that file is incomplete. [Workspace tab system](#workspace-tab-system) covers its tabs, and `../core/ARCHITECTURE.md`, Sessions and health, the `Session` itself. ## UI architecture @@ -141,7 +141,7 @@ Each engine builds its trust as `../core/ARCHITECTURE.md`, Trust, says. On Linux The app tells each session what its connection cannot see, as `../core/ARCHITECTURE.md`, Sessions and health, describes: `GNetworkMonitor` reports a change in the network, and while a session is open a 5 s timer compares `CLOCK_BOOTTIME` with `CLOCK_MONOTONIC` to notice a suspend. A session parked on an SSH host key shows the fingerprint in its banner's Review Key. When the review cannot accept the key, because ssh's configuration takes keys only from known_hosts or the key is revoked, its dialog offers Retry for after the user fixes the key outside TablePro. -The sidebar's tree lists an open connection's schemas, the default one first and the engine's own last, and each schema's tables and views, with one menu whose items carry the table they act on. Its rows come from a `SidebarIndex`, sorted by collation key and given its search keys on a blocking thread, behind a `GListModel` that makes a row's object only when asked for it; `GtkTreeListModel` asks for every table of a schema it opens. Each search, and each new list, picks the rows it keeps on a blocking thread too. What a search finds is a flat `GtkListView`, a section per schema in a `GtkFlattenListModel` that reads only the rows on screen, and it takes a search's rows in one removal and one addition unless a newer search or list overtook them. The Schemas button in the sidebar's bottom bar keeps the schemas the tree and its search list, by connection and database in the filter settings file; none kept lists every schema, and a banner says how many a filter leaves out. It follows every schema's list through a watch the window drops before the session closes, and reads that list again when a reconnect commits the default schema's; a refresh that fails keeps the list and says so in a toast. The editor's completion reads the catalog when it opens: the default schema's objects, a named schema's objects after `schema.`, and the columns of the tables the statement names. Its candidates are built with that read on the runtime, and its `ProposalList` ranks them for the typed word and makes a proposal only for a row GtkSourceView shows. Either list thus costs the GTK thread the rows on screen, not the catalog, which the large-catalog case checks with 50,000 tables ([testing.md](docs/testing.md#large-catalog-case)). +The sidebar's tree lists an open connection's schemas, the default one first and the engine's own last, and each schema's tables, after a row for each other kind it holds (views, materialized views, foreign tables, sequences, procedures, functions, triggers) that opens on that kind's objects, with one menu whose items carry the table they act on. Each kind is one stretch of its schema's run of the index, so a group's row lists it as lazily as a schema lists its tables; a group keeps its node across new lists, so the tree keeps it open. Its rows come from a `SidebarIndex`, sorted by collation key and given its search keys on a blocking thread, behind a `GListModel` that makes a row's object only when asked for it; `GtkTreeListModel` asks for every table of a schema it opens. Each search, and each new list, picks the rows it keeps on a blocking thread too. What a search finds is a flat `GtkListView`, a section per schema in a `GtkFlattenListModel` that reads only the rows on screen, and it takes a search's rows in one removal and one addition unless a newer search or list overtook them. The Schemas button in the sidebar's bottom bar keeps the schemas the tree and its search list, by connection and database in the filter settings file; none kept lists every schema, and a banner says how many a filter leaves out. It follows every schema's list through a watch the window drops before the session closes, and reads that list again when a reconnect commits the default schema's; a refresh that fails keeps the list and says so in a toast. The editor's completion reads the catalog when it opens: the default schema's objects, a named schema's objects after `schema.`, and the columns of the tables the statement names. Its candidates are built with that read on the runtime, and its `ProposalList` ranks them for the typed word and makes a proposal only for a row GtkSourceView shows. Either list thus costs the GTK thread the rows on screen, not the catalog, which the large-catalog case checks with 50,000 tables ([testing.md](docs/testing.md#large-catalog-case)). ## Workspace tab system diff --git a/linux/changelog.d/4155.added.md b/linux/changelog.d/4155.added.md new file mode 100644 index 0000000000..c3b5c02fee --- /dev/null +++ b/linux/changelog.d/4155.added.md @@ -0,0 +1 @@ +The sidebar can be widened by dragging its edge or with the arrow keys, and every window keeps that width. diff --git a/linux/changelog.d/4159.changed.md b/linux/changelog.d/4159.changed.md new file mode 100644 index 0000000000..0d26b00ee2 --- /dev/null +++ b/linux/changelog.d/4159.changed.md @@ -0,0 +1 @@ +The sidebar lists a schema's views, sequences, routines and triggers in a row for each kind, above its tables. diff --git a/linux/crates/app/src/ui/workspace/mod.rs b/linux/crates/app/src/ui/workspace/mod.rs index 98dc26594a..19eecb0954 100644 --- a/linux/crates/app/src/ui/workspace/mod.rs +++ b/linux/crates/app/src/ui/workspace/mod.rs @@ -26,6 +26,7 @@ mod schema_chooser; mod schema_filter; mod session_watches; mod sidebar; +mod sidebar_width; mod status_pages; mod structure; mod structure_target; diff --git a/linux/crates/app/src/ui/workspace/sidebar/connection_tree.rs b/linux/crates/app/src/ui/workspace/sidebar/connection_tree.rs index 7eefc7cba8..5a43ffc99d 100644 --- a/linux/crates/app/src/ui/workspace/sidebar/connection_tree.rs +++ b/linux/crates/app/src/ui/workspace/sidebar/connection_tree.rs @@ -782,9 +782,7 @@ impl TreeInner { let Some(node) = row.item().and_downcast::() else { continue; }; - if node.kind() != NodeKind::Schema { - rows.extend(child_rows(&row)); - } + rows.extend(rows_holding_nodes(&row, &node)); open.insert(node); } open @@ -804,9 +802,7 @@ impl TreeInner { continue; } expand(&row); - if node.kind() != NodeKind::Schema { - rows.extend(child_rows(&row)); - } + rows.extend(rows_holding_nodes(&row, &node)); } } @@ -829,7 +825,7 @@ impl TreeInner { let lone = (schemas.n_items() == 1) .then(|| schemas.item(0).and_downcast::()) .flatten() - .filter(|schema| schema.rows().is_some_and(|rows| rows.n_items() > 0)); + .filter(|schema| schema.children().is_some_and(|rows| rows.n_items() > 0)); { let mut branches = self.branches.borrow_mut(); let Some(branch) = branches.get_mut(key) else { @@ -979,15 +975,21 @@ impl TreeInner { table: &TableRef, open: bool, ) -> Option { - let (schema, offset) = self.view_of(key)?.locate(table)?; + let located = self.view_of(key)?.locate(table)?; if open { expand(connection); } - let schema = child_row(connection, &schema)?; + let mut parent = child_row(connection, &located.schema)?; if open { - expand(&schema); + expand(&parent); } - schema.child_row(offset) + if let Some(group) = &located.group { + parent = child_row(&parent, group)?; + if open { + expand(&parent); + } + } + parent.child_row(located.offset) } /// Select the row of `table`, or of the session's connection, in the @@ -1103,7 +1105,7 @@ impl TreeInner { }; match node.kind() { NodeKind::Connection => activate_connection(&self.pane(which).list_view, node, self.stored(node)), - NodeKind::Group | NodeKind::Schema => { + NodeKind::Group | NodeKind::Schema | NodeKind::ObjectGroup => { if let Some(row) = self.rows.row(position).filter(|_| which == Which::Tree) { row.set_expanded(!row.is_expanded()); } @@ -1223,7 +1225,7 @@ impl TreeInner { } NodeKind::Connection => self.connection_menu(node), NodeKind::Group => self.group_menu(node), - NodeKind::Placeholder => None, + NodeKind::ObjectGroup | NodeKind::Placeholder => None, } } @@ -1246,7 +1248,7 @@ impl TreeInner { match node.kind() { NodeKind::Group => node.group_id().map(LibraryItem::Group), NodeKind::Connection => self.stored(node).map(LibraryItem::Connection), - NodeKind::Schema | NodeKind::Placeholder => None, + NodeKind::Schema | NodeKind::ObjectGroup | NodeKind::Placeholder => None, } } @@ -1741,8 +1743,18 @@ fn top_rows(tree: >k::TreeListModel) -> Vec { (0..count).filter_map(|position| tree.child_row(position)).collect() } -/// The rows under an open row, which never holds a schema's tables when -/// walked from the roots. +// A schema's rows below its groups are objects, which may be many thousands. +fn rows_holding_nodes(row: >k::TreeListRow, node: &TreeNode) -> Vec { + match node.kind() { + NodeKind::Schema => { + let groups = node.groups().map_or(0, |groups| groups.n_items()); + (0..groups).filter_map(|position| row.child_row(position)).collect() + } + NodeKind::ObjectGroup | NodeKind::Placeholder => Vec::new(), + NodeKind::Group | NodeKind::Connection => child_rows(row), + } +} + fn child_rows(row: >k::TreeListRow) -> Vec { let count = row.children().map_or(0, |children| children.n_items()); (0..count).filter_map(|position| row.child_row(position)).collect() diff --git a/linux/crates/app/src/ui/workspace/sidebar/sidebar_index.rs b/linux/crates/app/src/ui/workspace/sidebar/sidebar_index.rs index bd46fca4b3..47f8bdc4a3 100644 --- a/linux/crates/app/src/ui/workspace/sidebar/sidebar_index.rs +++ b/linux/crates/app/src/ui/workspace/sidebar/sidebar_index.rs @@ -312,14 +312,94 @@ fn qualified(schema: Option<&str>, name: &str) -> String { } } -/// What the grid pages through first, then each kind that has SQL to read. +// The macOS app's order. Tables, partitions, dictionaries and keys stay in the schema's own list. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub(crate) enum ObjectGroup { + Views, + MaterializedViews, + ForeignTables, + Sequences, + Procedures, + Functions, + Triggers, +} + +const GROUPS: [ObjectGroup; 7] = [ + ObjectGroup::Views, + ObjectGroup::MaterializedViews, + ObjectGroup::ForeignTables, + ObjectGroup::Sequences, + ObjectGroup::Procedures, + ObjectGroup::Functions, + ObjectGroup::Triggers, +]; + +impl ObjectGroup { + fn of(kind: ObjectKind) -> Option { + match kind { + ObjectKind::View => Some(Self::Views), + ObjectKind::MaterializedView => Some(Self::MaterializedViews), + ObjectKind::ForeignTable => Some(Self::ForeignTables), + ObjectKind::Sequence => Some(Self::Sequences), + ObjectKind::Procedure => Some(Self::Procedures), + ObjectKind::Function => Some(Self::Functions), + ObjectKind::Trigger => Some(Self::Triggers), + // A kind the core adds later stays with the tables until it has a group. + _ => None, + } + } + + pub(crate) fn title(self) -> String { + use crate::i18n::pgettext; + match self { + Self::Views => pgettext("sidebar group", "Views"), + Self::MaterializedViews => pgettext("sidebar group", "Materialized Views"), + Self::ForeignTables => pgettext("sidebar group", "Foreign Tables"), + Self::Sequences => pgettext("sidebar group", "Sequences"), + Self::Procedures => pgettext("sidebar group", "Procedures"), + Self::Functions => pgettext("sidebar group", "Functions"), + Self::Triggers => pgettext("sidebar group", "Triggers"), + } + } +} + +// Each group is then one stretch of its section's run, after the objects no group takes. fn kind_rank(kind: ObjectKind) -> u8 { - match kind { - ObjectKind::Function => 1, - ObjectKind::Procedure => 2, - ObjectKind::Sequence => 3, - ObjectKind::Trigger => 4, - _ => 0, + ObjectGroup::of(kind) + .and_then(|group| GROUPS.iter().position(|each| *each == group)) + .map_or(0, |at| u8::try_from(at + 1).unwrap_or(u8::MAX)) +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub(crate) struct GroupRun { + pub(crate) group: Option, + pub(crate) start: u32, + pub(crate) end: u32, +} + +impl SidebarIndex { + // The objects no group takes come first, even when there are none. + pub(crate) fn group_runs(&self, run: SectionRun) -> Vec { + let entries = self + .entries + .get(run.start as usize..run.end as usize) + .unwrap_or_default(); + let mut runs = Vec::new(); + let mut start = 0; + for (rank, group) in std::iter::once(None).chain(GROUPS.map(Some)).enumerate() { + let end = + start + entries[start..].partition_point(|entry| usize::from(kind_rank(entry.object.kind)) <= rank); + if group.is_none() || end > start { + let at = |offset: usize| run.start + u32::try_from(offset).unwrap_or(u32::MAX); + runs.push(GroupRun { + group, + start: at(start), + end: at(end), + }); + } + start = end; + } + runs } } @@ -502,17 +582,69 @@ mod tests { assert_eq!( kinds, [ - row("active_users", ObjectKind::View, None), row("users", ObjectKind::Table, None), + row("active_users", ObjectKind::View, None), + row("ids", ObjectKind::Sequence, None), + row("archive", ObjectKind::Procedure, None), row("add", ObjectKind::Function, None), row("refresh", ObjectKind::Function, None), - row("archive", ObjectKind::Procedure, None), - row("ids", ObjectKind::Sequence, None), row("audit", ObjectKind::Trigger, Some("users")), row("audit", ObjectKind::Trigger, Some("orders")), ] ); assert_eq!(index.runs().len(), 1, "every kind shares its schema's section"); + let groups: Vec<(Option, u32, u32)> = index + .group_runs(index.runs()[0]) + .into_iter() + .map(|run| (run.group, run.start, run.end)) + .collect(); + assert_eq!( + groups, + [ + (None, 0, 1), + (Some(ObjectGroup::Views), 1, 2), + (Some(ObjectGroup::Sequences), 2, 3), + (Some(ObjectGroup::Procedures), 3, 4), + (Some(ObjectGroup::Functions), 4, 6), + (Some(ObjectGroup::Triggers), 6, 8), + ] + ); + } + + #[test] + fn tables_partitions_dictionaries_and_keys_have_no_group() { + for kind in [ + ObjectKind::Table, + ObjectKind::PartitionedTable, + ObjectKind::Dictionary, + ObjectKind::Key(tablepro_core::meta::KeyKind::Hash), + ] { + assert_eq!(ObjectGroup::of(kind), None, "{kind:?}"); + assert_eq!(kind_rank(kind), 0, "{kind:?} sorts with the tables"); + } + } + + #[test] + fn a_schema_of_views_alone_has_no_objects_of_its_own() { + let index = SidebarIndex::build(&[object(Some("public"), "recent", ObjectKind::View)], &[]); + + let groups = index.group_runs(index.runs()[0]); + + assert_eq!( + groups, + [ + GroupRun { + group: None, + start: 0, + end: 0 + }, + GroupRun { + group: Some(ObjectGroup::Views), + start: 0, + end: 1 + }, + ] + ); } #[test] diff --git a/linux/crates/app/src/ui/workspace/sidebar/sidebar_model.rs b/linux/crates/app/src/ui/workspace/sidebar/sidebar_model.rs index aa12ae8249..4ebca0210b 100644 --- a/linux/crates/app/src/ui/workspace/sidebar/sidebar_model.rs +++ b/linux/crates/app/src/ui/workspace/sidebar/sidebar_model.rs @@ -8,7 +8,7 @@ use gtk4::prelude::*; use tablepro_core::meta::{ObjectKind, TableRef}; use super::object_target::ObjectTarget; -use super::sidebar_index::{SidebarIndex, search_key}; +use super::sidebar_index::{ObjectGroup, SectionRun, SidebarIndex, search_key}; use super::sidebar_list::{Entries, SidebarList}; use super::tree_node::TreeNode; use crate::ui::store_sync; @@ -177,9 +177,7 @@ impl SidebarModel { .unwrap_or_else(|| TreeNode::schema(§ion.title, None)); node.set_schema_name(section.schema.clone()); let entries = run.map_or_else(Entries::default, |(_, run)| Entries::Run(run.start, run.end)); - if let Some(rows) = node.rows() { - rows.show(&index, entries.clone()); - } + show_groups(&node, &index, run.map(|(_, run)| run)); let results = match &mut found { Found::Nothing => Entries::default(), Found::Everything => entries, @@ -233,30 +231,79 @@ impl SidebarModel { index.entry(entry).map(|entry| entry.object.kind) } - /// The schema whose tables hold `table`, and where among them. - pub(crate) fn locate(&self, table: &TableRef) -> Option<(TreeNode, u32)> { - self.locate_in(table, TreeNode::rows) + pub(crate) fn locate(&self, table: &TableRef) -> Option { + let entry = self.shown.borrow().find(&ObjectTarget::Rows(table.clone()))?; + nodes_of(&self.schemas).into_iter().find_map(|schema| { + let groups = schema.groups()?; + if let Some(offset) = schema.rows().and_then(|rows| rows.position_of_entry(entry)) { + return Some(Located { + offset: groups.n_items() + offset, + group: None, + schema, + }); + } + nodes_of(&groups).into_iter().find_map(|group| { + let offset = group.rows()?.position_of_entry(entry)?; + Some(Located { + schema: schema.clone(), + group: Some(group), + offset, + }) + }) + }) } /// The schema whose found tables hold `table`, and where among them. pub(crate) fn locate_found(&self, table: &TableRef) -> Option<(TreeNode, u32)> { - self.locate_in(table, TreeNode::found_rows) + let entry = self.shown.borrow().find(&ObjectTarget::Rows(table.clone()))?; + nodes_of(&self.schemas).into_iter().find_map(|node| { + let offset = node.found_rows()?.position_of_entry(entry)?; + Some((node, offset)) + }) } +} - fn locate_in( - &self, - table: &TableRef, - list: fn(&TreeNode) -> Option, - ) -> Option<(TreeNode, u32)> { - let entry = self.shown.borrow().find(&ObjectTarget::Rows(table.clone()))?; - let store = &self.schemas; - (0..store.n_items()) - .filter_map(|at| store.item(at).and_downcast::()) - .find_map(|node| { - let offset = list(&node)?.position_of_entry(entry)?; - Some((node, offset)) - }) +// `offset` is under the group when there is one, else under the schema, after its groups. +#[derive(Debug)] +pub(crate) struct Located { + pub(crate) schema: TreeNode, + pub(crate) group: Option, + pub(crate) offset: u32, +} + +fn nodes_of(store: &impl IsA) -> Vec { + (0..store.n_items()) + .filter_map(|at| store.item(at).and_downcast::()) + .collect() +} + +// A group keeps its node across lists, so the tree keeps it open. +fn show_groups(schema: &TreeNode, index: &Arc, run: Option) { + let Some(store) = schema.groups() else { + return; + }; + let held: HashMap = nodes_of(&store) + .into_iter() + .filter_map(|node| Some((node.object_group()?, node))) + .collect(); + let mut own = Entries::default(); + let mut groups = Vec::new(); + for group_run in run.map(|run| index.group_runs(run)).unwrap_or_default() { + let entries = Entries::Run(group_run.start, group_run.end); + let Some(group) = group_run.group else { + own = entries; + continue; + }; + let node = held.get(&group).cloned().unwrap_or_else(|| TreeNode::objects(group)); + if let Some(rows) = node.rows() { + rows.show(index, entries); + } + groups.push(node); } + if let Some(rows) = schema.rows() { + rows.show(index, own); + } + store_sync::sync(&store, &groups); } fn flatten(first: &gio::ListStore, then: &gio::ListStore) -> gtk::FlattenListModel { @@ -329,9 +376,11 @@ mod tests { nodes(store) .into_iter() .map(|node| { + let groups = node.groups().map(|groups| nodes(&groups.upcast())).unwrap_or_default(); + let lists = std::iter::once(node.rows()).chain(groups.iter().map(TreeNode::rows)); ( node.title(), - node.children().map(|list| names(&list)).unwrap_or_default(), + lists.flatten().flat_map(|list| names(&list.upcast())).collect(), ) }) .collect() @@ -491,6 +540,75 @@ mod tests { assert_eq!(model.kind_of(&rows("active_users")), Some(ObjectKind::View)); } + fn under(node: &TreeNode) -> Vec { + let Some(children) = node.children() else { + return Vec::new(); + }; + (0..children.n_items()) + .filter_map(|at| children.item(at)) + .filter_map(|item| match item.downcast::() { + Ok(group) => Some(group.title()), + Err(item) => item.downcast::().ok().map(|object| object.name()), + }) + .collect() + } + + #[gtk4::test] + fn a_schema_lists_a_group_for_each_other_kind_before_its_tables() { + let model = SidebarModel::new(); + let of = |kind, name: &str| ObjectInfo { + kind, + ..object("public", name) + }; + let objects = [ + of(ObjectKind::Function, "total"), + object("public", "users"), + of(ObjectKind::Sequence, "ids"), + of(ObjectKind::View, "active_users"), + object("public", "orders"), + of(ObjectKind::Function, "add"), + ]; + replace(&model, &objects, &[]); + + let schema = nodes(&model.schemas()).remove(0); + assert_eq!(under(&schema), ["Views", "Sequences", "Functions", "orders", "users"]); + let groups = nodes(&schema.groups().expect("the schema's groups").upcast()); + assert_eq!(under(&groups[2]), ["add", "total"]); + assert_eq!(groups[0].object_group(), Some(ObjectGroup::Views)); + + replace(&model, &objects[..5], &[]); + let again = nodes(&model.schemas()).remove(0); + let kept = nodes(&again.groups().expect("the schema's groups").upcast()); + assert_eq!( + kept[0], groups[0], + "a new list keeps the group, and the tree keeps it open" + ); + assert_eq!(under(&kept[2]), ["total"]); + + let view = model + .locate(&TableRef::new(Some("public".to_owned()), "active_users")) + .expect("the view"); + assert_eq!(view.group.as_ref(), Some(&kept[0])); + assert_eq!(view.offset, 0); + let orders = model + .locate(&TableRef::new(Some("public".to_owned()), "orders")) + .expect("the table"); + assert_eq!((orders.group, orders.offset), (None, 3), "after the three groups"); + } + + #[gtk4::test] + fn a_key_listing_has_no_groups() { + let model = SidebarModel::new(); + let key = ObjectInfo { + kind: ObjectKind::Key(tablepro_core::meta::KeyKind::Hash), + ..object("public", "session:1") + }; + let asked = model.replace(SidebarIndex::keys(&[key], "Database 0".to_owned())); + model.show(asked.work_out()).expect("the rows"); + + assert_eq!(under(&nodes(&model.schemas()).remove(0)), ["session:1"]); + } + #[gtk4::test] fn a_table_is_located_in_its_schema_and_among_the_results() { let model = SidebarModel::new(); @@ -505,8 +623,9 @@ mod tests { ); let users = TableRef::new(Some("sales".to_owned()), "users"); - let (node, offset) = model.locate(&users).expect("the table in its schema"); - assert_eq!((node.title(), offset), ("sales".to_owned(), 0)); + let located = model.locate(&users).expect("the table in its schema"); + assert_eq!((located.schema.title(), located.offset), ("sales".to_owned(), 0)); + assert!(located.group.is_none()); assert!(model.locate_found(&users).is_none(), "found with no search"); search(&model, "user"); diff --git a/linux/crates/app/src/ui/workspace/sidebar/sidebar_view.rs b/linux/crates/app/src/ui/workspace/sidebar/sidebar_view.rs index 4e2135d835..15163a42e2 100644 --- a/linux/crates/app/src/ui/workspace/sidebar/sidebar_view.rs +++ b/linux/crates/app/src/ui/workspace/sidebar/sidebar_view.rs @@ -200,7 +200,7 @@ impl SidebarView { } /// The schema whose tables hold `table`, and where among them. - pub(crate) fn locate(&self, table: &TableRef) -> Option<(TreeNode, u32)> { + pub(crate) fn locate(&self, table: &TableRef) -> Option { self.inner.model.locate(table) } diff --git a/linux/crates/app/src/ui/workspace/sidebar/tests.rs b/linux/crates/app/src/ui/workspace/sidebar/tests.rs index f17fc569ff..6cef012271 100644 --- a/linux/crates/app/src/ui/workspace/sidebar/tests.rs +++ b/linux/crates/app/src/ui/workspace/sidebar/tests.rs @@ -1264,6 +1264,7 @@ fn a_row_tells_a_screen_reader_its_kind() { ); shown.open(&alpha, &view); shown.row("public").set_expanded(true); + shown.row("Views").set_expanded(true); let description = |name: &str| { let row = shown.row_widget(name); @@ -1273,8 +1274,52 @@ fn a_row_tells_a_screen_reader_its_kind() { assert_eq!(description("orders").as_deref(), Some("Table")); assert_eq!(description("totals").as_deref(), Some("View")); assert_eq!(description("public").as_deref(), Some("Schema")); + assert_eq!(description("Views").as_deref(), Some("1 object")); assert_eq!(description("Alpha").as_deref(), Some("Connection, connected")); assert_eq!(description("Beta").as_deref(), Some("Connection")); + + let view_named = |name: &str| ObjectInfo { + kind: ObjectKind::View, + ..object("public", name) + }; + view.show(SidebarIndex::build( + &[object("public", "orders"), view_named("totals"), view_named("weekly")], + &public(), + )); + assert_eq!( + description("Views").as_deref(), + Some("2 objects"), + "a new list recounts the group" + ); +} + +#[gtk4::test] +fn other_kinds_sit_in_groups_that_open_reveal_their_objects_and_offer_no_menu() { + let alpha = connection("Alpha", None); + let shown = Shown::new(std::slice::from_ref(&alpha)); + let totals = ObjectInfo { + kind: ObjectKind::View, + ..object("public", "totals") + }; + let (view, _) = session(&[object("public", "orders"), totals], every_affordance()); + let key = shown.open(&alpha, &view); + shown.row("Alpha").set_expanded(true); + shown.row("public").set_expanded(true); + assert_eq!(shown.rows(), ["Alpha", "public", "Views", "orders"]); + + shown.activate("Views"); + assert_eq!(shown.rows(), ["Alpha", "public", "Views", "totals", "orders"]); + shown.menu("Views"); + assert!(!shown.popover().is_visible(), "a group has a menu"); + shown.activate("Views"); + assert_eq!(shown.rows(), ["Alpha", "public", "Views", "orders"]); + + shown.tree.select(Some(&key), Some(&table("totals"))); + assert_eq!( + shown.selected().as_deref(), + Some("totals"), + "the view's group stayed folded" + ); } #[gtk4::test] diff --git a/linux/crates/app/src/ui/workspace/sidebar/tree_node.rs b/linux/crates/app/src/ui/workspace/sidebar/tree_node.rs index d9f8eb160d..9579f92b99 100644 --- a/linux/crates/app/src/ui/workspace/sidebar/tree_node.rs +++ b/linux/crates/app/src/ui/workspace/sidebar/tree_node.rs @@ -7,6 +7,7 @@ use gtk4::subclass::prelude::*; use tablepro_session::SessionKey; use uuid::Uuid; +use super::sidebar_index::ObjectGroup; use super::sidebar_list::SidebarList; /// What a row of the connection tree above the tables stands for. @@ -20,6 +21,7 @@ pub(crate) enum NodeKind { Connection, /// One schema, or database, of an open connection. Schema, + ObjectGroup, /// Says an open connection lists nothing. Placeholder, } @@ -38,6 +40,10 @@ mod imp { pub(super) schema: RefCell>, /// What the tree lists under the row. pub(super) children: RefCell>, + // A schema's or a group's objects, which a schema lists after its groups. + pub(super) rows: RefCell>, + pub(super) groups: RefCell>, + pub(super) object_group: Cell>, /// A schema's tables the search finds. pub(super) found: RefCell>, #[property(get, set)] @@ -101,11 +107,36 @@ impl TreeNode { let node = Self::of(NodeKind::Schema, title); let imp = node.imp(); imp.schema.replace(schema); - imp.children.replace(Some(SidebarList::new().upcast())); + let (groups, rows) = (gio::ListStore::new::(), SidebarList::new()); + let models = gio::ListStore::new::(); + models.append(&groups); + models.append(&rows); + imp.children + .replace(Some(gtk4::FlattenListModel::new(Some(models)).upcast())); + imp.groups.replace(Some(groups)); + imp.rows.replace(Some(rows)); imp.found.replace(Some(SidebarList::new().upcast())); node } + pub(crate) fn objects(group: ObjectGroup) -> Self { + let node = Self::of(NodeKind::ObjectGroup, &group.title()); + let imp = node.imp(); + let rows = SidebarList::new(); + imp.children.replace(Some(rows.clone().upcast())); + imp.rows.replace(Some(rows)); + imp.object_group.set(Some(group)); + node + } + + pub(crate) fn object_group(&self) -> Option { + self.imp().object_group.get() + } + + pub(crate) fn groups(&self) -> Option { + self.imp().groups.borrow().clone() + } + pub(crate) fn placeholder(title: &str) -> Self { Self::of(NodeKind::Placeholder, title) } @@ -154,7 +185,7 @@ impl TreeNode { /// A schema's tables. pub(crate) fn rows(&self) -> Option { - self.children().and_downcast::() + self.imp().rows.borrow().clone() } /// The schema's tables the search finds. diff --git a/linux/crates/app/src/ui/workspace/sidebar/tree_row.rs b/linux/crates/app/src/ui/workspace/sidebar/tree_row.rs index 21e1ff8068..b0c4079e2e 100644 --- a/linux/crates/app/src/ui/workspace/sidebar/tree_row.rs +++ b/linux/crates/app/src/ui/workspace/sidebar/tree_row.rs @@ -7,6 +7,7 @@ use gtk4::{glib, pango}; use libadwaita as adw; use tablepro_session::SessionKey; +use super::sidebar_list::SidebarList; use super::sidebar_object::SidebarObject; use super::tree_menu::DISCONNECT_SESSION; use super::tree_node::{NodeKind, TreeNode}; @@ -32,6 +33,8 @@ mod imp { pub(super) bindings: RefCell>, pub(super) expansion: RefCell>, pub(super) emptiness: RefCell>, + // A new list changes the count of a kind's group whose row stays bound. + pub(super) counted: RefCell>, // The expander still says open or folded from an earlier row, which GTK leaves on it. pub(super) stated: Cell, } @@ -57,6 +60,7 @@ mod imp { bindings: RefCell::new(Vec::new()), expansion: RefCell::new(None), emptiness: RefCell::new(None), + counted: RefCell::new(None), stated: Cell::new(false), } } @@ -214,6 +218,9 @@ impl TreeRow { if let Some((store, watch)) = imp.emptiness.take() { store.disconnect(watch); } + if let Some((rows, watch)) = imp.counted.take() { + rows.disconnect(watch); + } } // GTK updates the expanded state on the expander's arrow, not on the expander a screen reader reads. @@ -303,11 +310,28 @@ impl TreeRow { NodeKind::Schema => { self.show_plain(item, crate::ui::icons::DRIVE_HARDDISK, &crate::i18n::gettext("Schema")); } + NodeKind::ObjectGroup => self.show_object_group(item, node), NodeKind::Placeholder => self.show_plain(item, crate::ui::icons::VIEW_GRID, ""), NodeKind::Connection => self.show_connection(node), } } + fn show_object_group(&self, item: >k::ListItem, node: &TreeNode) { + let Some(rows) = node.rows() else { + return; + }; + self.show_plain(item, crate::ui::icons::FOLDER, &objects_description(rows.n_items())); + let item = item.downgrade(); + let watch = rows.connect_items_changed(move |rows, _, _, _| { + if let Some(item) = item.upgrade() { + describe(&item, &objects_description(rows.n_items())); + } + }); + if let Some((rows, watch)) = self.imp().counted.replace(Some((rows, watch))) { + rows.disconnect(watch); + } + } + fn show_plain(&self, item: >k::ListItem, icon: &str, description: &str) { let imp = self.imp(); if imp.icon.icon_name().as_deref() != Some(icon) { @@ -394,6 +418,15 @@ impl TreeRow { } } +fn objects_description(count: u32) -> String { + crate::i18n::ngettext_f( + "{count} object", + "{count} objects", + count, + &[("count", &count.to_string())], + ) +} + fn group_description(group: &TreeNode) -> String { let count = connections_in(group); // Translators: what a screen reader says of a group's row: how many connections it holds, its subgroups' too. diff --git a/linux/crates/app/src/ui/workspace/sidebar_width.rs b/linux/crates/app/src/ui/workspace/sidebar_width.rs new file mode 100644 index 0000000000..b89fcb8575 --- /dev/null +++ b/linux/crates/app/src/ui/workspace/sidebar_width.rs @@ -0,0 +1,124 @@ +use gtk4 as gtk; +use gtk4::prelude::*; +use gtk4::{gdk, gio, glib, graphene}; +use libadwaita as adw; +use tablepro_linux_platform::settings::keys::SIDEBAR_WIDTH; + +// The schema's range, which refuses a write outside it. +const NARROWEST: f64 = 220.0; +const WIDEST: f64 = 1200.0; +const STEP: f64 = 16.0; + +// The setting is the most the sidebar takes, which the split view's fraction +// lowers in a narrow window, so every window reads it and a drag writes it +// once it ends. +pub(super) fn follow(split: &adw::OverlaySplitView, handle: >k::Box, settings: &gio::Settings) { + settings.bind(SIDEBAR_WIDTH, split, "max-sidebar-width").get().build(); + // Collapsed, the sidebar lies over the content at its widest. + handle.set_visible(!split.is_collapsed()); + split.connect_collapsed_notify(glib::clone!( + #[weak] + handle, + move |split| handle.set_visible(!split.is_collapsed()) + )); + + let drag = gtk::GestureDrag::new(); + drag.connect_drag_update(glib::clone!( + #[weak] + split, + #[weak] + handle, + move |drag, _, _| { + if let Some(width) = pointer_width(&split, &handle, drag) { + split.set_max_sidebar_width(width.clamp(NARROWEST, WIDEST)); + } + } + )); + drag.connect_drag_end(glib::clone!( + #[weak] + split, + #[strong] + settings, + move |_, _, _| keep(&settings, split.max_sidebar_width()) + )); + handle.add_controller(drag); + + let keys = gtk::EventControllerKey::new(); + keys.connect_key_pressed(glib::clone!( + #[weak] + split, + #[strong] + settings, + #[upgrade_or] + glib::Propagation::Proceed, + move |_, key, _, _| match step(key, split.direction() == gtk::TextDirection::Rtl) { + Some(step) => { + keep(&settings, stepped(shown_width(&split), split.max_sidebar_width(), step)); + glib::Propagation::Stop + } + None => glib::Propagation::Proceed, + } + )); + handle.add_controller(keys); +} + +// Towards the content widens the sidebar, whichever side it is on. +fn step(key: gdk::Key, rtl: bool) -> Option { + match (key, rtl) { + (gdk::Key::Right, false) | (gdk::Key::Left, true) => Some(STEP), + (gdk::Key::Left, false) | (gdk::Key::Right, true) => Some(-STEP), + _ => None, + } +} + +// A window under twice the width kept shows the sidebar at half its width, which +// a wider window still gives it, so widening there keeps that width. +fn stepped(shown: f64, kept: f64, step: f64) -> f64 { + let width = shown + step; + if step > 0.0 { width.max(kept) } else { width } +} + +fn keep(settings: &gio::Settings, width: f64) { + if let Err(error) = settings.set_double(SIDEBAR_WIDTH, width.round().clamp(NARROWEST, WIDEST)) { + tracing::warn!(%error, "the sidebar's width was not kept"); + } +} + +fn shown_width(split: &adw::OverlaySplitView) -> f64 { + let pixels = split.sidebar().map_or(0, |sidebar| sidebar.width()); + split + .sidebar_width_unit() + .from_px(f64::from(pixels), Some(&split.settings())) +} + +// Measured in the split view, which stays put while the handle moves with the edge. +fn pointer_width(split: &adw::OverlaySplitView, handle: >k::Box, drag: >k::GestureDrag) -> Option { + // A touch has its own sequence; only a pointer's is none. + let (x, y) = drag.point(drag.current_sequence().as_ref())?; + let point = handle.compute_point(split, &graphene::Point::new(x as f32, y as f32))?; + let pixels = match split.direction() { + gtk::TextDirection::Rtl => f64::from(split.width()) - f64::from(point.x()), + _ => f64::from(point.x()), + }; + Some(split.sidebar_width_unit().from_px(pixels, Some(&split.settings()))) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn the_arrow_towards_the_content_widens_the_sidebar() { + assert_eq!(step(gdk::Key::Right, false), Some(STEP)); + assert_eq!(step(gdk::Key::Left, false), Some(-STEP)); + assert_eq!(step(gdk::Key::Left, true), Some(STEP), "the sidebar is on the right"); + assert_eq!(step(gdk::Key::Up, false), None); + } + + #[test] + fn widening_a_sidebar_the_window_holds_at_half_keeps_the_width_kept() { + assert_eq!(stepped(280.0, 280.0, STEP), 296.0); + assert_eq!(stepped(500.0, 600.0, STEP), 600.0, "the window is 1000 wide"); + assert_eq!(stepped(500.0, 600.0, -STEP), 484.0); + } +} diff --git a/linux/crates/app/src/ui/workspace/tests/shell.rs b/linux/crates/app/src/ui/workspace/tests/shell.rs index 92d0a0085e..a7e724aacb 100644 --- a/linux/crates/app/src/ui/workspace/tests/shell.rs +++ b/linux/crates/app/src/ui/workspace/tests/shell.rs @@ -946,3 +946,26 @@ fn the_schemas_button_chooses_what_the_sidebar_lists_and_keeps_it() { wait_until(WAIT, || !banner.is_revealed()).expect("Show All"); assert!(filters.sidebar_schemas(id, &database).is_empty()); } + +#[gtk4::test] +fn the_sidebar_takes_the_width_kept_in_settings_and_has_a_handle_to_set_it() { + use tablepro_linux_platform::settings::keys::SIDEBAR_WIDTH; + + let test = TestWindow::connected("SidebarWidth"); + let shell = shell_of(&test.workspace()); + let (split, handle) = (shell.imp().split_view.get(), shell.imp().sidebar_handle.get()); + let settings = test.services.settings.gio().clone(); + assert_eq!(split.max_sidebar_width(), 280.0, "the schema's default"); + + settings.set_double(SIDEBAR_WIDTH, 440.0).expect("a width in range"); + wait_until(WAIT, || split.max_sidebar_width() == 440.0).expect("the window follows the setting"); + assert!(settings.set_double(SIDEBAR_WIDTH, 100.0).is_err(), "under the floor"); + + assert!(handle.is_visible() && handle.is_focusable()); + assert_eq!(handle.accessible_role(), gtk::AccessibleRole::Separator); + crate::test_support::assert_labelled(&handle).expect("the handle is named"); + split.set_collapsed(true); + assert!(!handle.is_visible(), "a collapsed sidebar lies over the content"); + split.set_collapsed(false); + assert!(handle.is_visible()); +} diff --git a/linux/crates/app/src/ui/workspace/workspace_shell.rs b/linux/crates/app/src/ui/workspace/workspace_shell.rs index 1122d2022a..def3ec0b5c 100644 --- a/linux/crates/app/src/ui/workspace/workspace_shell.rs +++ b/linux/crates/app/src/ui/workspace/workspace_shell.rs @@ -175,6 +175,7 @@ impl WorkspaceShell { &imp.split_view.get(), "show-sidebar", )); + super::sidebar_width::follow(&imp.split_view, &imp.sidebar_handle, services.settings.gio()); window.add_action(&assistant_action(&shell)); imp.walk_hooks.replace(Some(shell.hook_recent_walk(window))); diff --git a/linux/crates/app/src/ui/workspace/workspace_shell_imp.rs b/linux/crates/app/src/ui/workspace/workspace_shell_imp.rs index f8c88f1a72..abfc10506c 100644 --- a/linux/crates/app/src/ui/workspace/workspace_shell_imp.rs +++ b/linux/crates/app/src/ui/workspace/workspace_shell_imp.rs @@ -69,6 +69,8 @@ pub struct WorkspaceShell { #[template_child] pub schema_filter_button: TemplateChild, #[template_child] + pub sidebar_handle: TemplateChild, + #[template_child] pub sidebar_slot: TemplateChild, #[template_child] pub scope_toggle: TemplateChild, diff --git a/linux/crates/platform/src/settings/keys.rs b/linux/crates/platform/src/settings/keys.rs index e4c21ca8a6..36d9b8e7a7 100644 --- a/linux/crates/platform/src/settings/keys.rs +++ b/linux/crates/platform/src/settings/keys.rs @@ -1,3 +1,4 @@ +pub const SIDEBAR_WIDTH: &str = "sidebar-width"; 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"; diff --git a/linux/crates/platform/tests/settings.rs b/linux/crates/platform/tests/settings.rs index 6939de58a3..ad95e06c84 100644 --- a/linux/crates/platform/tests/settings.rs +++ b/linux/crates/platform/tests/settings.rs @@ -62,6 +62,21 @@ async fn defaults_match_schema() -> TestResult { Ok(()) } +#[glib::async_test] +async fn the_sidebar_width_stays_between_its_floor_and_its_cap() -> TestResult { + use gio::prelude::SettingsExt; + + let fixture = Fixture::new()?; + let settings = fixture.settings.gio(); + + assert!((settings.double(keys::SIDEBAR_WIDTH) - 280.0).abs() < f64::EPSILON); + assert!(settings.set_double(keys::SIDEBAR_WIDTH, 219.0).is_err()); + assert!(settings.set_double(keys::SIDEBAR_WIDTH, 1201.0).is_err()); + settings.set_double(keys::SIDEBAR_WIDTH, 440.0)?; + assert!((settings.double(keys::SIDEBAR_WIDTH) - 440.0).abs() < f64::EPSILON); + Ok(()) +} + #[glib::async_test] async fn usage_data_turns_off_and_on_again() -> TestResult { 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 af9c9f021a..53d0504ee4 100644 --- a/linux/data/app.tablepro.TablePro.gschema.xml.in +++ b/linux/data/app.tablepro.TablePro.gschema.xml.in @@ -52,6 +52,13 @@ Whether the main window was maximized when it last closed. + + 280.0 + + Sidebar width + The most the sidebar takes, in scale-independent pixels; the content always keeps half the window. + + 1000 diff --git a/linux/data/resources/ui/workspace-shell.ui b/linux/data/resources/ui/workspace-shell.ui index 787e883a84..74fcee18d4 100644 --- a/linux/data/resources/ui/workspace-shell.ui +++ b/linux/data/resources/ui/workspace-shell.ui @@ -57,96 +57,121 @@ 220 280 + + 0.5 - - - - - false - - - system-search-symbolic - - - - - view-refresh-symbolic - win.refresh-tables - - - - - - - - - - Search connections and tables… - true - - Search connections and tables - + + + + + end + 4 + true + separator + + + col-resize + + Sidebar Width + - - - tables - true - 12 - 12 - 6 - 6 - - - tables - Tables + + + + + + false + + + system-search-symbolic + + + + + view-refresh-symbolic + win.refresh-tables + + - - - favorites - Favorites + + + + + + Search connections and tables… + true + + Search connections and tables + + + - - - - - - false - false - - - - - false - - - list-add-symbolic - up - false + + + tables + true + 12 + 12 + 6 + 6 + + + tables + Tables + + + + + favorites + Favorites + + - - - - Schemas - true - up - false + + + + false + false - - - - - - true + + + false + + + list-add-symbolic + up + false + + + + + + Schemas + true + up + false + + + + + + + + true + + diff --git a/linux/docs/storage.md b/linux/docs/storage.md index dc4cf8b719..65028590fc 100644 --- a/linux/docs/storage.md +++ b/linux/docs/storage.md @@ -340,6 +340,7 @@ The schema id is the application id and the path follows it: `app.tablepro.Table | `window-width` | `i` | `1200` | 360 to 32767 | | `window-height` | `i` | `760` | 294 to 32767 | | `is-maximized` | `b` | `false` | | +| `sidebar-width` | `d` | `280` | 220 to 1200, in sp: the most the sidebar takes | | `default-page-size` | `u` | `1000` | 100 to 100000 | | `show-alternate-rows` | `b` | `true` | | | `show-row-numbers` | `b` | `true` | | diff --git a/linux/docs/toolkit-workarounds.md b/linux/docs/toolkit-workarounds.md index 2bbbf0685a..2746a62f73 100644 --- a/linux/docs/toolkit-workarounds.md +++ b/linux/docs/toolkit-workarounds.md @@ -10,6 +10,14 @@ The places the app steps around a GTK, libadwaita, GtkSourceView, IBus or gtk-rs - **Test.** `a_tab_dropped_outside_every_window_stays_where_it_was` in `crates/app/src/ui/session_window/tests/sessions.rs`. - **Remove when** the floor's libadwaita offers a way to decline a detach, or tab groups: use it, and drop the position restore for this case. +## A sidebar the user can widen + +- **What libadwaita does.** `AdwOverlaySplitView` sizes its sidebar as a fraction of its own width between `min-sidebar-width` and `max-sidebar-width`, and has no divider to drag. `GtkPaned` has one, but has no collapsed overlay, no breakpoints and no header bar integration. This is the documented design, not a defect. +- **Seen in.** libadwaita 1.9 (the floor) and 1.10. +- **Workaround.** A focusable handle with the separator role lies over the sidebar's trailing edge (`data/resources/ui/workspace-shell.ui`, `crates/app/src/ui/workspace/sidebar_width.rs`). A drag or the arrow keys set `max-sidebar-width` through the `sidebar-width` setting, which every window follows; `sidebar-width-fraction` of 0.5 keeps half the window for the content, and the handle hides while the sidebar is collapsed. The handle covers the edge of the tree's scrollbar. +- **Test.** `the_sidebar_takes_the_width_kept_in_settings_and_has_a_handle_to_set_it` in `crates/app/src/ui/workspace/tests/shell.rs`, `the_sidebar_width_stays_between_its_floor_and_its_cap` in `crates/platform/tests/settings.rs`. +- **Remove when** the floor's libadwaita offers a resizable split view: use it. + ## IBus keeps every text view - **Defect.** From GTK 4.24 a `GtkTextView` or `GtkText` makes itself its input method's client widget at construction and clears it only in its own dispose (GTK commit 3df992599b). ibus-gtk4 holds the client with a strong reference (`ibus_im_context_set_client_widget`), so the view is never disposed, nor anything it holds. [ibus/ibus#2968](https://github.com/ibus/ibus/issues/2968), open. diff --git a/linux/po/POTFILES.in b/linux/po/POTFILES.in index b1c1b1a903..5bfce6ead8 100644 --- a/linux/po/POTFILES.in +++ b/linux/po/POTFILES.in @@ -681,6 +681,7 @@ crates/app/src/ui/workspace/sidebar/tests.rs crates/app/src/ui/workspace/sidebar/tree_menu.rs crates/app/src/ui/workspace/sidebar/tree_node.rs crates/app/src/ui/workspace/sidebar/tree_row.rs +crates/app/src/ui/workspace/sidebar_width.rs crates/app/src/ui/workspace/status_pages.rs crates/app/src/ui/workspace/structure.rs crates/app/src/ui/workspace/structure_target.rs