]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Add open in split view action
[dolphin.git] / src / dolphinmainwindow.cpp
index 00af38beb5607286f3a8ee4f5c181394b556ad2b..744ad8f0aa980d6ea00ef5a09421efdff0194aa5 100644 (file)
 #include <KDualAction>
 #include <KFileItemListProperties>
 #include <KIO/CommandLauncherJob>
-#include <kio_version.h>
-#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
 #include <KIO/JobUiDelegateFactory>
-#else
-#include <KIO/JobUiDelegate>
-#endif
 #include <KIO/OpenFileManagerWindowJob>
 #include <KIO/OpenUrlJob>
 #include <KJobWidgets>
@@ -69,9 +64,7 @@
 #include <KUrlNavigator>
 #include <KWindowSystem>
 #include <KXMLGUIFactory>
-
 #include <kio_version.h>
-#include <kwidgetsaddons_version.h>
 
 #include <QApplication>
 #include <QClipboard>
@@ -504,6 +497,32 @@ void DolphinMainWindow::openInNewWindow()
     }
 }
 
+void DolphinMainWindow::openInSplitView(const QUrl &url)
+{
+    QUrl newSplitViewUrl = url;
+
+    if (newSplitViewUrl.isEmpty()) {
+        const KFileItemList list = m_activeViewContainer->view()->selectedItems();
+        if (list.count() == 1) {
+            const KFileItem &item = list.first();
+            newSplitViewUrl = DolphinView::openItemAsFolderUrl(item);
+        }
+    }
+
+    if (newSplitViewUrl.isEmpty()) {
+        return;
+    }
+
+    DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
+    if (tabPage->splitViewEnabled()) {
+        tabPage->switchActiveView();
+        tabPage->activeViewContainer()->setUrl(newSplitViewUrl);
+    } else {
+        tabPage->setSplitViewEnabled(true, WithAnimation, newSplitViewUrl);
+        updateViewActions();
+    }
+}
+
 void DolphinMainWindow::showTarget()
 {
     const KFileItem link = m_activeViewContainer->view()->selectedItems().at(0);
@@ -629,7 +648,7 @@ void DolphinMainWindow::closeEvent(QCloseEvent *event)
             QStringList(),
             i18n("Do not ask again"),
             &doNotAskAgainCheckboxResult,
-            KMessageBox::Dangerous);
+            KMessageBox::Notify | KMessageBox::Dangerous);
 
         if (doNotAskAgainCheckboxResult) {
             GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
@@ -676,20 +695,12 @@ void DolphinMainWindow::readProperties(const KConfigGroup &group)
 void DolphinMainWindow::updateNewMenu()
 {
     m_newFileMenu->checkUpToDate();
-#if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
     m_newFileMenu->setWorkingDirectory(activeViewContainer()->url());
-#else
-    m_newFileMenu->setPopupFiles(QList<QUrl>() << activeViewContainer()->url());
-#endif
 }
 
 void DolphinMainWindow::createDirectory()
 {
-#if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
     m_newFileMenu->setWorkingDirectory(activeViewContainer()->url());
-#else
-    m_newFileMenu->setPopupFiles(QList<QUrl>() << activeViewContainer()->url());
-#endif
     m_newFileMenu->createDirectory();
 }
 
@@ -900,7 +911,6 @@ void DolphinMainWindow::toggleSplitView()
 {
     DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
     tabPage->setSplitViewEnabled(!tabPage->splitViewEnabled(), WithAnimation);
-
     updateViewActions();
 }
 
@@ -1159,7 +1169,8 @@ void DolphinMainWindow::openTerminalHere()
 {
     QList<QUrl> urls = {};
 
-    for (const KFileItem &item : m_activeViewContainer->view()->selectedItems()) {
+    const auto selectedItems = m_activeViewContainer->view()->selectedItems();
+    for (const KFileItem &item : selectedItems) {
         QUrl url = item.targetUrl();
         if (item.isFile()) {
             url.setPath(QFileInfo(url.path()).absolutePath());
@@ -1177,29 +1188,19 @@ void DolphinMainWindow::openTerminalHere()
 
     if (urls.count() > 5) {
         QString question = i18np("Are you sure you want to open 1 terminal window?", "Are you sure you want to open %1 terminal windows?", urls.count());
-#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
-        const int answer = KMessageBox::warningTwoActions(
-            this,
-            question,
-            {},
-#else
-        const int answer = KMessageBox::warningYesNo(
+        const int answer = KMessageBox::warningContinueCancel(
             this,
             question,
             {},
-#endif
             KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls.count()), QStringLiteral("utilities-terminal")),
-            KStandardGuiItem::cancel());
-#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
-        if (answer != KMessageBox::PrimaryAction) {
-#else
-        if (answer != KMessageBox::Yes) {
-#endif
+            KStandardGuiItem::cancel(),
+            QStringLiteral("ConfirmOpenManyTerminals"));
+        if (answer != KMessageBox::PrimaryAction && answer != KMessageBox::Continue) {
             return;
         }
     }
 
-    for (const QUrl &url : urls) {
+    for (const QUrl &url : std::as_const(urls)) {
         openTerminalJob(url);
     }
 }
@@ -1264,11 +1265,7 @@ void DolphinMainWindow::handleUrl(const QUrl &url)
         activeViewContainer()->setUrl(url);
     } else {
         m_lastHandleUrlOpenJob = new KIO::OpenUrlJob(url);
-#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
         m_lastHandleUrlOpenJob->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
-#else
-        m_lastHandleUrlOpenJob->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
-#endif
         m_lastHandleUrlOpenJob->setShowOpenOrExecuteDialog(true);
 
         connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::mimeTypeFound, this, [this, url](const QString &mimetype) {
@@ -1651,7 +1648,7 @@ void DolphinMainWindow::setupActions()
     connect(moveToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::moveToInactiveSplitView);
 
     QAction *showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar"));
-    showFilterBar->setText(i18nc("@action:inmenu Tools", "Filter..."));
+    showFilterBar->setText(i18nc("@action:inmenu Tools", "Filter"));
     showFilterBar->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
     showFilterBar->setWhatsThis(xi18nc("@info:whatsthis",
                                        "This opens the "
@@ -1675,7 +1672,7 @@ void DolphinMainWindow::setupActions()
     connect(toggleFilter, &QAction::triggered, this, &DolphinMainWindow::toggleFilterBar);
 
     QAction *searchAction = KStandardAction::find(this, &DolphinMainWindow::find, actionCollection());
-    searchAction->setText(i18n("Search..."));
+    searchAction->setText(i18n("Search"));
     searchAction->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
     searchAction->setWhatsThis(xi18nc("@info:whatsthis find",
                                       "<para>This helps you "
@@ -1766,7 +1763,14 @@ void DolphinMainWindow::setupActions()
     stashSplit->setVisible(sessionInterface && sessionInterface->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
     connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash);
 
-    KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection());
+    QAction *redisplay = KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection());
+    redisplay->setToolTip(i18nc("@info:tooltip", "Refresh view"));
+    redisplay->setWhatsThis(xi18nc("@info:whatsthis refresh",
+                                   "<para>This refreshes "
+                                   "the folder view.</para>"
+                                   "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
+                                   "and show you a newly-updated view of the files and folders contained here.</para>"
+                                   "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
 
     QAction *stop = actionCollection()->addAction(QStringLiteral("stop"));
     stop->setText(i18nc("@action:inmenu View", "Stop"));
@@ -1793,7 +1797,7 @@ void DolphinMainWindow::setupActions()
     replaceLocation->setWhatsThis(xi18nc("@info:whatsthis",
                                          "This switches to editing the location and selects it "
                                          "so you can quickly enter a different location."));
-    actionCollection()->setDefaultShortcut(replaceLocation, Qt::CTRL | Qt::Key_L);
+    actionCollection()->setDefaultShortcuts(replaceLocation, {Qt::CTRL | Qt::Key_L, Qt::ALT | Qt::Key_D});
     connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation);
 
     // setup 'Go' menu
@@ -2006,6 +2010,13 @@ void DolphinMainWindow::setupActions()
     openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
     openInNewWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
     connect(openInNewWindow, &QAction::triggered, this, &DolphinMainWindow::openInNewWindow);
+
+    QAction *openInSplitViewAction = actionCollection()->addAction(QStringLiteral("open_in_split_view"));
+    openInSplitViewAction->setText(i18nc("@action:inmenu", "Open in Split View"));
+    openInSplitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
+    connect(openInSplitViewAction, &QAction::triggered, this, [this]() {
+        openInSplitView(QUrl());
+    });
 }
 
 void DolphinMainWindow::setupDockWidgets()
@@ -2181,6 +2192,7 @@ void DolphinMainWindow::setupDockWidgets()
     connect(m_placesPanel, &PlacesPanel::newWindowRequested, this, [this](const QUrl &url) {
         Dolphin::openNewWindow({url}, this);
     });
+    connect(m_placesPanel, &PlacesPanel::openInSplitViewRequested, this, &DolphinMainWindow::openInSplitView);
     connect(m_placesPanel, &PlacesPanel::errorMessage, this, &DolphinMainWindow::showErrorMessage);
     connect(this, &DolphinMainWindow::urlChanged, m_placesPanel, &PlacesPanel::setUrl);
     connect(placesDock, &DolphinDockWidget::visibilityChanged, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged);
@@ -2691,3 +2703,5 @@ bool DolphinMainWindow::isItemVisibleInAnyView(const QString &urlOfItem)
 {
     return m_tabWidget->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem));
 }
+
+#include "moc_dolphinmainwindow.cpp"