Verified Commit d5c144db authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

runners: Instanciate QActions directry

The current KRunner utility methods have some issues:
- The runner id is kindof useless, especially when we only have one
action
- We basically create a bunch of temporaries whenever we use the utility
methods
- If one really has more actions and more complex logic one is better of
using QHash with the actions and an enum as the key
parent ac705436
......@@ -55,7 +55,7 @@ CalculatorRunner::CalculatorRunner(QObject *parent, const KPluginMetaData &metaD
addSyntax(Plasma::RunnerSyntax(QStringLiteral("=:q:"), description));
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:="), description));
addAction(QStringLiteral("copyToClipboard"), QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy to Clipboard"));
m_actions = {new QAction(QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy to Clipboard"), this)};
setMinLetterCount(2);
}
......@@ -286,7 +286,7 @@ void CalculatorRunner::match(Plasma::RunnerContext &context)
}
match.setData(result);
match.setId(term);
match.setActions(actions().values());
match.setActions(m_actions);
context.addMatch(match);
}
}
......
......@@ -21,6 +21,7 @@
#ifndef CALCULATORRUNNER_H
#define CALCULATORRUNNER_H
#include <QAction>
#include <QMimeData>
#ifdef ENABLE_QALCULATE
......@@ -58,6 +59,7 @@ private:
#ifdef ENABLE_QALCULATE
QalculateEngine *m_engine;
#endif
QList<QAction *> m_actions;
};
#endif
......@@ -39,9 +39,11 @@ KillRunner::KillRunner(QObject *parent, const KPluginMetaData &metaData, const Q
{
setObjectName(QStringLiteral("Kill Runner"));
addAction(QStringLiteral("SIGTERM"), QIcon::fromTheme(QStringLiteral("application-exit")), i18n("Send SIGTERM"))->setData(15);
addAction(QStringLiteral("SIGKILL"), QIcon::fromTheme(QStringLiteral("process-stop")), i18n("Send SIGKILL"))->setData(9);
m_actionList = {action(QStringLiteral("SIGTERM")), action(QStringLiteral("SIGKILL"))};
auto *sigterm = new QAction(QIcon::fromTheme(QStringLiteral("application-exit")), i18n("Send SIGTERM"), this);
sigterm->setData(15);
auto *sigkill = new QAction(QIcon::fromTheme(QStringLiteral("process-stop")), i18n("Send SIGKILL"), this);
sigkill->setData(9);
m_actionList = {sigterm, sigkill};
connect(this, &Plasma::AbstractRunner::prepare, this, &KillRunner::prep);
connect(this, &Plasma::AbstractRunner::teardown, this, &KillRunner::cleanup);
......
......@@ -46,7 +46,7 @@ RecentDocuments::RecentDocuments(QObject *parent, const KPluginMetaData &metaDat
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Looks for documents recently used with names matching :q:.")));
addAction(QStringLiteral("openParentDir"), QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"));
m_actions = {new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"), this)};
setMinLetterCount(3);
}
......
......@@ -22,6 +22,7 @@
#include <krunner/abstractrunner.h>
#include <QAction>
#include <QIcon>
class RecentDocuments : public Plasma::AbstractRunner
......@@ -34,6 +35,9 @@ public:
void match(Plasma::RunnerContext &context) override;
void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) override;
private:
QList<QAction *> m_actions;
};
#endif
......@@ -24,6 +24,7 @@
#include <KNotificationJobUiDelegate>
#include <KShell>
#include <KToolInvocation>
#include <QAction>
#include <QRegularExpression>
#include <QStandardPaths>
......@@ -41,7 +42,7 @@ ShellRunner::ShellRunner(QObject *parent, const KPluginMetaData &metaData, const
suspendMatching(!enabled);
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Finds commands that match :q:, using common shell syntax")));
m_actionList = {addAction(QStringLiteral("runInTerminal"), QIcon::fromTheme(QStringLiteral("utilities-terminal")), i18n("Run in Terminal Window"))};
m_actionList = {new QAction(QIcon::fromTheme(QStringLiteral("utilities-terminal")), i18n("Run in Terminal Window"), this)};
m_matchIcon = QIcon::fromTheme(QStringLiteral("system-run"));
}
......
......@@ -25,6 +25,7 @@
#include <KShell>
#include <KSycoca>
#include <KUriFilter>
#include <QAction>
#include <QDBusConnection>
#include <QDesktopServices>
......@@ -94,7 +95,7 @@ void WebshortcutRunner::configurePrivateBrowsingActions()
m_privateAction = action;
const QString actionText = containsPrivate ? i18n("Search in private window") : i18n("Search in incognito window");
const QIcon icon = QIcon::fromTheme(QStringLiteral("view-private"), QIcon::fromTheme(QStringLiteral("view-hidden")));
m_match.setActions({addAction(QStringLiteral("privateSearch"), icon, actionText)});
m_match.setActions({new QAction(icon, actionText, this)});
return;
}
}
......
Supports Markdown
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