forked from qt-creator/qt-creator
MenuBarFilter: Do not access menu bar and actions from non-UI thread
Nothing of this is thread-safe and needs to be done in the UI thread. Luckily this is easy for locator filters: prepareSearch is run in the UI thread, and matchesFor is guaranteed to never run while prepareSearch runs. Change-Id: I757a2488db7254b8973c21dbda221a116b4bf6e9 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -59,17 +59,8 @@ QList<LocatorFilterEntry> MenuBarFilter::matchesFor(QFutureInterface<LocatorFilt
|
|||||||
const QString &entry)
|
const QString &entry)
|
||||||
{
|
{
|
||||||
Q_UNUSED(future);
|
Q_UNUSED(future);
|
||||||
static const QString separators = ". >/";
|
Q_UNUSED(entry);
|
||||||
static const QRegularExpression seperatorRegExp(QString("[%1]").arg(separators));
|
return std::move(m_entries);
|
||||||
QList<LocatorFilterEntry> entries;
|
|
||||||
QString normalized = entry;
|
|
||||||
normalized.replace(seperatorRegExp, separators.at(0));
|
|
||||||
const QStringList entryPath = normalized.split(separators.at(0), QString::SkipEmptyParts);
|
|
||||||
QVector<const QMenu *> processedMenus;
|
|
||||||
for (QAction* action : menuBarActions())
|
|
||||||
entries << matchesForAction(action, entryPath, QStringList(), processedMenus);
|
|
||||||
|
|
||||||
return entries;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuBarFilter::accept(LocatorFilterEntry selection, QString *newText,
|
void MenuBarFilter::accept(LocatorFilterEntry selection, QString *newText,
|
||||||
@@ -161,6 +152,15 @@ static void requestMenuUpdate(const QAction* action)
|
|||||||
void Core::Internal::MenuBarFilter::prepareSearch(const QString &entry)
|
void Core::Internal::MenuBarFilter::prepareSearch(const QString &entry)
|
||||||
{
|
{
|
||||||
Q_UNUSED(entry);
|
Q_UNUSED(entry);
|
||||||
for (const QAction *action : menuBarActions())
|
static const QString separators = ". >/";
|
||||||
|
static const QRegularExpression seperatorRegExp(QString("[%1]").arg(separators));
|
||||||
|
QString normalized = entry;
|
||||||
|
normalized.replace(seperatorRegExp, separators.at(0));
|
||||||
|
const QStringList entryPath = normalized.split(separators.at(0), QString::SkipEmptyParts);
|
||||||
|
m_entries.clear();
|
||||||
|
QVector<const QMenu *> processedMenus;
|
||||||
|
for (QAction* action : menuBarActions()) {
|
||||||
requestMenuUpdate(action);
|
requestMenuUpdate(action);
|
||||||
|
m_entries << matchesForAction(action, entryPath, QStringList(), processedMenus);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -53,6 +53,7 @@ private:
|
|||||||
const QStringList &path,
|
const QStringList &path,
|
||||||
QVector<const QMenu *> &processedMenus);
|
QVector<const QMenu *> &processedMenus);
|
||||||
|
|
||||||
|
QList<LocatorFilterEntry> m_entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user