]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Add open in split view action
authorEric Armbruster <eric.armbruster@tum.de>
Wed, 6 Sep 2023 04:34:13 +0000 (06:34 +0200)
committerEric Armbruster <eric1@armbruster-online.de>
Sat, 9 Sep 2023 15:45:26 +0000 (15:45 +0000)
This action is shown only if a single folder is selected. The action
opens the selected folder in the inactive split view (and opens the
split view if necessary).

FEATURE: 465500

src/dolphincontextmenu.cpp
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphintabpage.h
src/panels/places/placespanel.cpp
src/panels/places/placespanel.h
src/settings/contextmenu/contextmenusettingspage.cpp
src/settings/dolphin_contextmenusettings.kcfg
src/settings/dolphinsettingsdialog.cpp

index 83329dd7144274b0272f33ea1069c6a774d36a39..4dc54946f6f869586de4f9cb3f6ae9fdb2257b0c 100644 (file)
@@ -165,6 +165,10 @@ void DolphinContextMenu::addDirectoryItemContextMenu()
         addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window")));
     }
 
+    if (ContextMenuSettings::showOpenInSplitView()) {
+        addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_split_view")));
+    }
+
     // Insert 'Open With' entries
     addOpenWithActions();
 
index e3373efe29e045275fbb39d44ab8320331bbf8be..744ad8f0aa980d6ea00ef5a09421efdff0194aa5 100644 (file)
@@ -497,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);
@@ -885,7 +911,6 @@ void DolphinMainWindow::toggleSplitView()
 {
     DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
     tabPage->setSplitViewEnabled(!tabPage->splitViewEnabled(), WithAnimation);
-
     updateViewActions();
 }
 
@@ -1985,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()
@@ -2160,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);
index 5bb17e79adb25aa0509399184edae3268e262f56..b45c846b83570c33daaf030ff78361c2cc6ea71c 100644 (file)
@@ -476,6 +476,11 @@ private Q_SLOTS:
      */
     void openInNewWindow();
 
+    /**
+     * Opens the selected folder in the other inactive split view, enables split view if necessary.
+     */
+    void openInSplitView(const QUrl &url);
+
     /**
      * Show the target of the selected symlink
      */
index 0c691830ebd7f3ce68ee51719234c9a43a602c05..4a8bd365a56a14bdf5042441fbabfb6e4034b047 100644 (file)
@@ -138,6 +138,8 @@ public:
      */
     void setActive(bool active);
 
+    void switchActiveView();
+
 Q_SIGNALS:
     void activeViewChanged(DolphinViewContainer *viewContainer);
     void activeViewUrlChanged(const QUrl &url);
@@ -170,8 +172,6 @@ private Q_SLOTS:
      */
     void slotViewUrlRedirection(const QUrl &oldUrl, const QUrl &newUrl);
 
-    void switchActiveView();
-
 private:
     /**
      * Creates a new view container and does the default initialization.
index 3c3f7bb87a449d8df1e3e736f52b90cdc8c2f2d8..e3d133ff0555b083c70ecad2b56c09d052b48b1a 100644 (file)
@@ -47,6 +47,15 @@ PlacesPanel::PlacesPanel(QWidget *parent)
     connect(m_configureTrashAction, &QAction::triggered, this, &PlacesPanel::slotConfigureTrash);
     addAction(m_configureTrashAction);
 
+    m_openInSplitView = new QAction(QIcon::fromTheme(QStringLiteral("view-right-new")), i18nc("@action:inmenu", "Open in Split View"));
+    m_openInSplitView->setPriority(QAction::HighPriority);
+    connect(m_openInSplitView, &QAction::triggered, this, [this]() {
+        const QUrl url = currentIndex().data(KFilePlacesModel::UrlRole).toUrl();
+        Q_EMIT openInSplitViewRequested(url);
+    });
+
+    addAction(m_openInSplitView);
+
     connect(this, &PlacesPanel::contextMenuAboutToShow, this, &PlacesPanel::slotContextMenuAboutToShow);
 
     connect(this, &PlacesPanel::iconSizeChanged, this, [](const QSize &newSize) {
@@ -188,6 +197,7 @@ void PlacesPanel::slotContextMenuAboutToShow(const QModelIndex &index, QMenu *me
     const Solid::Device device = placesModel->deviceForIndex(index);
 
     m_configureTrashAction->setVisible(url.scheme() == QLatin1String("trash"));
+    m_openInSplitView->setVisible(url.isValid());
 
     // show customContextMenuActions only on the view's context menu
     if (!url.isValid() && !device.isValid()) {
index 2eb309483103462c8eee4fc4bbd38750b4330475..cbd5fc224ce9763a5ba5fed97ad916dc7da47cbd 100644 (file)
@@ -51,6 +51,7 @@ Q_SIGNALS:
     void storageTearDownRequested(const QString &mountPath);
     void storageTearDownExternallyRequested(const QString &mountPath);
     void storageTearDownSuccessful();
+    void openInSplitViewRequested(const QUrl &url);
 
 protected:
     void showEvent(QShowEvent *event) override;
@@ -75,6 +76,7 @@ private:
     QPersistentModelIndex m_indexToTearDown;
 
     QAction *m_configureTrashAction;
+    QAction *m_openInSplitView;
     QAction *m_lockPanelsAction;
 };
 
index ea780550abe1ab436a3a31806ae99e969b1e6397..23ddfba31deed43f865162294b397e845266879c 100644 (file)
@@ -122,6 +122,8 @@ bool ContextMenuSettingsPage::entryVisible(const QString &id)
         return ContextMenuSettings::showOpenInNewTab();
     } else if (id == "open_in_new_window") {
         return ContextMenuSettings::showOpenInNewWindow();
+    } else if (id == "open_in_split_view") {
+        return ContextMenuSettings::showOpenInSplitView();
     } else if (id == "copy_location") {
         return ContextMenuSettings::showCopyLocation();
     } else if (id == "duplicate") {
@@ -148,6 +150,8 @@ void ContextMenuSettingsPage::setEntryVisible(const QString &id, bool visible)
         ContextMenuSettings::setShowOpenInNewTab(visible);
     } else if (id == "open_in_new_window") {
         ContextMenuSettings::setShowOpenInNewWindow(visible);
+    } else if (id == "open_in_split_view") {
+        return ContextMenuSettings::setShowOpenInSplitView(visible);
     } else if (id == "copy_location") {
         ContextMenuSettings::setShowCopyLocation(visible);
     } else if (id == "duplicate") {
index 63ca079af77926ae951eacc267c5ad5e5537b458..6e45d9bcdf80f4c9321992803f0ac5ebc5b1ae0a 100644 (file)
             <label>Show 'Open in New Window' in context menu.</label>
             <default>true</default>
         </entry>
+        <entry name="ShowOpenInSplitView" type="Bool">
+            <label>Show 'Open In Split View' in context menu.</label>
+            <default>true</default>
+        </entry>
         <entry name="ShowCopyLocation" type="Bool">
             <label>Show 'Copy Location' in context menu.</label>
             <default>true</default>
index 3a2ad31e9e79399550188a4ef521b390ec5c12bb..d05d5a81414ec37a5f20444da313a6970b20bf36 100644 (file)
@@ -68,6 +68,7 @@ DolphinSettingsDialog::DolphinSettingsDialog(const QUrl &url, QWidget *parent, K
                                                                 QStringLiteral("view_mode"),
                                                                 QStringLiteral("open_in_new_tab"),
                                                                 QStringLiteral("open_in_new_window"),
+                                                                QStringLiteral("open_in_split_view"),
                                                                 QStringLiteral("copy_location"),
                                                                 QStringLiteral("duplicate"),
                                                                 QStringLiteral("open_terminal_here"),