diff --git a/NEWS.md b/NEWS.md index aa305e3d..3ebc58d3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,7 @@ Red Panda C++ Version 2.11 - enhancement: Show progress dialog when search/find occurrencies in large projects. - enhancement: Improve auto indent. - enhancement: Change the way to calculate execution time. + - enhancement: Auto reload openned project files that use "Project Default" as the encoding, when the project encoding setting is changed in the project options dialog. Red Panda C++ Version 2.10 diff --git a/RedPandaIDE/SimpleIni.h b/RedPandaIDE/SimpleIni.h index 60c6f03e..8aa50ef2 100644 --- a/RedPandaIDE/SimpleIni.h +++ b/RedPandaIDE/SimpleIni.h @@ -2025,6 +2025,8 @@ CSimpleIniTempl::GetValue( } } + if (*(iKeyVal->second)==0) + return a_pDefault; return iKeyVal->second; } diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 9c5af808..7b3a73a7 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -237,17 +237,6 @@ void Editor::loadFile(QString filename) { if (mProject) { PProjectUnit unit = mProject->findUnit(this); if (unit) { -// if (mEncodingOption==ENCODING_AUTO_DETECT) { -// if (mFileEncoding==ENCODING_ASCII) -// unit->setEncoding(mProject->options().encoding); -// else -// unit->setEncoding(mFileEncoding); -// mEncodingOption=unit->encoding(); -// } else { -// unit->setEncoding(mEncodingOption); -// } -// unit->setRealEncoding(mFileEncoding); - //unit->setEncoding(mEncodingOption); unit->setRealEncoding(mFileEncoding); } } diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 4bfd325f..72007f55 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -1100,6 +1100,21 @@ bool Project::saveAsTemplate(const QString &templateFolder, return true; } +void Project::setEncoding(const QByteArray &encoding) +{ + if (encoding!=mOptions.encoding) { + mOptions.encoding=encoding; + foreach (const PProjectUnit& unit,mUnits) { + if (unit->encoding()!=ENCODING_PROJECT) + continue; + Editor * e=unitEditor(unit); + if (e) { + e->setEncodingOption(mOptions.encoding); + } + } + } +} + void Project::saveOptions() { SimpleIni ini; @@ -2067,7 +2082,7 @@ void Project::loadOptions(SimpleIni& ini) if (useUTF8) { mOptions.encoding = ini.GetValue("Project","Encoding", ENCODING_UTF8); } else { - mOptions.encoding = ini.GetValue("Project","Encoding", ENCODING_SYSTEM_DEFAULT); + mOptions.encoding = ini.GetValue("Project","Encoding", pSettings->editor().defaultEncoding()); } if (mOptions.encoding == ENCODING_AUTO_DETECT) mOptions.encoding = pSettings->editor().defaultEncoding(); diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index ad4101fd..579de37f 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -268,6 +268,8 @@ public: const QString& description, const QString& category); + void setEncoding(const QByteArray& encoding); + std::shared_ptr cppParser(); const QString &filename() const; diff --git a/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp b/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp index c66b8b7d..5712963f 100644 --- a/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp +++ b/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp @@ -97,7 +97,7 @@ void ProjectGeneralWidget::doSave() return; project->setName(ui->txtName->text().trimmed()); - project->options().encoding = ui->cbDefaultEncoding->currentText().toUtf8(); + project->setEncoding(ui->cbDefaultEncoding->currentText().toUtf8()); int row = std::max(0,ui->lstType->currentRow()); project->options().type = static_cast(row); diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts index 964d2125..60da914a 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts @@ -3353,7 +3353,7 @@ Are you really want to continue? Default - 缺省 + 默认 @@ -6888,7 +6888,7 @@ Are you really want to continue? Default - 缺省 + 默认 @@ -8661,7 +8661,7 @@ Are you really want to continue? default - 缺省 + 默认 Can't open file '%1' to write!