mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-26 03:09:08 +00:00
LibGUI: Allow HeaderView column selectability to be toggled
Previously, any TableView column could be made visible through a context menu shown by right clicking on the table header. This change allows columns to be marked as non-selectable, so their visibility cannot be toggled in this way.
This commit is contained in:
committed by
Andrew Kaster
parent
4ffd43a5f4
commit
1eb1f7bde9
@@ -342,6 +342,16 @@ void HeaderView::set_section_visible(int section, bool visible)
|
||||
update();
|
||||
}
|
||||
|
||||
void HeaderView::set_section_selectable(int section, bool selectable)
|
||||
{
|
||||
auto& data = section_data(section);
|
||||
if (data.selectable == selectable)
|
||||
return;
|
||||
data.selectable = selectable;
|
||||
if (m_context_menu)
|
||||
m_context_menu = nullptr;
|
||||
}
|
||||
|
||||
Menu& HeaderView::ensure_context_menu()
|
||||
{
|
||||
// FIXME: This menu needs to be rebuilt if the model is swapped out,
|
||||
@@ -358,6 +368,8 @@ Menu& HeaderView::ensure_context_menu()
|
||||
int section_count = this->section_count();
|
||||
for (int section = 0; section < section_count; ++section) {
|
||||
auto& column_data = this->section_data(section);
|
||||
if (!column_data.selectable)
|
||||
continue;
|
||||
auto name = model()->column_name(section).release_value_but_fixme_should_propagate_errors().to_byte_string();
|
||||
column_data.visibility_action = Action::create_checkable(name, [this, section](auto& action) {
|
||||
set_section_visible(section, action.is_checked());
|
||||
|
||||
Reference in New Issue
Block a user