From 6316525d500682cce13a3b7a62a338aa37b6ed99 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 28 Aug 2020 21:09:38 +0200 Subject: [PATCH] LibGUI: Add optional "tab key navigation" to AbstractView If enabled, the view cursor will move right/left when pressing tab/shift+tab. --- Libraries/LibGUI/AbstractTableView.cpp | 13 +++++++++++++ Libraries/LibGUI/AbstractView.h | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/Libraries/LibGUI/AbstractTableView.cpp b/Libraries/LibGUI/AbstractTableView.cpp index b2ffda454f..4662fbea17 100644 --- a/Libraries/LibGUI/AbstractTableView.cpp +++ b/Libraries/LibGUI/AbstractTableView.cpp @@ -378,6 +378,19 @@ void AbstractTableView::keydown_event(KeyEvent& event) selection_update = SelectionUpdate::Shift; } + if (is_tab_key_navigation_enabled()) { + if (event.modifiers() == KeyModifier::Mod_Shift && event.key() == KeyCode::Key_Tab) { + move_cursor(CursorMovement::Left, SelectionUpdate::Set); + event.accept(); + return; + } + if (!event.modifiers() && event.key() == KeyCode::Key_Tab) { + move_cursor(CursorMovement::Right, SelectionUpdate::Set); + event.accept(); + return; + } + } + if (event.key() == KeyCode::Key_Left) { move_cursor(CursorMovement::Left, selection_update); event.accept(); diff --git a/Libraries/LibGUI/AbstractView.h b/Libraries/LibGUI/AbstractView.h index b98724b3aa..add58c9cb0 100644 --- a/Libraries/LibGUI/AbstractView.h +++ b/Libraries/LibGUI/AbstractView.h @@ -116,6 +116,9 @@ public: const ModelIndex& cursor_index() const { return m_cursor_index; } void set_cursor(ModelIndex, SelectionUpdate); + bool is_tab_key_navigation_enabled() const { return m_tab_key_navigation_enabled; } + void set_tab_key_navigation_enabled(bool enabled) { m_tab_key_navigation_enabled = enabled; } + protected: AbstractView(); virtual ~AbstractView() override; @@ -162,6 +165,7 @@ private: unsigned m_edit_triggers { EditTrigger::DoubleClicked | EditTrigger::EditKeyPressed }; bool m_activates_on_selection { false }; bool m_multi_select { true }; + bool m_tab_key_navigation_enabled { false }; }; }