summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEaston Pillay <easton@planeteaston.com>2022-11-05 00:26:07 -0400
committerAndreas Kling <kling@serenityos.org>2022-11-05 14:49:22 +0100
commit22d54cd446a6d0c79584995a7e6ec31abcc4b3ef (patch)
tree9f1de2994af3f2e85f20dcac10caf2f0aeca1dcd
parent7809cc65579c52a2b3f69548bac86489ef4d2a0b (diff)
downloadserenity-22d54cd446a6d0c79584995a7e6ec31abcc4b3ef.zip
LibGUI: Hold down Alt when clicking TreeView to expand full subtree
On other operating systems, if you hold down Alt when you click to expand part of a tree, it expands all of the children of the node you clicked. This commit makes our TreeView act the same way :)
-rw-r--r--Userland/Libraries/LibGUI/TreeView.cpp27
-rw-r--r--Userland/Libraries/LibGUI/TreeView.h1
2 files changed, 28 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TreeView.cpp b/Userland/Libraries/LibGUI/TreeView.cpp
index ab57d46b59..a92df5cc9e 100644
--- a/Userland/Libraries/LibGUI/TreeView.cpp
+++ b/Userland/Libraries/LibGUI/TreeView.cpp
@@ -430,6 +430,33 @@ void TreeView::did_update_selection()
activate(index);
}
+void TreeView::mousedown_event(MouseEvent& event)
+{
+ if (!model())
+ return AbstractView::mousedown_event(event);
+
+ if (event.button() != MouseButton::Primary)
+ return AbstractView::mousedown_event(event);
+
+ bool is_toggle;
+ auto index = index_at_event_position(event.position(), is_toggle);
+
+ if (index.is_valid() && is_toggle && model()->row_count(index)) {
+ if (event.alt()) {
+ if (is_toggled(index)) {
+ collapse_tree(index);
+ } else {
+ expand_tree(index);
+ }
+ return;
+ }
+ toggle_index(index);
+ return;
+ }
+
+ AbstractView::mousedown_event(event);
+}
+
void TreeView::keydown_event(KeyEvent& event)
{
if (!model())
diff --git a/Userland/Libraries/LibGUI/TreeView.h b/Userland/Libraries/LibGUI/TreeView.h
index b369b75a14..4d1df1dbb5 100644
--- a/Userland/Libraries/LibGUI/TreeView.h
+++ b/Userland/Libraries/LibGUI/TreeView.h
@@ -43,6 +43,7 @@ public:
protected:
TreeView();
+ virtual void mousedown_event(MouseEvent&) override;
virtual void paint_event(PaintEvent&) override;
virtual void doubleclick_event(MouseEvent&) override;
virtual void keydown_event(KeyEvent&) override;