summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-09-18 18:38:27 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-18 21:29:01 +0200
commit3bccd99fe969ae0db3867cee0fb762d11171c5b8 (patch)
tree38ac3ec9a021c5a975b3faa453c501eb19c9ca25 /Libraries
parent76ae47c6ed0594329b67c7d45892b474be82b97e (diff)
downloadserenity-3bccd99fe969ae0db3867cee0fb762d11171c5b8.zip
LibGUI: Add TreeView::expand_all_parents_of(ModelIndex)
This does exactly what it sounds like. :^)
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/TreeView.cpp17
-rw-r--r--Libraries/LibGUI/TreeView.h2
2 files changed, 19 insertions, 0 deletions
diff --git a/Libraries/LibGUI/TreeView.cpp b/Libraries/LibGUI/TreeView.cpp
index 028b478ed3..fc79ba0742 100644
--- a/Libraries/LibGUI/TreeView.cpp
+++ b/Libraries/LibGUI/TreeView.cpp
@@ -125,6 +125,23 @@ void TreeView::set_open_state_of_all_in_subtree(const ModelIndex& root, bool ope
}
}
+void TreeView::expand_all_parents_of(const ModelIndex& index)
+{
+ if (!model())
+ return;
+
+ auto current = index;
+ while (current.is_valid()) {
+ ensure_metadata_for_index(current).open = true;
+ if (on_toggle)
+ on_toggle(current, true);
+ current = current.parent();
+ }
+ update_column_sizes();
+ update_content_size();
+ update();
+}
+
void TreeView::expand_tree(const ModelIndex& root)
{
if (!model())
diff --git a/Libraries/LibGUI/TreeView.h b/Libraries/LibGUI/TreeView.h
index 3b3f049370..d8e81dc431 100644
--- a/Libraries/LibGUI/TreeView.h
+++ b/Libraries/LibGUI/TreeView.h
@@ -44,6 +44,8 @@ public:
void expand_tree(const ModelIndex& root = {});
void collapse_tree(const ModelIndex& root = {});
+ void expand_all_parents_of(const ModelIndex&);
+
Function<void(const ModelIndex&, const bool)> on_toggle;
protected: