From 362244ccbe694442b9145bbcea975f91b4c44af1 Mon Sep 17 00:00:00 2001 From: Elvis Angelaccio Date: Wed, 25 Apr 2018 13:42:18 +0200 Subject: [PATCH] DolphinTabPage: deactivate secondary view after closing split view We deactivate the previously active view container whenever we change the active split view, but we never do the same when we close the split view. Long term we should probably even delete the secondary view after closing the split view, because it will never be used again and the pointer will be overwritten the next time the user opens the split view. --- src/dolphintabpage.cpp | 3 ++ src/tests/dolphinmainwindowtest.cpp | 55 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/dolphintabpage.cpp b/src/dolphintabpage.cpp index a96c8b6a32..b2bb5c896d 100644 --- a/src/dolphintabpage.cpp +++ b/src/dolphintabpage.cpp @@ -312,6 +312,9 @@ void DolphinTabPage::slotViewActivated() m_primaryViewActive = !m_primaryViewActive; } else { m_primaryViewActive = true; + if (m_secondaryViewContainer) { + m_secondaryViewContainer->setActive(false); + } } } diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp index a31237f3c5..70ec8dba04 100644 --- a/src/tests/dolphinmainwindowtest.cpp +++ b/src/tests/dolphinmainwindowtest.cpp @@ -34,6 +34,8 @@ class DolphinMainWindowTest : public QObject private slots: void init(); void testClosingTabsWithSearchBoxVisible(); + void testActiveViewAfterClosingSplitView_data(); + void testActiveViewAfterClosingSplitView(); void testUpdateWindowTitleAfterClosingSplitView(); private: @@ -68,6 +70,58 @@ void DolphinMainWindowTest::testClosingTabsWithSearchBoxVisible() QCOMPARE(tabWidget->count(), 1); } +void DolphinMainWindowTest::testActiveViewAfterClosingSplitView_data() +{ + QTest::addColumn("closeLeftView"); + + QTest::newRow("close left view") << true; + QTest::newRow("close right view") << false; +} + +void DolphinMainWindowTest::testActiveViewAfterClosingSplitView() +{ + m_mainWindow->openDirectories({ QUrl::fromLocalFile(QDir::homePath()) }, false); + m_mainWindow->show(); + QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); + QVERIFY(m_mainWindow->isVisible()); + + auto tabWidget = m_mainWindow->findChild("tabWidget"); + QVERIFY(tabWidget); + QVERIFY(tabWidget->currentTabPage()->primaryViewContainer()); + QVERIFY(!tabWidget->currentTabPage()->secondaryViewContainer()); + + // Open split view. + m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger(); + QVERIFY(tabWidget->currentTabPage()->splitViewEnabled()); + QVERIFY(tabWidget->currentTabPage()->secondaryViewContainer()); + + // Make sure the right view is the active one. + auto leftViewContainer = tabWidget->currentTabPage()->primaryViewContainer(); + auto rightViewContainer = tabWidget->currentTabPage()->secondaryViewContainer(); + QVERIFY(!leftViewContainer->isActive()); + QVERIFY(rightViewContainer->isActive()); + + QFETCH(bool, closeLeftView); + if (closeLeftView) { + // Activate left view. + leftViewContainer->setActive(true); + QVERIFY(leftViewContainer->isActive()); + QVERIFY(!rightViewContainer->isActive()); + + // Close left view. The secondary view (which was on the right) will become the primary one and must be active. + m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger(); + QVERIFY(!leftViewContainer->isActive()); + QVERIFY(rightViewContainer->isActive()); + QCOMPARE(rightViewContainer, tabWidget->currentTabPage()->activeViewContainer()); + } else { + // Close right view. The left view will become active. + m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger(); + QVERIFY(leftViewContainer->isActive()); + QVERIFY(!rightViewContainer->isActive()); + QCOMPARE(leftViewContainer, tabWidget->currentTabPage()->activeViewContainer()); + } +} + // Test case for bug #385111 void DolphinMainWindowTest::testUpdateWindowTitleAfterClosingSplitView() { @@ -99,6 +153,7 @@ void DolphinMainWindowTest::testUpdateWindowTitleAfterClosingSplitView() // Close split view. The secondary view (which was on the right) will become the primary one and must be active. m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger(); + QVERIFY(!leftViewContainer->isActive()); QVERIFY(rightViewContainer->isActive()); QCOMPARE(rightViewContainer, tabWidget->currentTabPage()->activeViewContainer());