forked from qt-creator/qt-creator
CMakeProjectManager: Move CMakeIndenter class definition to .cpp
Leaner internal interface. Change-Id: I297c74e667891efbeab0edabbfc82fb058501aa2 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -515,7 +515,7 @@ CMakeEditorFactory::CMakeEditorFactory()
|
|||||||
setEditorCreator([] { return new CMakeEditor; });
|
setEditorCreator([] { return new CMakeEditor; });
|
||||||
setEditorWidgetCreator([] { return new CMakeEditorWidget; });
|
setEditorWidgetCreator([] { return new CMakeEditorWidget; });
|
||||||
setDocumentCreator(createCMakeDocument);
|
setDocumentCreator(createCMakeDocument);
|
||||||
setIndenterCreator([](QTextDocument *doc) { return new CMakeIndenter(doc); });
|
setIndenterCreator(createCMakeIndenter);
|
||||||
setUseGenericHighlighter(true);
|
setUseGenericHighlighter(true);
|
||||||
setCommentDefinition(Utils::CommentDefinition::HashStyle);
|
setCommentDefinition(Utils::CommentDefinition::HashStyle);
|
||||||
setCodeFoldingSupported(true);
|
setCodeFoldingSupported(true);
|
||||||
|
|||||||
@@ -5,9 +5,20 @@
|
|||||||
|
|
||||||
namespace CMakeProjectManager::Internal {
|
namespace CMakeProjectManager::Internal {
|
||||||
|
|
||||||
CMakeIndenter::CMakeIndenter(QTextDocument *doc)
|
class CMakeIndenter final : public TextEditor::TextIndenter
|
||||||
: TextEditor::TextIndenter(doc)
|
{
|
||||||
{}
|
public:
|
||||||
|
explicit CMakeIndenter(QTextDocument *doc)
|
||||||
|
: TextEditor::TextIndenter(doc)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool isElectricCharacter(const QChar &ch) const final;
|
||||||
|
|
||||||
|
int indentFor(const QTextBlock &block,
|
||||||
|
const TextEditor::TabSettings &tabSettings,
|
||||||
|
int cursorPositionInEditor = -1) final;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
bool CMakeIndenter::isElectricCharacter(const QChar &ch) const
|
bool CMakeIndenter::isElectricCharacter(const QChar &ch) const
|
||||||
{
|
{
|
||||||
@@ -44,6 +55,7 @@ static bool lineContainsFunction(const QString &line, const QString &function)
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool lineStartsBlock(const QString &line)
|
static bool lineStartsBlock(const QString &line)
|
||||||
{
|
{
|
||||||
return lineContainsFunction(line, QStringLiteral("function")) ||
|
return lineContainsFunction(line, QStringLiteral("function")) ||
|
||||||
@@ -55,6 +67,7 @@ static bool lineStartsBlock(const QString &line)
|
|||||||
lineContainsFunction(line, QStringLiteral("else")) ||
|
lineContainsFunction(line, QStringLiteral("else")) ||
|
||||||
lineContainsFunction(line, QStringLiteral("block"));
|
lineContainsFunction(line, QStringLiteral("block"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool lineEndsBlock(const QString &line)
|
static bool lineEndsBlock(const QString &line)
|
||||||
{
|
{
|
||||||
return lineContainsFunction(line, QStringLiteral("endfunction")) ||
|
return lineContainsFunction(line, QStringLiteral("endfunction")) ||
|
||||||
@@ -66,6 +79,7 @@ static bool lineEndsBlock(const QString &line)
|
|||||||
lineContainsFunction(line, QStringLiteral("else")) ||
|
lineContainsFunction(line, QStringLiteral("else")) ||
|
||||||
lineContainsFunction(line, QStringLiteral("endblock"));
|
lineContainsFunction(line, QStringLiteral("endblock"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool lineIsEmpty(const QString &line)
|
static bool lineIsEmpty(const QString &line)
|
||||||
{
|
{
|
||||||
for (const QChar &c : line) {
|
for (const QChar &c : line) {
|
||||||
@@ -112,4 +126,9 @@ int CMakeIndenter::indentFor(const QTextBlock &block,
|
|||||||
return qMax(0, indentation);
|
return qMax(0, indentation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextEditor::Indenter *createCMakeIndenter(QTextDocument *doc)
|
||||||
|
{
|
||||||
|
return new CMakeIndenter(doc);
|
||||||
|
}
|
||||||
|
|
||||||
} // CMakeProjectManager::Internal
|
} // CMakeProjectManager::Internal
|
||||||
|
|||||||
@@ -3,21 +3,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cmake_global.h"
|
|
||||||
|
|
||||||
#include <texteditor/textindenter.h>
|
#include <texteditor/textindenter.h>
|
||||||
|
|
||||||
namespace CMakeProjectManager::Internal {
|
namespace CMakeProjectManager::Internal {
|
||||||
|
|
||||||
class CMAKE_EXPORT CMakeIndenter : public TextEditor::TextIndenter
|
TextEditor::Indenter *createCMakeIndenter(QTextDocument *doc);
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit CMakeIndenter(QTextDocument *doc);
|
|
||||||
bool isElectricCharacter(const QChar &ch) const override;
|
|
||||||
|
|
||||||
int indentFor(const QTextBlock &block,
|
|
||||||
const TextEditor::TabSettings &tabSettings,
|
|
||||||
int cursorPositionInEditor = -1) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // CMakeProjectManager::Internal
|
} // CMakeProjectManager::Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user