Fix marking files modified externally as modified

It replaces 59c90e00c1
and d0c537ca75

Task-number: QTCREATORBUG-17048
Change-Id: Ief4b1b72f2e5e7b1711be05d4ea8c03bbbf48fdf
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Jarek Kobus
2016-10-20 14:45:15 +02:00
committed by Jarek Kobus
parent ca4be197ef
commit 72e19c4886
8 changed files with 220 additions and 12 deletions

View File

@@ -39,6 +39,7 @@
#include <texteditor/generichighlighter/highlighter.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/documentmodel.h>
#include <utils/guard.h>
#include <utils/mimetypes/mimedatabase.h>
#include <QApplication>
@@ -106,6 +107,7 @@ public:
int m_autoSaveRevision;
TextMarks m_marksCache; // Marks not owned
Utils::Guard m_modificationChangedGuard;
};
QTextCursor TextDocumentPrivate::indentOrUnindent(const QTextCursor &textCursor, bool doIndent,
@@ -236,14 +238,8 @@ void TextDocumentPrivate::updateRevisions()
TextDocument::TextDocument(Id id)
: d(new TextDocumentPrivate)
{
QObject::connect(&d->m_document, &QTextDocument::modificationChanged, [this](bool modified) {
// we only want to update the block revisions when going back to the saved version,
// e.g. with undo
if (!modified)
d->updateRevisions();
emit changed();
});
connect(&d->m_document, &QTextDocument::modificationChanged,
this, &TextDocument::modificationChanged);
connect(&d->m_document, &QTextDocument::contentsChanged,
this, &Core::IDocument::contentsChanged);
connect(&d->m_document, &QTextDocument::contentsChange,
@@ -723,8 +719,21 @@ bool TextDocument::setPlainText(const QString &text)
bool TextDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type)
{
if (flag == FlagIgnore)
if (flag == FlagIgnore) {
if (type != TypeContents)
return true;
const bool wasModified = document()->isModified();
{
Utils::GuardLocker locker(d->m_modificationChangedGuard);
// hack to ensure we clean the clear state in QTextDocument
document()->setModified(false);
document()->setModified(true);
}
if (!wasModified)
modificationChanged(true);
return true;
}
if (type == TypePermissions) {
checkPermissions();
return true;
@@ -808,6 +817,17 @@ void TextDocument::ensureFinalNewLine(QTextCursor& cursor)
}
}
void TextDocument::modificationChanged(bool modified)
{
if (d->m_modificationChangedGuard.isLocked())
return;
// we only want to update the block revisions when going back to the saved version,
// e.g. with undo
if (!modified)
d->updateRevisions();
emit changed();
}
TextMarks TextDocument::marks() const
{
return d->m_marksCache;