mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 17:28:30 +00:00
LibGUI: Allow basic keyboard navigation in GTableView.
Pressing Enter will now "activate" the selected index, meaning that the model gets a call to activate(GModelIndex).
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <LibGUI/GTableModel.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
#include <SharedGraphics/Painter.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
|
||||
GTableView::GTableView(GWidget* parent)
|
||||
: GWidget(parent)
|
||||
@@ -167,3 +168,25 @@ int GTableView::item_count() const
|
||||
{
|
||||
return m_model->row_count();
|
||||
}
|
||||
|
||||
void GTableView::keydown_event(GKeyEvent& event)
|
||||
{
|
||||
if (!model())
|
||||
return;
|
||||
auto& model = *this->model();
|
||||
if (event.key() == KeyCode::Key_Return) {
|
||||
model.activate(model.selected_index());
|
||||
return;
|
||||
}
|
||||
if (event.key() == KeyCode::Key_Up) {
|
||||
model.set_selected_index({ model.selected_index().row() - 1, model.selected_index().column() });
|
||||
update();
|
||||
return;
|
||||
}
|
||||
if (event.key() == KeyCode::Key_Down) {
|
||||
model.set_selected_index({ model.selected_index().row() + 1, model.selected_index().column() });
|
||||
update();
|
||||
return;
|
||||
}
|
||||
return GTableView::keydown_event(event);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user