]> cloud.milkyroute.net Git - dolphin.git/commitdiff
## Summary
authorYann Holme-Nielsen <accs@liz3.net>
Mon, 29 Jun 2020 22:27:33 +0000 (22:27 +0000)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Mon, 29 Jun 2020 22:27:33 +0000 (22:27 +0000)
* Adds a "Copy location" item, after the "Copy" Context item and Edit Menu, which will attempt to copy the path of the fist item into clipboard.

## Reasoning
Most File Managers have this option through one or another way.
Also using the default Copy option often results in different behaviour depending on the target software, Konsole will take the path. Other Programs will use the URI. Which ultimately could lead to non optimal User Experience.

## Notes
* Should the target file **not** be on a local hard drive, this fallback to using the remote URL, feedback is wanted on that matter.

FEATURE: 407004

src/dolphincontextmenu.cpp
src/dolphinmainwindow.cpp
src/dolphinui.rc
src/views/dolphinview.cpp
src/views/dolphinview.h
src/views/dolphinviewactionhandler.cpp
src/views/dolphinviewactionhandler.h

index e80283c58b84b57c9e3b0315938b2bad1b177d8f..912caf859b8181a34b95405f18e6db9aa8e828b7 100644 (file)
@@ -392,9 +392,12 @@ void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties&
 {
     const KActionCollection* collection = m_mainWindow->actionCollection();
 
-    // Insert 'Cut', 'Copy' and 'Paste'
+    // Insert 'Cut', 'Copy', 'Copy location' and 'Paste'
     addAction(collection->action(KStandardAction::name(KStandardAction::Cut)));
     addAction(collection->action(KStandardAction::name(KStandardAction::Copy)));
+    QAction* copyPathAction = collection->action(QString("copy_location"));
+    copyPathAction->setEnabled(m_selectedItems.size() == 1);
+    addAction(copyPathAction);
     addAction(createPasteAction());
     addAction(m_mainWindow->actionCollection()->action(QStringLiteral("duplicate")));
 
index d45b77676cd01626471ca4da370d91d629b0dca0..5741e89439b9196980760392c5c7e8cd324e3cb4 100644 (file)
@@ -1129,6 +1129,7 @@ void DolphinMainWindow::updateControlMenu()
 
     // Add "Edit" actions
     bool added = addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Undo)), menu) |
+                 addActionToMenu(ac->action(QString("copy_location")), 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) |
@@ -1911,6 +1912,7 @@ void DolphinMainWindow::updateFileAndEditActions()
     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"));
+    QAction* copyLocation            = col->action(QString("copy_location"));
 
     if (list.isEmpty()) {
         stateChanged(QStringLiteral("has_no_selection"));
@@ -1918,6 +1920,7 @@ void DolphinMainWindow::updateFileAndEditActions()
         addToPlacesAction->setEnabled(true);
         copyToOtherViewAction->setEnabled(false);
         moveToOtherViewAction->setEnabled(false);
+        copyLocation->setEnabled(false);
     } else {
         stateChanged(QStringLiteral("has_selection"));
 
@@ -1959,6 +1962,7 @@ void DolphinMainWindow::updateFileAndEditActions()
         deleteAction->setEnabled(capabilitiesSource.supportsDeleting());
         deleteWithTrashShortcut->setEnabled(capabilitiesSource.supportsDeleting() && !enableMoveToTrash);
         cutAction->setEnabled(capabilitiesSource.supportsMoving());
+        copyLocation->setEnabled(list.length() == 1);
         showTarget->setEnabled(list.length() == 1 && list.at(0).isLink());
         duplicateAction->setEnabled(capabilitiesSource.supportsWriting());
     }
index acb2f1dcd75fe13b3d7d004bdce3acdf54e15ab9..46a4bac518c922064bdd63b80ff6399010b5db19 100644 (file)
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="dolphin" version="31">
+<kpartgui name="dolphin" version="32">
     <MenuBar>
         <Menu name="file">
             <Action name="new_menu" />
             <Action name="properties" />
         </Menu>
         <Menu name="edit">
+            <Action name="edit_undo" />
+            <Separator />
+            <Action name="edit_cut" />
+            <Action name="edit_copy" />
+            <Action name="copy_location" />
+            <Action name="edit_paste" />
+            <Separator />
+            <Action name="edit_find" />
+            <Separator />
             <Action name="copy_to_inactive_split_view" />
             <Action name="move_to_inactive_split_view" />
             <Action name="edit_select_all" />
index 9af6919277911779b9bbc74220bf5ad464a9f33f..54f2f721dd0c243d8a482f86a5b1d2a6f3ca0767 100644 (file)
@@ -1949,3 +1949,21 @@ void DolphinView::forceUrlsSelection(const QUrl& current, const QList<QUrl>& sel
     markUrlAsCurrent(current);
     markUrlsAsSelected(selected);
 }
+
+void DolphinView::copyPathToClipboard()
+{
+    const KFileItemList list = selectedItems();
+    if (list.isEmpty()) {
+        return;
+    }
+    const KFileItem& item = list.at(0);
+    QString path = item.localPath();
+    if (path.isEmpty()) {
+        path = item.url().toDisplayString();
+    }
+    QClipboard* clipboard = QApplication::clipboard();
+    if (clipboard == nullptr) {
+        return;
+    }
+    clipboard->setText(path);
+}
index 4306b3eb73aa44ee43736bc58284bd0c726118c9..91203b8e03501dd122a9f6b3c6a1e2c44fc2117a 100644 (file)
@@ -390,6 +390,11 @@ public slots:
      */
     void pasteIntoFolder();
 
+    /**
+     * Copies the path of the first selected KFileItem into Clipboard.
+     */
+    void copyPathToClipboard();
+
     /**
      * Creates duplicates of selected items, appending "copy"
      * to the end.
index e89e2e62c2b705e32223dca048334d6c22f7f224..29bd530b4e0e0f7ff49d0b70dc3d5a782ff356e9 100644 (file)
@@ -34,7 +34,6 @@
 #include <KNewFileMenu>
 #include <KPropertiesDialog>
 #include <KProtocolManager>
-
 #include <QMenu>
 #include <QPointer>
 
@@ -156,6 +155,17 @@ void DolphinViewActionHandler::createActions()
     m_actionCollection->setDefaultShortcuts(propertiesAction, {Qt::ALT + Qt::Key_Return, Qt::ALT + Qt::Key_Enter});
     connect(propertiesAction, &QAction::triggered, this, &DolphinViewActionHandler::slotProperties);
 
+    QAction *copyPathAction = m_actionCollection->addAction( QStringLiteral("copy_location") );
+    copyPathAction->setText(i18nc("@action:incontextmenu", "Copy location"));
+    copyPathAction->setWhatsThis(i18nc("@info:whatsthis copy_location",
+                                          "This will copy the path of the first selected item into the clipboard."
+                                ));
+
+    copyPathAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
+    m_actionCollection->setDefaultShortcuts(copyPathAction, {Qt::CTRL + Qt::SHIFT + Qt::Key_C});
+    connect(copyPathAction, &QAction::triggered, this, &DolphinViewActionHandler::slotCopyPath);
+
+
     // View menu
     KToggleAction* iconsAction = iconsModeAction();
     KToggleAction* compactAction = compactModeAction();
@@ -709,3 +719,8 @@ void DolphinViewActionHandler::slotProperties()
     dialog->raise();
     dialog->activateWindow();
 }
+
+void DolphinViewActionHandler::slotCopyPath()
+{
+    m_currentView->copyPathToClipboard();
+}
index 3228e7364cdc1ff6a72b8bb22daeb1efe4f40acb..d6b0d3b84bcd91e761f41f592d0df77a1332ddca 100644 (file)
@@ -219,6 +219,11 @@ private Q_SLOTS:
      */
     void slotProperties();
 
+    /**
+     * Copies the path of the first selected KFileItem into Clipboard.
+     */
+    void slotCopyPath();
+
 private:
     /**
      * Create all the actions.