forked from qt-creator/qt-creator
TextEditors: Update block revisions only once per document
Instead of once per editor. Also remove a related unused function. Change-Id: I4bcd86b9b0ec61b87500e546cf2138ec5d854561 Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -71,6 +71,7 @@ public:
|
||||
|
||||
QTextCursor indentOrUnindent(const QTextCursor &textCursor, bool doIndent);
|
||||
void resetRevisions();
|
||||
void updateRevisions();
|
||||
|
||||
QString m_defaultPath;
|
||||
QString m_suggestedFileName;
|
||||
@@ -161,6 +162,23 @@ void BaseTextDocumentPrivate::resetRevisions()
|
||||
block.setRevision(documentLayout->lastSaveRevision);
|
||||
}
|
||||
|
||||
void BaseTextDocumentPrivate::updateRevisions()
|
||||
{
|
||||
BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(m_document->documentLayout());
|
||||
QTC_ASSERT(documentLayout, return);
|
||||
int oldLastSaveRevision = documentLayout->lastSaveRevision;
|
||||
documentLayout->lastSaveRevision = m_document->revision();
|
||||
|
||||
if (oldLastSaveRevision != documentLayout->lastSaveRevision) {
|
||||
for (QTextBlock block = m_document->begin(); block.isValid(); block = block.next()) {
|
||||
if (block.revision() < 0 || block.revision() != oldLastSaveRevision)
|
||||
block.setRevision(-documentLayout->lastSaveRevision - 1);
|
||||
else
|
||||
block.setRevision(documentLayout->lastSaveRevision);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BaseTextDocument::BaseTextDocument() : d(new BaseTextDocumentPrivate(this))
|
||||
{
|
||||
connect(d->m_document, SIGNAL(modificationChanged(bool)), this, SIGNAL(changed()));
|
||||
@@ -451,6 +469,7 @@ bool BaseTextDocument::save(QString *errorString, const QString &saveFileName, b
|
||||
|
||||
// inform about the new filename
|
||||
const QFileInfo fi(fName);
|
||||
d->updateRevisions();
|
||||
d->m_document->setModified(false);
|
||||
setFilePath(QDir::cleanPath(fi.absoluteFilePath()));
|
||||
emit changed();
|
||||
@@ -539,6 +558,7 @@ bool BaseTextDocument::open(QString *errorString, const QString &fileName, const
|
||||
qobject_cast<BaseTextDocumentLayout*>(d->m_document->documentLayout());
|
||||
QTC_ASSERT(documentLayout, return true);
|
||||
documentLayout->lastSaveRevision = d->m_autoSaveRevision = d->m_document->revision();
|
||||
d->updateRevisions();
|
||||
d->m_document->setModified(fileName != realFileName);
|
||||
setFilePath(QDir::cleanPath(fi.absoluteFilePath()));
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ void BaseTextEditorWidget::ctor(const QSharedPointer<BaseTextDocument> &doc)
|
||||
connect(d->m_codeAssistant.data(), SIGNAL(finished()), this, SIGNAL(assistFinished()));
|
||||
|
||||
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(slotUpdateExtraAreaWidth()));
|
||||
connect(this, SIGNAL(modificationChanged(bool)), this, SLOT(slotModificationChanged(bool)));
|
||||
connect(this, SIGNAL(modificationChanged(bool)), d->m_extraArea, SLOT(update()));
|
||||
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(slotCursorPositionChanged()));
|
||||
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(slotUpdateRequest(QRect,int)));
|
||||
connect(this, SIGNAL(selectionChanged()), this, SLOT(slotSelectionChanged()));
|
||||
@@ -3826,30 +3826,6 @@ void BaseTextEditorWidget::drawFoldingMarker(QPainter *painter, const QPalette &
|
||||
}
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::slotModificationChanged(bool m)
|
||||
{
|
||||
if (m)
|
||||
return;
|
||||
|
||||
QTextDocument *doc = document();
|
||||
BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(doc->documentLayout());
|
||||
QTC_ASSERT(documentLayout, return);
|
||||
int oldLastSaveRevision = documentLayout->lastSaveRevision;
|
||||
documentLayout->lastSaveRevision = doc->revision();
|
||||
|
||||
if (oldLastSaveRevision != documentLayout->lastSaveRevision) {
|
||||
QTextBlock block = doc->begin();
|
||||
while (block.isValid()) {
|
||||
if (block.revision() < 0 || block.revision() != oldLastSaveRevision)
|
||||
block.setRevision(-documentLayout->lastSaveRevision - 1);
|
||||
else
|
||||
block.setRevision(documentLayout->lastSaveRevision);
|
||||
block = block.next();
|
||||
}
|
||||
}
|
||||
d->m_extraArea->update();
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::slotUpdateRequest(const QRect &r, int dy)
|
||||
{
|
||||
if (dy) {
|
||||
@@ -4712,22 +4688,6 @@ void BaseTextEditorWidget::clearLink()
|
||||
d->m_linkPressed = false;
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::markBlocksAsChanged(QList<int> blockNumbers)
|
||||
{
|
||||
QTextBlock block = document()->begin();
|
||||
while (block.isValid()) {
|
||||
if (block.revision() < 0)
|
||||
block.setRevision(-block.revision() - 1);
|
||||
block = block.next();
|
||||
}
|
||||
foreach (const int blockNumber, blockNumbers) {
|
||||
QTextBlock block = document()->findBlockByNumber(blockNumber);
|
||||
if (block.isValid())
|
||||
block.setRevision(-block.revision() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BaseTextEditorWidget::highlightSearchResults(const QString &txt, Core::FindFlags findFlags)
|
||||
{
|
||||
QString pattern = txt;
|
||||
|
||||
@@ -378,8 +378,6 @@ public:
|
||||
const DisplaySettings &displaySettings() const;
|
||||
const MarginSettings &marginSettings() const;
|
||||
|
||||
void markBlocksAsChanged(QList<int> blockNumbers);
|
||||
|
||||
void ensureCursorVisible();
|
||||
|
||||
enum ExtraSelectionKind {
|
||||
@@ -496,7 +494,6 @@ protected:
|
||||
protected slots:
|
||||
virtual void slotUpdateExtraArea();
|
||||
virtual void slotUpdateExtraAreaWidth();
|
||||
virtual void slotModificationChanged(bool);
|
||||
virtual void slotUpdateRequest(const QRect &r, int dy);
|
||||
virtual void slotCursorPositionChanged();
|
||||
virtual void slotUpdateBlockNotify(const QTextBlock &);
|
||||
|
||||
Reference in New Issue
Block a user