forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user