diff options
| author | Felix Ernst <[email protected]> | 2024-08-18 21:41:34 +0000 |
|---|---|---|
| committer | Felix Ernst <[email protected]> | 2024-08-18 21:41:34 +0000 |
| commit | f220e3b0783a24a6c7195f170297cf4b12a29d85 (patch) | |
| tree | 7ffe5976d8489b68d5b0624c46f391327ce73fb3 /src/tests/dolphinmainwindowtest.cpp | |
| parent | 9bac6eca0c21bf8ca8243d8038ad7d29a0094c9c (diff) | |
Implement "Focus Places Panel"
This commit implements an action to move focus to the Places panel
analogous to "Focus Terminal Panel" functionality-wise.
The implementation of the "Focus Terminal Panel" and "Focus Places
Panel" actions is streamlined while improving their code quality.
The "Focus Terminal Panel" action is moved into the "Show Panels"
sub-menu because it makes more sense to be there considering that its
previous location (the "Tools" menu) is meant for external applications
and not for functionality internal to Dolphin.
This commit also makes it so the keyboard focus is moved to and from
the Places panel whenever it is toggled visible or invisible. This is
now consistent with the focus handling when the Terminal panel is shown
or hidden.
The "Focus Places Panel" is one of the actions which was wished for in
KDE's accessibility chat room because people relying on keyboard
controls might need to press the Tab key a lot to move from the view to
the Places panel.
The new default shortcut is Ctrl+P.
Diffstat (limited to 'src/tests/dolphinmainwindowtest.cpp')
| -rw-r--r-- | src/tests/dolphinmainwindowtest.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp index 2d90ae52f..94e6d5be4 100644 --- a/src/tests/dolphinmainwindowtest.cpp +++ b/src/tests/dolphinmainwindowtest.cpp @@ -45,6 +45,7 @@ private Q_SLOTS: void testNewFileMenuEnabled(); void testWindowTitle_data(); void testWindowTitle(); + void testFocusPlacesPanel(); void testPlacesPanelWidthResistance(); void testGoActions(); void testOpenFiles(); @@ -282,6 +283,44 @@ void DolphinMainWindowTest::testWindowTitle() QCOMPARE(m_mainWindow->windowTitle(), expectedWindowTitle); } +void DolphinMainWindowTest::testFocusPlacesPanel() +{ + m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false); + m_mainWindow->show(); + QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); + QVERIFY(m_mainWindow->isVisible()); + + QWidget *placesPanel = reinterpret_cast<QWidget *>(m_mainWindow->m_placesPanel); + QVERIFY2(QTest::qWaitFor( + [&]() { + return placesPanel && placesPanel->isVisible() && placesPanel->width() > 0 && placesPanel->height() > 0; + }, + 5000), + "The test couldn't be initialised properly. The places panel should be visible."); + + QAction *focusPlacesPanelAction = m_mainWindow->actionCollection()->action(QStringLiteral("focus_places_panel")); + QAction *showPlacesPanelAction = m_mainWindow->actionCollection()->action(QStringLiteral("show_places_panel")); + + focusPlacesPanelAction->trigger(); + QVERIFY(placesPanel->hasFocus()); + + focusPlacesPanelAction->trigger(); + QVERIFY2(m_mainWindow->activeViewContainer()->isAncestorOf(QApplication::focusWidget()), + "Triggering focus_places_panel while the panel already has focus should return the focus to the view."); + + focusPlacesPanelAction->trigger(); + QVERIFY(placesPanel->hasFocus()); + + showPlacesPanelAction->trigger(); + QVERIFY(!placesPanel->isVisible()); + QVERIFY2(m_mainWindow->activeViewContainer()->isAncestorOf(QApplication::focusWidget()), + "Hiding the Places panel while it has focus should return the focus to the view."); + + showPlacesPanelAction->trigger(); + QVERIFY(placesPanel->isVisible()); + QVERIFY2(placesPanel->hasFocus(), "Enabling the Places panel should move keyboard focus there."); +} + /** * The places panel will resize itself if any of the other widgets requires too much horizontal space * but a user never wants the size of the places panel to change unless they resized it themselves explicitly. |
