Revert "CommandLocator: Use Acceptor for LocatorFilterEntry"

This reverts commit 962888cb02.

Reason for revert: Applied too early and produced a conflict

Change-Id: I98a2895a81196b61cf7020a187d3740be231f671
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Jarek Kobus
2023-04-17 09:16:36 +00:00
parent 837967a77a
commit 20a4954cbd
2 changed files with 24 additions and 13 deletions

View File

@@ -17,7 +17,7 @@ namespace Core {
struct CommandLocatorPrivate struct CommandLocatorPrivate
{ {
QList<Command *> commands; QList<Command *> commands;
QList<QPair<QAction *, QString>> commandsData; QList<QPair<int, QString>> commandsData;
}; };
/*! /*!
@@ -61,7 +61,7 @@ void CommandLocator::prepareSearch(const QString &entry)
continue; continue;
QAction *action = command->action(); QAction *action = command->action();
if (action && action->isEnabled()) if (action && action->isEnabled())
d->commandsData.append({action, action->text()}); d->commandsData.append({i, action->text()});
} }
} }
@@ -77,17 +77,8 @@ QList<LocatorFilterEntry> CommandLocator::matchesFor(QFutureInterface<LocatorFil
const QString text = Utils::stripAccelerator(pair.second); const QString text = Utils::stripAccelerator(pair.second);
const int index = text.indexOf(entry, 0, entryCaseSensitivity); const int index = text.indexOf(entry, 0, entryCaseSensitivity);
if (index >= 0) { if (index >= 0) {
QAction *action = pair.first; LocatorFilterEntry filterEntry(this, text);
LocatorFilterEntry filterEntry; filterEntry.internalData = QVariant(pair.first);
filterEntry.displayName = text;
filterEntry.acceptor = [action] {
// avoid nested stack trace and blocking locator by delayed triggering
QMetaObject::invokeMethod(action, [action] {
if (action->isEnabled())
action->trigger();
}, Qt::QueuedConnection);
return AcceptResult();
};
filterEntry.highlightInfo = {index, int(entry.length())}; filterEntry.highlightInfo = {index, int(entry.length())};
if (index == 0) if (index == 0)
@@ -100,4 +91,21 @@ QList<LocatorFilterEntry> CommandLocator::matchesFor(QFutureInterface<LocatorFil
return betterEntries; return betterEntries;
} }
void CommandLocator::accept(const LocatorFilterEntry &entry,
QString *newText, int *selectionStart, int *selectionLength) const
{
Q_UNUSED(newText)
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
// Retrieve action via index.
const int index = entry.internalData.toInt();
QTC_ASSERT(index >= 0 && index < d->commands.size(), return);
QAction *action = d->commands.at(index)->action();
// avoid nested stack trace and blocking locator by delayed triggering
QMetaObject::invokeMethod(action, [action] {
if (action->isEnabled())
action->trigger();
}, Qt::QueuedConnection);
}
} // namespace Core } // namespace Core

View File

@@ -26,6 +26,9 @@ public:
void prepareSearch(const QString &entry) override; void prepareSearch(const QString &entry) override;
QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future, QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future,
const QString &entry) override; const QString &entry) override;
void accept(const LocatorFilterEntry &selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
private: private:
CommandLocatorPrivate *d = nullptr; CommandLocatorPrivate *d = nullptr;
}; };