forked from qt-creator/qt-creator
CppTools: Make CppCurrentDocumentFilter thread safe
Change-Id: I6ca4711bad282279c913fe913712ae7b905ab55a Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -71,25 +71,9 @@ QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor(
|
|||||||
if (!regexp.isValid())
|
if (!regexp.isValid())
|
||||||
return goodEntries;
|
return goodEntries;
|
||||||
bool hasWildcard = (entry.contains(asterisk) || entry.contains(QLatin1Char('?')));
|
bool hasWildcard = (entry.contains(asterisk) || entry.contains(QLatin1Char('?')));
|
||||||
|
|
||||||
if (m_currentFileName.isEmpty())
|
|
||||||
return goodEntries;
|
|
||||||
|
|
||||||
if (m_itemsOfCurrentDoc.isEmpty()) {
|
|
||||||
Snapshot snapshot = m_modelManager->snapshot();
|
|
||||||
Document::Ptr thisDocument = snapshot.document(m_currentFileName);
|
|
||||||
if (thisDocument) {
|
|
||||||
IndexItem::Ptr rootNode = search(thisDocument);
|
|
||||||
rootNode->visitAllChildren([&](const IndexItem::Ptr &info) -> IndexItem::VisitorResult {
|
|
||||||
m_itemsOfCurrentDoc.append(info);
|
|
||||||
return IndexItem::Recurse;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
|
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
|
||||||
|
|
||||||
foreach (IndexItem::Ptr info, m_itemsOfCurrentDoc) {
|
foreach (IndexItem::Ptr info, itemsOfCurrentDocument()) {
|
||||||
if (future.isCanceled())
|
if (future.isCanceled())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -138,12 +122,14 @@ void CppCurrentDocumentFilter::refresh(QFutureInterface<void> &future)
|
|||||||
|
|
||||||
void CppCurrentDocumentFilter::onDocumentUpdated(Document::Ptr doc)
|
void CppCurrentDocumentFilter::onDocumentUpdated(Document::Ptr doc)
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
if (m_currentFileName == doc->fileName())
|
if (m_currentFileName == doc->fileName())
|
||||||
m_itemsOfCurrentDoc.clear();
|
m_itemsOfCurrentDoc.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCurrentDocumentFilter::onCurrentEditorChanged(Core::IEditor * currentEditor)
|
void CppCurrentDocumentFilter::onCurrentEditorChanged(Core::IEditor *currentEditor)
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
if (currentEditor)
|
if (currentEditor)
|
||||||
m_currentFileName = currentEditor->document()->filePath();
|
m_currentFileName = currentEditor->document()->filePath();
|
||||||
else
|
else
|
||||||
@@ -151,11 +137,35 @@ void CppCurrentDocumentFilter::onCurrentEditorChanged(Core::IEditor * currentEdi
|
|||||||
m_itemsOfCurrentDoc.clear();
|
m_itemsOfCurrentDoc.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCurrentDocumentFilter::onEditorAboutToClose(Core::IEditor * editorAboutToClose)
|
void CppCurrentDocumentFilter::onEditorAboutToClose(Core::IEditor *editorAboutToClose)
|
||||||
{
|
{
|
||||||
if (!editorAboutToClose) return;
|
if (!editorAboutToClose)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
if (m_currentFileName == editorAboutToClose->document()->filePath()) {
|
if (m_currentFileName == editorAboutToClose->document()->filePath()) {
|
||||||
m_currentFileName.clear();
|
m_currentFileName.clear();
|
||||||
m_itemsOfCurrentDoc.clear();
|
m_itemsOfCurrentDoc.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<CppTools::IndexItem::Ptr> CppCurrentDocumentFilter::itemsOfCurrentDocument()
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
|
|
||||||
|
if (m_currentFileName.isEmpty())
|
||||||
|
return QList<CppTools::IndexItem::Ptr>();
|
||||||
|
|
||||||
|
if (m_itemsOfCurrentDoc.isEmpty()) {
|
||||||
|
const Snapshot snapshot = m_modelManager->snapshot();
|
||||||
|
if (const Document::Ptr thisDocument = snapshot.document(m_currentFileName)) {
|
||||||
|
IndexItem::Ptr rootNode = search(thisDocument);
|
||||||
|
rootNode->visitAllChildren([&](const IndexItem::Ptr &info) -> IndexItem::VisitorResult {
|
||||||
|
m_itemsOfCurrentDoc.append(info);
|
||||||
|
return IndexItem::Recurse;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_itemsOfCurrentDoc;
|
||||||
|
}
|
||||||
|
@@ -56,14 +56,18 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDocumentUpdated(CPlusPlus::Document::Ptr doc);
|
void onDocumentUpdated(CPlusPlus::Document::Ptr doc);
|
||||||
void onCurrentEditorChanged(Core::IEditor * currentEditor);
|
void onCurrentEditorChanged(Core::IEditor *currentEditor);
|
||||||
void onEditorAboutToClose(Core::IEditor * currentEditor);
|
void onEditorAboutToClose(Core::IEditor *currentEditor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QList<IndexItem::Ptr> itemsOfCurrentDocument();
|
||||||
|
|
||||||
CppModelManager * m_modelManager;
|
CppModelManager * m_modelManager;
|
||||||
|
SearchSymbols search;
|
||||||
|
|
||||||
|
mutable QMutex m_mutex;
|
||||||
QString m_currentFileName;
|
QString m_currentFileName;
|
||||||
QList<IndexItem::Ptr> m_itemsOfCurrentDoc;
|
QList<IndexItem::Ptr> m_itemsOfCurrentDoc;
|
||||||
SearchSymbols search;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user