Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion linux/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions linux/changelog.d/4139.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Session Menu puts database commands beside the workspace, with app commands in Main Menu.
6 changes: 5 additions & 1 deletion linux/crates/app/src/ui/data_grid/row_detail/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
8 changes: 7 additions & 1 deletion linux/crates/app/src/ui/menu_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
}
}
Expand Down
4 changes: 2 additions & 2 deletions linux/crates/app/src/ui/session_window/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ fn ticked_level(test: &TestWindow) -> Option<String> {
}

#[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"));

Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion linux/crates/app/src/ui/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
2 changes: 1 addition & 1 deletion linux/crates/app/src/ui/shell/primary_menu_button.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
126 changes: 126 additions & 0 deletions linux/crates/app/src/ui/workspace/tests/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<bool>("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]
Expand Down Expand Up @@ -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::<gtk::MenuButton>().ok())
.find(|button| button.tooltip_text().as_deref() == Some("Session Menu"))
.expect("Session Menu in the content header")
}

fn click_menu_item(menu: &gtk::Popover, label: &str) {
let mut found = None;
wait_until(WAIT, || {
found = descendants(menu).into_iter().find(|widget| {
widget.type_().name() == "GtkModelButton"
&& widget.property::<Option<String>>("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::<String>()),
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::<gtk::MenuButton>()
.is_some_and(|button| button.tooltip_text().as_deref() == Some("Session Menu"))
}));
}

#[gtk4::test]
fn f9_toggles_sidebar() {
let test = TestWindow::picker("F9");
Expand Down Expand Up @@ -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<String>) {
for item in 0..menu.n_items() {
if let Some(action) = menu
.item_attribute_value(item, "action", None)
.and_then(|value| value.get::<String>())
{
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;
Expand Down
23 changes: 13 additions & 10 deletions linux/crates/app/src/ui/workspace/workspace_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
}
}
60 changes: 29 additions & 31 deletions linux/data/resources/gtk/menus.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,6 @@
<attribute name="action">app.new-window</attribute>
</item>
</section>
<section>
<!-- A workspace adds these; the picker has no session to show
history for. -->
<item>
<attribute name="label" translatable="yes">Query _History</attribute>
<attribute name="action">win.show-history</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Saved _Queries</attribute>
<attribute name="action">win.show-saved-queries</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
<item>
<attribute name="label" translatable="yes">E_xport Database…</attribute>
<attribute name="action">win.export-database</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Import SQL _File…</attribute>
<attribute name="action">win.import-sql-file</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
<!-- The window always has it, enabled only while it shows a
session. -->
<item>
<attribute name="label" translatable="yes">_Disconnect</attribute>
<attribute name="action">win.disconnect</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">_Import Connections…</attribute>
Expand Down Expand Up @@ -81,6 +50,35 @@
</item>
</section>
</menu>
<menu id="session_menu">
<section>
<item>
<attribute name="label" translatable="yes">Query _History</attribute>
<attribute name="action">win.show-history</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Saved _Queries</attribute>
<attribute name="action">win.show-saved-queries</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
<item>
<attribute name="label" translatable="yes">E_xport Database…</attribute>
<attribute name="action">win.export-database</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Import SQL _File…</attribute>
<attribute name="action">win.import-sql-file</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Disconnect</attribute>
<attribute name="action">win.disconnect</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
</section>
</menu>
<menu id="tab_overview_menu">
<section>
<item>
Expand Down
3 changes: 3 additions & 0 deletions linux/data/resources/ui/workspace-shell.ui
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<setter object="assistant_split" property="collapsed">true</setter>
<setter object="tab_bar" property="visible">false</setter>
<setter object="tab_button" property="visible">true</setter>
<!-- The overview the tab button opens has New Tab, and the
header has to fit the window's floor. -->
<setter object="new_tab_button" property="visible">false</setter>
</object>
</child>
<property name="child">
Expand Down
Loading