windowsrunner: Deduplicate/optimize strings
This commit is contained in:
parent
11d813625a
commit
3e5ae3b247
2 changed files with 26 additions and 27 deletions
|
@ -36,38 +36,38 @@ RemoteMatches WindowsRunner::Match(const QString &searchTerm)
|
|||
{
|
||||
RemoteMatches matches;
|
||||
|
||||
auto term = searchTerm;
|
||||
QString term = searchTerm;
|
||||
WindowsRunnerAction action = ActivateAction;
|
||||
if (term.endsWith(i18nc("Note this is a KRunner keyword", "activate"), Qt::CaseInsensitive)) {
|
||||
if (QString keyword = i18nc("Note this is a KRunner keyword", "activate"); term.endsWith(keyword, Qt::CaseInsensitive)) {
|
||||
action = ActivateAction;
|
||||
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "activate")) - 1);
|
||||
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "close"), Qt::CaseInsensitive)) {
|
||||
term = term.left(term.lastIndexOf(keyword) - 1);
|
||||
} else if (QString keyword = i18nc("Note this is a KRunner keyword", "close"); term.endsWith(keyword, Qt::CaseInsensitive)) {
|
||||
action = CloseAction;
|
||||
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "close")) - 1);
|
||||
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "min"), Qt::CaseInsensitive)) {
|
||||
term = term.left(term.lastIndexOf(keyword) - 1);
|
||||
} else if (QString keyword = i18nc("Note this is a KRunner keyword", "min"); term.endsWith(keyword, Qt::CaseInsensitive)) {
|
||||
action = MinimizeAction;
|
||||
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "min")) - 1);
|
||||
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "minimize"), Qt::CaseInsensitive)) {
|
||||
term = term.left(term.lastIndexOf(keyword) - 1);
|
||||
} else if (QString keyword = i18nc("Note this is a KRunner keyword", "minimize"); term.endsWith(keyword, Qt::CaseInsensitive)) {
|
||||
action = MinimizeAction;
|
||||
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "minimize")) - 1);
|
||||
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "max"), Qt::CaseInsensitive)) {
|
||||
term = term.left(term.lastIndexOf(keyword) - 1);
|
||||
} else if (QString keyword = i18nc("Note this is a KRunner keyword", "max"); term.endsWith(keyword, Qt::CaseInsensitive)) {
|
||||
action = MaximizeAction;
|
||||
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "max")) - 1);
|
||||
term = term.left(term.lastIndexOf(keyword) - 1);
|
||||
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "maximize"), Qt::CaseInsensitive)) {
|
||||
action = MaximizeAction;
|
||||
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "maximize")) - 1);
|
||||
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "fullscreen"), Qt::CaseInsensitive)) {
|
||||
} else if (QString keyword = i18nc("Note this is a KRunner keyword", "fullscreen"); term.endsWith(keyword, Qt::CaseInsensitive)) {
|
||||
action = FullscreenAction;
|
||||
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "fullscreen")) - 1);
|
||||
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "shade"), Qt::CaseInsensitive)) {
|
||||
term = term.left(term.lastIndexOf(keyword) - 1);
|
||||
} else if (QString keyword = i18nc("Note this is a KRunner keyword", "shade"); term.endsWith(keyword, Qt::CaseInsensitive)) {
|
||||
action = ShadeAction;
|
||||
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "shade")) - 1);
|
||||
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "keep above"), Qt::CaseInsensitive)) {
|
||||
term = term.left(term.lastIndexOf(keyword) - 1);
|
||||
} else if (QString keyword = i18nc("Note this is a KRunner keyword", "keep above"); term.endsWith(keyword, Qt::CaseInsensitive)) {
|
||||
action = KeepAboveAction;
|
||||
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "keep above")) - 1);
|
||||
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "keep below"), Qt::CaseInsensitive)) {
|
||||
term = term.left(term.lastIndexOf(keyword) - 1);
|
||||
} else if (QString keyword = i18nc("Note this is a KRunner keyword", "keep below"); term.endsWith(keyword, Qt::CaseInsensitive)) {
|
||||
action = KeepBelowAction;
|
||||
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "keep below")) - 1);
|
||||
term = term.left(term.lastIndexOf(keyword) - 1);
|
||||
}
|
||||
|
||||
// keyword match: when term starts with "window" we list all windows
|
||||
|
@ -82,12 +82,12 @@ RemoteMatches WindowsRunner::Match(const QString &searchTerm)
|
|||
if (keyword.endsWith(QLatin1Char('='))) {
|
||||
continue;
|
||||
}
|
||||
if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "name") + QStringLiteral("="), Qt::CaseInsensitive)) {
|
||||
windowName = keyword.split(QStringLiteral("="))[1];
|
||||
} else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "appname") + QStringLiteral("="), Qt::CaseInsensitive)) {
|
||||
windowAppName = keyword.split(QStringLiteral("="))[1];
|
||||
} else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "desktop") + QStringLiteral("="), Qt::CaseInsensitive)) {
|
||||
desktopId = keyword.split(QStringLiteral("="))[1];
|
||||
if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "name") + QLatin1Char('='), Qt::CaseInsensitive)) {
|
||||
windowName = keyword.split(QLatin1Char('='))[1];
|
||||
} else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "appname") + QLatin1Char('='), Qt::CaseInsensitive)) {
|
||||
windowAppName = keyword.split(QLatin1Char('='))[1];
|
||||
} else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "desktop") + QLatin1Char('='), Qt::CaseInsensitive)) {
|
||||
desktopId = keyword.split(QLatin1Char('='))[1];
|
||||
for (const auto desktop : VirtualDesktopManager::self()->desktops()) {
|
||||
if (desktop->name().contains(desktopId.toString(), Qt::CaseInsensitive) || desktop->x11DesktopNumber() == desktopId.toUInt()) {
|
||||
targetDesktop = desktop;
|
||||
|
|
|
@ -32,7 +32,6 @@ class WindowsRunner : public Plugin, protected QDBusContext
|
|||
Q_CLASSINFO("D-Bus Interface", "org.kde.KWin.WindowsRunner")
|
||||
public:
|
||||
explicit WindowsRunner();
|
||||
~WindowsRunner() override;
|
||||
|
||||
RemoteActions Actions()
|
||||
{
|
||||
|
@ -53,7 +52,7 @@ private:
|
|||
KeepAboveAction,
|
||||
KeepBelowAction,
|
||||
// Desktop related actions
|
||||
ActivateDesktopAction
|
||||
ActivateDesktopAction,
|
||||
};
|
||||
|
||||
RemoteMatch desktopMatch(const VirtualDesktop *desktop, const WindowsRunnerAction action = ActivateDesktopAction, qreal relevance = 1.0) const;
|
||||
|
|
Loading…
Reference in a new issue