Commit b74fcb77 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Cache the UTF-8 encoded contents of the text editors, and some cleanup in updateEditorSelections().

parent a8cfda0d
...@@ -662,7 +662,7 @@ QMap<QString, QByteArray> CppModelManager::buildWorkingCopyList() ...@@ -662,7 +662,7 @@ QMap<QString, QByteArray> CppModelManager::buildWorkingCopyList()
TextEditor::ITextEditor *textEditor = it.key(); TextEditor::ITextEditor *textEditor = it.key();
CppEditorSupport *editorSupport = it.value(); CppEditorSupport *editorSupport = it.value();
QString fileName = textEditor->file()->fileName(); QString fileName = textEditor->file()->fileName();
workingCopy[fileName] = editorSupport->contents().toUtf8(); workingCopy[fileName] = editorSupport->contents();
} }
// add the project configuration file // add the project configuration file
...@@ -846,12 +846,12 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc) ...@@ -846,12 +846,12 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
QList<Editor> todo; QList<Editor> todo;
foreach (const Editor &e, todo) { foreach (const Editor &e, todo) {
if (e.widget != ed) if (e.textEditor != textEditor)
todo.append(e); todo.append(e);
} }
Editor e; Editor e;
e.widget = ed; e.textEditor = textEditor;
e.selections = selections; e.selections = selections;
e.ifdefedOutBlocks = blockRanges; e.ifdefedOutBlocks = blockRanges;
todo.append(e); todo.append(e);
...@@ -870,16 +870,22 @@ void CppModelManager::postEditorUpdate() ...@@ -870,16 +870,22 @@ void CppModelManager::postEditorUpdate()
void CppModelManager::updateEditorSelections() void CppModelManager::updateEditorSelections()
{ {
foreach (const Editor &ed, m_todo) { foreach (const Editor &ed, m_todo) {
if (! ed.widget) if (! ed.textEditor)
continue; continue;
ed.widget->setExtraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection, TextEditor::ITextEditor *textEditor = ed.textEditor;
ed.selections); TextEditor::BaseTextEditor *editor = qobject_cast<TextEditor::BaseTextEditor *>(textEditor->widget());
if (! editor)
continue;
editor->setExtraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection,
ed.selections);
ed.widget->setIfdefedOutBlocks(ed.ifdefedOutBlocks); editor->setIfdefedOutBlocks(ed.ifdefedOutBlocks);
} }
m_todo.clear(); m_todo.clear();
} }
void CppModelManager::onProjectAdded(ProjectExplorer::Project *) void CppModelManager::onProjectAdded(ProjectExplorer::Project *)
......
...@@ -167,7 +167,7 @@ private: ...@@ -167,7 +167,7 @@ private:
mutable QMutex mutex; mutable QMutex mutex;
struct Editor { struct Editor {
QPointer<TextEditor::BaseTextEditor> widget; QPointer<TextEditor::ITextEditor> textEditor;
QList<QTextEdit::ExtraSelection> selections; QList<QTextEdit::ExtraSelection> selections;
QList<TextEditor::BaseTextEditor::BlockRange> ifdefedOutBlocks; QList<TextEditor::BaseTextEditor::BlockRange> ifdefedOutBlocks;
}; };
......
...@@ -66,12 +66,12 @@ void CppEditorSupport::setTextEditor(TextEditor::ITextEditor *textEditor) ...@@ -66,12 +66,12 @@ void CppEditorSupport::setTextEditor(TextEditor::ITextEditor *textEditor)
updateDocument(); updateDocument();
} }
QString CppEditorSupport::contents() QByteArray CppEditorSupport::contents()
{ {
if (! _textEditor) if (! _textEditor)
return QString(); return QByteArray();
else if (! _cachedContents.isEmpty()) else if (! _cachedContents.isEmpty())
_cachedContents = _textEditor->contents(); _cachedContents = _textEditor->contents().toUtf8();
return _cachedContents; return _cachedContents;
} }
...@@ -96,13 +96,15 @@ void CppEditorSupport::updateDocument() ...@@ -96,13 +96,15 @@ void CppEditorSupport::updateDocument()
void CppEditorSupport::updateDocumentNow() void CppEditorSupport::updateDocumentNow()
{ {
qDebug() << "*** update document now";
if (_documentParser.isRunning()) { if (_documentParser.isRunning()) {
_updateDocumentTimer->start(_updateDocumentInterval); _updateDocumentTimer->start(_updateDocumentInterval);
} else { } else {
_updateDocumentTimer->stop(); _updateDocumentTimer->stop();
QStringList sourceFiles(_textEditor->file()->fileName()); QStringList sourceFiles(_textEditor->file()->fileName());
_cachedContents = _textEditor->contents(); _cachedContents = _textEditor->contents().toUtf8();
_documentParser = _modelManager->refreshSourceFiles(sourceFiles); _documentParser = _modelManager->refreshSourceFiles(sourceFiles);
} }
} }
......
...@@ -61,7 +61,7 @@ public: ...@@ -61,7 +61,7 @@ public:
int updateDocumentInterval() const; int updateDocumentInterval() const;
void setUpdateDocumentInterval(int updateDocumentInterval); void setUpdateDocumentInterval(int updateDocumentInterval);
QString contents(); QByteArray contents(); // UTF-8 encoded
Q_SIGNALS: Q_SIGNALS:
void contentsChanged(); void contentsChanged();
...@@ -78,7 +78,7 @@ private: ...@@ -78,7 +78,7 @@ private:
QTimer *_updateDocumentTimer; QTimer *_updateDocumentTimer;
int _updateDocumentInterval; int _updateDocumentInterval;
QFuture<void> _documentParser; QFuture<void> _documentParser;
QString _cachedContents; QByteArray _cachedContents;
}; };
} // namespace Internal } // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment