mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:38:10 +00:00
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.
This commit is contained in:
parent
6697513d30
commit
22d1961c9a
1 changed files with 22 additions and 12 deletions
|
@ -376,30 +376,40 @@ void GTreeView::keydown_event(GKeyEvent& event)
|
||||||
selection().set(found_index);
|
selection().set(found_index);
|
||||||
return;
|
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 (event.key() == KeyCode::Key_Left) {
|
||||||
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);
|
auto& metadata = ensure_metadata_for_index(cursor_index);
|
||||||
if (metadata.open) {
|
if (metadata.open)
|
||||||
metadata.open = false;
|
open_tree_node(false, metadata);
|
||||||
update_column_sizes();
|
|
||||||
update_content_size();
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key() == KeyCode::Key_Right) {
|
if (event.key() == KeyCode::Key_Right) {
|
||||||
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);
|
auto& metadata = ensure_metadata_for_index(cursor_index);
|
||||||
if (!metadata.open) {
|
if (!metadata.open)
|
||||||
metadata.open = true;
|
open_tree_node(true, metadata);
|
||||||
update_column_sizes();
|
|
||||||
update_content_size();
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
return;
|
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
|
int GTreeView::item_count() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue