1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-07-04 17:30:55 +00:00

Add open in split view action

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
This commit is contained in:
Eric Armbruster 2023-09-06 06:34:13 +02:00 committed by Eric Armbruster
parent f900801540
commit a85863befd
9 changed files with 66 additions and 3 deletions

View 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();

View 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);

View 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
*/

View 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.

View 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()) {

View 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;
};

View 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") {

View File

@ -30,6 +30,10 @@
<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>

View 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"),