From ebabce30bdfd87cadea6cada9aed12039c50d5ff Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Thu, 30 Apr 2020 23:54:05 +0200 Subject: [PATCH] LibGUI: Display hidden columns as hidden Until now, hidden columns were displayed as visible in the context menu. An easy way to reproduce this is: - Open the TextEditor - Ctrl-O to open the file selector - Switch to table view - Right-click the header Expected behavior: Hidden columns like 'Owner' and 'Group' should not have a checkmark, because they are hidden. Actual behavior: They did have a checkmark. Clicking on it to 'hide' the already hidden column removed the checkmark, but was a no-op to the table view. This commit fixes this behavior, by correctly initializing the context menu, and properly updating the context menu if external code calls 'set_column_hidden' later. --- Libraries/LibGUI/AbstractTableView.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Libraries/LibGUI/AbstractTableView.cpp b/Libraries/LibGUI/AbstractTableView.cpp index 705d94c0aa..ecfb85c266 100644 --- a/Libraries/LibGUI/AbstractTableView.cpp +++ b/Libraries/LibGUI/AbstractTableView.cpp @@ -184,6 +184,9 @@ void AbstractTableView::set_column_hidden(int column, bool hidden) if (column_data.visibility == !hidden) return; column_data.visibility = !hidden; + if (column_data.visibility_action) { + column_data.visibility_action->set_checked(!hidden); + } update_content_size(); update(); } @@ -202,7 +205,7 @@ Menu& AbstractTableView::ensure_header_context_menu() column_data.visibility_action = Action::create_checkable(name, [this, column](auto& action) { set_column_hidden(column, !action.is_checked()); }); - column_data.visibility_action->set_checked(true); + column_data.visibility_action->set_checked(column_data.visibility); m_header_context_menu->add_action(*column_data.visibility_action); }