]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphintabwidget.cpp
FoldersPanel: Fix inline renaming
[dolphin.git] / src / dolphintabwidget.cpp
index eb3f741ee741be46e8a067313f95e62364c4925c..cfb695e7db24a05a1f3a931f0823859ff917adf3 100644 (file)
@@ -8,7 +8,6 @@
 
 #include "dolphin_generalsettings.h"
 #include "dolphintabbar.h"
-#include "dolphintabpage.h"
 #include "dolphinviewcontainer.h"
 
 #include <KConfigGroup>
@@ -88,15 +87,8 @@ void DolphinTabWidget::readProperties(const KConfigGroup& group)
         if (i >= count()) {
             openNewActivatedTab();
         }
-        if (group.hasKey("Tab Data " % QString::number(i))) {
-            // Tab state created with Dolphin > 4.14.x
-            const QByteArray state = group.readEntry("Tab Data " % QString::number(i), QByteArray());
-            tabPageAt(i)->restoreState(state);
-        } else {
-            // Tab state created with Dolphin <= 4.14.x
-            const QByteArray state = group.readEntry("Tab " % QString::number(i), QByteArray());
-            tabPageAt(i)->restoreStateV1(state);
-        }
+        const QByteArray state = group.readEntry("Tab Data " % QString::number(i), QByteArray());
+        tabPageAt(i)->restoreState(state);
     }
 
     const int index = group.readEntry("Active Tab Index", 0);
@@ -153,10 +145,14 @@ void DolphinTabWidget::openNewActivatedTab()
 void DolphinTabWidget::openNewActivatedTab(const QUrl& primaryUrl, const QUrl& secondaryUrl)
 {
     openNewTab(primaryUrl, secondaryUrl);
-    setCurrentIndex(count() - 1);
+    if (GeneralSettings::openNewTabAfterLastTab()) {
+        setCurrentIndex(count() - 1);
+    } else {
+        setCurrentIndex(currentIndex() + 1);
+    }
 }
 
-void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl, TabPlacement tabPlacement)
+void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl)
 {
     QWidget* focusWidget = QApplication::focusWidget();
 
@@ -167,7 +163,7 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU
     connect(tabPage, &DolphinTabPage::activeViewUrlChanged,
             this, &DolphinTabWidget::tabUrlChanged);
     int newTabIndex = -1;
-    if (tabPlacement == AfterCurrentTab) {
+    if (!GeneralSettings::openNewTabAfterLastTab()) {
         newTabIndex = currentIndex() + 1;
     }
     insertTab(newTabIndex, tabPage, QIcon() /* loaded in tabInserted */, tabName(tabPage));
@@ -183,14 +179,20 @@ void DolphinTabWidget::openDirectories(const QList<QUrl>& dirs, bool splitView)
 {
     Q_ASSERT(dirs.size() > 0);
 
+    bool somethingWasAlreadyOpen = false;
+
     QList<QUrl>::const_iterator it = dirs.constBegin();
     while (it != dirs.constEnd()) {
         const QUrl& primaryUrl = *(it++);
         const QPair<int, bool> indexInfo = indexByUrl(primaryUrl);
         const int index = indexInfo.first;
         const bool isInPrimaryView = indexInfo.second;
+
+        // When the user asks for a URL that's already open, activate it instead
+        // of opening a second copy
         if (index >= 0) {
-            setCurrentIndex(index);
+            somethingWasAlreadyOpen = true;
+            activateTab(index);
             const auto tabPage = tabPageAt(index);
             if (isInPrimaryView) {
                 tabPage->primaryViewContainer()->setActive(true);
@@ -201,13 +203,19 @@ void DolphinTabWidget::openDirectories(const QList<QUrl>& dirs, bool splitView)
             // Required for updateViewState() call in openFiles() to work as expected
             // If there is a selection, updateViewState() calls are effectively a no-op
             tabPage->activeViewContainer()->view()->clearSelection();
-            continue;
-        }
-        if (splitView && (it != dirs.constEnd())) {
+        } else if (splitView && (it != dirs.constEnd())) {
             const QUrl& secondaryUrl = *(it++);
-            openNewActivatedTab(primaryUrl, secondaryUrl);
+            if (somethingWasAlreadyOpen) {
+                openNewTab(primaryUrl, secondaryUrl);
+            } else {
+                openNewActivatedTab(primaryUrl, secondaryUrl);
+            }
         } else {
-            openNewActivatedTab(primaryUrl);
+            if (somethingWasAlreadyOpen) {
+                openNewTab(primaryUrl);
+            } else {
+                openNewActivatedTab(primaryUrl);
+            }
         }
     }
 }
@@ -407,7 +415,7 @@ void DolphinTabWidget::currentTabChanged(int index)
     tabPage->setActive(true);
     tabPage->connectNavigators(m_navigatorsWidget);
     m_navigatorsWidget->setSecondaryNavigatorVisible(tabPage->splitViewEnabled());
-    m_lastViewedTab = tabPageAt(index);
+    m_lastViewedTab = tabPage;
 }
 
 void DolphinTabWidget::tabInserted(int index)