diff options
author | Andreas Kling <kling@serenityos.org> | 2020-09-24 21:35:47 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-24 21:35:47 +0200 |
commit | d3adbed23133d652092c74721d7158229445a125 (patch) | |
tree | 086435ddc80d1a58879eaf68efbf1b7e07610f37 | |
parent | d8553a64064cdd67da826905b904c9a2c4e27bf5 (diff) | |
download | serenity-d3adbed23133d652092c74721d7158229445a125.zip |
LibGUI: Move keyboard item activation up to AbstractView
All views want the same behavior, so move this to the base class. :^)
-rw-r--r-- | Libraries/LibGUI/AbstractTableView.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibGUI/AbstractView.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibGUI/ColumnsView.cpp | 13 | ||||
-rw-r--r-- | Libraries/LibGUI/ColumnsView.h | 1 | ||||
-rw-r--r-- | Libraries/LibGUI/IconView.cpp | 14 | ||||
-rw-r--r-- | Libraries/LibGUI/IconView.h | 1 | ||||
-rw-r--r-- | Libraries/LibGUI/ListView.cpp | 5 | ||||
-rw-r--r-- | Libraries/LibGUI/TableView.cpp | 5 |
8 files changed, 9 insertions, 40 deletions
diff --git a/Libraries/LibGUI/AbstractTableView.cpp b/Libraries/LibGUI/AbstractTableView.cpp index d4da28a368..bc96785de1 100644 --- a/Libraries/LibGUI/AbstractTableView.cpp +++ b/Libraries/LibGUI/AbstractTableView.cpp @@ -399,7 +399,7 @@ void AbstractTableView::keydown_event(KeyEvent& event) } } - return AbstractView::keydown_event(event); + AbstractView::keydown_event(event); } } diff --git a/Libraries/LibGUI/AbstractView.cpp b/Libraries/LibGUI/AbstractView.cpp index 73a54d3d46..4e98de2a3c 100644 --- a/Libraries/LibGUI/AbstractView.cpp +++ b/Libraries/LibGUI/AbstractView.cpp @@ -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); } } diff --git a/Libraries/LibGUI/ColumnsView.cpp b/Libraries/LibGUI/ColumnsView.cpp index 06c4104141..b624f3761a 100644 --- a/Libraries/LibGUI/ColumnsView.cpp +++ b/Libraries/LibGUI/ColumnsView.cpp @@ -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()) diff --git a/Libraries/LibGUI/ColumnsView.h b/Libraries/LibGUI/ColumnsView.h index fc3ba1d350..5694d20d0e 100644 --- a/Libraries/LibGUI/ColumnsView.h +++ b/Libraries/LibGUI/ColumnsView.h @@ -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; diff --git a/Libraries/LibGUI/IconView.cpp b/Libraries/LibGUI/IconView.cpp index d1afb19ed6..442a7c9fa9 100644 --- a/Libraries/LibGUI/IconView.cpp +++ b/Libraries/LibGUI/IconView.cpp @@ -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()) diff --git a/Libraries/LibGUI/IconView.h b/Libraries/LibGUI/IconView.h index 24f0326ca8..3772f930a4 100644 --- a/Libraries/LibGUI/IconView.h +++ b/Libraries/LibGUI/IconView.h @@ -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; diff --git a/Libraries/LibGUI/ListView.cpp b/Libraries/LibGUI/ListView.cpp index 255b63d8fd..59eeb0eae0 100644 --- a/Libraries/LibGUI/ListView.cpp +++ b/Libraries/LibGUI/ListView.cpp @@ -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(); diff --git a/Libraries/LibGUI/TableView.cpp b/Libraries/LibGUI/TableView.cpp index 2000e43ef4..65fd141183 100644 --- a/Libraries/LibGUI/TableView.cpp +++ b/Libraries/LibGUI/TableView.cpp @@ -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()) |