LibGUI: Move keyboard item activation up to AbstractView

All views want the same behavior, so move this to the base class. :^)
This commit is contained in:
Andreas Kling 2020-09-24 21:35:47 +02:00
parent d8553a6406
commit d3adbed231
Notes: sideshowbarker 2024-07-19 02:15:11 +09:00
8 changed files with 9 additions and 40 deletions

View file

@ -399,7 +399,7 @@ void AbstractTableView::keydown_event(KeyEvent& event)
}
}
return AbstractView::keydown_event(event);
AbstractView::keydown_event(event);
}
}

View file

@ -461,6 +461,12 @@ void AbstractView::keydown_event(KeyEvent& event)
}
}
if (event.key() == KeyCode::Key_Return) {
activate_selected();
event.accept();
return;
}
SelectionUpdate selection_update = SelectionUpdate::Set;
if (event.modifiers() == KeyModifier::Mod_Shift) {
selection_update = SelectionUpdate::Shift;
@ -506,6 +512,8 @@ void AbstractView::keydown_event(KeyEvent& event)
event.accept();
return;
}
Widget::keydown_event(event);
}
}

View file

@ -315,19 +315,6 @@ void ColumnsView::move_cursor(CursorMovement movement, SelectionUpdate selection
set_cursor(new_index, selection_update);
}
void ColumnsView::keydown_event(KeyEvent& event)
{
if (!model())
return;
if (event.key() == KeyCode::Key_Return) {
activate_selected();
return;
}
AbstractView::keydown_event(event);
}
Gfx::IntRect ColumnsView::content_rect(const ModelIndex& index) const
{
if (!index.is_valid())

View file

@ -54,7 +54,6 @@ private:
virtual void did_update_model(unsigned flags) override;
virtual void paint_event(PaintEvent&) override;
virtual void mousedown_event(MouseEvent& event) override;
virtual void keydown_event(KeyEvent& event) override;
void move_cursor(CursorMovement, SelectionUpdate) override;

View file

@ -603,20 +603,6 @@ void IconView::set_selection(const ModelIndex& new_index)
AbstractView::set_selection(new_index);
}
void IconView::keydown_event(KeyEvent& event)
{
if (!model())
return;
if (!m_visual_row_count || !m_visual_column_count)
return;
if (event.key() == KeyCode::Key_Return) {
activate_selected();
return;
}
AbstractView::keydown_event(event);
}
void IconView::move_cursor(CursorMovement movement, SelectionUpdate selection_update)
{
if (!model())

View file

@ -63,7 +63,6 @@ private:
virtual void mousedown_event(MouseEvent&) override;
virtual void mousemove_event(MouseEvent&) override;
virtual void mouseup_event(MouseEvent&) override;
virtual void keydown_event(KeyEvent&) override;
virtual void drag_move_event(DragEvent&) override;
virtual void move_cursor(CursorMovement, SelectionUpdate) override;

View file

@ -198,11 +198,6 @@ void ListView::keydown_event(KeyEvent& event)
if (!model())
return;
ModelIndex new_index;
if (event.key() == KeyCode::Key_Return) {
activate_selected();
return;
}
if (event.key() == KeyCode::Key_Escape) {
if (on_escape_pressed)
on_escape_pressed();

View file

@ -166,11 +166,6 @@ void TableView::keydown_event(KeyEvent& event)
if (!model())
return;
if (event.key() == KeyCode::Key_Return) {
activate(cursor_index());
return;
}
AbstractTableView::keydown_event(event);
if (event.is_accepted())