GUI round 11 (#9): option to hide columns with no scanned values
build-test-release / release (push) Failing after 11m10s
build-test-release / release (push) Failing after 11m10s
The Columns dialog gains a "Hide columns with no scanned values" checkbox. When on, columns whose cell is blank for every current row are hidden from the table. It is non-destructive: the hiding is applied at table-build time via a new App::table_columns() (used by every table-path caller in place of view.display_columns()), so clearing the option restores the columns and the underlying column order/visibility is never mutated. IP is never hidden, and nothing is hidden before the first scan (no rows -> nothing empty). Note: while the option is hiding columns, drag-reorder of the header is a no-op (the reorder validates against the full visible set); turn the option off to reorder. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
This commit is contained in:
@@ -481,6 +481,11 @@ pub struct App {
|
||||
ranges_auto: Widget,
|
||||
columns_dialog: Widget,
|
||||
columns_list: Widget,
|
||||
/// The columns-dialog "hide empty columns" checkbox, read at Apply.
|
||||
columns_hide_empty_cb: Widget,
|
||||
/// When set, columns with no scanned value in any row are hidden from the
|
||||
/// table (non-destructively -- clearing it restores them) (round 11 #9).
|
||||
auto_hide_empty: bool,
|
||||
// Filter dialog (Excel-style, one column at a time via a dropdown).
|
||||
filter_dialog: Widget,
|
||||
filter_col_choice: Widget, // which column to filter
|
||||
@@ -707,6 +712,8 @@ pub fn build(frame: Widget) -> App {
|
||||
ranges_auto: frame,
|
||||
columns_dialog: frame,
|
||||
columns_list: frame,
|
||||
columns_hide_empty_cb: frame,
|
||||
auto_hide_empty: false,
|
||||
filter_dialog: frame,
|
||||
filter_col_choice: frame,
|
||||
filter_controls: frame,
|
||||
@@ -732,6 +739,28 @@ pub fn build(frame: Widget) -> App {
|
||||
}
|
||||
|
||||
impl App {
|
||||
/// Whether `c` has no scanned value in any current row (round 11 #9). IP is
|
||||
/// never empty. With no rows loaded, nothing is considered empty (so the
|
||||
/// table isn't blanked before the first scan).
|
||||
fn column_is_empty(&self, c: Column) -> bool {
|
||||
c != Column::Ip
|
||||
&& !self.rows.is_empty()
|
||||
&& self.rows.iter().all(|r| c.cell(r).trim().is_empty())
|
||||
}
|
||||
|
||||
/// The columns the table actually shows: the view's display columns, minus
|
||||
/// any that are empty across all rows when the "hide empty columns" option is
|
||||
/// on (round 11 #9). Every table-path caller uses this (not
|
||||
/// `view.display_columns()` directly) so header/sort/reorder indices agree
|
||||
/// with what is rendered.
|
||||
fn table_columns(&self) -> Vec<Column> {
|
||||
let mut cols = self.view.display_columns();
|
||||
if self.auto_hide_empty {
|
||||
cols.retain(|c| !self.column_is_empty(*c));
|
||||
}
|
||||
cols
|
||||
}
|
||||
|
||||
pub fn rebuild_table(&mut self) {
|
||||
// Detach the old table from the sizer before destroying it, so the
|
||||
// sizer never holds a dangling item, then drop it.
|
||||
@@ -748,7 +777,7 @@ impl App {
|
||||
// an ASCII direction marker in its header ("^" asc, "v" desc) -- wx's
|
||||
// native SetSortOrder re-sorts the store lexically and would fight our
|
||||
// numeric sort, so we mark the header text instead.
|
||||
for c in self.view.display_columns() {
|
||||
for c in self.table_columns() {
|
||||
let fixed = self.view.is_fixed(c);
|
||||
let mut title = c.title().to_string();
|
||||
match self.view.sort {
|
||||
@@ -781,7 +810,7 @@ impl App {
|
||||
let top = t.dvlc_get_top_row();
|
||||
t.dvlc_clear();
|
||||
self.view_idx = self.view.view(&self.rows);
|
||||
let cols = self.view.display_columns();
|
||||
let cols = self.table_columns();
|
||||
for &ri in &self.view_idx {
|
||||
let r = &self.rows[ri];
|
||||
let cells: Vec<String> = cols.iter().map(|c| c.cell(r)).collect();
|
||||
@@ -1964,7 +1993,7 @@ impl App {
|
||||
// Columns are appended in display order; map the clicked creation index
|
||||
// back to a model column through display_columns() (hidden columns don't
|
||||
// shift the mapping). Every column, including IP at index 0, is sortable.
|
||||
let cols = self.view.display_columns();
|
||||
let cols = self.table_columns();
|
||||
if creation_idx >= cols.len() {
|
||||
return;
|
||||
}
|
||||
@@ -1997,7 +2026,7 @@ impl App {
|
||||
/// auto-size, and open the full column picker).
|
||||
fn header_context_menu(&mut self, creation_idx: usize) {
|
||||
let Some(t) = self.table else { return };
|
||||
let cols = self.view.display_columns();
|
||||
let cols = self.table_columns();
|
||||
let Some(&col) = cols.get(creation_idx) else { return };
|
||||
self.header_menu_col = Some(col);
|
||||
let menu = Widget::menu_new();
|
||||
@@ -2050,7 +2079,7 @@ impl App {
|
||||
}
|
||||
ID_HDR_AUTOSIZE => {
|
||||
if let (Some(t), Some(pos)) =
|
||||
(self.table, self.view.display_columns().iter().position(|c| *c == col))
|
||||
(self.table, self.table_columns().iter().position(|c| *c == col))
|
||||
{
|
||||
t.dvlc_autosize_col(pos);
|
||||
}
|
||||
@@ -2065,7 +2094,7 @@ impl App {
|
||||
/// place, without recreating the table.
|
||||
fn update_headers(&self) {
|
||||
let Some(t) = self.table else { return };
|
||||
for (i, c) in self.view.display_columns().iter().enumerate() {
|
||||
for (i, c) in self.table_columns().iter().enumerate() {
|
||||
let mut title = c.title().to_string();
|
||||
match self.view.sort {
|
||||
Some((sc, true)) if sc == *c => title.push_str(" ^"),
|
||||
@@ -2087,7 +2116,7 @@ impl App {
|
||||
// model column via display_columns(). Read the new visible order from
|
||||
// the drag result and hand it to the model, which splices it back into
|
||||
// the full column order while leaving hidden columns in place.
|
||||
let disp = self.view.display_columns();
|
||||
let disp = self.table_columns();
|
||||
let n = t.dvlc_col_count();
|
||||
let mut new_visible = Vec::with_capacity(n);
|
||||
for pos in 0..n {
|
||||
@@ -2309,6 +2338,11 @@ impl App {
|
||||
}
|
||||
let list = Widget::rearrange_list(dlg, &order, &titles);
|
||||
root.add(list, 1, sf::EXPAND | sf::BORDER_ALL, 6);
|
||||
// Option: hide columns with no scanned value in any row (round 11 #9).
|
||||
let hide_empty = Widget::check_box(dlg, "Hide columns with no scanned values");
|
||||
hide_empty.set_checked(self.auto_hide_empty);
|
||||
root.add(hide_empty, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT | sf::BORDER_BOTTOM, 6);
|
||||
self.columns_hide_empty_cb = hide_empty;
|
||||
let btns = Widget::box_sizer(false);
|
||||
btns.add(Widget::button(dlg, "OK", ID_COLUMNS_OK), 0, sf::BORDER_ALL, 6);
|
||||
btns.add(Widget::button(dlg, "Cancel", ID_COLUMNS_CANCEL), 0, sf::BORDER_ALL, 6);
|
||||
@@ -2321,6 +2355,9 @@ impl App {
|
||||
}
|
||||
|
||||
fn apply_columns(&mut self) {
|
||||
// Persist the "hide empty columns" option (round 11 #9); table_columns()
|
||||
// applies it non-destructively when the table is (re)built below.
|
||||
self.auto_hide_empty = self.columns_hide_empty_cb.is_checked();
|
||||
let base = Self::selectable_columns();
|
||||
let order = self.columns_list.rearrange_get_order();
|
||||
let mut new_order: Vec<Column> = vec![Column::Ip];
|
||||
@@ -2788,7 +2825,7 @@ impl App {
|
||||
check("table exists", false, "no table widget".into());
|
||||
return false;
|
||||
};
|
||||
let cols = self.view.display_columns();
|
||||
let cols = self.table_columns();
|
||||
|
||||
// 2. Row count in the store matches the (unfiltered) fixture count.
|
||||
let want_rows = self.view_idx.len();
|
||||
|
||||
Reference in New Issue
Block a user