mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 19:37:34 +00:00
LibGUI: Add on_toggle function to TreeView
This adds a function to expose the index and open/close state of expandible nodes in TreeView.
This commit is contained in:
parent
27109c3467
commit
cbf3c2caeb
2 changed files with 7 additions and 2 deletions
|
@ -145,6 +145,8 @@ void TreeView::toggle_index(const ModelIndex& index)
|
||||||
ASSERT(model()->row_count(index));
|
ASSERT(model()->row_count(index));
|
||||||
auto& metadata = ensure_metadata_for_index(index);
|
auto& metadata = ensure_metadata_for_index(index);
|
||||||
metadata.open = !metadata.open;
|
metadata.open = !metadata.open;
|
||||||
|
if (on_toggle)
|
||||||
|
on_toggle(index, metadata.open);
|
||||||
update_column_sizes();
|
update_column_sizes();
|
||||||
update_content_size();
|
update_content_size();
|
||||||
update();
|
update();
|
||||||
|
@ -452,6 +454,8 @@ void TreeView::keydown_event(KeyEvent& event)
|
||||||
}
|
}
|
||||||
|
|
||||||
auto open_tree_node = [&](bool open, MetadataForIndex& metadata) {
|
auto open_tree_node = [&](bool open, MetadataForIndex& metadata) {
|
||||||
|
if (on_toggle)
|
||||||
|
on_toggle(cursor_index, open);
|
||||||
metadata.open = open;
|
metadata.open = open;
|
||||||
update_column_sizes();
|
update_column_sizes();
|
||||||
update_content_size();
|
update_content_size();
|
||||||
|
@ -499,8 +503,7 @@ void TreeView::keydown_event(KeyEvent& event)
|
||||||
|
|
||||||
if (event.key() == KeyCode::Key_Return) {
|
if (event.key() == KeyCode::Key_Return) {
|
||||||
if (cursor_index.is_valid() && model()->row_count(cursor_index)) {
|
if (cursor_index.is_valid() && model()->row_count(cursor_index)) {
|
||||||
auto& metadata = ensure_metadata_for_index(cursor_index);
|
toggle_index(cursor_index);
|
||||||
open_tree_node(!metadata.open, metadata);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,8 @@ public:
|
||||||
void expand_tree(const ModelIndex& root = {});
|
void expand_tree(const ModelIndex& root = {});
|
||||||
void collapse_tree(const ModelIndex& root = {});
|
void collapse_tree(const ModelIndex& root = {});
|
||||||
|
|
||||||
|
Function<void(const ModelIndex&, const bool)> on_toggle;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TreeView();
|
TreeView();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue