[dolphin] /: Allow to copy or move selection to the other split view
Nate Graham
null at kde.org
Thu May 14 23:20:20 BST 2020
Git commit a291c5999035bb17fe764c1910c3e78ba041f8ac by Nate Graham, on behalf of Antonio Prcela.
Committed on 14/05/2020 at 22:20.
Pushed by ngraham into branch 'master'.
Allow to copy or move selection to the other split view
Summary:
FEATURE: 276167
Default keyboard shortcuts set to `SHIFT+F5` for `copy`, `SHIFT+F6` for `move`
Reviewers: #dolphin, elvisangelaccio, ngraham, meven, dfaure
Reviewed By: #dolphin, elvisangelaccio, ngraham, meven, dfaure
Subscribers: yurchor, kde-doc-english, dfaure, meven, kfm-devel
Tags: #dolphin, #documentation
Differential Revision: https://phabricator.kde.org/D29006
M +23 -0 doc/index.docbook
M +49 -7 src/dolphinmainwindow.cpp
M +34 -0 src/dolphintabwidget.cpp
M +6 -0 src/dolphintabwidget.h
M +3 -1 src/dolphinui.rc
M +29 -3 src/views/dolphinview.cpp
M +14 -1 src/views/dolphinview.h
https://commits.kde.org/dolphin/a291c5999035bb17fe764c1910c3e78ba041f8ac
diff --git a/doc/index.docbook b/doc/index.docbook
index 965303477f..344ab8ac01 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -1729,6 +1729,29 @@ The name of this file has to be entered in a dialog.
</action></para></listitem>
</varlistentry>
+<varlistentry>
+<term><menuchoice>
+<shortcut>
+<keycombo action="simul">&Ctrl;<keycap>F5</keycap></keycombo>
+</shortcut>
+<guimenu>Edit</guimenu>
+<guimenuitem>Copy to inactive split view</guimenuitem>
+</menuchoice></term>
+<listitem><para><action>Copies the currently selected item(s) from the active split view to the inactive split view.</action></para></listitem>
+</varlistentry>
+
+<varlistentry>
+<term><menuchoice>
+<shortcut>
+<keycombo action="simul">&Ctrl;<keycap>F6</keycap></keycombo>
+</shortcut>
+<guimenu>Edit</guimenu>
+<guimenuitem>Move to inactive split view</guimenuitem>
+</menuchoice></term>
+<listitem><para><action>Moves the currently selected item(s) from the active split view to the inactive split view.
+Is disabled if the current user does not have write permission on the selected item(s).</action></para></listitem>
+</varlistentry>
+
<varlistentry>
<term><menuchoice>
<shortcut>
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index 501949a64c..668f511ee0 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -1149,6 +1149,8 @@ void DolphinMainWindow::updateControlMenu()
// Add "Edit" actions
bool added = addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Undo)), menu) |
+ addActionToMenu(ac->action(QStringLiteral("copy_to_inactive_split_view")), menu) |
+ addActionToMenu(ac->action(QStringLiteral("move_to_inactive_split_view")), menu) |
addActionToMenu(ac->action(KStandardAction::name(KStandardAction::SelectAll)), menu) |
addActionToMenu(ac->action(QStringLiteral("invert_selection")), menu);
@@ -1382,6 +1384,24 @@ void DolphinMainWindow::setupActions()
"If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
"action they are removed from their old location.") + cutCopyPastePara);
+ QAction* copyToOtherViewAction = actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
+ copyToOtherViewAction->setText(i18nc("@action:inmenu", "Copy to inactive split view"));
+ copyToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
+ "the <emphasis>active</emphasis> view to the inactive split view."));
+ copyToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
+ copyToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Copy to inactive split view"));
+ actionCollection()->setDefaultShortcut(copyToOtherViewAction, Qt::SHIFT + Qt::Key_F5 );
+ connect(copyToOtherViewAction, &QAction::triggered, m_tabWidget, &DolphinTabWidget::copyToInactiveSplitView);
+
+ QAction* moveToOtherViewAction = actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
+ moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to inactive split view"));
+ moveToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
+ "the <emphasis>active</emphasis> view to the inactive split view."));
+ moveToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
+ moveToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Move to inactive split view"));
+ actionCollection()->setDefaultShortcut(moveToOtherViewAction, Qt::SHIFT + Qt::Key_F6 );
+ connect(moveToOtherViewAction, &QAction::triggered, m_tabWidget, &DolphinTabWidget::moveToInactiveSplitView);
+
QAction *searchAction = KStandardAction::find(this, &DolphinMainWindow::find, actionCollection());
searchAction->setText(i18n("Search..."));
searchAction->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
@@ -1907,12 +1927,18 @@ void DolphinMainWindow::updateFileAndEditActions()
{
const KFileItemList list = m_activeViewContainer->view()->selectedItems();
const KActionCollection* col = actionCollection();
+ KFileItemListProperties capabilitiesSource(list);
+
QAction* addToPlacesAction = col->action(QStringLiteral("add_to_places"));
+ QAction* copyToOtherViewAction = col->action(QStringLiteral("copy_to_inactive_split_view"));
+ QAction* moveToOtherViewAction = col->action(QStringLiteral("move_to_inactive_split_view"));
if (list.isEmpty()) {
stateChanged(QStringLiteral("has_no_selection"));
addToPlacesAction->setEnabled(true);
+ copyToOtherViewAction->setEnabled(false);
+ moveToOtherViewAction->setEnabled(false);
} else {
stateChanged(QStringLiteral("has_selection"));
@@ -1930,16 +1956,32 @@ void DolphinMainWindow::updateFileAndEditActions()
addToPlacesAction->setEnabled(false);
}
- KFileItemListProperties capabilities(list);
- const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
+ if (m_tabWidget->currentTabPage()->splitViewEnabled()) {
+ DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
+ KFileItem capabilitiesDestination;
+
+ if (tabPage->primaryViewActive()) {
+ capabilitiesDestination = tabPage->secondaryViewContainer()->url();
+ } else {
+ capabilitiesDestination = tabPage->primaryViewContainer()->url();
+ }
+
+ copyToOtherViewAction->setEnabled(capabilitiesDestination.isWritable());
+ moveToOtherViewAction->setEnabled(capabilitiesSource.supportsMoving() && capabilitiesDestination.isWritable());
+ } else {
+ copyToOtherViewAction->setEnabled(false);
+ moveToOtherViewAction->setEnabled(false);
+ }
+
+ const bool enableMoveToTrash = capabilitiesSource.isLocal() && capabilitiesSource.supportsMoving();
- renameAction->setEnabled(capabilities.supportsMoving());
+ renameAction->setEnabled(capabilitiesSource.supportsMoving());
moveToTrashAction->setEnabled(enableMoveToTrash);
- deleteAction->setEnabled(capabilities.supportsDeleting());
- deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
- cutAction->setEnabled(capabilities.supportsMoving());
+ deleteAction->setEnabled(capabilitiesSource.supportsDeleting());
+ deleteWithTrashShortcut->setEnabled(capabilitiesSource.supportsDeleting() && !enableMoveToTrash);
+ cutAction->setEnabled(capabilitiesSource.supportsMoving());
showTarget->setEnabled(list.length() == 1 && list.at(0).isLink());
- duplicateAction->setEnabled(capabilities.supportsWriting());
+ duplicateAction->setEnabled(capabilitiesSource.supportsWriting());
}
}
diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp
index fba6fe0849..9fd6005673 100644
--- a/src/dolphintabwidget.cpp
+++ b/src/dolphintabwidget.cpp
@@ -320,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);
diff --git a/src/dolphintabwidget.h b/src/dolphintabwidget.h
index 746aec6c64..f0ce11ce89 100644
--- a/src/dolphintabwidget.h
+++ b/src/dolphintabwidget.h
@@ -189,6 +189,12 @@ public slots:
*/
void restoreClosedTab(const QByteArray& state);
+ /** Copies all selected items to the inactive view. */
+ void copyToInactiveSplitView();
+
+ /** Moves all selected items to the inactive view. */
+ void moveToInactiveSplitView();
+
private slots:
/**
* Opens the tab with the index \a index in a new Dolphin instance and closes
diff --git a/src/dolphinui.rc b/src/dolphinui.rc
index e717b67ae9..acb2f1dcd7 100644
--- a/src/dolphinui.rc
+++ b/src/dolphinui.rc
@@ -1,5 +1,5 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="dolphin" version="30">
+<kpartgui name="dolphin" version="31">
<MenuBar>
<Menu name="file">
<Action name="new_menu" />
@@ -20,6 +20,8 @@
<Action name="properties" />
</Menu>
<Menu name="edit">
+ <Action name="copy_to_inactive_split_view" />
+ <Action name="move_to_inactive_split_view" />
<Action name="edit_select_all" />
<Action name="invert_selection" />
</Menu>
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index 2500902afe..aef0e85d60 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -692,6 +692,27 @@ void DolphinView::copySelectedItemsToClipboard()
QApplication::clipboard()->setMimeData(mimeData);
}
+void DolphinView::copySelectedItemsToInactiveSplitView(const KFileItemList &selection, const QUrl &destinationUrl)
+{
+ KIO::CopyJob* job = KIO::copy(selection.urlList(), destinationUrl, KIO::DefaultFlags);
+ KJobWidgets::setWindow(job, this);
+
+ connect(job, &KIO::DropJob::result, this, &DolphinView::slotJobResult);
+ connect(job, &KIO::CopyJob::copyingDone, this, &DolphinView::slotCopyingDone);
+ KIO::FileUndoManager::self()->recordCopyJob(job);
+}
+
+void DolphinView::moveSelectedItemsToInactiveSplitView(const KFileItemList &selection, const QUrl &destinationUrl)
+{
+ KIO::CopyJob* job = KIO::move(selection.urlList(), destinationUrl, KIO::DefaultFlags);
+ KJobWidgets::setWindow(job, this);
+
+ connect(job, &KIO::DropJob::result, this, &DolphinView::slotJobResult);
+ connect(job, &KIO::CopyJob::copyingDone, this, &DolphinView::slotCopyingDone);
+ KIO::FileUndoManager::self()->recordCopyJob(job);
+
+}
+
void DolphinView::paste()
{
pasteToUrl(url());
@@ -1132,7 +1153,7 @@ void DolphinView::dropUrls(const QUrl &destUrl, QDropEvent *dropEvent, QWidget *
KIO::DropJob* job = DragAndDropHelper::dropUrls(destUrl, dropEvent, dropWidget);
if (job) {
- connect(job, &KIO::DropJob::result, this, &DolphinView::slotPasteJobResult);
+ connect(job, &KIO::DropJob::result, this, &DolphinView::slotJobResult);
if (destUrl == url()) {
// Mark the dropped urls as selected.
@@ -1185,6 +1206,11 @@ void DolphinView::slotSelectedItemTextPressed(int index)
}
}
+void DolphinView::slotCopyingDone(KIO::Job *, const QUrl &, const QUrl &to)
+{
+ slotItemCreated(to);
+}
+
void DolphinView::slotItemCreated(const QUrl& url)
{
if (m_markFirstNewlySelectedItemAsCurrent) {
@@ -1194,7 +1220,7 @@ void DolphinView::slotItemCreated(const QUrl& url)
m_selectedUrls << url;
}
-void DolphinView::slotPasteJobResult(KJob *job)
+void DolphinView::slotJobResult(KJob *job)
{
if (job->error()) {
emit errorMessage(job->errorString());
@@ -1845,7 +1871,7 @@ void DolphinView::pasteToUrl(const QUrl& url)
m_clearSelectionBeforeSelectingNewItems = true;
m_markFirstNewlySelectedItemAsCurrent = true;
connect(job, &KIO::PasteJob::itemCreated, this, &DolphinView::slotItemCreated);
- connect(job, &KIO::PasteJob::result, this, &DolphinView::slotPasteJobResult);
+ connect(job, &KIO::PasteJob::result, this, &DolphinView::slotJobResult);
}
QList<QUrl> DolphinView::simplifiedSelectedUrls() const
diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h
index 766540d99d..0b2c0bce48 100644
--- a/src/views/dolphinview.h
+++ b/src/views/dolphinview.h
@@ -370,6 +370,18 @@ public slots:
/** Copies all selected items to the clipboard. */
void copySelectedItemsToClipboard();
+ /**
+ * Copies all selected items to the inactive split view.
+ * Only used in Split View.
+ */
+ void copySelectedItemsToInactiveSplitView(const KFileItemList &selection, const QUrl &destinationUrl);
+
+ /**
+ * Moves all selected items to the inactive split view.
+ * Only used in Split View.
+ */
+ void moveSelectedItemsToInactiveSplitView(const KFileItemList &selection, const QUrl &destinationUrl);
+
/** Pastes the clipboard data to this view. */
void paste();
@@ -608,6 +620,7 @@ private slots:
void slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons);
void slotRenameDialogRenamingFinished(const QList<QUrl>& urls);
void slotSelectedItemTextPressed(int index);
+ void slotCopyingDone(KIO::Job *, const QUrl &, const QUrl &to);
/*
* Is called when new items get pasted or dropped.
@@ -616,7 +629,7 @@ private slots:
/*
* Is called after all pasted or dropped items have been copied to destination.
*/
- void slotPasteJobResult(KJob *job);
+ void slotJobResult(KJob *job);
/**
* Emits the signal \a selectionChanged() with a small delay. This is
More information about the kde-doc-english
mailing list