Skip to content

Commit

Permalink
## Summary
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
liz3 authored and elvisangelaccio committed Jun 29, 2020
1 parent d1baf33 commit 86e3b82
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/dolphincontextmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")));

Expand Down
4 changes: 4 additions & 0 deletions src/dolphinmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down Expand Up @@ -1911,13 +1912,15 @@ 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"));

addToPlacesAction->setEnabled(true);
copyToOtherViewAction->setEnabled(false);
moveToOtherViewAction->setEnabled(false);
copyLocation->setEnabled(false);
} else {
stateChanged(QStringLiteral("has_selection"));

Expand Down Expand Up @@ -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());
}
Expand Down
11 changes: 10 additions & 1 deletion src/dolphinui.rc
Original file line number Diff line number Diff line change
@@ -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" />
Expand All @@ -20,6 +20,15 @@
<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" />
Expand Down
18 changes: 18 additions & 0 deletions src/views/dolphinview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
5 changes: 5 additions & 0 deletions src/views/dolphinview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 16 additions & 1 deletion src/views/dolphinviewactionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <KNewFileMenu>
#include <KPropertiesDialog>
#include <KProtocolManager>

#include <QMenu>
#include <QPointer>

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -709,3 +719,8 @@ void DolphinViewActionHandler::slotProperties()
dialog->raise();
dialog->activateWindow();
}

void DolphinViewActionHandler::slotCopyPath()
{
m_currentView->copyPathToClipboard();
}
5 changes: 5 additions & 0 deletions src/views/dolphinviewactionhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 86e3b82

Please sign in to comment.