]> cloud.milkyroute.net Git - dolphin.git/commitdiff
New tab should be placed after the current tab
authorDavid Hallas <david@davidhallas.dk>
Tue, 12 Feb 2019 10:07:43 +0000 (11:07 +0100)
committerDavid Hallas <david@davidhallas.dk>
Sat, 16 Feb 2019 15:51:44 +0000 (16:51 +0100)
Summary:
When opening a new using the context menu the new tab should be placed
after the currently open tab, not at the end of the tab list.

BUG: 403690

Test Plan:
Open multiple tabs and select a different tab than the last one.
Open a new tab using the context menu and see that it opens after the currently
selected tab.
Open a tab using Ctrl+T and see that it opens at the end.

Reviewers: #dolphin, ngraham, elvisangelaccio

Reviewed By: #dolphin, ngraham, elvisangelaccio

Subscribers: elvisangelaccio, ngraham, kfm-devel

Tags: #dolphin

Differential Revision: https://phabricator.kde.org/D18945

src/dolphinmainwindow.cpp
src/dolphintabwidget.cpp
src/dolphintabwidget.h

index 8be788eaea6cbd2b3d7d551ccbd638b49290abe7..3e4a60571f494a19183cfc9c5b1f6fd90ba2ef57 100644 (file)
@@ -328,7 +328,7 @@ void DolphinMainWindow::openInNewTab()
     foreach (const KFileItem& item, list) {
         const QUrl& url = DolphinView::openItemAsFolderUrl(item);
         if (!url.isEmpty()) {
-            openNewTab(url);
+            m_tabWidget->openNewTab(url, QUrl(), DolphinTabWidget::AfterCurrentTab);
             tabCreated = true;
         }
     }
@@ -336,7 +336,7 @@ void DolphinMainWindow::openInNewTab()
     // if no new tab has been created from the selection
     // open the current directory in a new tab
     if (!tabCreated) {
-        openNewTab(m_activeViewContainer->url());
+        m_tabWidget->openNewTab(m_activeViewContainer->url(), QUrl(), DolphinTabWidget::AfterCurrentTab);
     }
 }
 
index c708c64947f6d384da6d06e6aa99c956777ac05b..73c2752428c8c016c19f036a6e1a1b0e25facfd4 100644 (file)
@@ -147,7 +147,7 @@ void DolphinTabWidget::openNewActivatedTab(const QUrl& primaryUrl, const QUrl& s
     setCurrentIndex(count() - 1);
 }
 
-void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl)
+void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl, TabPlacement tabPlacement)
 {
     QWidget* focusWidget = QApplication::focusWidget();
 
@@ -157,7 +157,11 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU
             this, &DolphinTabWidget::activeViewChanged);
     connect(tabPage, &DolphinTabPage::activeViewUrlChanged,
             this, &DolphinTabWidget::tabUrlChanged);
-    addTab(tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(tabPage));
+    int newTabIndex = -1;
+    if (tabPlacement == AfterCurrentTab) {
+        newTabIndex = currentIndex() + 1;
+    }
+    insertTab(newTabIndex, tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(tabPage));
 
     if (focusWidget) {
         // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
index 0cb662966a76a4a07b45da950edb811a6ee54f22..85b2d66f0afc9538e1020ff2fb3ca51f0d97839f 100644 (file)
@@ -32,6 +32,19 @@ class DolphinTabWidget : public QTabWidget
     Q_OBJECT
 
 public:
+    /**
+     * @brief Controls where tabs are placed
+     */
+    enum TabPlacement {
+        /**
+          * The new tab is placed after the current tab
+          */
+        AfterCurrentTab,
+        /**
+          * The new tab is placed after the last tab
+          */
+        AfterLastTab
+    };
     explicit DolphinTabWidget(QWidget* parent);
 
     /**
@@ -105,9 +118,11 @@ public slots:
 
     /**
      * Opens a new tab in the background showing the URL \a primaryUrl and the
-     * optional URL \a secondaryUrl.
+     * optional URL \a secondaryUrl. \a tabPlacement controls where the new tab
+     * is placed.
      */
-    void openNewTab(const QUrl &primaryUrl, const QUrl &secondaryUrl = QUrl());
+    void openNewTab(const QUrl &primaryUrl, const QUrl &secondaryUrl = QUrl(),
+                    TabPlacement tabPlacement = AfterLastTab);
 
     /**
      * Opens each directory in \p dirs in a separate tab. If \a splitView is set,