C++: Move preprocessor settings handling to the document.

This cleans up the handling of those settings, and makes sure that the
C++ document is setting those settings before parsing. This also
prevents lock contention in the parser, because before this patch the
document would kick of the initial parse (after opening a document),
after which the editor would come in and try to set the preprocessor
settings, resulting in the UI thread locking until the initial parse was
done.

Change-Id: Ia2e18a9667e10279f045c1c5849046ec4cfe85ae
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
Erik Verbruggen
2014-09-09 16:02:31 +02:00
committed by Nikolai Kosjar
parent 914adeab82
commit cc6a9babe0
5 changed files with 52 additions and 37 deletions

View File

@@ -58,8 +58,6 @@
#include <cpptools/cppworkingcopy.h>
#include <cpptools/symbolfinder.h>
#include <projectexplorer/session.h>
#include <texteditor/basetextdocument.h>
#include <texteditor/basetextdocumentlayout.h>
#include <texteditor/codeassist/assistproposalitem.h>
@@ -172,9 +170,6 @@ void CppEditorWidget::finalizeInitialization()
connect(d->m_declDefLinkFinder, SIGNAL(foundLink(QSharedPointer<FunctionDeclDefLink>)),
this, SLOT(onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefLink>)));
connect(textDocument(), SIGNAL(filePathChanged(QString,QString)),
this, SLOT(onFilePathChanged()));
connect(&d->m_useSelectionsUpdater,
SIGNAL(selectionsForVariableUnderCursorUpdated(QList<QTextEdit::ExtraSelection>)),
&d->m_localRenaming,
@@ -197,6 +192,12 @@ void CppEditorWidget::finalizeInitialization()
connect(this, SIGNAL(cursorPositionChanged()),
d->m_cppEditorOutline, SLOT(updateIndex()));
connect(cppEditorDocument(), &CppEditorDocument::preprocessorSettingsChanged,
[this](bool customSettings) {
d->m_preprocessorButton->setProperty("highlightWidget", customSettings);
d->m_preprocessorButton->update();
});
// set up function declaration - definition link
d->m_updateFunctionDeclDefLinkTimer.setSingleShot(true);
d->m_updateFunctionDeclDefLinkTimer.setInterval(UPDATE_FUNCTION_DECL_DEF_LINK_INTERVAL);
@@ -712,26 +713,6 @@ void CppEditorWidget::onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefL
}
void CppEditorWidget::onFilePathChanged()
{
QTC_ASSERT(d->m_modelManager, return);
QByteArray additionalDirectives;
const QString &filePath = textDocument()->filePath();
if (!filePath.isEmpty()) {
const QString &projectFile = ProjectExplorer::SessionManager::value(
QLatin1String(Constants::CPP_PREPROCESSOR_PROJECT_PREFIX) + filePath).toString();
additionalDirectives = ProjectExplorer::SessionManager::value(
projectFile + QLatin1Char(',') + filePath).toString().toUtf8();
BaseEditorDocumentParser *parser = BaseEditorDocumentParser::get(filePath);
QTC_ASSERT(parser, return);
parser->setProjectPart(d->m_modelManager->projectPartForProjectFile(projectFile));
parser->setEditorDefines(additionalDirectives);
}
d->m_preprocessorButton->setProperty("highlightWidget", !additionalDirectives.trimmed().isEmpty());
d->m_preprocessorButton->update();
}
void CppEditorWidget::applyDeclDefLinkChanges(bool jumpToMatch)
{
if (!d->m_declDefLink)
@@ -782,15 +763,10 @@ void CppEditorWidget::showPreProcessorWidget()
CppPreProcessorDialog preProcessorDialog(this, textDocument()->filePath(), projectParts);
if (preProcessorDialog.exec() == QDialog::Accepted) {
BaseEditorDocumentParser *parser = BaseEditorDocumentParser::get(fileName);
QTC_ASSERT(parser, return);
const QString &additionals = preProcessorDialog.additionalPreProcessorDirectives();
parser->setProjectPart(preProcessorDialog.projectPart());
parser->setEditorDefines(additionals.toUtf8());
parser->update(d->m_modelManager->workingCopy());
d->m_preprocessorButton->setProperty("highlightWidget", !additionals.trimmed().isEmpty());
d->m_preprocessorButton->update();
cppEditorDocument()->setPreprocessorSettings(
preProcessorDialog.projectPart(),
preProcessorDialog.additionalPreProcessorDirectives().toUtf8());
cppEditorDocument()->scheduleProcessDocument();
}
}