From 5f59651601a8ae70dd1255a4fd28472271ac6dd4 Mon Sep 17 00:00:00 2001 From: sedax90 <5001801+sedax90@users.noreply.github.com> Date: Sun, 8 Nov 2026 16:46:00 +0100 Subject: [PATCH 01/15] feat(linux-sidebar): add a bottom bar with an Add menu --- linux/changelog.d/4145.added.md | 1 + .../app/src/ui/session_window/connections.rs | 1 + linux/crates/app/src/ui/workspace/mod.rs | 2 +- .../app/src/ui/workspace/tests/shell.rs | 17 +++++++ .../app/src/ui/workspace/workspace_actions.rs | 46 ++++++++++++++++++- .../app/src/ui/workspace/workspace_shell.rs | 1 + .../src/ui/workspace/workspace_shell_imp.rs | 2 + linux/data/resources/ui/workspace-shell.ui | 38 +++++++++++++++ 8 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 linux/changelog.d/4145.added.md diff --git a/linux/changelog.d/4145.added.md b/linux/changelog.d/4145.added.md new file mode 100644 index 0000000000..dff40e5a6a --- /dev/null +++ b/linux/changelog.d/4145.added.md @@ -0,0 +1 @@ +The sidebar has a bottom bar with an Add menu for a new table, schema or database in the connection in front, as macOS's sidebar does. diff --git a/linux/crates/app/src/ui/session_window/connections.rs b/linux/crates/app/src/ui/session_window/connections.rs index 920d443960..03fe334842 100644 --- a/linux/crates/app/src/ui/session_window/connections.rs +++ b/linux/crates/app/src/ui/session_window/connections.rs @@ -702,6 +702,7 @@ impl SessionWindow { let front = self.front_session().map(|(_, session)| session); super::window_actions::show_safe_mode(self.upcast_ref(), front.as_ref().map(|session| session.safe_mode())); crate::ui::workspace::show_transfer_actions(self.upcast_ref(), front.as_deref()); + crate::ui::workspace::show_creation_actions(self.upcast_ref(), front.as_deref()); } /// Run a change to a saved connection, holding the process until it diff --git a/linux/crates/app/src/ui/workspace/mod.rs b/linux/crates/app/src/ui/workspace/mod.rs index 6e4edd63b6..d8354d57ff 100644 --- a/linux/crates/app/src/ui/workspace/mod.rs +++ b/linux/crates/app/src/ui/workspace/mod.rs @@ -66,7 +66,7 @@ pub(crate) use self::catalog_ops::DatabaseDrop; pub(crate) use self::database_transfer::TransferInput; use self::session_watches::SessionWatches; use self::tab_title::ConnectionLabel; -pub(crate) use self::workspace_actions::show_transfer_actions; +pub(crate) use self::workspace_actions::{show_creation_actions, show_transfer_actions}; pub(crate) use self::workspace_shell::WorkspaceShell; pub(crate) use self::workspace_tab_view::page_position; use super::browse_tab::BrowseTab; diff --git a/linux/crates/app/src/ui/workspace/tests/shell.rs b/linux/crates/app/src/ui/workspace/tests/shell.rs index b264b074a4..5e31dba14e 100644 --- a/linux/crates/app/src/ui/workspace/tests/shell.rs +++ b/linux/crates/app/src/ui/workspace/tests/shell.rs @@ -563,3 +563,20 @@ fn the_main_menu_adds_a_connection_with_none_open() { choose_new_connection(&test, &test.window.content().expect("the picker")); } + +#[gtk4::test] +fn the_sidebar_add_button_is_there_to_use_only_while_the_menu_offers_something() { + let test = TestWindow::connected("SidebarAdd"); + let shell = test + .window + .content() + .and_downcast::() + .expect("the shell page"); + let offered = ["new-table", "new-schema", "new-database"].iter().any(|name| { + gtk4::prelude::ActionMapExt::lookup_action(&test.window, name) + .expect("the window's action") + .is_enabled() + }); + + assert_eq!(shell.imp().sidebar_add_button.is_sensitive(), offered); +} diff --git a/linux/crates/app/src/ui/workspace/workspace_actions.rs b/linux/crates/app/src/ui/workspace/workspace_actions.rs index 6314971252..9cd2546583 100644 --- a/linux/crates/app/src/ui/workspace/workspace_actions.rs +++ b/linux/crates/app/src/ui/workspace/workspace_actions.rs @@ -23,7 +23,13 @@ type ActionInput = fn() -> WorkspaceInput; /// they are not left greyed out with no reason. const HISTORY_ACTIONS: [&str; 2] = ["show-history", "show-saved-queries"]; -const ENTRIES: [(&str, ActionInput); 9] = [ +/// What the sidebar's (+) menu makes in the connection in front. +const CREATION_ACTIONS: [&str; 3] = [NEW_TABLE, NEW_SCHEMA, NEW_DATABASE]; + +const ENTRIES: [(&str, ActionInput); 12] = [ + (NEW_TABLE, || WorkspaceInput::NewTableTab { schema: None }), + (NEW_SCHEMA, || WorkspaceInput::NewSchemaPrompt), + (NEW_DATABASE, || WorkspaceInput::NewDatabasePrompt), ("new-editor-tab", || WorkspaceInput::NewEditorTab), (EXPORT_DATABASE, || { WorkspaceInput::Transfer(TransferInput::ExportDatabase) @@ -41,6 +47,9 @@ const ENTRIES: [(&str, ActionInput); 9] = [ (super::health_banner::REVIEW_HOST_KEY, || WorkspaceInput::ReviewHostKey), ]; +const NEW_TABLE: &str = "new-table"; +const NEW_SCHEMA: &str = "new-schema"; +const NEW_DATABASE: &str = "new-database"; const EXPORT_DATABASE: &str = "export-database"; const IMPORT_SQL_FILE: &str = "import-sql-file"; const REOPEN_CLOSED_TAB: &str = "reopen-closed-tab"; @@ -111,6 +120,27 @@ pub(super) fn install(window: &adw::ApplicationWindow, shell: &WorkspaceShell) { .build(); } } + // Nothing is offered until a session is in front, and the (+) button is + // there to use only while one of its entries is. + for name in CREATION_ACTIONS { + set_enabled(window, name, false); + } + let button = shell.imp().sidebar_add_button.downgrade(); + let creating = window.downgrade(); + for name in CREATION_ACTIONS { + if let Some(action) = window.lookup_action(name) { + let (button, window) = (button.clone(), creating.clone()); + action.connect_notify_local(Some("enabled"), move |_, _| { + if let (Some(button), Some(window)) = (button.upgrade(), window.upgrade()) { + button.set_sensitive( + CREATION_ACTIONS + .iter() + .any(|name| window.lookup_action(name).is_some_and(|action| action.is_enabled())), + ); + } + }); + } + } // Insensitive until the query database has opened or failed to. for name in HISTORY_ACTIONS { set_enabled(window, name, false); @@ -128,6 +158,20 @@ pub(super) fn remove(window: &adw::ApplicationWindow) { window.remove_action(SHOW_TABS); } +/// Offer New Table, New Schema and New Database where the session in +/// front lets them be made: the engine makes them, and the connection is +/// not read-only. The sidebar rows offer the same by the same rules. +pub(crate) fn show_creation_actions(window: &adw::ApplicationWindow, front: Option<&tablepro_session::Session>) { + let affordances = front.map(super::sidebar::SidebarAffordances::for_session); + for (name, offered) in [ + (NEW_TABLE, affordances.is_some_and(|a| a.offers_new_table())), + (NEW_SCHEMA, affordances.is_some_and(|a| a.offers_new_schema())), + (NEW_DATABASE, affordances.is_some_and(|a| a.offers_new_database())), + ] { + set_enabled(window, name, offered); + } +} + /// Offer Export Database and Import SQL File where the session in front /// has a SQL dump, and Import only where it may write. pub(crate) fn show_transfer_actions(window: &adw::ApplicationWindow, front: Option<&tablepro_session::Session>) { diff --git a/linux/crates/app/src/ui/workspace/workspace_shell.rs b/linux/crates/app/src/ui/workspace/workspace_shell.rs index 25eb2ae449..1b699b00ba 100644 --- a/linux/crates/app/src/ui/workspace/workspace_shell.rs +++ b/linux/crates/app/src/ui/workspace/workspace_shell.rs @@ -42,6 +42,7 @@ glib::wrapper! { pub(super) fn describe_buttons(shell: &WorkspaceShell) { let imp = shell.imp(); describe_icon_button(&imp.table_search_toggle.get(), &gettext("Search"), None); + describe_icon_button(&imp.sidebar_add_button.get(), &gettext("Add"), None); describe_icon_button( &imp.refresh_tables_button.get(), &gettext("Refresh"), 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 0b88179f47..bb8d421937 100644 --- a/linux/crates/app/src/ui/workspace/workspace_shell_imp.rs +++ b/linux/crates/app/src/ui/workspace/workspace_shell_imp.rs @@ -57,6 +57,8 @@ pub struct WorkspaceShell { #[template_child] pub refresh_tables_button: TemplateChild, #[template_child] + pub sidebar_add_button: TemplateChild, + #[template_child] pub table_search_bar: TemplateChild, #[template_child] pub table_search: TemplateChild, diff --git a/linux/data/resources/ui/workspace-shell.ui b/linux/data/resources/ui/workspace-shell.ui index 040ecb5aee..955c4f4d7a 100644 --- a/linux/data/resources/ui/workspace-shell.ui +++ b/linux/data/resources/ui/workspace-shell.ui @@ -2,6 +2,30 @@ + + +
+ + New _Table… + win.new-table + action-disabled + +
+
+ + New _Schema… + win.new-schema + action-disabled + + + New _Database… + win.new-database + action-disabled + +
+