summaryrefslogtreecommitdiff
path: root/src/plugins/texteditor
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r--src/plugins/texteditor/basetextdocument.cpp4
-rw-r--r--src/plugins/texteditor/basetextdocument.h4
-rw-r--r--src/plugins/texteditor/basetexteditor.cpp7
-rw-r--r--src/plugins/texteditor/basetexteditor.h3
-rw-r--r--src/plugins/texteditor/basetextmark.cpp23
-rw-r--r--src/plugins/texteditor/behaviorsettingswidget.ui8
-rw-r--r--src/plugins/texteditor/codestylepool.cpp2
-rw-r--r--src/plugins/texteditor/generichighlighter/highlighter.cpp83
-rw-r--r--src/plugins/texteditor/generichighlighter/highlighter.h13
-rw-r--r--src/plugins/texteditor/generichighlighter/highlightersettingspage.cpp2
-rw-r--r--src/plugins/texteditor/itexteditor.cpp2
-rw-r--r--src/plugins/texteditor/itexteditor.h6
12 files changed, 69 insertions, 88 deletions
diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp
index 239041311c..adf2e2364d 100644
--- a/src/plugins/texteditor/basetextdocument.cpp
+++ b/src/plugins/texteditor/basetextdocument.cpp
@@ -92,7 +92,7 @@ BaseTextDocument::~BaseTextDocument()
delete d;
}
-QString BaseTextDocument::contents() const
+QString BaseTextDocument::plainText() const
{
return document()->toPlainText();
}
@@ -195,7 +195,7 @@ SyntaxHighlighter *BaseTextDocument::syntaxHighlighter() const
return d->m_highlighter;
}
-ITextMarkable *BaseTextDocument::documentMarker() const
+ITextMarkable *BaseTextDocument::markableInterface() const
{
BaseTextDocumentLayout *documentLayout =
qobject_cast<BaseTextDocumentLayout *>(d->m_document->documentLayout());
diff --git a/src/plugins/texteditor/basetextdocument.h b/src/plugins/texteditor/basetextdocument.h
index a8f8f2ca7a..1a0a8ff3f5 100644
--- a/src/plugins/texteditor/basetextdocument.h
+++ b/src/plugins/texteditor/basetextdocument.h
@@ -58,7 +58,7 @@ public:
virtual ~BaseTextDocument();
// ITextEditorDocument
- QString contents() const;
+ QString plainText() const;
QString textAt(int pos, int length) const;
QChar characterAt(int pos) const;
@@ -72,7 +72,7 @@ public:
const TabSettings &tabSettings() const;
const ExtraEncodingSettings &extraEncodingSettings() const;
- ITextMarkable *documentMarker() const;
+ ITextMarkable *markableInterface() const;
// IDocument implementation.
bool save(QString *errorString, const QString &fileName, bool autoSave);
diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index 63f2a3d719..268f265f2e 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -486,11 +486,6 @@ int BaseTextEditorWidgetPrivate::visualIndent(const QTextBlock &block) const
return 0;
}
-ITextMarkable *BaseTextEditorWidget::markableInterface() const
-{
- return baseTextDocument()->documentMarker();
-}
-
BaseTextEditor *BaseTextEditorWidget::editor() const
{
if (!d->m_editor) {
@@ -3863,8 +3858,6 @@ void BaseTextEditorWidget::drawFoldingMarker(QPainter *painter, const QPalette &
bool active,
bool hovered) const
{
- Q_UNUSED(active)
- Q_UNUSED(hovered)
QStyle *s = style();
if (ManhattanStyle *ms = qobject_cast<ManhattanStyle*>(s))
s = ms->baseStyle();
diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h
index 6994a90e97..9ce78d7783 100644
--- a/src/plugins/texteditor/basetexteditor.h
+++ b/src/plugins/texteditor/basetexteditor.h
@@ -148,7 +148,6 @@ public:
void convertPosition(int pos, int *line, int *column) const;
BaseTextEditor *editor() const;
- ITextMarkable *markableInterface() const;
void print(QPrinter *);
@@ -624,8 +623,6 @@ public:
QString selectedText() const;
- ITextMarkable *markableInterface() { return m_editorWidget->markableInterface(); }
-
QString contextHelpId() const; // from IContext
// ITextEditor
diff --git a/src/plugins/texteditor/basetextmark.cpp b/src/plugins/texteditor/basetextmark.cpp
index dd5832a7bb..f0f045dd4a 100644
--- a/src/plugins/texteditor/basetextmark.cpp
+++ b/src/plugins/texteditor/basetextmark.cpp
@@ -60,14 +60,11 @@ void BaseTextMarkRegistry::add(BaseTextMark *mark)
{
m_marks[FileName::fromString(mark->fileName())].insert(mark);
DocumentModel *documentModel = EditorManager::documentModel();
- IDocument *document = documentModel->documentForFilePath(mark->fileName());
+ ITextEditorDocument *document
+ = qobject_cast<ITextEditorDocument*>(documentModel->documentForFilePath(mark->fileName()));
if (!document)
return;
- // TODO: markableInterface should be moved to ITextEditorDocument
- if (ITextEditor *textEditor
- = qobject_cast<ITextEditor *>(documentModel->editorsForDocument(document).first())) {
- textEditor->markableInterface()->addMark(mark);
- }
+ document->markableInterface()->addMark(mark);
}
bool BaseTextMarkRegistry::remove(BaseTextMark *mark)
@@ -77,16 +74,14 @@ bool BaseTextMarkRegistry::remove(BaseTextMark *mark)
void BaseTextMarkRegistry::editorOpened(Core::IEditor *editor)
{
- ITextEditor *textEditor = qobject_cast<ITextEditor *>(editor);
- if (!textEditor)
+ ITextEditorDocument *document = qobject_cast<ITextEditorDocument *>(editor ? editor->document() : 0);
+ if (!document)
return;
- if (!m_marks.contains(FileName::fromString(editor->document()->filePath())))
+ if (!m_marks.contains(FileName::fromString(document->filePath())))
return;
- foreach (BaseTextMark *mark, m_marks.value(FileName::fromString(editor->document()->filePath()))) {
- ITextMarkable *markableInterface = textEditor->markableInterface();
- markableInterface->addMark(mark);
- }
+ foreach (BaseTextMark *mark, m_marks.value(FileName::fromString(document->filePath())))
+ document->markableInterface()->addMark(mark);
}
void BaseTextMarkRegistry::documentRenamed(IDocument *document, const
@@ -102,7 +97,7 @@ void BaseTextMarkRegistry::documentRenamed(IDocument *document, const
return;
QSet<BaseTextMark *> toBeMoved;
- foreach (ITextMark *mark, baseTextDocument->documentMarker()->marks())
+ foreach (ITextMark *mark, baseTextDocument->markableInterface()->marks())
if (BaseTextMark *baseTextMark = dynamic_cast<BaseTextMark *>(mark))
toBeMoved.insert(baseTextMark);
diff --git a/src/plugins/texteditor/behaviorsettingswidget.ui b/src/plugins/texteditor/behaviorsettingswidget.ui
index 324313b74a..5aeb0f37c5 100644
--- a/src/plugins/texteditor/behaviorsettingswidget.ui
+++ b/src/plugins/texteditor/behaviorsettingswidget.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>802</width>
- <height>416</height>
+ <height>441</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
@@ -207,7 +207,7 @@ Specifies how backspace interacts with indentation.
</sizepolicy>
</property>
<property name="toolTip">
- <string>Clean whitespace in entire document instead of only for changed parts.</string>
+ <string>Cleans whitespace in entire document instead of only for changed parts.</string>
</property>
<property name="text">
<string>In entire &amp;document</string>
@@ -220,7 +220,7 @@ Specifies how backspace interacts with indentation.
<bool>false</bool>
</property>
<property name="toolTip">
- <string>Correct leading whitespace according to tab settings.</string>
+ <string>Corrects leading whitespace according to tab settings.</string>
</property>
<property name="text">
<string>Clean indentation</string>
@@ -230,7 +230,7 @@ Specifies how backspace interacts with indentation.
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="addFinalNewLine">
<property name="toolTip">
- <string>Always write a newline character at the end of the file.</string>
+ <string>Always writes a newline character at the end of the file.</string>
</property>
<property name="text">
<string>&amp;Ensure newline at end of file</string>
diff --git a/src/plugins/texteditor/codestylepool.cpp b/src/plugins/texteditor/codestylepool.cpp
index 009b1e5454..5b5a7132d3 100644
--- a/src/plugins/texteditor/codestylepool.cpp
+++ b/src/plugins/texteditor/codestylepool.cpp
@@ -290,6 +290,6 @@ void CodeStylePool::exportCodeStyle(const Utils::FileName &fileName, ICodeStyleP
tmp.insert(QLatin1String(displayNameKey), codeStyle->displayName());
tmp.insert(QLatin1String(codeStyleDataKey), map);
Utils::PersistentSettingsWriter writer(fileName, QLatin1String(codeStyleDocKey));
- writer.save(tmp, 0);
+ writer.save(tmp, Core::ICore::mainWindow());
}
diff --git a/src/plugins/texteditor/generichighlighter/highlighter.cpp b/src/plugins/texteditor/generichighlighter/highlighter.cpp
index a894b2f092..3a195d37e2 100644
--- a/src/plugins/texteditor/generichighlighter/highlighter.cpp
+++ b/src/plugins/texteditor/generichighlighter/highlighter.cpp
@@ -50,6 +50,30 @@ namespace {
static const QLatin1Char kHash('#');
}
+class HighlighterCodeFormatterData : public CodeFormatterData
+{
+public:
+ HighlighterCodeFormatterData() : m_foldingIndentDelta(0), m_originalObservableState(-1) {}
+ ~HighlighterCodeFormatterData() {}
+ int m_foldingIndentDelta;
+ int m_originalObservableState;
+ QStack<QString> m_foldingRegions;
+ QSharedPointer<Internal::Context> m_contextToContinue;
+};
+
+HighlighterCodeFormatterData *formatterData(const QTextBlock &block)
+{
+ HighlighterCodeFormatterData *data = 0;
+ if (TextBlockUserData *userData = BaseTextDocumentLayout::userData(block)) {
+ data = static_cast<HighlighterCodeFormatterData *>(userData->codeFormatterData());
+ if (!data) {
+ data = new HighlighterCodeFormatterData;
+ userData->setCodeFormatterData(data);
+ }
+ }
+ return data;
+}
+
Highlighter::Highlighter(QTextDocument *parent) :
TextEditor::SyntaxHighlighter(parent),
m_regionDepth(0),
@@ -85,12 +109,6 @@ Highlighter::Highlighter(QTextDocument *parent) :
Highlighter::~Highlighter()
{}
-Highlighter::BlockData::BlockData() : m_foldingIndentDelta(0), m_originalObservableState(-1)
-{}
-
-Highlighter::BlockData::~BlockData()
-{}
-
// Mapping from Kate format strings to format ids.
struct KateFormatMap
{
@@ -135,8 +153,6 @@ void Highlighter::highlightBlock(const QString &text)
{
if (!m_defaultContext.isNull() && !m_isBroken) {
try {
- if (!currentBlockUserData())
- initializeBlockData();
setupDataForBlock(text);
handleContextChange(m_currentContext->lineBeginContext(),
@@ -188,8 +204,8 @@ void Highlighter::setupDataForBlock(const QString &text)
else
setupFromPersistent();
- blockData(currentBlockUserData())->m_foldingRegions =
- blockData(currentBlock().previous().userData())->m_foldingRegions;
+ formatterData(currentBlock())->m_foldingRegions =
+ formatterData(currentBlock().previous())->m_foldingRegions;
}
assignCurrentContext();
@@ -204,7 +220,7 @@ void Highlighter::setupDefault()
void Highlighter::setupFromWillContinue()
{
- BlockData *previousData = blockData(currentBlock().previous().userData());
+ HighlighterCodeFormatterData *previousData = formatterData(currentBlock().previous());
if (previousData->m_originalObservableState == Default ||
previousData->m_originalObservableState == -1) {
m_contexts.push_back(previousData->m_contextToContinue);
@@ -212,7 +228,7 @@ void Highlighter::setupFromWillContinue()
pushContextSequence(previousData->m_originalObservableState);
}
- BlockData *data = blockData(currentBlock().userData());
+ HighlighterCodeFormatterData *data = formatterData(currentBlock());
data->m_originalObservableState = previousData->m_originalObservableState;
if (currentBlockState() == -1 || extractObservableState(currentBlockState()) == Default)
@@ -221,7 +237,7 @@ void Highlighter::setupFromWillContinue()
void Highlighter::setupFromContinued()
{
- BlockData *previousData = blockData(currentBlock().previous().userData());
+ HighlighterCodeFormatterData *previousData = formatterData(currentBlock().previous());
Q_ASSERT(previousData->m_originalObservableState != WillContinue &&
previousData->m_originalObservableState != Continued);
@@ -264,19 +280,19 @@ void Highlighter::iterateThroughRules(const QString &text,
if (!m_indentationBasedFolding) {
if (!rule->beginRegion().isEmpty()) {
- blockData(currentBlockUserData())->m_foldingRegions.push(rule->beginRegion());
+ formatterData(currentBlock())->m_foldingRegions.push(rule->beginRegion());
++m_regionDepth;
if (progress->isOpeningBraceMatchAtFirstNonSpace())
- ++blockData(currentBlockUserData())->m_foldingIndentDelta;
+ ++formatterData(currentBlock())->m_foldingIndentDelta;
}
if (!rule->endRegion().isEmpty()) {
QStack<QString> *currentRegions =
- &blockData(currentBlockUserData())->m_foldingRegions;
+ &formatterData(currentBlock())->m_foldingRegions;
if (!currentRegions->isEmpty() && rule->endRegion() == currentRegions->top()) {
currentRegions->pop();
--m_regionDepth;
if (progress->isClosingBraceMatchAtNonEnd())
- --blockData(currentBlockUserData())->m_foldingIndentDelta;
+ --formatterData(currentBlock())->m_foldingIndentDelta;
}
}
progress->clearBracesMatches();
@@ -442,10 +458,10 @@ void Highlighter::applyFormat(int offset,
void Highlighter::createWillContinueBlock()
{
- BlockData *data = blockData(currentBlockUserData());
+ HighlighterCodeFormatterData *data = formatterData(currentBlock());
const int currentObservableState = extractObservableState(currentBlockState());
if (currentObservableState == Continued) {
- BlockData *previousData = blockData(currentBlock().previous().userData());
+ HighlighterCodeFormatterData *previousData = formatterData(currentBlock().previous());
data->m_originalObservableState = previousData->m_originalObservableState;
} else if (currentObservableState != WillContinue) {
data->m_originalObservableState = currentObservableState;
@@ -464,7 +480,7 @@ void Highlighter::analyseConsistencyOfWillContinueBlock(const QString &text)
}
if (text.length() == 0 || text.at(text.length() - 1) != kBackSlash) {
- BlockData *data = blockData(currentBlockUserData());
+ HighlighterCodeFormatterData *data = formatterData(currentBlock());
data->m_contextToContinue.clear();
setCurrentBlockState(computeState(data->m_originalObservableState));
}
@@ -503,18 +519,6 @@ QString Highlighter::currentContextSequence() const
return sequence;
}
-Highlighter::BlockData *Highlighter::initializeBlockData()
-{
- BlockData *data = new BlockData;
- setCurrentBlockUserData(data);
- return data;
-}
-
-Highlighter::BlockData *Highlighter::blockData(QTextBlockUserData *userData)
-{
- return static_cast<BlockData *>(userData);
-}
-
void Highlighter::pushDynamicContext(const QSharedPointer<Context> &baseContext)
{
// A dynamic context is created from another context which serves as its basis. Then,
@@ -556,26 +560,27 @@ int Highlighter::computeState(const int observableState) const
void Highlighter::applyRegionBasedFolding() const
{
int folding = 0;
- BlockData *data = blockData(currentBlockUserData());
- BlockData *previousData = blockData(currentBlock().previous().userData());
+ TextBlockUserData *currentBlockUserData = BaseTextDocumentLayout::userData(currentBlock());
+ HighlighterCodeFormatterData *data = formatterData(currentBlock());
+ HighlighterCodeFormatterData *previousData = formatterData(currentBlock().previous());
if (previousData) {
folding = extractRegionDepth(previousBlockState());
if (data->m_foldingIndentDelta != 0) {
folding += data->m_foldingIndentDelta;
if (data->m_foldingIndentDelta > 0)
- data->setFoldingStartIncluded(true);
+ currentBlockUserData->setFoldingStartIncluded(true);
else
- previousData->setFoldingEndIncluded(false);
+ BaseTextDocumentLayout::userData(currentBlock().previous())->setFoldingEndIncluded(false);
data->m_foldingIndentDelta = 0;
}
}
- data->setFoldingEndIncluded(true);
- data->setFoldingIndent(folding);
+ currentBlockUserData->setFoldingEndIncluded(true);
+ currentBlockUserData->setFoldingIndent(folding);
}
void Highlighter::applyIndentationBasedFolding(const QString &text) const
{
- BlockData *data = blockData(currentBlockUserData());
+ TextBlockUserData *data = BaseTextDocumentLayout::userData(currentBlock());
data->setFoldingEndIncluded(true);
// If this line is empty, check its neighbours. They all might be part of the same block.
diff --git a/src/plugins/texteditor/generichighlighter/highlighter.h b/src/plugins/texteditor/generichighlighter/highlighter.h
index ef0498036a..caf7275449 100644
--- a/src/plugins/texteditor/generichighlighter/highlighter.h
+++ b/src/plugins/texteditor/generichighlighter/highlighter.h
@@ -135,18 +135,7 @@ private:
void applyIndentationBasedFolding(const QString &text) const;
int neighbouringNonEmptyBlockIndent(QTextBlock block, const bool previous) const;
- struct BlockData : TextBlockUserData
- {
- BlockData();
- virtual ~BlockData();
-
- int m_foldingIndentDelta;
- int m_originalObservableState;
- QStack<QString> m_foldingRegions;
- QSharedPointer<Internal::Context> m_contextToContinue;
- };
- BlockData *initializeBlockData();
- static BlockData *blockData(QTextBlockUserData *userData);
+ static TextBlockUserData *blockData(QTextBlockUserData *userData);
// Block states are composed by the region depth (used for code folding) and what I call
// observable states. Observable states occupy the 12 least significant bits. They might have
diff --git a/src/plugins/texteditor/generichighlighter/highlightersettingspage.cpp b/src/plugins/texteditor/generichighlighter/highlightersettingspage.cpp
index c04a5d72e9..637a580434 100644
--- a/src/plugins/texteditor/generichighlighter/highlightersettingspage.cpp
+++ b/src/plugins/texteditor/generichighlighter/highlightersettingspage.cpp
@@ -94,9 +94,11 @@ QWidget *HighlighterSettingsPage::createPage(QWidget *parent)
m_d->m_page = new Ui::HighlighterSettingsPage;
m_d->m_page->setupUi(w);
m_d->m_page->definitionFilesPath->setExpectedKind(Utils::PathChooser::ExistingDirectory);
+ m_d->m_page->definitionFilesPath->setHistoryCompleter(QLatin1String("TextEditor.Highlighter.History"));
m_d->m_page->definitionFilesPath->addButton(tr("Download Definitions..."), this,
SLOT(requestAvailableDefinitionsMetaData()));
m_d->m_page->fallbackDefinitionFilesPath->setExpectedKind(Utils::PathChooser::ExistingDirectory);
+ m_d->m_page->fallbackDefinitionFilesPath->setHistoryCompleter(QLatin1String("TextEditor.Highlighter.History"));
m_d->m_page->fallbackDefinitionFilesPath->addButton(tr("Autodetect"), this,
SLOT(resetDefinitionsLocation()));
diff --git a/src/plugins/texteditor/itexteditor.cpp b/src/plugins/texteditor/itexteditor.cpp
index ab2b80b9b2..67a511033a 100644
--- a/src/plugins/texteditor/itexteditor.cpp
+++ b/src/plugins/texteditor/itexteditor.cpp
@@ -46,7 +46,7 @@ QMap<QString, QString> ITextEditor::openedTextDocumentContents()
if (!textEditorDocument)
continue;
QString fileName = textEditorDocument->filePath();
- workingCopy[fileName] = textEditorDocument->contents();
+ workingCopy[fileName] = textEditorDocument->plainText();
}
return workingCopy;
}
diff --git a/src/plugins/texteditor/itexteditor.h b/src/plugins/texteditor/itexteditor.h
index 2fa63d34c1..a3ac48bd48 100644
--- a/src/plugins/texteditor/itexteditor.h
+++ b/src/plugins/texteditor/itexteditor.h
@@ -81,9 +81,11 @@ class TEXTEDITOR_EXPORT ITextEditorDocument : public Core::TextDocument
public:
explicit ITextEditorDocument(QObject *parent = 0);
- virtual QString contents() const = 0;
+ virtual QString plainText() const = 0;
virtual QString textAt(int pos, int length) const = 0;
virtual QChar characterAt(int pos) const = 0;
+
+ virtual ITextMarkable *markableInterface() const = 0;
};
class TEXTEDITOR_EXPORT ITextEditor : public Core::IEditor
@@ -126,8 +128,6 @@ public:
/*! Selects text between current cursor position and \a toPos. */
virtual void select(int toPos) = 0;
- virtual ITextMarkable *markableInterface() = 0;
-
virtual const Utils::CommentDefinition* commentDefinition() const = 0;
static QMap<QString, QString> openedTextDocumentContents();