Commit 34229955 authored by Eike Ziller's avatar Eike Ziller
Browse files

VCS editors: Fix revision markers



Resets the revisions when setting the contents of text editor documents
in general.

Task-number: QTCREATORBUG-11356
Change-Id: I4069d629d8a612d42c7deae707300d50690e2db7
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 445735be
......@@ -200,7 +200,7 @@ void GitEditor::setPlainTextFiltered(const QString &text)
break;
}
setPlainText(modText);
baseTextDocument()->setPlainText(modText);
}
void GitEditor::commandFinishedGotoLine(bool ok, int exitCode, const QVariant &v)
......
......@@ -70,6 +70,7 @@ public:
explicit BaseTextDocumentPrivate(BaseTextDocument *q);
QTextCursor indentOrUnindent(const QTextCursor &textCursor, bool doIndent);
void resetRevisions();
QString m_defaultPath;
QString m_suggestedFileName;
......@@ -150,6 +151,16 @@ QTextCursor BaseTextDocumentPrivate::indentOrUnindent(const QTextCursor &textCur
return cursor;
}
void BaseTextDocumentPrivate::resetRevisions()
{
BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(m_document->documentLayout());
QTC_ASSERT(documentLayout, return);
documentLayout->lastSaveRevision = m_document->revision();
for (QTextBlock block = m_document->begin(); block.isValid(); block = block.next())
block.setRevision(documentLayout->lastSaveRevision);
}
BaseTextDocument::BaseTextDocument() : d(new BaseTextDocumentPrivate(this))
{
connect(d->m_document, SIGNAL(modificationChanged(bool)), this, SIGNAL(changed()));
......@@ -448,14 +459,7 @@ bool BaseTextDocument::save(QString *errorString, const QString &saveFileName, b
bool BaseTextDocument::setContents(const QByteArray &contents)
{
if (contents.size() > EditorManager::maxTextFileSize()) {
document()->setPlainText(BaseTextEditorWidget::msgTextTooLarge(contents.size()));
document()->setModified(false);
return false;
}
document()->setPlainText(QString::fromUtf8(contents));
document()->setModified(false);
return true;
return setPlainText(QString::fromUtf8(contents));
}
bool BaseTextDocument::shouldAutoSave() const
......@@ -566,6 +570,20 @@ bool BaseTextDocument::reload(QString *errorString)
return success;
}
bool BaseTextDocument::setPlainText(const QString &text)
{
if (text.size() > EditorManager::maxTextFileSize()) {
document()->setPlainText(BaseTextEditorWidget::msgTextTooLarge(text.size()));
d->resetRevisions();
document()->setModified(false);
return false;
}
document()->setPlainText(text);
d->resetRevisions();
document()->setModified(false);
return true;
}
bool BaseTextDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type)
{
if (flag == FlagIgnore)
......
......@@ -105,6 +105,7 @@ public:
virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName);
virtual bool reload(QString *errorString);
bool setPlainText(const QString &text);
QTextDocument *document() const;
void setSyntaxHighlighter(SyntaxHighlighter *highlighter);
SyntaxHighlighter *syntaxHighlighter() const;
......
......@@ -1184,21 +1184,13 @@ DiffChunk VcsBaseEditorWidget::diffChunk(QTextCursor cursor) const
return rc;
}
void VcsBaseEditorWidget::setPlainText(const QString &text)
{
if (text.size() > Core::EditorManager::maxTextFileSize())
TextEditor::BaseTextEditorWidget::setPlainText(msgTextTooLarge(text.size()));
else
TextEditor::BaseTextEditorWidget::setPlainText(text);
}
void VcsBaseEditorWidget::reportCommandFinished(bool ok, int exitCode, const QVariant &data)
{
Q_UNUSED(exitCode);
Q_UNUSED(data);
if (!ok)
setPlainText(tr("Failed to retrieve data."));
baseTextDocument()->setPlainText(tr("Failed to retrieve data."));
}
const VcsBaseEditorParameters *VcsBaseEditorWidget::findType(const VcsBaseEditorParameters *array,
......@@ -1596,7 +1588,7 @@ void VcsBase::VcsBaseEditorWidget::testLogResolving(QByteArray &data,
const QByteArray &entry2)
{
init();
setPlainText(QLatin1String(data));
baseTextDocument()->setPlainText(QLatin1String(data));
QCOMPARE(d->entriesComboBox()->itemText(0), QString::fromLatin1(entry1));
QCOMPARE(d->entriesComboBox()->itemText(1), QString::fromLatin1(entry2));
}
......
......@@ -209,9 +209,6 @@ signals:
void diffChunkReverted(const VcsBase::DiffChunk &dc);
public slots:
// Convenience slot to set data read from stdout, will use the
// documents' codec to decode
void setPlainText(const QString &text);
void reportCommandFinished(bool ok, int exitCode, const QVariant &data);
protected:
......
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