- fix: Correctly set file's real encoding to ASCII after saving
This commit is contained in:
parent
fde8a868fa
commit
5bd8fedb2b
|
@ -231,9 +231,12 @@ void Editor::saveFile(QString filename) {
|
|||
QByteArray encoding = mFileEncoding;
|
||||
if (mEncodingOption!=ENCODING_AUTO_DETECT || mFileEncoding==ENCODING_ASCII)
|
||||
encoding = mEncodingOption;
|
||||
|
||||
this->document()->saveToFile(file,encoding,
|
||||
pSettings->editor().defaultEncoding(),
|
||||
mFileEncoding);
|
||||
if (isVisible())
|
||||
pMainWindow->updateForEncodingInfo(this);
|
||||
emit fileSaved(filename, inProject());
|
||||
}
|
||||
|
||||
|
@ -258,7 +261,7 @@ bool Editor::save(bool force, bool doReparse) {
|
|||
pMainWindow->fileSystemWatcher()->addPath(mFilename);
|
||||
setModified(false);
|
||||
mIsNew = false;
|
||||
this->updateCaption();
|
||||
updateCaption();
|
||||
} catch (SaveException& exception) {
|
||||
if (!force) {
|
||||
QMessageBox::critical(pMainWindow,tr("Error"),
|
||||
|
@ -347,7 +350,6 @@ bool Editor::saveAs(const QString &name, bool fromProject){
|
|||
saveFile(mFilename);
|
||||
mIsNew = false;
|
||||
setModified(false);
|
||||
this->updateCaption();
|
||||
} catch (SaveException& exception) {
|
||||
QMessageBox::critical(pMainWindow,tr("Error"),
|
||||
exception.reason());
|
||||
|
@ -390,7 +392,6 @@ bool Editor::saveAs(const QString &name, bool fromProject){
|
|||
if (!shouldOpenInReadonly()) {
|
||||
setReadOnly(false);
|
||||
}
|
||||
pMainWindow->updateForEncodingInfo(this);
|
||||
updateCaption();
|
||||
|
||||
emit renamed(oldName, newName , firstSave);
|
||||
|
|
|
@ -657,8 +657,6 @@ void Document::saveToFile(QFile &file, const QByteArray& encoding,
|
|||
throw FileError(tr("Can't open file '%1' for save!").arg(file.fileName()));
|
||||
if (mLines.isEmpty())
|
||||
return;
|
||||
bool allAscii = true;
|
||||
|
||||
QTextCodec* codec;
|
||||
realEncoding = encoding;
|
||||
if (realEncoding == ENCODING_UTF8_BOM) {
|
||||
|
@ -675,6 +673,7 @@ void Document::saveToFile(QFile &file, const QByteArray& encoding,
|
|||
} else {
|
||||
codec = QTextCodec::codecForName(realEncoding);
|
||||
}
|
||||
bool allAscii = true;
|
||||
for (PDocumentLine& line:mLines) {
|
||||
if (allAscii) {
|
||||
allAscii = isTextAllAscii(line->fString);
|
||||
|
@ -686,10 +685,10 @@ void Document::saveToFile(QFile &file, const QByteArray& encoding,
|
|||
}
|
||||
file.write(lineBreak().toLatin1());
|
||||
}
|
||||
if (encoding == ENCODING_AUTO_DETECT) {
|
||||
if (allAscii)
|
||||
realEncoding = ENCODING_ASCII;
|
||||
else if (codec->name() == "System") {
|
||||
if (allAscii) {
|
||||
realEncoding = ENCODING_ASCII;
|
||||
} else if (encoding == ENCODING_AUTO_DETECT) {
|
||||
if (codec->name() == "System") {
|
||||
realEncoding = pCharsetInfoManager->getDefaultSystemEncoding();
|
||||
} else {
|
||||
realEncoding = codec->name();
|
||||
|
|
Loading…
Reference in New Issue