From: Antonio Prcela Date: Thu, 14 May 2020 22:17:31 +0000 (-0600) Subject: Allow to copy or move selection to the other split view X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/a291c5999035bb17fe764c1910c3e78ba041f8ac 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 --- diff --git a/doc/index.docbook b/doc/index.docbook index 965303477..344ab8ac0 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. + + + +&Ctrl;F5 + +Edit +Copy to inactive split view + +Copies the currently selected item(s) from the active split view to the inactive split view. + + + + + +&Ctrl;F6 + +Edit +Move to inactive split view + +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). + + diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 501949a64..668f511ee 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 Cut " "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 active 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 active 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 fba6fe084..9fd600567 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 746aec6c6..f0ce11ce8 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 e717b67ae..acb2f1dcd 100644 --- a/src/dolphinui.rc +++ b/src/dolphinui.rc @@ -1,5 +1,5 @@ - + @@ -20,6 +20,8 @@ + + diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 2500902af..aef0e85d6 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 DolphinView::simplifiedSelectedUrls() const diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index 766540d99..0b2c0bce4 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& 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