Skip to content

Commit 87db2fa

Browse files
authored
feat(linux-grid): add the Columns button to the bottom bar (#4118)
1 parent 6dde185 commit 87db2fa

6 files changed

Lines changed: 140 additions & 0 deletions

File tree

‎linux/changelog.d/4118.added.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The bottom bar has a Columns button that opens the column chooser.

‎linux/crates/app/src/ui/browse_tab/layout.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ fn more_menu(page_sizes: &[u64]) -> gio::Menu {
7171
}
7272
let actions = gio::Menu::new();
7373
actions.append(Some(&gettext("_Filter Rows")), Some("browse.filter"));
74+
actions.append(Some(&gettext("Col_umns…")), Some("grid.columns"));
7475
actions.append_item(&export);
7576
actions.append(Some(&gettext("_Count Rows")), Some("browse.count-rows"));
7677
let sizes = gio::Menu::new();

‎linux/crates/app/src/ui/browse_tab/tests/mod.rs‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,3 +1536,64 @@ fn a_dotted_field_of_a_document_neither_sorts_nor_takes_an_edit() {
15361536
assert!(!grid.edit().edit_cell(&cell), "the dotted field opened for editing");
15371537
assert_eq!(harness.tracker.pending_count(), 0);
15381538
}
1539+
1540+
#[gtk4::test]
1541+
fn the_bottom_bar_offers_the_column_chooser() {
1542+
use gtk4::subclass::prelude::ObjectSubclassIsExt;
1543+
use libadwaita::prelude::*;
1544+
1545+
let mut script = serving_table();
1546+
script.query_bound.always(FakeReply::ok(rows(&["Ada"])));
1547+
let harness = Harness::open(script, []);
1548+
let tab = harness.tab();
1549+
let window = crate::test_support::OwnedWindow::presented(
1550+
libadwaita::Window::builder()
1551+
.default_width(1000)
1552+
.default_height(500)
1553+
.content(tab)
1554+
.build(),
1555+
);
1556+
let button = crate::test_support::find_by_action_name(tab, "grid.columns")
1557+
.and_downcast::<gtk4::Button>()
1558+
.expect("a Columns button");
1559+
// A pending initial surface configure can otherwise overwrite the later resize.
1560+
wait_until(WAIT, || {
1561+
window.is_mapped() && tab.width() >= 900 && !harness.shown().is_empty()
1562+
})
1563+
.expect("the wide window is allocated");
1564+
assert!(tab.current_breakpoint().is_none());
1565+
assert!(button.is_visible(), "the wide bar shows Columns");
1566+
assert_eq!(button.label().as_deref(), Some("Columns"));
1567+
assert!(button.is_focusable());
1568+
button.emit_clicked();
1569+
wait_until(WAIT, || window.visible_dialog().is_some()).expect("Columns opens a dialog");
1570+
let chooser = window.visible_dialog().expect("the chooser");
1571+
assert!(chooser.is::<crate::ui::data_grid::ColumnChooser>());
1572+
chooser.close();
1573+
wait_until(WAIT, || window.visible_dialog().is_none() && chooser.parent().is_none()).expect("the chooser closes");
1574+
1575+
window.set_default_size(600, 500);
1576+
assert!(
1577+
wait_until(WAIT, || tab.width() > 0 && tab.width() <= 600).is_ok(),
1578+
"the tab did not resize: window width {}, tab width {}",
1579+
window.width(),
1580+
tab.width(),
1581+
);
1582+
assert!(!button.is_visible(), "the narrow bar hides Columns");
1583+
assert!(tab.imp().more_button.is_visible(), "the narrow bar offers More");
1584+
let menu = tab.imp().more_button.menu_model().expect("More menu");
1585+
let actions = menu
1586+
.item_link(0, gtk4::gio::MENU_LINK_SECTION)
1587+
.expect("actions section");
1588+
assert!((0..actions.n_items()).any(|index| {
1589+
actions
1590+
.item_attribute_value(index, gtk4::gio::MENU_ATTRIBUTE_ACTION, None)
1591+
.and_then(|value| value.get::<String>())
1592+
.as_deref()
1593+
== Some("grid.columns")
1594+
}));
1595+
tab.activate_action("grid.columns", None)
1596+
.expect("More reaches the grid");
1597+
wait_until(WAIT, || window.visible_dialog().is_some()).expect("More opens Columns");
1598+
window.visible_dialog().expect("the chooser").close();
1599+
}

‎linux/crates/app/src/ui/editor/results_pane.rs‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ mod imp {
5454
#[template_child]
5555
pub details_toggle: TemplateChild<gtk4::ToggleButton>,
5656
#[template_child]
57+
pub columns_button: TemplateChild<gtk4::Button>,
58+
#[template_child]
5759
pub transaction_bar: TemplateChild<gtk4::Box>,
5860
#[template_child]
5961
pub transaction_label: TemplateChild<gtk4::Label>,
@@ -307,6 +309,7 @@ impl ResultsPane {
307309
let actions = grid.map(DataGrid::actions);
308310
self.insert_action_group("grid", actions.as_ref());
309311
self.imp().details_toggle.set_visible(grid.is_some());
312+
self.imp().columns_button.set_visible(grid.is_some());
310313
}
311314

312315
/// Put the page of line `index` first among the kept ones, building
@@ -562,6 +565,10 @@ mod tests {
562565
gtk4::AccessibleProperty::Label
563566
));
564567
}
568+
assert!(gtk4::test_accessible_has_property(
569+
&pane.imp().columns_button.get(),
570+
gtk4::AccessibleProperty::Label
571+
));
565572
}
566573

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

573580
assert!(!pane.imp().details_toggle.is_visible());
581+
assert!(
582+
!pane.imp().columns_button.is_visible(),
583+
"Columns without a grid to choose from"
584+
);
574585
assert!(
575586
pane.activate_action("grid.show-details", None).is_err(),
576587
"the pane reaches a grid it does not show"
577588
);
578589
}
579590

591+
#[gtk4::test]
592+
fn columns_follows_the_shown_result_and_clears_with_the_run() {
593+
use crate::ui::data_grid::test_grid::{Grid, named};
594+
use std::cell::Cell;
595+
use std::rc::Rc;
596+
597+
let grid = Grid::open(vec![named("id", "int", true)], vec![]);
598+
grid.window.set_child(None::<&gtk4::Widget>);
599+
let pane = pane();
600+
let result_grid = grid.grid.clone();
601+
pane.set_page_builder(move |index| {
602+
Some(if index == 0 {
603+
ResultPage {
604+
widget: result_grid.clone().upcast(),
605+
grid: Some(result_grid.clone()),
606+
}
607+
} else {
608+
ResultPage::plain(gtk4::Label::new(Some("Done")).upcast())
609+
})
610+
});
611+
grid.window.set_child(Some(&pane));
612+
let activated = Rc::new(Cell::new(0));
613+
let count = activated.clone();
614+
let action = gio::SimpleAction::new("columns", None);
615+
action.connect_activate(move |_, _| count.set(count.get() + 1));
616+
grid.grid.actions().add_action(&action);
617+
pane.append(&[command(), command()]);
618+
assert!(pane.imp().columns_button.is_visible());
619+
pane.imp().columns_button.emit_clicked();
620+
assert_eq!(activated.get(), 1);
621+
pane.select(1);
622+
assert!(!pane.imp().columns_button.is_visible());
623+
assert!(pane.activate_action("grid.columns", None).is_err());
624+
pane.select(0);
625+
pane.imp().columns_button.emit_clicked();
626+
assert_eq!(activated.get(), 2);
627+
pane.clear();
628+
assert!(!pane.imp().columns_button.is_visible());
629+
assert!(pane.activate_action("grid.columns", None).is_err());
630+
}
631+
580632
#[gtk4::test]
581633
fn a_long_list_builds_only_the_page_it_shows() {
582634
let pane = pane();

‎linux/data/resources/ui/browse-tab.ui‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<condition>max-width: 680sp</condition>
1414
<setter object="export_button" property="visible">false</setter>
1515
<setter object="filter_button" property="visible">false</setter>
16+
<setter object="columns_button" property="visible">false</setter>
1617
<setter object="page_size_box" property="visible">false</setter>
1718
<setter object="more_button" property="visible">true</setter>
1819
<setter object="pager_bar" property="compact">true</setter>
@@ -195,6 +196,16 @@
195196
</property>
196197
</object>
197198
</child>
199+
<child type="end">
200+
<object class="GtkButton" id="columns_button">
201+
<property name="label" translatable="yes">Columns</property>
202+
<property name="tooltip-text" translatable="yes">Choose which columns the grid shows</property>
203+
<property name="action-name">grid.columns</property>
204+
<style>
205+
<class name="flat"/>
206+
</style>
207+
</object>
208+
</child>
198209
<child type="end">
199210
<object class="GtkBox" id="page_size_box">
200211
<property name="spacing">6</property>

‎linux/data/resources/ui/results-pane.ui‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@
8080
</child>
8181
</object>
8282
</child>
83+
<child>
84+
<object class="GtkButton" id="columns_button">
85+
<property name="icon-name">view-reveal-symbolic</property>
86+
<property name="tooltip-text" translatable="yes">Choose which columns the grid shows</property>
87+
<property name="action-name">grid.columns</property>
88+
<property name="visible">false</property>
89+
<style>
90+
<class name="flat"/>
91+
</style>
92+
<accessibility>
93+
<property name="label" translatable="yes">Columns</property>
94+
</accessibility>
95+
</object>
96+
</child>
8397
<child>
8498
<!-- The pane inserts the shown result's grid actions as
8599
grid, and hides this while the result has no grid. -->

0 commit comments

Comments
 (0)