diff --git a/applets/icon/iconapplet.cpp b/applets/icon/iconapplet.cpp --- a/applets/icon/iconapplet.cpp +++ b/applets/icon/iconapplet.cpp @@ -274,56 +274,7 @@ delete m_openContainingFolderAction; m_openContainingFolderAction = nullptr; m_openWithActions.clear(); - - if (desktopFile.hasLinkType()) { - const QUrl &linkUrl = QUrl(desktopFile.readUrl()); - - if (!m_fileItemActions) { - m_fileItemActions = new KFileItemActions(this); - } - KFileItemListProperties itemProperties(KFileItemList({KFileItem(linkUrl)})); - m_fileItemActions->setItemListProperties(itemProperties); - - if (!m_openWithMenu) { - m_openWithMenu.reset(new QMenu()); - } - m_openWithMenu->clear(); - m_fileItemActions->addOpenWithActionsTo(m_openWithMenu.data()); - - m_openWithActions = m_openWithMenu->actions(); - - if (KProtocolManager::supportsListing(linkUrl)) { - if (!m_openContainingFolderAction) { - m_openContainingFolderAction = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"), this); - connect(m_openContainingFolderAction, &QAction::triggered, this, [this] { - KIO::highlightInFileManager({m_openContainingFolderAction->property("linkUrl").toUrl()}); - }); - } - m_openContainingFolderAction->setProperty("linkUrl", linkUrl); - } - } - m_jumpListActions.clear(); - foreach (const QString &actionName, desktopFile.readActions()) { - const KConfigGroup &actionGroup = desktopFile.actionGroup(actionName); - - if (!actionGroup.isValid() || !actionGroup.exists()) { - continue; - } - - const QString &name = actionGroup.readEntry(QStringLiteral("Name")); - const QString &exec = actionGroup.readEntry(QStringLiteral("Exec")); - if (name.isEmpty() || exec.isEmpty()) { - continue; - } - - QAction *action = new QAction(QIcon::fromTheme(actionGroup.readEntry("Icon")), name, this); - connect(action, &QAction::triggered, this, [this, exec] { - KRun::run(exec, {}, nullptr, m_name, m_iconName); - }); - - m_jumpListActions << action; - } m_localPath = path; @@ -374,6 +325,36 @@ QList IconApplet::contextualActions() { QList actions; + if (m_localPath.isEmpty()) { + return actions; + } + + KDesktopFile desktopFile(m_localPath); + + if (m_jumpListActions.isEmpty()) { + const QStringList actions = desktopFile.readActions(); + for (const QString &actionName : actions) { + const KConfigGroup &actionGroup = desktopFile.actionGroup(actionName); + + if (!actionGroup.isValid() || !actionGroup.exists()) { + continue; + } + + const QString name = actionGroup.readEntry(QStringLiteral("Name")); + const QString exec = actionGroup.readEntry(QStringLiteral("Exec")); + if (name.isEmpty() || exec.isEmpty()) { + continue; + } + + QAction *action = new QAction(QIcon::fromTheme(actionGroup.readEntry("Icon")), name, this); + connect(action, &QAction::triggered, this, [this, exec] { + KRun::run(exec, {}, nullptr, m_name, m_iconName); + }); + + m_jumpListActions << action; + } + } + actions << m_jumpListActions; if (!actions.isEmpty()) { @@ -384,6 +365,35 @@ actions << m_separatorAction; } + if (desktopFile.hasLinkType()) { + const QUrl linkUrl = QUrl(desktopFile.readUrl()); + + if (m_openWithActions.isEmpty()) { + if (!m_fileItemActions) { + m_fileItemActions = new KFileItemActions(this); + } + KFileItemListProperties itemProperties(KFileItemList({KFileItem(linkUrl)})); + m_fileItemActions->setItemListProperties(itemProperties); + + if (!m_openWithMenu) { + m_openWithMenu.reset(new QMenu()); + } + m_openWithMenu->clear(); + m_fileItemActions->addOpenWithActionsTo(m_openWithMenu.data()); + + m_openWithActions = m_openWithMenu->actions(); + } + + if (!m_openContainingFolderAction) { + if (KProtocolManager::supportsListing(linkUrl)) { + m_openContainingFolderAction = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"), this); + connect(m_openContainingFolderAction, &QAction::triggered, this, [this, linkUrl] { + KIO::highlightInFileManager({linkUrl}); + }); + } + } + } + actions << m_openWithActions; if (m_openContainingFolderAction) {