Bläddra i källkod

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.
Ben Wiederhake 5 år sedan
förälder
incheckning
ebabce30bd
1 ändrade filer med 4 tillägg och 1 borttagningar
  1. 4 1
      Libraries/LibGUI/AbstractTableView.cpp

+ 4 - 1
Libraries/LibGUI/AbstractTableView.cpp

@@ -184,6 +184,9 @@ void AbstractTableView::set_column_hidden(int column, bool hidden)
     if (column_data.visibility == !hidden)
     if (column_data.visibility == !hidden)
         return;
         return;
     column_data.visibility = !hidden;
     column_data.visibility = !hidden;
+    if (column_data.visibility_action) {
+        column_data.visibility_action->set_checked(!hidden);
+    }
     update_content_size();
     update_content_size();
     update();
     update();
 }
 }
@@ -202,7 +205,7 @@ Menu& AbstractTableView::ensure_header_context_menu()
             column_data.visibility_action = Action::create_checkable(name, [this, column](auto& action) {
             column_data.visibility_action = Action::create_checkable(name, [this, column](auto& action) {
                 set_column_hidden(column, !action.is_checked());
                 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);
             m_header_context_menu->add_action(*column_data.visibility_action);
         }
         }