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/4118.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The bottom bar has a Columns button that opens the column chooser.
1 change: 1 addition & 0 deletions linux/crates/app/src/ui/browse_tab/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ fn more_menu(page_sizes: &[u64]) -> gio::Menu {
}
let actions = gio::Menu::new();
actions.append(Some(&gettext("_Filter Rows")), Some("browse.filter"));
actions.append(Some(&gettext("Col_umns…")), Some("grid.columns"));
actions.append_item(&export);
actions.append(Some(&gettext("_Count Rows")), Some("browse.count-rows"));
let sizes = gio::Menu::new();
Expand Down
61 changes: 61 additions & 0 deletions linux/crates/app/src/ui/browse_tab/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,3 +1536,64 @@ fn a_dotted_field_of_a_document_neither_sorts_nor_takes_an_edit() {
assert!(!grid.edit().edit_cell(&cell), "the dotted field opened for editing");
assert_eq!(harness.tracker.pending_count(), 0);
}

#[gtk4::test]
fn the_bottom_bar_offers_the_column_chooser() {
use gtk4::subclass::prelude::ObjectSubclassIsExt;
use libadwaita::prelude::*;

let mut script = serving_table();
script.query_bound.always(FakeReply::ok(rows(&["Ada"])));
let harness = Harness::open(script, []);
let tab = harness.tab();
let window = crate::test_support::OwnedWindow::presented(
libadwaita::Window::builder()
.default_width(1000)
.default_height(500)
.content(tab)
.build(),
);
let button = crate::test_support::find_by_action_name(tab, "grid.columns")
.and_downcast::<gtk4::Button>()
.expect("a Columns button");
// A pending initial surface configure can otherwise overwrite the later resize.
wait_until(WAIT, || {
window.is_mapped() && tab.width() >= 900 && !harness.shown().is_empty()
})
.expect("the wide window is allocated");
assert!(tab.current_breakpoint().is_none());
assert!(button.is_visible(), "the wide bar shows Columns");
assert_eq!(button.label().as_deref(), Some("Columns"));
assert!(button.is_focusable());
button.emit_clicked();
wait_until(WAIT, || window.visible_dialog().is_some()).expect("Columns opens a dialog");
let chooser = window.visible_dialog().expect("the chooser");
assert!(chooser.is::<crate::ui::data_grid::ColumnChooser>());
chooser.close();
wait_until(WAIT, || window.visible_dialog().is_none() && chooser.parent().is_none()).expect("the chooser closes");

window.set_default_size(600, 500);
assert!(
wait_until(WAIT, || tab.width() > 0 && tab.width() <= 600).is_ok(),
"the tab did not resize: window width {}, tab width {}",
window.width(),
tab.width(),
);
assert!(!button.is_visible(), "the narrow bar hides Columns");
assert!(tab.imp().more_button.is_visible(), "the narrow bar offers More");
let menu = tab.imp().more_button.menu_model().expect("More menu");
let actions = menu
.item_link(0, gtk4::gio::MENU_LINK_SECTION)
.expect("actions section");
assert!((0..actions.n_items()).any(|index| {
actions
.item_attribute_value(index, gtk4::gio::MENU_ATTRIBUTE_ACTION, None)
.and_then(|value| value.get::<String>())
.as_deref()
== Some("grid.columns")
}));
tab.activate_action("grid.columns", None)
.expect("More reaches the grid");
wait_until(WAIT, || window.visible_dialog().is_some()).expect("More opens Columns");
window.visible_dialog().expect("the chooser").close();
}
52 changes: 52 additions & 0 deletions linux/crates/app/src/ui/editor/results_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ mod imp {
#[template_child]
pub details_toggle: TemplateChild<gtk4::ToggleButton>,
#[template_child]
pub columns_button: TemplateChild<gtk4::Button>,
#[template_child]
pub transaction_bar: TemplateChild<gtk4::Box>,
#[template_child]
pub transaction_label: TemplateChild<gtk4::Label>,
Expand Down Expand Up @@ -307,6 +309,7 @@ impl ResultsPane {
let actions = grid.map(DataGrid::actions);
self.insert_action_group("grid", actions.as_ref());
self.imp().details_toggle.set_visible(grid.is_some());
self.imp().columns_button.set_visible(grid.is_some());
}

/// Put the page of line `index` first among the kept ones, building
Expand Down Expand Up @@ -562,6 +565,10 @@ mod tests {
gtk4::AccessibleProperty::Label
));
}
assert!(gtk4::test_accessible_has_property(
&pane.imp().columns_button.get(),
gtk4::AccessibleProperty::Label
));
}

#[gtk4::test]
Expand All @@ -571,12 +578,57 @@ mod tests {
pane.append(&[command()]);

assert!(!pane.imp().details_toggle.is_visible());
assert!(
!pane.imp().columns_button.is_visible(),
"Columns without a grid to choose from"
);
assert!(
pane.activate_action("grid.show-details", None).is_err(),
"the pane reaches a grid it does not show"
);
}

#[gtk4::test]
fn columns_follows_the_shown_result_and_clears_with_the_run() {
use crate::ui::data_grid::test_grid::{Grid, named};
use std::cell::Cell;
use std::rc::Rc;

let grid = Grid::open(vec![named("id", "int", true)], vec![]);
grid.window.set_child(None::<&gtk4::Widget>);
let pane = pane();
let result_grid = grid.grid.clone();
pane.set_page_builder(move |index| {
Some(if index == 0 {
ResultPage {
widget: result_grid.clone().upcast(),
grid: Some(result_grid.clone()),
}
} else {
ResultPage::plain(gtk4::Label::new(Some("Done")).upcast())
})
});
grid.window.set_child(Some(&pane));
let activated = Rc::new(Cell::new(0));
let count = activated.clone();
let action = gio::SimpleAction::new("columns", None);
action.connect_activate(move |_, _| count.set(count.get() + 1));
grid.grid.actions().add_action(&action);
pane.append(&[command(), command()]);
assert!(pane.imp().columns_button.is_visible());
pane.imp().columns_button.emit_clicked();
assert_eq!(activated.get(), 1);
pane.select(1);
assert!(!pane.imp().columns_button.is_visible());
assert!(pane.activate_action("grid.columns", None).is_err());
pane.select(0);
pane.imp().columns_button.emit_clicked();
assert_eq!(activated.get(), 2);
pane.clear();
assert!(!pane.imp().columns_button.is_visible());
assert!(pane.activate_action("grid.columns", None).is_err());
}

#[gtk4::test]
fn a_long_list_builds_only_the_page_it_shows() {
let pane = pane();
Expand Down
11 changes: 11 additions & 0 deletions linux/data/resources/ui/browse-tab.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<condition>max-width: 680sp</condition>
<setter object="export_button" property="visible">false</setter>
<setter object="filter_button" property="visible">false</setter>
<setter object="columns_button" property="visible">false</setter>
<setter object="page_size_box" property="visible">false</setter>
<setter object="more_button" property="visible">true</setter>
<setter object="pager_bar" property="compact">true</setter>
Expand Down Expand Up @@ -195,6 +196,16 @@
</property>
</object>
</child>
<child type="end">
<object class="GtkButton" id="columns_button">
<property name="label" translatable="yes">Columns</property>
<property name="tooltip-text" translatable="yes">Choose which columns the grid shows</property>
<property name="action-name">grid.columns</property>
<style>
<class name="flat"/>
</style>
</object>
</child>
<child type="end">
<object class="GtkBox" id="page_size_box">
<property name="spacing">6</property>
Expand Down
14 changes: 14 additions & 0 deletions linux/data/resources/ui/results-pane.ui
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@
</child>
</object>
</child>
<child>
<object class="GtkButton" id="columns_button">
<property name="icon-name">view-reveal-symbolic</property>
<property name="tooltip-text" translatable="yes">Choose which columns the grid shows</property>
<property name="action-name">grid.columns</property>
<property name="visible">false</property>
<style>
<class name="flat"/>
</style>
<accessibility>
<property name="label" translatable="yes">Columns</property>
</accessibility>
</object>
</child>
<child>
<!-- The pane inserts the shown result's grid actions as
grid, and hides this while the result has no grid. -->
Expand Down
Loading