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 @@ -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. 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. 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

Expand Down
1 change: 1 addition & 0 deletions linux/changelog.d/4146.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The sidebar has an Add button below the tree for a new table, schema or database in the connection in front.
25 changes: 11 additions & 14 deletions linux/crates/app/src/ui/session_window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,21 +463,11 @@ impl SessionWindow {
SessionWindowInput::DialogClosed => drop(self.imp().dialog.take()),
SessionWindowInput::CancelConnect => self.on_cancel_connect(),
SessionWindowInput::StopConnecting(key) => self.stop_connecting(&key),
SessionWindowInput::RetryConnect => {
if let Some(key) = self.failed_key() {
self.on_retry_connect(&key);
}
}
SessionWindowInput::RetryConnect => self.on_failed(|key| self.on_retry_connect(key)),
SessionWindowInput::RetryWithNewSecret(kind) => {
if let Some(key) = self.failed_key() {
self.on_retry_with_new_secret(&key, kind);
}
}
SessionWindowInput::EditConnection => {
if let Some(key) = self.failed_key() {
self.on_edit_connection(&key);
}
self.on_failed(|key| self.on_retry_with_new_secret(key, kind));
}
SessionWindowInput::EditConnection => self.on_failed(|key| self.on_edit_connection(key)),
SessionWindowInput::Remedy { key, remedy } => self.on_remedy(key, remedy),
SessionWindowInput::ShowConnectFailure(key) => self.on_show_connect_failure(key),
SessionWindowInput::ForgetConnectFailure(key) => self.forget_failure(&key),
Expand All @@ -486,6 +476,7 @@ impl SessionWindow {
SessionWindowInput::Disconnect => self.on_disconnect_front(),
SessionWindowInput::DisconnectSession(key) => self.on_disconnect(key),
SessionWindowInput::ChooseDatabaseIn(key) => self.choose_database_in(key),
SessionWindowInput::NewTableIn(key) => self.deliver_to(&key, WorkspaceInput::NewTableTab { schema: None }),
SessionWindowInput::NewDatabaseIn(key) => self.deliver_to(&key, WorkspaceInput::NewDatabasePrompt),
SessionWindowInput::NewSchemaIn(key) => self.deliver_to(&key, WorkspaceInput::NewSchemaPrompt),
SessionWindowInput::DropDatabaseIn(key) => self.drop_database_in(key),
Expand Down Expand Up @@ -1600,7 +1591,13 @@ impl SessionWindow {
self.connects_changed();
}

/// The key the failed page is about.
// The failure page's buttons act on the connect that failed.
fn on_failed(&self, act: impl FnOnce(&SessionKey)) {
if let Some(key) = self.failed_key() {
act(&key);
}
}

fn failed_key(&self) -> Option<SessionKey> {
self.imp()
.failed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub(crate) enum SessionWindowInput {
/// Open Database… on a connection's row: pick another of its server's
/// databases to open beside it.
ChooseDatabaseIn(SessionKey),
NewTableIn(SessionKey),
/// New Database… on a connection's row.
NewDatabaseIn(SessionKey),
/// New Schema… on a connection's row.
Expand Down
3 changes: 2 additions & 1 deletion linux/crates/app/src/ui/session_window/window_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ const ACTIONS: [(&str, ActionInput); 12] = [

/// The actions a connection tree row or a toast fires for its own
/// session, which take the session as their target (`session_target`).
const SESSION_ACTIONS: [(&str, SessionInput); 11] = [
const SESSION_ACTIONS: [(&str, SessionInput); 12] = [
("show-session", SessionWindowInput::ShowSession),
("disconnect-session", SessionWindowInput::DisconnectSession),
("stop-connecting", SessionWindowInput::StopConnecting),
("new-query-in", SessionWindowInput::NewQueryIn),
("refresh-in", SessionWindowInput::RefreshIn),
("open-database-in", SessionWindowInput::ChooseDatabaseIn),
("new-table-in", SessionWindowInput::NewTableIn),
("new-database-in", SessionWindowInput::NewDatabaseIn),
("new-schema-in", SessionWindowInput::NewSchemaIn),
("drop-database-in", SessionWindowInput::DropDatabaseIn),
Expand Down
4 changes: 3 additions & 1 deletion linux/crates/app/src/ui/workspace/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::sync::OnceLock;

use glib::subclass::Signal;
use gtk4 as gtk;
use gtk4::glib;
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
use gtk4::{gio, glib};
use libadwaita as adw;
use libadwaita::subclass::prelude::*;
use tablepro_core::DataModel;
Expand Down Expand Up @@ -56,6 +56,8 @@ pub struct Workspace {
pub(super) assistant_available: Cell<bool>,
#[property(get)]
pub(super) can_refresh: Cell<bool>,
#[property(get)]
pub(super) creation_menu: RefCell<Option<gio::MenuModel>>,

pub(super) key: OnceCell<SessionKey>,
// File sessions and saved connections must use the editor save's identity.
Expand Down
6 changes: 6 additions & 0 deletions linux/crates/app/src/ui/workspace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ impl Workspace {
/// which titles its row and the header bars from these.
fn hold(&self, model: WorkspaceModel, blockers: [Rc<dyn CloseBlocker>; 2]) {
model.refresh_title();
model.show_affordances();
model.refresh_assistant();
self.imp().model.replace(Some(model));
for blocker in blockers {
Expand All @@ -943,6 +944,11 @@ impl Workspace {
self.with_model(WorkspaceModel::open);
}

fn show_creation_menu(&self, menu: gio::MenuModel) {
self.imp().creation_menu.replace(Some(menu));
self.notify_creation_menu();
}

/// The key the session is open under.
pub(crate) fn key(&self) -> Option<SessionKey> {
self.imp().key.get().cloned()
Expand Down
14 changes: 12 additions & 2 deletions linux/crates/app/src/ui/workspace/sidebar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub(crate) use key_listing::{KeySidebar, KeysListed};
pub(super) use sidebar_affordances::SidebarAffordances;
use sidebar_index::SidebarIndex;
pub(super) use sidebar_view::SidebarView;
pub(super) use tree_menu::creation_menu;

use super::table_naming::TableNaming;
use super::{OpenMode, WorkspaceInput, WorkspaceModel, WorkspaceSender};
Expand Down Expand Up @@ -354,8 +355,17 @@ impl WorkspaceModel {
/// The connection was replaced, perhaps by one to another server
/// version, so what the sidebar offers is read again.
pub(super) fn on_link_changed(&self) {
if let Some(session) = self.context.active.get() {
self.sidebar.set_affordances(SidebarAffordances::for_session(&session));
self.show_affordances();
}

pub(super) fn show_affordances(&self) {
let Some(session) = self.context.active.get() else {
return;
};
let affordances = SidebarAffordances::for_session(&session);
self.sidebar.set_affordances(affordances);
if let Some(workspace) = self.this.upgrade() {
workspace.show_creation_menu(creation_menu(&self.key, affordances).upcast());
}
}
}
38 changes: 37 additions & 1 deletion linux/crates/app/src/ui/workspace/sidebar/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ fn target(key: &SessionKey) -> Option<String> {
}

/// Each menu item's action and target, sections and submenus flattened.
fn menu_items(menu: &gio::MenuModel) -> Vec<(String, Option<glib::Variant>)> {
pub(crate) fn menu_items(menu: &gio::MenuModel) -> Vec<(String, Option<glib::Variant>)> {
let mut found = Vec::new();
for index in 0..menu.n_items() {
if let Some(action) = menu
Expand Down Expand Up @@ -2588,6 +2588,42 @@ fn a_search_finds_tables_under_their_schema_past_an_empty_one() {
wait_until(WAIT, || shown.headings() == ["sales (Alpha)"]).expect("the table's own schema");
}

#[gtk4::test]
fn the_add_menu_offers_what_the_engine_makes_for_its_own_session() {
let key = SessionKey::Saved(Uuid::new_v4());
let offered = |affordances| {
let menu = creation_menu(&key, affordances).upcast::<gio::MenuModel>();
crate::test_support::assert_access_keys(&menu);
let targets = menu_items(&menu)
.into_iter()
.map(|(action, target)| (action, target.and_then(|target| target.get::<String>())))
.collect::<Vec<_>>();
(menu_labels(&menu), targets)
};

let (labels, targets) = offered(catalog_affordance());
assert_eq!(labels, ["New _Table…", "New _Schema…", "New _Database…"]);
assert_eq!(
targets,
[
("win.new-table-in".to_owned(), target(&key)),
("win.new-schema-in".to_owned(), target(&key)),
("win.new-database-in".to_owned(), target(&key)),
]
);

let mut keyspaces = catalog_affordance();
keyspaces.catalog.database_noun = tablepro_core::ddl::DatabaseNoun::Keyspace;
keyspaces.lists_databases = true;
assert_eq!(offered(keyspaces).0, ["New _Table…", "New _Keyspace…"]);

let read_only = SidebarAffordances {
read_only: true,
..catalog_affordance()
};
assert!(offered(read_only).0.is_empty(), "a read-only connection makes nothing");
}

#[gtk4::test]
fn a_connections_row_makes_and_drops_databases_and_a_databases_row_drops_its_own() {
let alpha = connection("Alpha", None);
Expand Down
29 changes: 29 additions & 0 deletions linux/crates/app/src/ui/workspace/sidebar/tree_menu.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use gtk4::gio::prelude::MenuModelExt;
use gtk4::{gio, glib};
use tablepro_core::ddl::DatabaseNoun;
use tablepro_session::SessionKey;
Expand All @@ -10,6 +11,7 @@ pub(super) const SHOW_SESSION: &str = "win.show-session";
const NEW_QUERY_IN: &str = "win.new-query-in";
const REFRESH_IN: &str = "win.refresh-in";
const OPEN_DATABASE_IN: &str = "win.open-database-in";
const NEW_TABLE_IN: &str = "win.new-table-in";
const NEW_DATABASE_IN: &str = "win.new-database-in";
const NEW_SCHEMA_IN: &str = "win.new-schema-in";
const DROP_DATABASE_IN: &str = "win.drop-database-in";
Expand Down Expand Up @@ -91,6 +93,33 @@ pub(super) fn session_section(key: &SessionKey, state: InWindow, affordances: Si
menu
}

// Empty when the engine makes none of these or the connection is read-only, which hides the Add button.
pub(crate) fn creation_menu(key: &SessionKey, affordances: SidebarAffordances) -> gio::Menu {
let target = crate::ui::session_target::to_variant(key);
let objects = gio::Menu::new();
if affordances.offers_new_table() {
objects.append_item(&item(&crate::i18n::gettext("New _Table…"), NEW_TABLE_IN, &target));
}
let containers = gio::Menu::new();
if affordances.offers_new_schema() {
containers.append_item(&item(&crate::i18n::gettext("New _Schema…"), NEW_SCHEMA_IN, &target));
}
if affordances.offers_new_database() {
let label = match affordances.catalog.database_noun {
DatabaseNoun::Database => crate::i18n::gettext("New _Database…"),
DatabaseNoun::Keyspace => crate::i18n::gettext("New _Keyspace…"),
};
containers.append_item(&item(&label, NEW_DATABASE_IN, &target));
}
let menu = gio::Menu::new();
for section in [objects, containers] {
if section.n_items() > 0 {
menu.append_section(None, &section);
}
}
menu
}

/// Whether the row of an open session offers Drop Database…. Only
/// engines whose connection holds one database open another beside it,
/// and a file holds no other.
Expand Down
52 changes: 52 additions & 0 deletions linux/crates/app/src/ui/workspace/tests/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,3 +840,55 @@ fn the_header_refresh_follows_the_selected_tabs_capability() {
wait_until(WAIT, || shell.tab_view().n_pages() == 0).expect("all clean tabs close");
wait_until(WAIT, || !button.is_sensitive()).expect("no refresh after the last tab closes");
}

fn postgres(script: &mut tablepro_test_support::ConnectionScript) {
script.dialect = Arc::new(tablepro_driver_postgres::PgDialect::new(
&tablepro_core::ServerInfo::new("PostgreSQL", "18.0", 18, 0, 0),
));
}

#[gtk4::test]
fn the_sidebar_add_menu_makes_objects_in_the_session_in_front() {
let test = TestWindow::connected_with("SidebarAdd", postgres);
let shell = shell_of(&test.workspace());
let imp = shell.imp();
let (bar, button) = (imp.sidebar_bar.get(), imp.sidebar_add_button.get());
wait_until(WAIT, || bar.is_revealed()).expect("the bar under the tree");
crate::test_support::assert_labelled(&button).expect("the Add button is named");
let target = crate::ui::session_target::to_variant(&test.key());
let offered = button
.menu_model()
.map(|menu| crate::ui::workspace::sidebar::tests::menu_items(&menu))
.unwrap_or_default();
assert_eq!(
offered,
[
("win.new-table-in".to_owned(), Some(target.clone())),
("win.new-schema-in".to_owned(), Some(target.clone())),
("win.new-database-in".to_owned(), Some(target.clone())),
]
);

imp.scope_toggle.set_active_name(Some("favorites"));
assert!(!bar.is_revealed(), "the bar makes tables under Favorites");
imp.scope_toggle.set_active_name(Some("tables"));
assert!(bar.is_revealed());

WidgetExt::activate_action(&button, "win.new-table-in", Some(&target)).expect("the window's action");
wait_until(WAIT, || shell.tab_view().n_pages() == 1).expect("a new table's tab");
}

#[gtk4::test]
fn a_read_only_connection_has_no_add_menu() {
let test = TestWindow::connected_with("SidebarAddReadOnly", |script| {
postgres(script);
script.read_only = true;
});
let shell = shell_of(&test.workspace());
let imp = shell.imp();
wait_until(WAIT, || test.workspace().creation_menu().is_some()).expect("the session's Add menu");

assert_eq!(test.workspace().creation_menu().map(|menu| menu.n_items()), Some(0));
assert!(!imp.sidebar_add_button.is_visible());
assert!(!imp.sidebar_bar.is_revealed());
}
Loading
Loading