Coding style fixes

This commit is contained in:
dt
2010-03-30 12:58:58 +02:00
parent 4d05808813
commit 6b389129af
3 changed files with 38 additions and 60 deletions

View File

@@ -54,7 +54,6 @@ CMakeEditorEditable::CMakeEditorEditable(CMakeEditor *editor)
Core::UniqueIDManager *uidm = Core::UniqueIDManager::instance(); Core::UniqueIDManager *uidm = Core::UniqueIDManager::instance();
m_context << uidm->uniqueIdentifier(CMakeProjectManager::Constants::C_CMAKEEDITOR); m_context << uidm->uniqueIdentifier(CMakeProjectManager::Constants::C_CMAKEEDITOR);
m_context << uidm->uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR); m_context << uidm->uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR);
// m_contexts << uidm->uniqueIdentifier(Qt4ProjectManager::Constants::PROJECT_KIND);
} }
QList<int> CMakeEditorEditable::context() const QList<int> CMakeEditorEditable::context() const
@@ -103,23 +102,21 @@ TextEditor::BaseTextEditorEditable *CMakeEditor::createEditableInterface()
void CMakeEditor::setFontSettings(const TextEditor::FontSettings &fs) void CMakeEditor::setFontSettings(const TextEditor::FontSettings &fs)
{ {
// TextEditor::BaseTextEditor::setFontSettings(fs); CMakeHighlighter *highlighter = qobject_cast<CMakeHighlighter*>(baseTextDocument()->syntaxHighlighter());
// return; if (!highlighter)
CMakeHighlighter *highlighter = qobject_cast<CMakeHighlighter*>(baseTextDocument()->syntaxHighlighter()); return;
if (!highlighter)
return;
static QVector<QString> categories; static QVector<QString> categories;
if (categories.isEmpty()) { if (categories.isEmpty()) {
categories << QLatin1String(TextEditor::Constants::C_LABEL) // variables categories << QLatin1String(TextEditor::Constants::C_LABEL) // variables
<< QLatin1String(TextEditor::Constants::C_LINK) // functions << QLatin1String(TextEditor::Constants::C_LINK) // functions
<< QLatin1String(TextEditor::Constants::C_COMMENT) << QLatin1String(TextEditor::Constants::C_COMMENT)
<< QLatin1String(TextEditor::Constants::C_STRING); << QLatin1String(TextEditor::Constants::C_STRING);
} }
const QVector<QTextCharFormat> formats = fs.toTextCharFormats(categories); const QVector<QTextCharFormat> formats = fs.toTextCharFormats(categories);
highlighter->setFormats(formats.constBegin(), formats.constEnd()); highlighter->setFormats(formats.constBegin(), formats.constEnd());
highlighter->rehighlight(); highlighter->rehighlight();
} }
// //

View File

@@ -74,7 +74,6 @@ public:
bool save(const QString &fileName = QString()); bool save(const QString &fileName = QString());
CMakeEditorFactory *factory() { return m_factory; } CMakeEditorFactory *factory() { return m_factory; }
TextEditor::TextEditorActionHandler *actionHandler() const { return m_ah; } TextEditor::TextEditorActionHandler *actionHandler() const { return m_ah; }
protected: protected:

View File

@@ -39,11 +39,9 @@ using namespace CMakeProjectManager::Internal;
static bool isVariable(const QString &word) static bool isVariable(const QString &word)
{ {
if (word.length() < 4) { // must be at least "${.}" if (word.length() < 4) // must be at least "${.}"
return false; return false;
} return word.startsWith("${") && word.endsWith('}');
return word.startsWith("${") && word.endsWith('}');
} }
@@ -65,44 +63,34 @@ void CMakeHighlighter::highlightBlock(const QString &text)
const QChar c = text.at(i); const QChar c = text.at(i);
if (inCommentMode) { if (inCommentMode) {
setFormat(i, 1, m_formats[CMakeCommentFormat]); setFormat(i, 1, m_formats[CMakeCommentFormat]);
} } else {
else {
if (c == '#') { if (c == '#') {
if (!inStringMode) { if (!inStringMode) {
inCommentMode = true; inCommentMode = true;
setFormat(i, 1, m_formats[CMakeCommentFormat]); setFormat(i, 1, m_formats[CMakeCommentFormat]);
buf.clear(); buf.clear();
} } else {
else {
buf += c; buf += c;
} }
} } else if (c == '(') {
else if (c == '(') {
if (!inStringMode) { if (!inStringMode) {
if (!buf.isEmpty()) { if (!buf.isEmpty())
setFormat(i - buf.length(), buf.length(), m_formats[CMakeFunctionFormat]); setFormat(i - buf.length(), buf.length(), m_formats[CMakeFunctionFormat]);
}
buf.clear(); buf.clear();
} } else {
else {
buf += c;
}
}
else if (c.isSpace()) {
if (!inStringMode) {
buf.clear();
}
else {
buf += c; buf += c;
} }
} } else if (c.isSpace()) {
else if (c == '\"') { if (!inStringMode)
buf.clear();
else
buf += c;
} else if (c == '\"') {
buf += c; buf += c;
if (inStringMode) { if (inStringMode) {
setFormat(i + 1 - buf.length(), buf.length(), m_formats[CMakeStringFormat]); setFormat(i + 1 - buf.length(), buf.length(), m_formats[CMakeStringFormat]);
buf.clear(); buf.clear();
} } else {
else {
setFormat(i, 1, m_formats[CMakeStringFormat]); setFormat(i, 1, m_formats[CMakeStringFormat]);
} }
inStringMode = !inStringMode; inStringMode = !inStringMode;
@@ -116,24 +104,19 @@ void CMakeHighlighter::highlightBlock(const QString &text)
setFormat(i, 1, emptyFormat); setFormat(i, 1, emptyFormat);
buf += c; buf += c;
} }
} } else if (c == '$') {
else if (c == '$') { if (inStringMode)
if (inStringMode) { setFormat(i - buf.length(), buf.length(), m_formats[CMakeStringFormat]);
setFormat(i - buf.length(), buf.length(), m_formats[CMakeStringFormat]); buf.clear();
}
buf.clear();
buf += c;
setFormat(i, 1, emptyFormat);
}
else if (c == '}') {
buf += c; buf += c;
if (isVariable(buf)) setFormat(i, 1, emptyFormat);
{ } else if (c == '}') {
buf += c;
if (isVariable(buf)) {
setFormat(i + 1 - buf.length(), buf.length(), m_formats[CMakeVariableFormat]); setFormat(i + 1 - buf.length(), buf.length(), m_formats[CMakeVariableFormat]);
buf.clear(); buf.clear();
} }
} } else {
else {
buf += c; buf += c;
setFormat(i, 1, emptyFormat); setFormat(i, 1, emptyFormat);
} }
@@ -143,8 +126,7 @@ void CMakeHighlighter::highlightBlock(const QString &text)
if (inStringMode) { if (inStringMode) {
setFormat(i - buf.length(), buf.length(), m_formats[CMakeStringFormat]); setFormat(i - buf.length(), buf.length(), m_formats[CMakeStringFormat]);
setCurrentBlockState(1); setCurrentBlockState(1);
} } else {
else {
setCurrentBlockState(0); setCurrentBlockState(0);
} }
} }