]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphintabwidget.cpp
Allow to copy or move selection to the other split view
[dolphin.git] / src / dolphintabwidget.cpp
index ec0c783bc34a491426dadda1d5ce4656dbbf4f01..9fd6005673f405d3f743004f711543c61df2c83b 100644 (file)
 #include "dolphinviewcontainer.h"
 
 #include <KConfigGroup>
-#include <KRun>
 #include <KShell>
 #include <kio/global.h>
+#include <KIO/CommandLauncherJob>
+#include <KAcceleratorManager>
 
 #include <QApplication>
 #include <QDropEvent>
@@ -37,6 +38,8 @@ DolphinTabWidget::DolphinTabWidget(QWidget* parent) :
     m_placesSelectorVisible(true),
     m_lastViewedTab(0)
 {
+    KAcceleratorManager::setNoAccel(this);
+
     connect(this, &DolphinTabWidget::tabCloseRequested,
             this, QOverload<int>::of(&DolphinTabWidget::closeTab));
     connect(this, &DolphinTabWidget::currentChanged,
@@ -203,6 +206,10 @@ void DolphinTabWidget::openDirectories(const QList<QUrl>& dirs, bool splitView)
             } else {
                 tabPage->secondaryViewContainer()->setActive(true);
             }
+            // BUG: 417230
+            // 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())) {
@@ -236,10 +243,14 @@ void DolphinTabWidget::openFiles(const QList<QUrl>& files, bool splitView)
     // Select the files. Although the files can be split between several
     // tabs, there is no need to split 'files' accordingly, as
     // the DolphinView will just ignore invalid selections.
-    for (int i = oldTabCount; i < tabCount; ++i) {
+    for (int i = 0; i < tabCount; ++i) {
         DolphinTabPage* tabPage = tabPageAt(i);
         tabPage->markUrlsAsSelected(files);
         tabPage->markUrlAsCurrent(files.first());
+        if (i < oldTabCount) {
+            // Force selection of file if directory was already open, BUG: 417230
+            tabPage->activeViewContainer()->view()->updateViewState();
+        }
     }
 }
 
@@ -266,6 +277,18 @@ void DolphinTabWidget::closeTab(const int index)
     tabPage->deleteLater();
 }
 
+void DolphinTabWidget::activateTab(const int index)
+{
+    if (index < count()) {
+        setCurrentIndex(index);
+    }
+}
+
+void DolphinTabWidget::activateLastTab()
+{
+    setCurrentIndex(count() - 1);
+}
+
 void DolphinTabWidget::activateNextTab()
 {
     const int index = currentIndex() + 1;
@@ -297,6 +320,40 @@ void DolphinTabWidget::restoreClosedTab(const QByteArray& state)
     currentTabPage()->restoreState(state);
 }
 
+void DolphinTabWidget::copyToInactiveSplitView()
+{
+    const DolphinTabPage* tabPage = tabPageAt(currentIndex());
+    DolphinViewContainer* activeViewContainer = currentTabPage()->activeViewContainer();
+    if (!tabPage->splitViewEnabled() || activeViewContainer->view()->selectedItems().isEmpty()) {
+        return;
+    }
+
+    if (tabPage->primaryViewActive()) {
+        // copy from left panel to right
+        activeViewContainer->view()->copySelectedItemsToInactiveSplitView(activeViewContainer->view()->selectedItems(), tabPage->secondaryViewContainer()->url());
+    } else {
+        // copy from right panel to left
+        activeViewContainer->view()->copySelectedItemsToInactiveSplitView(activeViewContainer->view()->selectedItems(), tabPage->primaryViewContainer()->url());
+    }
+}
+
+void DolphinTabWidget::moveToInactiveSplitView()
+{
+    const DolphinTabPage* tabPage = tabPageAt(currentIndex());
+    DolphinViewContainer* activeViewContainer = currentTabPage()->activeViewContainer();
+    if (!tabPage->splitViewEnabled() || activeViewContainer->view()->selectedItems().isEmpty()) {
+        return;
+    }
+
+    if (tabPage->primaryViewActive()) {
+        // move from left panel to right
+        activeViewContainer->view()->moveSelectedItemsToInactiveSplitView(activeViewContainer->view()->selectedItems(), tabPage->secondaryViewContainer()->url());
+    } else {
+        // move from right panel to left
+        activeViewContainer->view()->moveSelectedItemsToInactiveSplitView(activeViewContainer->view()->selectedItems(), tabPage->primaryViewContainer()->url());
+    }
+}
+
 void DolphinTabWidget::detachTab(int index)
 {
     Q_ASSERT(index >= 0);
@@ -311,8 +368,9 @@ void DolphinTabWidget::detachTab(int index)
     }
     args << QStringLiteral("--new-window");
 
-    const QString command = QStringLiteral("dolphin %1").arg(KShell::joinArgs(args));
-    KRun::runCommand(command, this);
+    KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob("dolphin", args, this);
+    job->setDesktopName(QStringLiteral("org.kde.dolphin"));
+    job->start();
 
     closeTab(index);
 }