forked from qt-creator/qt-creator
CommandLocator: Use Acceptor for LocatorFilterEntry
Change-Id: I965cf7117d882afe4ac60df7d16dc67d4dac3891 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -17,7 +17,7 @@ namespace Core {
|
|||||||
struct CommandLocatorPrivate
|
struct CommandLocatorPrivate
|
||||||
{
|
{
|
||||||
QList<Command *> commands;
|
QList<Command *> commands;
|
||||||
QList<QPair<int, QString>> commandsData;
|
QList<QPair<QAction *, 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({i, action->text()});
|
d->commandsData.append({action, action->text()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,8 +77,17 @@ 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) {
|
||||||
LocatorFilterEntry filterEntry(this, text);
|
QAction *action = pair.first;
|
||||||
filterEntry.internalData = QVariant(pair.first);
|
LocatorFilterEntry filterEntry;
|
||||||
|
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)
|
||||||
@@ -91,21 +100,4 @@ 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
|
||||||
|
@@ -26,9 +26,6 @@ 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;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user