diff options
author | David Schulz <david.schulz@digia.com> | 2013-01-24 08:47:31 +0100 |
---|---|---|
committer | David Schulz <david.schulz@digia.com> | 2013-01-24 15:44:05 +0100 |
commit | 2f9574582d800b43d9593b3587f6a35d6bbd8749 (patch) | |
tree | d9c7b0e3335a34a65d5326178a8bddafda0581f3 /src | |
parent | 8d4618e43d44bee687771f3ff4b03801037d0d38 (diff) | |
download | qt-creator-2f9574582d800b43d9593b3587f6a35d6bbd8749.tar.gz |
Editor: Disable adding UTF-8 BOM for qmake project files
Removes the "Add/Remove UTF-8 BOM" entry in the context menu
of the project file editor. Also ignores the setting
"Add If Encoding Is UTF-8" under
Options -> Text Editor -> Behavior -> File Encodings.
Task-number: QTCREATORBUG-8501
Change-Id: I368966b5235ee60011f2051ebdb82f9fe09bc4cc
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/coreplugin/textdocument.h | 1 | ||||
-rw-r--r-- | src/plugins/qt4projectmanager/profileeditor.h | 4 | ||||
-rw-r--r-- | src/plugins/texteditor/basetextdocument.cpp | 5 | ||||
-rw-r--r-- | src/plugins/texteditor/basetexteditor.cpp | 2 |
4 files changed, 9 insertions, 3 deletions
diff --git a/src/plugins/coreplugin/textdocument.h b/src/plugins/coreplugin/textdocument.h index 27fbabef10..ac6f6a3883 100644 --- a/src/plugins/coreplugin/textdocument.h +++ b/src/plugins/coreplugin/textdocument.h @@ -53,6 +53,7 @@ public: const QTextCodec *codec() const; void setCodec(const QTextCodec *); void switchUtf8Bom(); + virtual bool supportsUtf8Bom() { return true; } ReadResult read(const QString &fileName, QStringList *plainTextList, QString *errorString); ReadResult read(const QString &fileName, QString *plainText, QString *errorString); diff --git a/src/plugins/qt4projectmanager/profileeditor.h b/src/plugins/qt4projectmanager/profileeditor.h index 020c579064..2a599d4339 100644 --- a/src/plugins/qt4projectmanager/profileeditor.h +++ b/src/plugins/qt4projectmanager/profileeditor.h @@ -95,6 +95,10 @@ public: ProFileDocument(); QString defaultPath() const; QString suggestedFileName() const; + + // qmake project files doesn't support UTF8-BOM + // If the BOM would be added qmake would fail and QtCreator couldn't parse the project file + bool supportsUtf8Bom() { return false; } }; } // namespace Internal diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp index 388ed6b43c..4dce034f96 100644 --- a/src/plugins/texteditor/basetextdocument.cpp +++ b/src/plugins/texteditor/basetextdocument.cpp @@ -237,8 +237,9 @@ bool BaseTextDocument::save(QString *errorString, const QString &fileName, bool if (!fileName.isEmpty()) fName = fileName; + // check if UTF8-BOM has to be added or removed Utils::TextFileFormat saveFormat = format(); - if (saveFormat.codec->name() == "UTF-8") { + if (saveFormat.codec->name() == "UTF-8" && supportsUtf8Bom()) { switch (d->m_extraEncodingSettings.m_utf8BomSetting) { case TextEditor::ExtraEncodingSettings::AlwaysAdd: saveFormat.hasUtf8Bom = true; @@ -249,7 +250,7 @@ bool BaseTextDocument::save(QString *errorString, const QString &fileName, bool saveFormat.hasUtf8Bom = false; break; } - } // "UTF-8" + } const bool ok = write(fName, saveFormat, d->m_document->toPlainText(), errorString); diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 5ff92136ee..aece1ce50c 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -6238,7 +6238,7 @@ void BaseTextEditorWidget::appendStandardContextMenuActions(QMenu *menu) menu->addAction(a); QSharedPointer<BaseTextDocument> doc = baseTextDocument(); - if (doc->codec()->name() == QByteArray("UTF-8")) { + if (doc->codec()->name() == QByteArray("UTF-8") && doc->supportsUtf8Bom()) { a = Core::ActionManager::command(Constants::SWITCH_UTF8BOM)->action(); if (a && a->isEnabled()) { a->setText(doc->format().hasUtf8Bom ? tr("Delete UTF-8 BOM on Save") |