Verified Commit 093c2ece 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: https://phabricator.kde.org/F10042697

CCBUG: 433636
parent e4d90f78
Pipeline #87347 passed with stage
in 1 minute and 26 seconds
......@@ -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)
return;
}
d->requestedText.clear(); // Invalidate this field whenever the query changes
d->term = term;
#if KRUNNER_BUILD_DEPRECATED_SINCE(5, 76)
d->determineType();
......@@ -433,6 +436,12 @@ QueryMatch RunnerContext::match(const QString &id) const
}
#endif
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)
match.run(*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;
#endif
/**
* 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.88
*/
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();
private:
QString requestedQueryString() const;
int requestedCursorPosition() const;
friend class RunnerManager;
QExplicitlySharedDataPointer<RunnerContextPrivate> d;
};
......
......@@ -740,7 +740,12 @@ bool RunnerManager::runMatch(const QueryMatch &match)
}
}
d->context.run(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)
......
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