Commit 14829aef authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

RunerContext: Allow runners to update the query string

Before this was only possible when the match type is set to InformationalMatch.
This did not include the cursorPosition feature and the text needed to be specified
before the match is added.

To make sure the method can be called in AbstractRunner::run it is marked as const.

The usecase is a help functionality where the placeholder for the query should get focused
so that the user can overwrite it by typing:

CCBUG: 433636
parent 344c6a23
......@@ -172,6 +172,8 @@ public:
static RunnerContext s_dummyContext;
bool singleRunnerQueryMode = false;
QMap<QString, QueryMatch> uniqueIds;
QString requestedText;
int requestedCursorPosition = 0;
RunnerContext RunnerContextPrivate::s_dummyContext;
......@@ -251,6 +253,7 @@ void RunnerContext::setQuery(const QString &term)
d->requestedText.clear(); // Invalidate this field whenever the query changes
d->term = term;
......@@ -433,6 +436,12 @@ QueryMatch RunnerContext::match(const QString &id) const
void RunnerContext::requestQueryStringUpdate(const QString &text, int cursorPosition) const
d->requestedText = text;
d->requestedCursorPosition = cursorPosition;
void RunnerContext::setSingleRunnerQueryMode(bool enabled)
d->singleRunnerQueryMode = enabled;
......@@ -479,6 +488,15 @@ void RunnerContext::run(const QueryMatch &match)*this);
QString RunnerContext::requestedQueryString() const
return d->requestedText;
int RunnerContext::requestedCursorPosition() const
return d->requestedCursorPosition;
} // Plasma namespace
#include "moc_runnercontext.cpp"
......@@ -231,6 +231,18 @@ public:
QueryMatch match(const QString &id) const;
* Request that KRunner updates the query string and stasy open, even after running a match.
* This method is const so it can be called in a const context.
* @param text Text that will be displayed in the search field
* @param cursorPosition Position of the cursor, if this is different than the length of the text,
* the characters between the position and text will be selected
* @since 5.90
void requestQueryStringUpdate(const QString &text, int cursorPosition) const;
* Sets single runner query mode. Note that a call to reset() will
* turn off single runner query mode.
......@@ -279,6 +291,9 @@ Q_SIGNALS:
void matchesChanged();
QString requestedQueryString() const;
int requestedCursorPosition() const;
friend class RunnerManager;
QExplicitlySharedDataPointer<RunnerContextPrivate> d;
......@@ -740,7 +740,12 @@ bool RunnerManager::runMatch(const QueryMatch &match)
return true;
if (d->context.requestedQueryString().isEmpty()) {
return true;
} else {
Q_EMIT setSearchTerm(d->context.requestedQueryString(), d->context.requestedCursorPosition());
return false;
QList<QAction *> RunnerManager::actionsForMatch(const QueryMatch &match)
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