Add "Show Target" into symlink context menu and file menu

Summary:
Add "Show Target" into symlink context menu and file menu

FEATURE: 215069

Reviewers: ngraham, elvisangelaccio

Reviewed By: ngraham, elvisangelaccio

Subscribers: rkflx, ngraham, elvisangelaccio, markg, #dolphin

Differential Revision: https://phabricator.kde.org/D10990
This commit is contained in:
Roman Inflianskas 2018-03-18 13:55:24 +03:00
parent eb68fae15c
commit 6f05c66cc0
4 changed files with 31 additions and 22 deletions

View file

@ -194,7 +194,7 @@ void DolphinContextMenu::openItemContextMenu()
if (m_selectedItems.count() == 1) { if (m_selectedItems.count() == 1) {
if (m_fileInfo.isLink()) { if (m_fileInfo.isLink()) {
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("show_original"))); addAction(m_mainWindow->actionCollection()->action(QStringLiteral("show_target")));
addSeparator(); addSeparator();
} else if (m_fileInfo.isDir()) { } else if (m_fileInfo.isDir()) {
// setup 'Create New' menu // setup 'Create New' menu

View file

@ -357,6 +357,22 @@ void DolphinMainWindow::openInNewWindow()
} }
} }
void DolphinMainWindow::showTarget()
{
const auto link = m_activeViewContainer->view()->selectedItems().at(0);
const auto linkLocationDir = QFileInfo(link.localPath()).absoluteDir();
auto linkDestination = link.linkDest();
if (QFileInfo(linkDestination).isRelative()) {
linkDestination = linkLocationDir.filePath(linkDestination);
}
if (QFileInfo::exists(linkDestination)) {
KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination).adjusted(QUrl::StripTrailingSlash)});
} else {
m_activeViewContainer->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination),
DolphinViewContainer::Warning);
}
}
void DolphinMainWindow::showEvent(QShowEvent* event) void DolphinMainWindow::showEvent(QShowEvent* event)
{ {
KXmlGuiWindow::showEvent(event); KXmlGuiWindow::showEvent(event);
@ -1215,23 +1231,11 @@ void DolphinMainWindow::setupActions()
actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys); actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys);
// for context menu // for context menu
QAction* showOriginal = actionCollection()->addAction(QStringLiteral("show_original")); QAction* showTarget = actionCollection()->addAction(QStringLiteral("show_target"));
showOriginal->setText(i18nc("@action:inmenu", "Show Original")); showTarget->setText(i18nc("@action:inmenu", "Show Target"));
showOriginal->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder"))); showTarget->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
showOriginal->setEnabled(false); showTarget->setEnabled(false);
connect(showOriginal, &QAction::triggered, [this]() { connect(showTarget, &QAction::triggered, this, &DolphinMainWindow::showTarget);
const auto link = m_activeViewContainer->view()->selectedItems().at(0);
const auto linkLocationDir = QFileInfo(link.localPath()).absoluteDir();
auto linkDestination = link.linkDest();
if (QFileInfo(linkDestination).isRelative())
linkDestination = linkLocationDir.filePath(linkDestination);
if (QFileInfo(linkDestination).exists()) {
KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination).adjusted(QUrl::StripTrailingSlash)});
} else {
m_activeViewContainer->showMessage(
i18n("Could not access \"%1\".").arg(linkDestination), DolphinViewContainer::Warning);
}
});
QAction* openInNewTab = actionCollection()->addAction(QStringLiteral("open_in_new_tab")); QAction* openInNewTab = actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab")); openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
@ -1398,7 +1402,7 @@ void DolphinMainWindow::updateEditActions()
QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile)); QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut)); QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
QAction* showOriginal = col->action(QStringLiteral("show_original")); QAction* showTarget = col->action(QStringLiteral("show_target"));
KFileItemListProperties capabilities(list); KFileItemListProperties capabilities(list);
const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving(); const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
@ -1408,7 +1412,7 @@ void DolphinMainWindow::updateEditActions()
deleteAction->setEnabled(capabilities.supportsDeleting()); deleteAction->setEnabled(capabilities.supportsDeleting());
deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash); deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
cutAction->setEnabled(capabilities.supportsMoving()); cutAction->setEnabled(capabilities.supportsMoving());
showOriginal->setEnabled(list.length() == 1 && list.at(0).isLink()); showTarget->setEnabled(list.length() == 1 && list.at(0).isLink());
} }
} }

View file

@ -339,6 +339,11 @@ private slots:
*/ */
void openInNewWindow(); void openInNewWindow();
/**
* Show the target of the selected symlink
*/
void showTarget();
/** /**
* Indicates in the statusbar that the execution of the command \a command * Indicates in the statusbar that the execution of the command \a command
* has been finished. * has been finished.

View file

@ -1,5 +1,5 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="dolphin" version="18"> <kpartgui name="dolphin" version="19">
<MenuBar> <MenuBar>
<Menu name="file"> <Menu name="file">
<Action name="new_menu" /> <Action name="new_menu" />
@ -12,7 +12,7 @@
<Action name="movetotrash" /> <Action name="movetotrash" />
<Action name="deletefile" /> <Action name="deletefile" />
<Separator/> <Separator/>
<Action name="show_original" /> <Action name="show_target" />
<Separator/> <Separator/>
<Action name="properties" /> <Action name="properties" />
</Menu> </Menu>