Do not clean whitespaces/ensure final line in autosave

Calling beginEditBlock() triggers a textChanged() signal and
did "confuse" Qt Quick Designer.

We could just suppress the signal to work around the issue, but I think
it is cleaner to not alter the text document in autosave at all.

Changing the current text document in autosave might have other
unforeseeable implications.

What happened in the Qt Quick Designer was that textChanged() triggered
a reload of the document.
While the reload of the document usually just triggered a
short/unnoticed dealay, it can also trigger a message box with warnings.

Since we (correctly) assume the .QML file was altered outside
of Qt Quick Designer we do sanity checks and warn about code that
might not be supported.

Having those warnings whenever a file is autosaved is annoying.

Change-Id: I62f5486878956cbb776998e4aba468a91cb9ec8e
Reviewed-by: hjk <hjk121@nokiamail.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
Thomas Hartmann
2013-02-13 12:14:09 +01:00
parent 643263ff26
commit e3f5597b26

View File

@@ -198,7 +198,8 @@ ITextMarkable *BaseTextDocument::documentMarker() const
* \brief Saves the document to the specified file.
* \param errorString output parameter, contains error reason.
* \param autoSave signalise that this function was called by the automatic save routine.
* If autosave is true, the cursor will be restored and some signals suppressed.
* If autosave is true, the cursor will be restored and some signals suppressed
* and we do not clean up the text file (cleanWhitespace(), ensureFinalNewLine()).
*/
bool BaseTextDocument::save(QString *errorString, const QString &fileName, bool autoSave)
{
@@ -227,14 +228,16 @@ bool BaseTextDocument::save(QString *errorString, const QString &fileName, bool
}
}
cursor.beginEditBlock();
cursor.movePosition(QTextCursor::Start);
if (!autoSave) {
cursor.beginEditBlock();
cursor.movePosition(QTextCursor::Start);
if (d->m_storageSettings.m_cleanWhitespace)
cleanWhitespace(cursor, d->m_storageSettings.m_cleanIndentation, d->m_storageSettings.m_inEntireDocument);
if (d->m_storageSettings.m_addFinalNewLine)
ensureFinalNewLine(cursor);
cursor.endEditBlock();
if (d->m_storageSettings.m_cleanWhitespace)
cleanWhitespace(cursor, d->m_storageSettings.m_cleanIndentation, d->m_storageSettings.m_inEntireDocument);
if (d->m_storageSettings.m_addFinalNewLine)
ensureFinalNewLine(cursor);
cursor.endEditBlock();
}
QString fName = d->m_fileName;
if (!fileName.isEmpty())