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
1 change: 1 addition & 0 deletions linux/changelog.d/4124.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The header has a lock that shows the connection's Safe Mode level and changes it.
2 changes: 2 additions & 0 deletions linux/crates/app/src/ui/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -90,6 +91,7 @@ pub const ALL: &[&str] = &[
APPLICATIONS_ENGINEERING,
APPLICATIONS_SCIENCE,
ASSISTANT,
CHANGES_ALLOW,
CHANGES_PREVENT,
COMPUTER,
DIALOG_ERROR,
Expand Down
53 changes: 53 additions & 0 deletions linux/crates/app/src/ui/session_window/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>())
.as_deref(),
Some("win.safe-mode")
);
assert_eq!(
menu.item_attribute_value(index, gio::MENU_ATTRIBUTE_TARGET, None)
.and_then(|value| value.get::<String>())
.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");
Expand Down
9 changes: 9 additions & 0 deletions linux/crates/app/src/ui/session_window/tests/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions linux/crates/app/src/ui/session_window/window_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ pub(super) fn show_safe_mode(window: &adw::ApplicationWindow, level: Option<Safe
return;
};
action.set_enabled(level.is_some());
if let Some(shell) = window.downcast_ref::<SessionWindow>().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());
}
Expand Down
24 changes: 24 additions & 0 deletions linux/crates/app/src/ui/workspace/tests/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 24 additions & 1 deletion linux/crates/app/src/ui/workspace/workspace_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -594,6 +596,22 @@ impl WorkspaceShell {
self.notify_front();
}

pub(crate) fn show_safe_mode(&self, level: Option<tablepro_core::SafeModeLevel>) {
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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions linux/crates/app/src/ui/workspace/workspace_shell_imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ pub struct WorkspaceShell {
#[template_child]
pub assistant_toggle: TemplateChild<gtk::ToggleButton>,
#[template_child]
pub safe_mode_slot: TemplateChild<adw::Bin>,
#[template_child]
pub safe_mode_button: TemplateChild<gtk::MenuButton>,
#[template_child]
pub tab_button: TemplateChild<adw::TabButton>,
#[template_child]
pub export_operations_button: TemplateChild<ExportOperationsButton>,
Expand Down
14 changes: 14 additions & 0 deletions linux/data/resources/ui/workspace-shell.ui
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<!-- 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>
<!-- The Session Menu holds the Safe Mode levels. -->
<setter object="safe_mode_slot" property="visible">false</setter>
</object>
</child>
<property name="child">
Expand Down Expand Up @@ -181,6 +183,18 @@
</child>
</object>
</property>
<child type="end">
<!-- The narrow layout hides the slot, and a window
with no session hides the lock itself. -->
<object class="AdwBin" id="safe_mode_slot">
<property name="child">
<object class="GtkMenuButton" id="safe_mode_button">
<property name="icon-name">changes-allow-symbolic</property>
<property name="visible">false</property>
</object>
</property>
</object>
</child>
<child type="end">
<object class="GtkToggleButton" id="assistant_toggle">
<property name="icon-name">assistant-symbolic</property>
Expand Down
Loading