forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/12.0'
Conflicts: src/plugins/clangformat/clangformatconfigwidget.cpp Change-Id: I84fba4e6f952e9aca606951e7fb7763b451e35d9
This commit is contained in:
@@ -772,7 +772,8 @@ void ClangFormatBaseIndenter::autoIndent(const QTextCursor &cursor,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clang::format::FormatStyle overrideStyle(const Utils::FilePath &fileName)
|
clang::format::FormatStyle ClangFormatBaseIndenter::overrideStyle(
|
||||||
|
const Utils::FilePath &fileName) const
|
||||||
{
|
{
|
||||||
const ProjectExplorer::Project *projectForFile
|
const ProjectExplorer::Project *projectForFile
|
||||||
= ProjectExplorer::ProjectManager::projectForFile(fileName);
|
= ProjectExplorer::ProjectManager::projectForFile(fileName);
|
||||||
@@ -782,6 +783,9 @@ clang::format::FormatStyle overrideStyle(const Utils::FilePath &fileName)
|
|||||||
? projectForFile->editorConfiguration()->codeStyle("Cpp")->currentPreferences()
|
? projectForFile->editorConfiguration()->codeStyle("Cpp")->currentPreferences()
|
||||||
: TextEditor::TextEditorSettings::codeStyle("Cpp")->currentPreferences();
|
: TextEditor::TextEditorSettings::codeStyle("Cpp")->currentPreferences();
|
||||||
|
|
||||||
|
if (m_overriddenPreferences)
|
||||||
|
preferences = m_overriddenPreferences->currentPreferences();
|
||||||
|
|
||||||
Utils::FilePath filePath = filePathToCurrentSettings(preferences);
|
Utils::FilePath filePath = filePathToCurrentSettings(preferences);
|
||||||
|
|
||||||
if (!filePath.exists())
|
if (!filePath.exists())
|
||||||
@@ -844,4 +848,9 @@ const clang::format::FormatStyle &ClangFormatBaseIndenter::styleForFile() const
|
|||||||
return m_cachedStyle.style;
|
return m_cachedStyle.style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClangFormatBaseIndenter::setOverriddenPreferences(TextEditor::ICodeStylePreferences *preferences)
|
||||||
|
{
|
||||||
|
m_overriddenPreferences = preferences;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ClangFormat
|
} // namespace ClangFormat
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ public:
|
|||||||
|
|
||||||
const clang::format::FormatStyle &styleForFile() const;
|
const clang::format::FormatStyle &styleForFile() const;
|
||||||
|
|
||||||
|
void setOverriddenPreferences(TextEditor::ICodeStylePreferences *preferences);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool formatCodeInsteadOfIndent() const { return false; }
|
virtual bool formatCodeInsteadOfIndent() const { return false; }
|
||||||
virtual bool formatWhileTyping() const { return false; }
|
virtual bool formatWhileTyping() const { return false; }
|
||||||
@@ -84,6 +86,9 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
mutable CachedStyle m_cachedStyle;
|
mutable CachedStyle m_cachedStyle;
|
||||||
|
|
||||||
|
clang::format::FormatStyle overrideStyle(const Utils::FilePath &fileName) const;
|
||||||
|
TextEditor::ICodeStylePreferences *m_overriddenPreferences = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ClangFormat
|
} // namespace ClangFormat
|
||||||
|
|||||||
@@ -150,7 +150,9 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc
|
|||||||
displaySettings.m_visualizeWhitespace = true;
|
displaySettings.m_visualizeWhitespace = true;
|
||||||
m_preview->setDisplaySettings(displaySettings);
|
m_preview->setDisplaySettings(displaySettings);
|
||||||
m_preview->setPlainText(QLatin1String(CppEditor::Constants::DEFAULT_CODE_STYLE_SNIPPETS[0]));
|
m_preview->setPlainText(QLatin1String(CppEditor::Constants::DEFAULT_CODE_STYLE_SNIPPETS[0]));
|
||||||
m_preview->textDocument()->setIndenter(new ClangFormatIndenter(m_preview->document()));
|
auto *indenter = new ClangFormatIndenter(m_preview->document());
|
||||||
|
indenter->setOverriddenPreferences(codeStyle);
|
||||||
|
m_preview->textDocument()->setIndenter(indenter);
|
||||||
m_preview->textDocument()->setFontSettings(TextEditor::TextEditorSettings::fontSettings());
|
m_preview->textDocument()->setFontSettings(TextEditor::TextEditorSettings::fontSettings());
|
||||||
m_preview->textDocument()->resetSyntaxHighlighter(
|
m_preview->textDocument()->resetSyntaxHighlighter(
|
||||||
[] { return new CppEditor::CppHighlighter(); });
|
[] { return new CppEditor::CppHighlighter(); });
|
||||||
@@ -288,7 +290,7 @@ void ClangFormatConfigWidget::updatePreview()
|
|||||||
QTextCursor cursor(m_preview->document());
|
QTextCursor cursor(m_preview->document());
|
||||||
cursor.setPosition(0);
|
cursor.setPosition(0);
|
||||||
cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
|
cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
|
||||||
m_preview->textDocument()->autoIndent(cursor);
|
m_preview->textDocument()->autoFormatOrIndent(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ClangFormatConfigWidget::readFile(const QString &path)
|
std::string ClangFormatConfigWidget::readFile(const QString &path)
|
||||||
|
|||||||
@@ -605,6 +605,11 @@ public:
|
|||||||
m_codeStyleEditor->apply();
|
m_codeStyleEditor->apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void finish() final
|
||||||
|
{
|
||||||
|
m_codeStyleEditor->finish();
|
||||||
|
}
|
||||||
|
|
||||||
CppCodeStylePreferences *m_pageCppCodeStylePreferences = nullptr;
|
CppCodeStylePreferences *m_pageCppCodeStylePreferences = nullptr;
|
||||||
CodeStyleEditorWidget *m_codeStyleEditor;
|
CodeStyleEditorWidget *m_codeStyleEditor;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user