diff --git a/linux/ARCHITECTURE.md b/linux/ARCHITECTURE.md index df1511b24c..9ee031dedb 100644 --- a/linux/ARCHITECTURE.md +++ b/linux/ARCHITECTURE.md @@ -85,7 +85,7 @@ Each window is a `SessionWindow` (`crates/app/src/ui/session_window/`) for its c - The close prompts (`CloseGuards`) belong to the window, so a tab's close, the close button and Ctrl+W ask on every page, one prompt at a time. While the workspace has something a logout would lose, a `WindowInhibitor` holds logout back, and suspend too while a save or an export runs. - The window's actions (`disconnect`, `reconnect`, `close-current` and the rest) go on its own action map, which GTK exports as `win`. The ones the tree's rows fire, such as `disconnect-session` and `show-session`, take the session's key as a string target (`crate::ui::session_target`). - 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 main menu comes from `data/resources/gtk/menus.ui`, which `GtkApplication` loads at startup. +- 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. 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. diff --git a/linux/changelog.d/4139.added.md b/linux/changelog.d/4139.added.md new file mode 100644 index 0000000000..4a34897a98 --- /dev/null +++ b/linux/changelog.d/4139.added.md @@ -0,0 +1 @@ +Session Menu puts database commands beside the workspace, with app commands in Main Menu. 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 ce300f2e15..b06cfdb1c5 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 @@ -328,7 +328,11 @@ impl RowDetailPane { if wanted.is_empty() || column.name.to_lowercase().contains(&wanted) { return true; } - let value = field_value(&grid.tracked(), &row, &column); + let Some(config) = grid.config() else { + return false; + }; + let preferences = config.settings.grid_preferences().snapshot(); + let value = field_value(&grid.tracked(), &row, &column, &preferences.null_display); !value.null && value.text.to_lowercase().contains(&wanted) } diff --git a/linux/crates/app/src/ui/menu_label.rs b/linux/crates/app/src/ui/menu_label.rs index e31af1da0a..5664ce2be9 100644 --- a/linux/crates/app/src/ui/menu_label.rs +++ b/linux/crates/app/src/ui/menu_label.rs @@ -70,7 +70,13 @@ mod tests { } } - for id in ["primary_menu", "tab_overview_menu", "editor_menu", "options_menu"] { + for id in [ + "primary_menu", + "session_menu", + "tab_overview_menu", + "editor_menu", + "options_menu", + ] { assert!(checked.iter().any(|read| read == id), "{id} was not read: {checked:?}"); } } diff --git a/linux/crates/app/src/ui/session_window/tests/mod.rs b/linux/crates/app/src/ui/session_window/tests/mod.rs index 0c143b072b..f79e92a6fb 100644 --- a/linux/crates/app/src/ui/session_window/tests/mod.rs +++ b/linux/crates/app/src/ui/session_window/tests/mod.rs @@ -538,7 +538,7 @@ fn ticked_level(test: &TestWindow) -> Option { } #[gtk4::test] -fn the_main_menu_moves_the_session_between_levels_that_write_and_saves_it() { +fn the_safe_mode_action_moves_the_session_between_levels_that_write_and_saves_it() { let test = TestWindow::connected("SafeModeLive"); assert_eq!(ticked_level(&test).as_deref(), Some("off")); @@ -557,7 +557,7 @@ fn the_main_menu_moves_the_session_between_levels_that_write_and_saves_it() { } #[gtk4::test] -fn read_only_from_the_main_menu_saves_it_and_connects_again_read_only() { +fn read_only_from_the_safe_mode_action_saves_it_and_connects_again_read_only() { let test = TestWindow::connected("SafeModeReadOnly"); pick_level(&test, "read-only"); diff --git a/linux/crates/app/src/ui/shell/mod.rs b/linux/crates/app/src/ui/shell/mod.rs index 9c935351ee..1e749b8e49 100644 --- a/linux/crates/app/src/ui/shell/mod.rs +++ b/linux/crates/app/src/ui/shell/mod.rs @@ -2,4 +2,4 @@ mod primary_menu_button; -pub(crate) use primary_menu_button::{PRIMARY_MENU, TAB_OVERVIEW_MENU, app_menu, primary_menu_button}; +pub(crate) use primary_menu_button::{SESSION_MENU, TAB_OVERVIEW_MENU, app_menu, primary_menu_button}; diff --git a/linux/crates/app/src/ui/shell/primary_menu_button.rs b/linux/crates/app/src/ui/shell/primary_menu_button.rs index b194354d16..034e823827 100644 --- a/linux/crates/app/src/ui/shell/primary_menu_button.rs +++ b/linux/crates/app/src/ui/shell/primary_menu_button.rs @@ -1,8 +1,8 @@ use gtk4 as gtk; use gtk4::prelude::*; -/// The ids of the menus in `gtk/menus.ui`. pub(crate) const PRIMARY_MENU: &str = "primary_menu"; +pub(crate) const SESSION_MENU: &str = "session_menu"; pub(crate) const TAB_OVERVIEW_MENU: &str = "tab_overview_menu"; /// A menu GtkApplication read from `gtk/menus.ui` at startup. A missing diff --git a/linux/crates/app/src/ui/workspace/tests/shell.rs b/linux/crates/app/src/ui/workspace/tests/shell.rs index eab94ed2a6..5847a9a357 100644 --- a/linux/crates/app/src/ui/workspace/tests/shell.rs +++ b/linux/crates/app/src/ui/workspace/tests/shell.rs @@ -220,7 +220,17 @@ fn narrow_window_swaps_tab_bar_for_tab_button() { assert!(!imp.tab_bar.is_visible(), "the tab bar stayed"); assert!(imp.tab_button.is_visible(), "no tab button took its place"); + assert!( + !imp.new_tab_button.is_visible(), + "New Query stayed beside the tab button" + ); + assert!(imp.tab_overview.property::("enable-new-tab")); assert!(imp.split_view.is_collapsed()); + let button = session_menu_button(&test); + wait_until(WAIT, || button.is_mapped()).expect("Session Menu at the window floor"); + assert!(imp.content_header.measure(gtk::Orientation::Horizontal, -1).0 <= 360); + button.popup(); + wait_until(WAIT, || button.popover().is_some_and(|menu| menu.is_mapped())).expect("the narrow menu opens"); } #[gtk4::test] @@ -407,6 +417,106 @@ fn primary_menu_has_no_quit() { ); } +#[gtk4::test] +fn application_and_session_commands_have_separate_native_menus() { + let test = TestWindow::connected("NativeMenus"); + assert!( + test.app.menubar().is_none(), + "AdwApplicationWindow does not support a menu bar" + ); + let primary = test.app.menu_by_id("primary_menu").expect("the primary menu"); + let mut app_actions = Vec::new(); + collect_actions(primary.upcast_ref(), &mut app_actions); + assert_eq!(app_actions.len(), 10); + let button = session_menu_button(&test); + assert!(!button.is_primary(), "F10 belongs to Main Menu"); + crate::test_support::assert_labelled(&button).expect("the menu's accessible name"); + let mut session_actions = Vec::new(); + collect_actions(&button.menu_model().expect("the session menu"), &mut session_actions); + for expected in [ + "win.safe-mode", + "win.show-history", + "win.show-saved-queries", + "win.export-database", + "win.import-sql-file", + "win.disconnect", + ] { + assert!( + session_actions.iter().any(|action| action == expected), + "{expected} is missing" + ); + assert!( + !app_actions.iter().any(|action| action == expected), + "{expected} is duplicated" + ); + } + for action in &app_actions { + assert!(!session_actions.contains(action), "{action} belongs to Main Menu"); + } +} + +fn session_menu_button(test: &TestWindow) -> gtk::MenuButton { + let shell = test.window.shell().expect("the workspace shell"); + descendants(&shell.imp().content_header.get()) + .into_iter() + .filter_map(|widget| widget.downcast::().ok()) + .find(|button| button.tooltip_text().as_deref() == Some("Session Menu")) + .expect("Session Menu in the content header") +} + +fn click_menu_item(menu: >k::Popover, label: &str) { + let mut found = None; + wait_until(WAIT, || { + found = descendants(menu).into_iter().find(|widget| { + widget.type_().name() == "GtkModelButton" + && widget.property::>("text").as_deref() == Some(label) + && widget.is_mapped() + && widget.is_sensitive() + }); + found.is_some() + }) + .unwrap_or_else(|_| panic!("no enabled menu item {label}")); + found.expect("the item").emit_by_name::<()>("clicked", &[]); +} + +#[gtk4::test] +fn the_session_menu_changes_safe_mode_through_its_radio_item() { + let test = TestWindow::connected("SessionMenuSafeMode"); + let button = session_menu_button(&test); + button.popup(); + let menu = button.popover().expect("the session menu"); + click_menu_item(&menu, "Safe Mode"); + click_menu_item(&menu, "Confirm Writes"); + wait_until(WAIT, || { + test.window + .front_session() + .is_some_and(|(_, session)| session.safe_mode() == tablepro_core::SafeModeLevel::ConfirmWrites) + }) + .expect("the selected level to reach the session"); + assert_eq!( + test.window + .lookup_action("safe-mode") + .and_then(|action| action.state()) + .and_then(|state| state.get::()), + Some("confirm-writes".to_owned()) + ); +} + +#[gtk4::test] +fn the_session_menu_disconnects_the_session_in_front() { + let test = TestWindow::connected("SessionMenuDisconnect"); + let button = session_menu_button(&test); + button.popup(); + click_menu_item(&button.popover().expect("the menu"), "Disconnect"); + test.wait_for_page("picker"); + assert!(test.window.front_session().is_none()); + assert!(!descendants(&test.window).iter().any(|widget| { + widget + .downcast_ref::() + .is_some_and(|button| button.tooltip_text().as_deref() == Some("Session Menu")) + })); +} + #[gtk4::test] fn f9_toggles_sidebar() { let test = TestWindow::picker("F9"); @@ -577,6 +687,22 @@ fn the_main_menu_adds_a_connection_with_none_open() { choose_new_connection(&test, &test.window.content().expect("the picker")); } +fn collect_actions(menu: &gio::MenuModel, actions: &mut Vec) { + for item in 0..menu.n_items() { + if let Some(action) = menu + .item_attribute_value(item, "action", None) + .and_then(|value| value.get::()) + { + actions.push(action); + } + for link in ["section", "submenu"] { + if let Some(inner) = menu.item_link(item, link) { + collect_actions(&inner, actions); + } + } + } +} + #[gtk4::test] fn the_header_refresh_follows_the_selected_tabs_capability() { use super::super::structure_target::StructureTarget; diff --git a/linux/crates/app/src/ui/workspace/workspace_shell.rs b/linux/crates/app/src/ui/workspace/workspace_shell.rs index e8d974d017..0ae70b528f 100644 --- a/linux/crates/app/src/ui/workspace/workspace_shell.rs +++ b/linux/crates/app/src/ui/workspace/workspace_shell.rs @@ -24,7 +24,7 @@ use crate::i18n::{gettext, gettext_f}; use crate::runtime::{DeliverInput, InputSender}; use crate::ui::SessionWindowInput; use crate::ui::a11y::describe_icon_button; -use crate::ui::shell::{PRIMARY_MENU, TAB_OVERVIEW_MENU, app_menu, primary_menu_button}; +use crate::ui::shell::{SESSION_MENU, TAB_OVERVIEW_MENU, app_menu, primary_menu_button}; /// The window action that shows and hides the sidebar, as GNOME Files /// names it. @@ -144,11 +144,16 @@ impl WorkspaceShell { let _ = imp.sender.set(sender); let app = window.application(); - let menu_button = primary_menu_button(app.as_ref()); - if let Some(menu) = app_menu(app.as_ref(), PRIMARY_MENU) { - menu_button.set_menu_model(Some(&with_safe_mode(&menu))); + imp.sidebar_header.pack_end(&primary_menu_button(app.as_ref())); + let session_menu = gtk::MenuButton::builder() + .icon_name(crate::ui::icons::VIEW_MORE) + .build(); + crate::ui::a11y::describe_icon_button(&session_menu, &gettext("Session Menu"), None); + match app_menu(app.as_ref(), SESSION_MENU) { + Some(menu) => session_menu.set_menu_model(Some(&with_safe_mode(&menu))), + None => session_menu.set_sensitive(false), } - imp.sidebar_header.pack_end(&menu_button); + imp.content_header.pack_end(&session_menu); super::workspace_actions::install(window, &shell); imp.history_gate @@ -1041,8 +1046,6 @@ fn tab_menu() -> gio::Menu { menu } -/// The main menu with the session's Safe Mode levels on top, as radio -/// items of the window's stateful `safe-mode` action. fn with_safe_mode(menu: &gio::MenuModel) -> gio::Menu { let levels = gio::Menu::new(); for level in tablepro_core::SafeModeLevel::ALL { @@ -1233,12 +1236,12 @@ mod tests { } #[gtk4::test] - fn the_tab_menu_and_the_main_menu_give_each_item_its_own_access_key() { + fn the_tab_and_session_menus_give_each_item_its_own_access_key() { crate::register_test_resources(); let builder = gtk::Builder::from_resource(&format!("{RESOURCE_BASE_PATH}/gtk/menus.ui")); - let main: gio::MenuModel = builder.object(PRIMARY_MENU).expect("the main menu"); + let session: gio::MenuModel = builder.object(SESSION_MENU).expect("the session menu"); assert_access_keys(&tab_menu()); - assert_access_keys(&with_safe_mode(&main)); + assert_access_keys(&with_safe_mode(&session)); } } diff --git a/linux/data/resources/gtk/menus.ui b/linux/data/resources/gtk/menus.ui index 1ee0fd0a97..19a4b6979d 100644 --- a/linux/data/resources/gtk/menus.ui +++ b/linux/data/resources/gtk/menus.ui @@ -17,37 +17,6 @@ app.new-window -
- - - Query _History - win.show-history - action-missing - - - Saved _Queries - win.show-saved-queries - action-missing - - - E_xport Database… - win.export-database - action-missing - - - Import SQL _File… - win.import-sql-file - action-missing - - - - _Disconnect - win.disconnect - action-disabled - -
_Import Connections… @@ -81,6 +50,35 @@
+ +
+ + Query _History + win.show-history + action-missing + + + Saved _Queries + win.show-saved-queries + action-missing + + + E_xport Database… + win.export-database + action-missing + + + Import SQL _File… + win.import-sql-file + action-missing + + + _Disconnect + win.disconnect + action-disabled + +
+
diff --git a/linux/data/resources/ui/workspace-shell.ui b/linux/data/resources/ui/workspace-shell.ui index 527d9c8b23..41f30f192d 100644 --- a/linux/data/resources/ui/workspace-shell.ui +++ b/linux/data/resources/ui/workspace-shell.ui @@ -42,6 +42,9 @@ true false true + + false