summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorShannon Booth <shannon.ml.booth@gmail.com>2020-01-18 12:11:09 +1300
committerAndreas Kling <awesomekling@gmail.com>2020-01-18 00:27:39 +0100
commit22d1961c9a9f1265c123262c1f81aec0f7836256 (patch)
tree51f9d8693aa2a82ec762745f202df0333d13432c /Libraries
parent6697513d30c6ed31fa865883d23870973c7a72da (diff)
downloadserenity-22d1961c9a9f1265c123262c1f81aec0f7836256.zip
LibGUI: Handle "Return" key events
I kept on trying to use the enter key to navigate a tree view, when only left and right arrow keys are used for this. Now also suport the return key, is used as a toggle to open a tree.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/GTreeView.cpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/Libraries/LibGUI/GTreeView.cpp b/Libraries/LibGUI/GTreeView.cpp
index f358916683..3e6a2a9362 100644
--- a/Libraries/LibGUI/GTreeView.cpp
+++ b/Libraries/LibGUI/GTreeView.cpp
@@ -376,30 +376,40 @@ void GTreeView::keydown_event(GKeyEvent& event)
selection().set(found_index);
return;
}
+
+ auto open_tree_node = [&](bool open, MetadataForIndex& metadata) {
+ metadata.open = open;
+ update_column_sizes();
+ update_content_size();
+ update();
+ };
+
if (event.key() == KeyCode::Key_Left) {
if (cursor_index.is_valid() && model()->row_count(cursor_index)) {
auto& metadata = ensure_metadata_for_index(cursor_index);
- if (metadata.open) {
- metadata.open = false;
- update_column_sizes();
- update_content_size();
- update();
- }
+ if (metadata.open)
+ open_tree_node(false, metadata);
return;
}
}
+
if (event.key() == KeyCode::Key_Right) {
if (cursor_index.is_valid() && model()->row_count(cursor_index)) {
auto& metadata = ensure_metadata_for_index(cursor_index);
- if (!metadata.open) {
- metadata.open = true;
- update_column_sizes();
- update_content_size();
- update();
- }
+ if (!metadata.open)
+ open_tree_node(true, metadata);
return;
}
}
+
+ if (event.key() == KeyCode::Key_Return) {
+ if (cursor_index.is_valid() && model()->row_count(cursor_index)) {
+ auto& metadata = ensure_metadata_for_index(cursor_index);
+ open_tree_node(!metadata.open, metadata);
+ return;
+ }
+ }
+
}
int GTreeView::item_count() const