LibGUI: Make it easier to create checkable GUI::Actions

This patch adds GUI::Action::create_checkable() helpers that work just
like the existing create() helpers, but the actions become checkable(!)

Clients are no longer required to manage the checked state of their
actions manually, but instead they will be checked/unchecked as needed
by GUI::Action itself before the activation hook is fired.
This commit is contained in:
Andreas Kling 2020-04-21 17:19:27 +02:00
parent 1032ae0140
commit 705cee528a
Notes: sideshowbarker 2024-07-19 07:24:49 +09:00
18 changed files with 135 additions and 158 deletions

View file

@ -199,11 +199,9 @@ Menu& AbstractTableView::ensure_header_context_menu()
for (int column = 0; column < model()->column_count(); ++column) {
auto& column_data = this->column_data(column);
auto name = model()->column_name(column);
column_data.visibility_action = Action::create(name, [this, column](Action& action) {
action.set_checked(!action.is_checked());
column_data.visibility_action = Action::create_checkable(name, [this, column](auto& action) {
set_column_hidden(column, !action.is_checked());
});
column_data.visibility_action->set_checkable(true);
column_data.visibility_action->set_checked(true);
m_header_context_menu->add_action(*column_data.visibility_action);