mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 05:34:58 +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:
parent
4ffd43a5f4
commit
1eb1f7bde9
2 changed files with 15 additions and 0 deletions
|
@ -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());
|
||||
|
|
|
@ -36,6 +36,8 @@ public:
|
|||
bool is_section_visible(int section) const;
|
||||
void set_section_visible(int section, bool);
|
||||
|
||||
void set_section_selectable(int section, bool);
|
||||
|
||||
int section_count() const;
|
||||
Gfx::IntRect section_rect(int section) const;
|
||||
|
||||
|
@ -92,6 +94,7 @@ private:
|
|||
bool has_initialized_size { false };
|
||||
bool has_initialized_default_size { false };
|
||||
bool visibility { true };
|
||||
bool selectable { true };
|
||||
RefPtr<Action> visibility_action;
|
||||
Gfx::TextAlignment alignment { Gfx::TextAlignment::CenterLeft };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue