]> cloud.milkyroute.net Git - dolphin.git/commitdiff
DolphinTabPage: deactivate secondary view after closing split view
authorElvis Angelaccio <elvis.angelaccio@kde.org>
Wed, 25 Apr 2018 11:42:18 +0000 (13:42 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Wed, 25 Apr 2018 11:42:18 +0000 (13:42 +0200)
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
src/tests/dolphinmainwindowtest.cpp

index a96c8b6a32dc6706c6aae1abb90dd465ea2703fb..b2bb5c896d95d720c4cab58a8f4d268c6c46214a 100644 (file)
@@ -312,6 +312,9 @@ void DolphinTabPage::slotViewActivated()
             m_primaryViewActive = !m_primaryViewActive;
         } else {
             m_primaryViewActive = true;
+            if (m_secondaryViewContainer) {
+                m_secondaryViewContainer->setActive(false);
+            }
         }
     }
 
index a31237f3c56f824f0fdae679463e74e4cced3bd6..70ec8dba04dd91f1e624c1002c6a288b4c608c79 100644 (file)
@@ -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<bool>("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<DolphinTabWidget*>("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());