diff --git a/linux/changelog.d/4124.added.md b/linux/changelog.d/4124.added.md new file mode 100644 index 0000000000..e5c64958c4 --- /dev/null +++ b/linux/changelog.d/4124.added.md @@ -0,0 +1 @@ +The header has a lock that shows the connection's Safe Mode level and changes it. diff --git a/linux/crates/app/src/ui/icons.rs b/linux/crates/app/src/ui/icons.rs index d27cdb630c..c4fa788d9a 100644 --- a/linux/crates/app/src/ui/icons.rs +++ b/linux/crates/app/src/ui/icons.rs @@ -7,6 +7,7 @@ pub const APPLICATIONS_ENGINEERING: &str = "applications-engineering-symbolic"; pub const APPLICATIONS_SCIENCE: &str = "applications-science-symbolic"; /// Bundled: a speech bubble, for the AI assistant. pub const ASSISTANT: &str = "assistant-symbolic"; +pub const CHANGES_ALLOW: &str = "changes-allow-symbolic"; pub const CHANGES_PREVENT: &str = "changes-prevent-symbolic"; pub const COMPUTER: &str = "computer-symbolic"; pub const DIALOG_ERROR: &str = "dialog-error-symbolic"; @@ -90,6 +91,7 @@ pub const ALL: &[&str] = &[ APPLICATIONS_ENGINEERING, APPLICATIONS_SCIENCE, ASSISTANT, + CHANGES_ALLOW, CHANGES_PREVENT, COMPUTER, DIALOG_ERROR, 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 f79e92a6fb..90bd3358cd 100644 --- a/linux/crates/app/src/ui/session_window/tests/mod.rs +++ b/linux/crates/app/src/ui/session_window/tests/mod.rs @@ -571,6 +571,59 @@ fn read_only_from_the_safe_mode_action_saves_it_and_connects_again_read_only() { wait_until(WAIT, || ticked_level(&test).as_deref() == Some("read-only")).expect("Read-Only ticked"); } +#[gtk4::test] +fn the_header_lock_follows_the_front_connections_level() { + let test = TestWindow::connected("SafeModeButton"); + let button = test.window.shell().expect("the shell").imp().safe_mode_button.get(); + + crate::test_support::assert_labelled(&button).expect("the lock has an accessible name"); + let menu = button.menu_model().expect("the level chooser"); + assert_eq!(menu.n_items(), 3); + for (index, target) in ["off", "confirm-writes", "read-only"].into_iter().enumerate() { + let index = i32::try_from(index).expect("three levels"); + assert_eq!( + menu.item_attribute_value(index, gio::MENU_ATTRIBUTE_ACTION, None) + .and_then(|value| value.get::()) + .as_deref(), + Some("win.safe-mode") + ); + assert_eq!( + menu.item_attribute_value(index, gio::MENU_ATTRIBUTE_TARGET, None) + .and_then(|value| value.get::()) + .as_deref(), + Some(target) + ); + } + assert!(button.is_visible()); + assert_eq!(button.icon_name().as_deref(), Some("changes-allow-symbolic")); + assert_eq!(button.tooltip_text().as_deref(), Some("Safe Mode: Off")); + + pick_level(&test, "confirm-writes"); + wait_until(WAIT, || { + button.tooltip_text().as_deref() == Some("Safe Mode: Confirm Writes") + }) + .expect("the lock to name the new level"); + assert_eq!(button.icon_name().as_deref(), Some("changes-prevent-symbolic")); + + pick_level(&test, "read-only"); + wait_until(WAIT, || ticked_level(&test).as_deref() == Some("read-only")).expect("Read-Only after reconnect"); + let shell = test.window.shell().expect("the reopened shell"); + let button = shell.imp().safe_mode_button.get(); + assert_eq!(button.tooltip_text().as_deref(), Some("Safe Mode: Read-Only")); + assert_eq!(button.icon_name().as_deref(), Some("changes-prevent-symbolic")); + crate::test_support::assert_labelled(&button).expect("the reopened lock is named"); + shell.show_safe_mode(None); + assert!(!button.is_visible()); + + let picker = TestWindow::picker("SafeModeButtonPicker"); + assert!( + picker + .window + .shell() + .is_none_or(|shell| !shell.imp().safe_mode_button.is_visible()) + ); +} + #[gtk4::test] fn the_levels_are_off_without_a_session() { let test = TestWindow::picker("SafeModePicker"); diff --git a/linux/crates/app/src/ui/session_window/tests/sessions.rs b/linux/crates/app/src/ui/session_window/tests/sessions.rs index e184a61059..9ae9238464 100644 --- a/linux/crates/app/src/ui/session_window/tests/sessions.rs +++ b/linux/crates/app/src/ui/session_window/tests/sessions.rs @@ -336,6 +336,15 @@ fn a_safe_mode_level_goes_to_the_session_it_was_picked_for() { Some(tablepro_core::SafeModeLevel::Off), "the level moved another connection" ); + let button = shell.imp().safe_mode_button.get(); + wait_until(WAIT, || button.tooltip_text().as_deref() == Some("Safe Mode: Off")) + .expect("the header to keep naming the other session"); + shell.tab_view().set_selected_page(&first_tab); + wait_until(WAIT, || { + button.tooltip_text().as_deref() == Some("Safe Mode: Confirm Writes") + }) + .expect("the header to follow the selected session"); + assert_eq!(super::ticked_level(&test).as_deref(), Some("confirm-writes")); } #[gtk4::test] diff --git a/linux/crates/app/src/ui/session_window/window_actions.rs b/linux/crates/app/src/ui/session_window/window_actions.rs index 21f64174a4..1babc96a56 100644 --- a/linux/crates/app/src/ui/session_window/window_actions.rs +++ b/linux/crates/app/src/ui/session_window/window_actions.rs @@ -150,6 +150,9 @@ pub(super) fn show_safe_mode(window: &adw::ApplicationWindow, level: Option().and_then(SessionWindow::shell) { + shell.show_safe_mode(level); + } if let Some(level) = level { action.set_state(&crate::ui::safe_mode::action_target(level).to_variant()); } diff --git a/linux/crates/app/src/ui/workspace/tests/shell.rs b/linux/crates/app/src/ui/workspace/tests/shell.rs index 2b04b90626..dde902900f 100644 --- a/linux/crates/app/src/ui/workspace/tests/shell.rs +++ b/linux/crates/app/src/ui/workspace/tests/shell.rs @@ -233,6 +233,30 @@ fn narrow_window_swaps_tab_bar_for_tab_button() { wait_until(WAIT, || button.popover().is_some_and(|menu| menu.is_mapped())).expect("the narrow menu opens"); } +#[gtk4::test] +fn the_safe_mode_lock_leaves_the_narrow_header_to_the_session_menu() { + for (name, width, height, shown) in [("NarrowLock", 360, 294, false), ("WideLock", 1200, 760, true)] { + let test = sized(name, width, height); + let workspace = test.workspace(); + let shell = shell_of(&workspace); + let imp = shell.imp(); + let narrow = (!shown).then(|| imp.narrow_breakpoint.get()); + wait_until(Duration::from_secs(2), || { + imp.breakpoint_bin.width() > 0 && imp.breakpoint_bin.current_breakpoint() == narrow + }) + .expect("the breakpoint for the width"); + // is_visible also reads the slot, which the narrow breakpoint hides. + wait_until(WAIT, || imp.safe_mode_button.get_visible()).expect("the connection's level"); + assert_eq!(imp.safe_mode_button.is_visible(), shown, "{name}"); + shell.show_safe_mode(Some(tablepro_core::SafeModeLevel::ReadOnly)); + assert_eq!( + imp.safe_mode_button.is_visible(), + shown, + "a level change kept the {name} layout" + ); + } +} + #[gtk4::test] fn wide_window_shows_tab_bar() { let test = sized("Wide", 1200, 760); diff --git a/linux/crates/app/src/ui/workspace/workspace_shell.rs b/linux/crates/app/src/ui/workspace/workspace_shell.rs index 0ae70b528f..ccc73b40ef 100644 --- a/linux/crates/app/src/ui/workspace/workspace_shell.rs +++ b/linux/crates/app/src/ui/workspace/workspace_shell.rs @@ -52,6 +52,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.safe_mode_button.get(), &gettext("Safe Mode"), None); describe_icon_button( &imp.refresh_tables_button.get(), &gettext("Refresh"), @@ -154,6 +155,7 @@ impl WorkspaceShell { None => session_menu.set_sensitive(false), } imp.content_header.pack_end(&session_menu); + imp.safe_mode_button.set_menu_model(Some(&safe_mode_levels())); super::workspace_actions::install(window, &shell); imp.history_gate @@ -594,6 +596,22 @@ impl WorkspaceShell { self.notify_front(); } + pub(crate) fn show_safe_mode(&self, level: Option) { + let button = self.imp().safe_mode_button.get(); + button.set_visible(level.is_some()); + let Some(level) = level else { + return; + }; + button.set_icon_name(match level { + tablepro_core::SafeModeLevel::Off => crate::ui::icons::CHANGES_ALLOW, + tablepro_core::SafeModeLevel::ConfirmWrites | tablepro_core::SafeModeLevel::ReadOnly => { + crate::ui::icons::CHANGES_PREVENT + } + }); + let said = gettext_f("Safe Mode: {level}", &[("level", &crate::ui::safe_mode::label(level))]); + describe_icon_button(&button, &said, None); + } + fn on_scope_changed(&self) { let imp = self.imp(); let favorites = imp.scope_toggle.active_name().as_deref() == Some(FAVORITES); @@ -1046,7 +1064,7 @@ fn tab_menu() -> gio::Menu { menu } -fn with_safe_mode(menu: &gio::MenuModel) -> gio::Menu { +fn safe_mode_levels() -> gio::Menu { let levels = gio::Menu::new(); for level in tablepro_core::SafeModeLevel::ALL { let item = gio::MenuItem::new(Some(&crate::ui::safe_mode::menu_label(level)), None); @@ -1056,6 +1074,11 @@ fn with_safe_mode(menu: &gio::MenuModel) -> gio::Menu { ); levels.append_item(&item); } + levels +} + +fn with_safe_mode(menu: &gio::MenuModel) -> gio::Menu { + let levels = safe_mode_levels(); let section = gio::Menu::new(); section.append_submenu(Some(&gettext("_Safe Mode")), &levels); let whole = gio::Menu::new(); 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 62cee3b795..1a96a32da8 100644 --- a/linux/crates/app/src/ui/workspace/workspace_shell_imp.rs +++ b/linux/crates/app/src/ui/workspace/workspace_shell_imp.rs @@ -87,6 +87,10 @@ pub struct WorkspaceShell { #[template_child] pub assistant_toggle: TemplateChild, #[template_child] + pub safe_mode_slot: TemplateChild, + #[template_child] + pub safe_mode_button: TemplateChild, + #[template_child] pub tab_button: TemplateChild, #[template_child] pub export_operations_button: TemplateChild, diff --git a/linux/data/resources/ui/workspace-shell.ui b/linux/data/resources/ui/workspace-shell.ui index 41f30f192d..cd558698eb 100644 --- a/linux/data/resources/ui/workspace-shell.ui +++ b/linux/data/resources/ui/workspace-shell.ui @@ -45,6 +45,8 @@ false + + false @@ -181,6 +183,18 @@ + + + + + + changes-allow-symbolic + false + + + + assistant-symbolic