summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-04-05 00:19:52 +0200
committerAndreas Kling <kling@serenityos.org>2022-04-06 12:47:50 +0200
commit4e8cb0508f6f62a03a136f7f4b858f4606661b94 (patch)
tree516ee6f7fc8a289f3f2f74cc0605ce66b89b2957 /Userland
parentd813bf77ee980d8c9f6b0fbc28ac005915250f59 (diff)
downloadserenity-4e8cb0508f6f62a03a136f7f4b858f4606661b94.zip
LibGUI: Add is_toggled getter for TreeView
This has safer fallbacks than toggle_index, because we want to be able to call it on indices that don't have children.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/TreeView.cpp12
-rw-r--r--Userland/Libraries/LibGUI/TreeView.h1
2 files changed, 13 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TreeView.cpp b/Userland/Libraries/LibGUI/TreeView.cpp
index 87d58ad7d6..b5cc4a0978 100644
--- a/Userland/Libraries/LibGUI/TreeView.cpp
+++ b/Userland/Libraries/LibGUI/TreeView.cpp
@@ -158,6 +158,18 @@ void TreeView::toggle_index(ModelIndex const& index)
update();
}
+bool TreeView::is_toggled(ModelIndex const& index)
+{
+ if (model()->row_count(index) == 0) {
+ if (model()->parent_index(index).is_valid())
+ return is_toggled(model()->parent_index(index));
+ return false;
+ }
+
+ auto& metadata = ensure_metadata_for_index(index);
+ return metadata.open;
+}
+
template<typename Callback>
void TreeView::traverse_in_paint_order(Callback callback) const
{
diff --git a/Userland/Libraries/LibGUI/TreeView.h b/Userland/Libraries/LibGUI/TreeView.h
index 3e1543e8a8..b369b75a14 100644
--- a/Userland/Libraries/LibGUI/TreeView.h
+++ b/Userland/Libraries/LibGUI/TreeView.h
@@ -21,6 +21,7 @@ public:
virtual int item_count() const override;
virtual void toggle_index(ModelIndex const&) override;
+ bool is_toggled(ModelIndex const& index);
void expand_tree(ModelIndex const& root = {});
void collapse_tree(ModelIndex const& root = {});