Commit 86f4fcb8 authored by Roman Inflianskas's avatar Roman Inflianskas

Add "Open symlink destination folder" into symlink's context menu

Summary:
This is not complete. I'm wondering about "Open symlink destination folder in new tab/window".

Feature wants also "Copy symlink destination". I dislike this, because then it's good to have "Cut symlink destination" and that's too much.

FEATURE: 215069

Reviewers: #dolphin, ngraham

Reviewed By: #dolphin, ngraham

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

Differential Revision: https://phabricator.kde.org/D10990
parent 6ab76d79
......@@ -193,7 +193,10 @@ void DolphinContextMenu::openItemContextMenu()
const KFileItemListProperties& selectedItemsProps = selectedItemsProperties();
if (m_selectedItems.count() == 1) {
if (m_fileInfo.isDir()) {
if (m_fileInfo.isLink()) {
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("show_original")));
addSeparator();
} else if (m_fileInfo.isDir()) {
// setup 'Create New' menu
DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow);
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
......
......@@ -51,6 +51,7 @@
#include <KFilePlacesModel>
#include <KHelpMenu>
#include <KIO/JobUiDelegate>
#include <KIO/OpenFileManagerWindowJob>
#include <KJobWidgets>
#include <KLocalizedString>
#include <KMessageBox>
......@@ -69,6 +70,7 @@
#include <QClipboard>
#include <QCloseEvent>
#include <QDialog>
#include <QFileInfo>
#include <QLineEdit>
#include <QMenu>
#include <QMenuBar>
......@@ -1213,6 +1215,24 @@ void DolphinMainWindow::setupActions()
actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys);
// for context menu
QAction* showOriginal = actionCollection()->addAction(QStringLiteral("show_original"));
showOriginal->setText(i18nc("@action:inmenu", "Show Original"));
showOriginal->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
showOriginal->setEnabled(false);
connect(showOriginal, &QAction::triggered, [this]() {
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"));
openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
openInNewTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
......@@ -1373,11 +1393,12 @@ void DolphinMainWindow::updateEditActions()
stateChanged(QStringLiteral("has_selection"));
KActionCollection* col = actionCollection();
QAction* renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile));
QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
QAction* renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile));
QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
QAction* showOriginal = col->action(QStringLiteral("show_original"));
KFileItemListProperties capabilities(list);
const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
......@@ -1387,6 +1408,7 @@ void DolphinMainWindow::updateEditActions()
deleteAction->setEnabled(capabilities.supportsDeleting());
deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
cutAction->setEnabled(capabilities.supportsMoving());
showOriginal->setEnabled(list.length() == 1 && list.at(0).isLink());
}
}
......
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="dolphin" version="17">
<kpartgui name="dolphin" version="18">
<MenuBar>
<Menu name="file">
<Action name="new_menu" />
......@@ -12,6 +12,8 @@
<Action name="movetotrash" />
<Action name="deletefile" />
<Separator/>
<Action name="show_original" />
<Separator/>
<Action name="properties" />
</Menu>
<Menu name="edit">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment