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);
|
QTextCursor indentOrUnindent(const QTextCursor &textCursor, bool doIndent);
|
||||||
void resetRevisions();
|
void resetRevisions();
|
||||||
|
void updateRevisions();
|
||||||
|
|
||||||
QString m_defaultPath;
|
QString m_defaultPath;
|
||||||
QString m_suggestedFileName;
|
QString m_suggestedFileName;
|
||||||
@@ -161,6 +162,23 @@ void BaseTextDocumentPrivate::resetRevisions()
|
|||||||
block.setRevision(documentLayout->lastSaveRevision);
|
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))
|
BaseTextDocument::BaseTextDocument() : d(new BaseTextDocumentPrivate(this))
|
||||||
{
|
{
|
||||||
connect(d->m_document, SIGNAL(modificationChanged(bool)), this, SIGNAL(changed()));
|
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
|
// inform about the new filename
|
||||||
const QFileInfo fi(fName);
|
const QFileInfo fi(fName);
|
||||||
|
d->updateRevisions();
|
||||||
d->m_document->setModified(false);
|
d->m_document->setModified(false);
|
||||||
setFilePath(QDir::cleanPath(fi.absoluteFilePath()));
|
setFilePath(QDir::cleanPath(fi.absoluteFilePath()));
|
||||||
emit changed();
|
emit changed();
|
||||||
@@ -539,6 +558,7 @@ bool BaseTextDocument::open(QString *errorString, const QString &fileName, const
|
|||||||
qobject_cast<BaseTextDocumentLayout*>(d->m_document->documentLayout());
|
qobject_cast<BaseTextDocumentLayout*>(d->m_document->documentLayout());
|
||||||
QTC_ASSERT(documentLayout, return true);
|
QTC_ASSERT(documentLayout, return true);
|
||||||
documentLayout->lastSaveRevision = d->m_autoSaveRevision = d->m_document->revision();
|
documentLayout->lastSaveRevision = d->m_autoSaveRevision = d->m_document->revision();
|
||||||
|
d->updateRevisions();
|
||||||
d->m_document->setModified(fileName != realFileName);
|
d->m_document->setModified(fileName != realFileName);
|
||||||
setFilePath(QDir::cleanPath(fi.absoluteFilePath()));
|
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(d->m_codeAssistant.data(), SIGNAL(finished()), this, SIGNAL(assistFinished()));
|
||||||
|
|
||||||
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(slotUpdateExtraAreaWidth()));
|
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(cursorPositionChanged()), this, SLOT(slotCursorPositionChanged()));
|
||||||
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(slotUpdateRequest(QRect,int)));
|
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(slotUpdateRequest(QRect,int)));
|
||||||
connect(this, SIGNAL(selectionChanged()), this, SLOT(slotSelectionChanged()));
|
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)
|
void BaseTextEditorWidget::slotUpdateRequest(const QRect &r, int dy)
|
||||||
{
|
{
|
||||||
if (dy) {
|
if (dy) {
|
||||||
@@ -4712,22 +4688,6 @@ void BaseTextEditorWidget::clearLink()
|
|||||||
d->m_linkPressed = false;
|
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)
|
void BaseTextEditorWidget::highlightSearchResults(const QString &txt, Core::FindFlags findFlags)
|
||||||
{
|
{
|
||||||
QString pattern = txt;
|
QString pattern = txt;
|
||||||
|
|||||||
@@ -378,8 +378,6 @@ public:
|
|||||||
const DisplaySettings &displaySettings() const;
|
const DisplaySettings &displaySettings() const;
|
||||||
const MarginSettings &marginSettings() const;
|
const MarginSettings &marginSettings() const;
|
||||||
|
|
||||||
void markBlocksAsChanged(QList<int> blockNumbers);
|
|
||||||
|
|
||||||
void ensureCursorVisible();
|
void ensureCursorVisible();
|
||||||
|
|
||||||
enum ExtraSelectionKind {
|
enum ExtraSelectionKind {
|
||||||
@@ -496,7 +494,6 @@ protected:
|
|||||||
protected slots:
|
protected slots:
|
||||||
virtual void slotUpdateExtraArea();
|
virtual void slotUpdateExtraArea();
|
||||||
virtual void slotUpdateExtraAreaWidth();
|
virtual void slotUpdateExtraAreaWidth();
|
||||||
virtual void slotModificationChanged(bool);
|
|
||||||
virtual void slotUpdateRequest(const QRect &r, int dy);
|
virtual void slotUpdateRequest(const QRect &r, int dy);
|
||||||
virtual void slotCursorPositionChanged();
|
virtual void slotCursorPositionChanged();
|
||||||
virtual void slotUpdateBlockNotify(const QTextBlock &);
|
virtual void slotUpdateBlockNotify(const QTextBlock &);
|
||||||
|
|||||||
Reference in New Issue
Block a user