mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-07 16:40:59 +00:00
LibGUI: Handle cursor keydown events in AbstractView
Move the basic movement keys (up/down/left/right/home/end/pgup/pgdn) up to AbstractView::keydown_event() and have it call the virtual move_cursor() which is then implemented by subclasses.
This commit is contained in:
parent
4ba12e9c23
commit
27687b1c6e
|
@ -373,11 +373,6 @@ void AbstractTableView::set_row_height(int height)
|
||||||
|
|
||||||
void AbstractTableView::keydown_event(KeyEvent& event)
|
void AbstractTableView::keydown_event(KeyEvent& event)
|
||||||
{
|
{
|
||||||
SelectionUpdate selection_update = SelectionUpdate::Set;
|
|
||||||
if (event.modifiers() == KeyModifier::Mod_Shift) {
|
|
||||||
selection_update = SelectionUpdate::Shift;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_tab_key_navigation_enabled()) {
|
if (is_tab_key_navigation_enabled()) {
|
||||||
if (event.modifiers() == KeyModifier::Mod_Shift && event.key() == KeyCode::Key_Tab) {
|
if (event.modifiers() == KeyModifier::Mod_Shift && event.key() == KeyCode::Key_Tab) {
|
||||||
move_cursor(CursorMovement::Left, SelectionUpdate::Set);
|
move_cursor(CursorMovement::Left, SelectionUpdate::Set);
|
||||||
|
@ -391,46 +386,6 @@ void AbstractTableView::keydown_event(KeyEvent& event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key() == KeyCode::Key_Left) {
|
|
||||||
move_cursor(CursorMovement::Left, selection_update);
|
|
||||||
event.accept();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_Right) {
|
|
||||||
move_cursor(CursorMovement::Right, selection_update);
|
|
||||||
event.accept();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_Up) {
|
|
||||||
move_cursor(CursorMovement::Up, selection_update);
|
|
||||||
event.accept();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_Down) {
|
|
||||||
move_cursor(CursorMovement::Down, selection_update);
|
|
||||||
event.accept();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_Home) {
|
|
||||||
move_cursor(CursorMovement::Home, selection_update);
|
|
||||||
event.accept();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_End) {
|
|
||||||
move_cursor(CursorMovement::End, selection_update);
|
|
||||||
event.accept();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_PageUp) {
|
|
||||||
move_cursor(CursorMovement::PageUp, selection_update);
|
|
||||||
event.accept();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_PageDown) {
|
|
||||||
move_cursor(CursorMovement::PageDown, selection_update);
|
|
||||||
event.accept();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return AbstractView::keydown_event(event);
|
return AbstractView::keydown_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -443,4 +443,53 @@ void AbstractView::set_edit_triggers(unsigned triggers)
|
||||||
m_edit_triggers = triggers;
|
m_edit_triggers = triggers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AbstractView::keydown_event(KeyEvent& event)
|
||||||
|
{
|
||||||
|
SelectionUpdate selection_update = SelectionUpdate::Set;
|
||||||
|
if (event.modifiers() == KeyModifier::Mod_Shift) {
|
||||||
|
selection_update = SelectionUpdate::Shift;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.key() == KeyCode::Key_Left) {
|
||||||
|
move_cursor(CursorMovement::Left, selection_update);
|
||||||
|
event.accept();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.key() == KeyCode::Key_Right) {
|
||||||
|
move_cursor(CursorMovement::Right, selection_update);
|
||||||
|
event.accept();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.key() == KeyCode::Key_Up) {
|
||||||
|
move_cursor(CursorMovement::Up, selection_update);
|
||||||
|
event.accept();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.key() == KeyCode::Key_Down) {
|
||||||
|
move_cursor(CursorMovement::Down, selection_update);
|
||||||
|
event.accept();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.key() == KeyCode::Key_Home) {
|
||||||
|
move_cursor(CursorMovement::Home, selection_update);
|
||||||
|
event.accept();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.key() == KeyCode::Key_End) {
|
||||||
|
move_cursor(CursorMovement::End, selection_update);
|
||||||
|
event.accept();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.key() == KeyCode::Key_PageUp) {
|
||||||
|
move_cursor(CursorMovement::PageUp, selection_update);
|
||||||
|
event.accept();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.key() == KeyCode::Key_PageDown) {
|
||||||
|
move_cursor(CursorMovement::PageDown, selection_update);
|
||||||
|
event.accept();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,7 @@ protected:
|
||||||
AbstractView();
|
AbstractView();
|
||||||
virtual ~AbstractView() override;
|
virtual ~AbstractView() override;
|
||||||
|
|
||||||
|
virtual void keydown_event(KeyEvent&) override;
|
||||||
virtual void mousedown_event(MouseEvent&) override;
|
virtual void mousedown_event(MouseEvent&) override;
|
||||||
virtual void mousemove_event(MouseEvent&) override;
|
virtual void mousemove_event(MouseEvent&) override;
|
||||||
virtual void mouseup_event(MouseEvent&) override;
|
virtual void mouseup_event(MouseEvent&) override;
|
||||||
|
|
|
@ -320,32 +320,12 @@ void ColumnsView::keydown_event(KeyEvent& event)
|
||||||
if (!model())
|
if (!model())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SelectionUpdate selection_update = SelectionUpdate::Set;
|
|
||||||
|
|
||||||
if (event.key() == KeyCode::Key_Return) {
|
if (event.key() == KeyCode::Key_Return) {
|
||||||
activate_selected();
|
activate_selected();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key() == KeyCode::Key_Up) {
|
AbstractView::keydown_event(event);
|
||||||
move_cursor(CursorMovement::Up, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key() == KeyCode::Key_Down) {
|
|
||||||
move_cursor(CursorMovement::Down, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key() == KeyCode::Key_Left) {
|
|
||||||
move_cursor(CursorMovement::Left, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key() == KeyCode::Key_Right) {
|
|
||||||
move_cursor(CursorMovement::Right, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -602,45 +602,11 @@ void IconView::keydown_event(KeyEvent& event)
|
||||||
if (!m_visual_row_count || !m_visual_column_count)
|
if (!m_visual_row_count || !m_visual_column_count)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SelectionUpdate selection_update = SelectionUpdate::Set;
|
|
||||||
|
|
||||||
if (event.key() == KeyCode::Key_Return) {
|
if (event.key() == KeyCode::Key_Return) {
|
||||||
activate_selected();
|
activate_selected();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.key() == KeyCode::Key_Home) {
|
AbstractView::keydown_event(event);
|
||||||
move_cursor(CursorMovement::Home, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_End) {
|
|
||||||
move_cursor(CursorMovement::End, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_Up) {
|
|
||||||
move_cursor(CursorMovement::Up, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_Down) {
|
|
||||||
move_cursor(CursorMovement::Down, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_Left) {
|
|
||||||
move_cursor(CursorMovement::Left, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_Right) {
|
|
||||||
move_cursor(CursorMovement::Right, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_PageUp) {
|
|
||||||
move_cursor(CursorMovement::PageUp, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_PageDown) {
|
|
||||||
move_cursor(CursorMovement::PageDown, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return Widget::keydown_event(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconView::move_cursor(CursorMovement movement, SelectionUpdate selection_update)
|
void IconView::move_cursor(CursorMovement movement, SelectionUpdate selection_update)
|
||||||
|
|
|
@ -194,35 +194,17 @@ void ListView::keydown_event(KeyEvent& event)
|
||||||
if (!model())
|
if (!model())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SelectionUpdate selection_update = SelectionUpdate::Set;
|
|
||||||
|
|
||||||
ModelIndex new_index;
|
ModelIndex new_index;
|
||||||
if (event.key() == KeyCode::Key_Return) {
|
if (event.key() == KeyCode::Key_Return) {
|
||||||
activate_selected();
|
activate_selected();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.key() == KeyCode::Key_Up) {
|
|
||||||
move_cursor(CursorMovement::Up, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_Down) {
|
|
||||||
move_cursor(CursorMovement::Down, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_PageUp) {
|
|
||||||
move_cursor(CursorMovement::PageUp, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_PageDown) {
|
|
||||||
move_cursor(CursorMovement::PageDown, selection_update);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.key() == KeyCode::Key_Escape) {
|
if (event.key() == KeyCode::Key_Escape) {
|
||||||
if (on_escape_pressed)
|
if (on_escape_pressed)
|
||||||
on_escape_pressed();
|
on_escape_pressed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return AbstractView::keydown_event(event);
|
AbstractView::keydown_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListView::move_cursor_relative(int steps, SelectionUpdate selection_update)
|
void ListView::move_cursor_relative(int steps, SelectionUpdate selection_update)
|
||||||
|
|
Loading…
Reference in a new issue