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/4125.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refresh the current table, key or diagram from the header.
10 changes: 9 additions & 1 deletion linux/crates/app/src/application/accelerators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ShortcutListing::{Listed, Unlisted};
use ShortcutOwner::{
AssistantComposer, BrowseTab, CellEditor, ConnectionTree, DiagramCanvas, DiagramTab, EditorResults, FilterStrip,
Grid, GridCell, HistoryRow, InlineSuggestion, PickerPage, PickerRow, SqlEditor, SqlEditorCursors, SqlEditorTab,
StructureTab,
StructureTab, WorkspaceShell,
};
use ShortcutSection::{BrowseTable, DataGrid, ErDiagram, General, TableStructure, Tabs};

Expand Down Expand Up @@ -113,6 +113,13 @@ pub const ACCELERATORS: &[Accelerator] = &[
Unlisted,
),
stock("tab-view.select-tenth", &["<Alt>0"], Unlisted),
local(
WorkspaceShell,
BUBBLE,
"win.refresh-page",
&["F5", "<Primary>r"],
Listed(Tabs),
),
local(BrowseTab, BUBBLE, "browse.filter", &["<Primary>f"], Listed(BrowseTable)),
// F5 as in GNOME Files, and Ctrl+R as the GNOME HIG names Reload.
local(
Expand Down Expand Up @@ -556,6 +563,7 @@ pub fn local_shortcut_controller(owner: ShortcutOwner) -> gtk::ShortcutControlle
/// The name `local_shortcut_controller` gives the owner's controller.
pub const fn controller_name(owner: ShortcutOwner) -> &'static str {
match owner {
WorkspaceShell => "tablepro-workspace-shell-shortcuts",
BrowseTab => "tablepro-browse-tab-shortcuts",
GridCell => "tablepro-grid-cell-shortcuts",
Grid => "tablepro-grid-shortcuts",
Expand Down
1 change: 1 addition & 0 deletions linux/crates/app/src/application/shortcut_owner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ShortcutOwner {
WorkspaceShell,
BrowseTab,
/// A data grid's column view, ahead of the list's own key bindings.
GridCell,
Expand Down
2 changes: 1 addition & 1 deletion linux/crates/app/src/ui/session_window/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ fn f002_late_show_create_reply_after_disconnect_is_dropped() {
// The reply comes back through the workspace's input, which the
// teardown closes before the reply is due.
assert_eq!(
input.try_deliver(WorkspaceInput::RefreshPage),
input.try_deliver(WorkspaceInput::RefreshPage(None)),
Delivery::ReceiverGone,
"the torn-down workspace still takes input"
);
Expand Down
2 changes: 1 addition & 1 deletion linux/crates/app/src/ui/session_window/window_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ mod tests {
);
action.activate(None);
assert_eq!(
input.try_deliver(crate::ui::workspace::WorkspaceInput::RefreshPage),
input.try_deliver(crate::ui::workspace::WorkspaceInput::RefreshPage(None)),
Delivery::ReceiverGone
);
}
Expand Down
2 changes: 2 additions & 0 deletions linux/crates/app/src/ui/workspace/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub struct Workspace {
/// A provider is chosen, so the assistant's column and toggle show.
#[property(get)]
pub(super) assistant_available: Cell<bool>,
#[property(get)]
pub(super) can_refresh: Cell<bool>,

pub(super) key: OnceCell<SessionKey>,
pub(super) data_model: OnceCell<DataModel>,
Expand Down
4 changes: 2 additions & 2 deletions linux/crates/app/src/ui/workspace/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl WorkspaceModel {
imports.settle(ticket.id);
match finished {
Ok(Ok(rows)) => {
input.deliver(WorkspaceInput::RefreshPage);
input.deliver(WorkspaceInput::RefreshPage(None));
input.deliver(WorkspaceInput::ShowToast(crate::i18n::ngettext_f(
"Imported {n} row.",
"Imported {n} rows.",
Expand All @@ -180,7 +180,7 @@ impl WorkspaceModel {
"That file has no rows to import.",
))),
Ok(Err(ImportEnd::Stopped)) => {
input.deliver(WorkspaceInput::RefreshPage);
input.deliver(WorkspaceInput::RefreshPage(None));
input.deliver(WorkspaceInput::ShowToast(crate::i18n::gettext("Import stopped.")));
}
Ok(Err(ImportEnd::Declined)) => {}
Expand Down
9 changes: 6 additions & 3 deletions linux/crates/app/src/ui/workspace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ pub(crate) enum WorkspaceInput {
id: Uuid,
approved: bool,
},
RefreshPage,
RefreshPage(Option<Uuid>),
ExportResults {
tab: Uuid,
offer: Box<ExportOffer>,
Expand Down Expand Up @@ -1102,7 +1102,10 @@ impl Workspace {
}

fn handle_input(&self, message: WorkspaceInput) {
self.with_model(|model| model.update(message));
self.with_model(|model| {
model.update(message);
model.refresh_header_actions();
});
}

fn with_model<R>(&self, f: impl FnOnce(&mut WorkspaceModel) -> R) -> Option<R> {
Expand Down Expand Up @@ -1408,7 +1411,7 @@ impl WorkspaceModel {
WorkspaceInput::SaveQueryNamed { name, query } => self.on_save_query_named(name, query),
WorkspaceInput::OpenHistoryQuery(text) => self.open_editor_tab(Some(text)),
WorkspaceInput::ReplaceActiveTabQuery(text) => self.on_replace_active_tab_query(text),
WorkspaceInput::RefreshPage => self.on_refresh_active_tab(),
WorkspaceInput::RefreshPage(tab) => self.on_refresh_page(tab),
WorkspaceInput::ExportResults { tab, offer } => self.on_export_results(tab, *offer),
WorkspaceInput::ExportEnded { tab, outcome } => self.on_export_ended(tab, outcome),
WorkspaceInput::ReopenClosedTab(tab) => self.on_reopen_closed_tab(tab),
Expand Down
49 changes: 49 additions & 0 deletions linux/crates/app/src/ui/workspace/tests/close_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,52 @@ fn close_all_tabs_asks_before_closing_unsaved_work() {
assert!(tab_is_open(&test, id), "the tab with unsaved changes closed");
assert_eq!(crate::test_support::read_text_file(&path), "SELECT 1;");
}

#[gtk4::test]
fn header_refresh_commits_the_inline_edit_before_asking_to_discard() {
let test = TestWindow::connected_with("HeaderRefreshEdit", serving_tables);
let (_, tab) = open_table(&test, "users");
let cell = type_a_name(&tab);
let button = shell_of(&test.workspace()).imp().refresh_page_button.get();
wait_until(WAIT, || button.is_sensitive()).expect("table refresh enabled");
let before = test.connection().observed_sql("query_bound").len();

button.emit_clicked();
wait_until(WAIT, || crate::workspace::visible_alert(&test.window).is_some()).expect("discard confirmation");
assert!(!cell.is_editing());
assert_eq!(test.connection().observed_sql("query_bound").len(), before);
assert!(crate::workspace::answer(&test.window, "cancel"));
crate::test_support::drain_main_context();
assert_eq!(test.connection().observed_sql("query_bound").len(), before);

button.emit_clicked();
wait_until(WAIT, || crate::workspace::visible_alert(&test.window).is_some()).expect("discard confirmation again");
assert!(crate::workspace::answer(&test.window, "discard"));
wait_until(WAIT, || test.connection().observed_sql("query_bound").len() > before).expect("table reloaded");
}

#[gtk4::test]
fn header_refresh_keeps_the_tab_clicked_before_selection_moves() {
let test = TestWindow::connected_with("HeaderRefreshTarget", serving_tables);
let (_, first) = open_table(&test, "users");
let (_, second) = open_table(&test, "orders");
wait_until(WAIT, || first.grid().row_count() == 2 && second.grid().row_count() == 2).expect("both tables loaded");
let shell = shell_of(&test.workspace());
let view = shell.tab_view();
let first_page = view.page(&first);
let second_page = view.page(&second);
view.set_selected_page(&first_page);
let button = shell.imp().refresh_page_button.get();
wait_until(WAIT, || button.is_sensitive()).expect("refresh enabled");
let before = test.connection().observed_sql("query_bound").len();
button.emit_clicked();
view.set_selected_page(&second_page);
wait_until(WAIT, || test.connection().observed_sql("query_bound").len() > before).expect("refresh read");
assert!(
test.connection()
.observed_sql("query_bound")
.last()
.and_then(Option::as_deref)
.is_some_and(|sql| sql.contains("users"))
);
}
13 changes: 13 additions & 0 deletions linux/crates/app/src/ui/workspace/tests/diagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,16 @@ fn the_diagram_draws_in_the_themes_colours() {
assert_eq!(palette.background.alpha(), 1.0);
assert!(palette.accent.alpha() > 0.0);
}

#[gtk4::test]
fn the_header_refresh_reads_the_selected_diagram_again() {
let test = TestWindow::connected_with("HeaderRefreshDiagram", sales);
show_diagram(&test, "sales");
wait_until(WAIT, || diagrams(&test).len() == 1).expect("the diagram tab");
drawn(&diagrams(&test)[0]);
let button = shell_of(&test.workspace()).imp().refresh_page_button.get();
wait_until(WAIT, || button.is_sensitive()).expect("diagram refresh enabled");
let before = test.connection().observed_sql("list_objects").len();
button.emit_clicked();
wait_until(WAIT, || test.connection().observed_sql("list_objects").len() > before).expect("diagram reloaded");
}
16 changes: 16 additions & 0 deletions linux/crates/app/src/ui/workspace/tests/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,19 @@ fn a_key_tab_is_reopened_with_the_session() {

wait_until(WAIT, || key_tabs(&workspace) == ["user:2"]).expect("the saved key tab");
}

#[gtk4::test]
fn the_header_refresh_reads_the_selected_key_again() {
let test = keys_window("HeaderRefreshKey", |script| {
script.scan_keys.always(listing(three_keys(), true));
script.read_key.always(string_page("Ada"));
});
let workspace = test.workspace();
open_key(&workspace, "user:2");
wait_until(WAIT, || !test.connection().observed_sql("read_key").is_empty()).expect("the key loaded");
let button = shell(&workspace).imp().refresh_page_button.get();
wait_until(WAIT, || button.is_sensitive()).expect("key refresh enabled");
let before = test.connection().observed_sql("read_key").len();
button.emit_clicked();
wait_until(WAIT, || test.connection().observed_sql("read_key").len() > before).expect("key reloaded");
}
54 changes: 54 additions & 0 deletions linux/crates/app/src/ui/workspace/tests/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,57 @@ fn the_main_menu_adds_a_connection_with_none_open() {

choose_new_connection(&test, &test.window.content().expect("the picker"));
}

#[gtk4::test]
fn the_header_refresh_follows_the_selected_tabs_capability() {
use super::super::structure_target::StructureTarget;
use super::super::tab_spec::{TabSpec, TablePage};
use crate::ui::browse_tab::TableFilter;
use tablepro_core::meta::TableRef;

let test = TestWindow::connected("HeaderRefresh");
let workspace = test.workspace();
let shell = shell_of(&workspace);
let button = shell.imp().refresh_page_button.get();
assert_eq!(button.action_name().as_deref(), Some("win.refresh-page"));
crate::test_support::assert_labelled(&button).expect("the refresh button is named");
assert!(gtk::test_accessible_has_property(
&button,
gtk::AccessibleProperty::KeyShortcuts
));
assert!(!button.is_sensitive(), "there is no tab to refresh");

let table = workspace
.with_model(|model| {
model.open_tab(TabSpec::Table {
table: TableRef::unqualified("customers"),
page: TablePage::first(100),
filter: TableFilter::Remembered,
})
})
.flatten()
.expect("a table");
wait_until(WAIT, || button.is_sensitive()).expect("table refresh");
super::open_editor(&workspace);
wait_until(WAIT, || !button.is_sensitive()).expect("no editor rerun");
workspace
.with_model(|model| {
model.open_tab(TabSpec::Structure {
target: StructureTarget::Existing(TableRef::unqualified("customers")),
})
})
.flatten()
.expect("a structure draft");
wait_until(WAIT, || !button.is_sensitive()).expect("no draft to reload");
workspace.with_model(|model| model.tab_view.set_selected_page(&table));
wait_until(WAIT, || button.is_sensitive()).expect("refresh after selection inside the model");

for page in (0..shell.tab_view().n_pages())
.map(|i| shell.tab_view().nth_page(i))
.collect::<Vec<_>>()
{
shell.tab_view().close_page(&page);
}
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");
}
14 changes: 14 additions & 0 deletions linux/crates/app/src/ui/workspace/workspace_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ pub(super) fn install(window: &adw::ApplicationWindow, shell: &WorkspaceShell) {
.build()
});
window.add_action_entries(actions);
let refreshing = shell.downgrade();
window.add_action_entries([gio::ActionEntry::<adw::ApplicationWindow>::builder("refresh-page")
.activate(move |_, _, _| {
if let Some(shell) = refreshing.upgrade()
&& let Some(page) = shell.tab_view().selected_page()
&& let Some((owner, id)) = shell.owner_of(&page)
&& let Some(input) = owner.sender()
{
input.deliver(WorkspaceInput::RefreshPage(Some(id)));
}
})
.build()]);
set_enabled(window, "refresh-page", false);
let reopening = shell.downgrade();
window.add_action_entries([gio::ActionEntry::<adw::ApplicationWindow>::builder(REOPEN_CLOSED_TAB)
.activate(move |_, _, _| {
Expand Down Expand Up @@ -126,6 +139,7 @@ pub(super) fn remove(window: &adw::ApplicationWindow) {
window.remove_action(CLOSE_ALL_TABS);
window.remove_action(SWITCH_RECENT_TAB);
window.remove_action(SHOW_TABS);
window.remove_action("refresh-page");
}

/// Offer Export Database and Import SQL File where the session in front
Expand Down
9 changes: 9 additions & 0 deletions linux/crates/app/src/ui/workspace/workspace_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ pub(super) fn describe_buttons(shell: &WorkspaceShell) {
&gettext("Show Sidebar"),
Some("win.show-sidebar"),
);
describe_icon_button(
&imp.refresh_page_button.get(),
&gettext("Refresh Tab"),
Some("win.refresh-page"),
);
describe_icon_button(
&imp.new_tab_button.get(),
&gettext("New Query"),
Expand Down Expand Up @@ -125,6 +130,9 @@ impl WorkspaceShell {
shell.connect_view();
shell.connect_front_notify(Self::on_front_changed);
shell.bind_front();
shell.add_controller(crate::application::local_shortcut_controller(
crate::application::ShortcutOwner::WorkspaceShell,
));
shell.describe_front();

imp.table_search_bar.connect_entry(&*imp.table_search);
Expand Down Expand Up @@ -327,6 +335,7 @@ impl WorkspaceShell {
for (name, property) in [
(SHOW_ASSISTANT, "assistant-available"),
(REVIEW_HOST_KEY, "can-review-host-key"),
("refresh-page", "can-refresh"),
] {
if let Some(action) = window.lookup_action(name).and_downcast::<gio::SimpleAction>() {
// Off until a session is in front to say.
Expand Down
2 changes: 2 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 @@ -81,6 +81,8 @@ pub struct WorkspaceShell {
#[template_child]
pub connection_icon: TemplateChild<gtk::Image>,
#[template_child]
pub refresh_page_button: TemplateChild<gtk::Button>,
#[template_child]
pub assistant_toggle: TemplateChild<gtk::ToggleButton>,
#[template_child]
pub tab_button: TemplateChild<adw::TabButton>,
Expand Down
Loading
Loading