* 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
{
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")));
// 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) |
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"));
addToPlacesAction->setEnabled(true);
copyToOtherViewAction->setEnabled(false);
moveToOtherViewAction->setEnabled(false);
+ copyLocation->setEnabled(false);
} else {
stateChanged(QStringLiteral("has_selection"));
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());
}
<!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" />
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);
+}
*/
void pasteIntoFolder();
+ /**
+ * Copies the path of the first selected KFileItem into Clipboard.
+ */
+ void copyPathToClipboard();
+
/**
* Creates duplicates of selected items, appending "copy"
* to the end.
#include <KNewFileMenu>
#include <KPropertiesDialog>
#include <KProtocolManager>
-
#include <QMenu>
#include <QPointer>
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();
dialog->raise();
dialog->activateWindow();
}
+
+void DolphinViewActionHandler::slotCopyPath()
+{
+ m_currentView->copyPathToClipboard();
+}
*/
void slotProperties();
+ /**
+ * Copies the path of the first selected KFileItem into Clipboard.
+ */
+ void slotCopyPath();
+
private:
/**
* Create all the actions.