diff --git a/RedPandaIDE/platform.cpp b/RedPandaIDE/platform.cpp index f796bc34..301f3f31 100644 --- a/RedPandaIDE/platform.cpp +++ b/RedPandaIDE/platform.cpp @@ -68,8 +68,7 @@ QList CharsetInfoManager::findCharsetsByLanguageName(const QString { QList result; foreach (const PCharsetInfo& info, mCodePages) { - if (info->language == languageName - && info->enabled) + if (info->enabled && info->language == languageName) result.append(info); } std::sort(result.begin(),result.end(),[](const PCharsetInfo& info1,const PCharsetInfo& info2){ @@ -78,6 +77,17 @@ QList CharsetInfoManager::findCharsetsByLanguageName(const QString return result; } +QString CharsetInfoManager::findLanguageByCharsetName(const QString &encodingName) +{ + + foreach (const PCharsetInfo& info, mCodePages) { + if (info->enabled && + QString::compare(info->name, encodingName, Qt::CaseInsensitive)==0) + return info->language; + } + return "Unknown"; +} + CharsetInfoManager::CharsetInfoManager():QObject() { mCodePages.append(std::make_shared(37,"IBM037","",false)); diff --git a/RedPandaIDE/platform.h b/RedPandaIDE/platform.h index fc809fa5..cacdacd9 100644 --- a/RedPandaIDE/platform.h +++ b/RedPandaIDE/platform.h @@ -42,6 +42,7 @@ public: PCharsetInfo findCharsetByCodepage(int codepage); QStringList languageNames(); QList findCharsetsByLanguageName(const QString& languageName); + QString findLanguageByCharsetName(const QString& encodingName); private: QList mCodePages; }; diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index d8266d66..8240c5d0 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -2307,6 +2307,16 @@ QByteArray Settings::CompilerSet::getCompilerOutput(const QString &binDir, const return result.trimmed(); } +const QString &Settings::CompilerSet::execCharser() const +{ + return mExecCharser; +} + +void Settings::CompilerSet::setExecCharser(const QString &newExecCharser) +{ + mExecCharser = newExecCharser; +} + const QString &Settings::CompilerSet::debugServer() const { return mDebugServer; @@ -2750,6 +2760,7 @@ void Settings::CompilerSets::saveSet(int index) mSettings->mSettings.setValue("customLinkParams", pSet->customLinkParams()); mSettings->mSettings.setValue("AddCharset", pSet->autoAddCharsetParams()); mSettings->mSettings.setValue("StaticLink", pSet->staticLink()); + mSettings->mSettings.setValue("ExecCharser", pSet->execCharser()); // Misc. properties mSettings->mSettings.setValue("DumpMachine", pSet->dumpMachine()); @@ -2815,6 +2826,7 @@ Settings::PCompilerSet Settings::CompilerSets::loadSet(int index) pSet->setCustomLinkParams(mSettings->mSettings.value("customLinkParams").toString()); pSet->setAutoAddCharsetParams(mSettings->mSettings.value("AddCharset").toBool()); pSet->setStaticLink(mSettings->mSettings.value("StaticLink").toBool()); + pSet->setExecCharser(mSettings->mSettings.value("ExecCharser").toString()); pSet->setDumpMachine(mSettings->mSettings.value("DumpMachine").toString()); pSet->setVersion(mSettings->mSettings.value("Version").toString()); diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index 9f47e14a..62ff1c4d 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -1177,6 +1177,9 @@ public: int compilerSetType() const; void setCompilerSetType(int newCompilerSetType); + const QString &execCharser() const; + void setExecCharser(const QString &newExecCharser); + private: // Initialization void setExecutables(); @@ -1222,6 +1225,7 @@ public: QString mCustomCompileParams; QString mCustomLinkParams; bool mAutoAddCharsetParams; + QString mExecCharser; bool mStaticLink; // Options diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp index 48d743f8..60f451b7 100644 --- a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp @@ -22,6 +22,7 @@ #include #include "../utils.h" #include "../iconsmanager.h" +#include "../platform.h" #include #include #include @@ -56,6 +57,19 @@ CompilerSetOptionWidget::~CompilerSetOptionWidget() delete ui; } +void CompilerSetOptionWidget::init() +{ + ui->cbEncodingDetails->setVisible(false); + ui->cbEncoding->clear(); + ui->cbEncoding->addItem(tr("Auto detect"),ENCODING_AUTO_DETECT); + ui->cbEncoding->addItem(tr("ANSI"),ENCODING_SYSTEM_DEFAULT); + ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8); + foreach (const QString& langName, pCharsetInfoManager->languageNames()) { + ui->cbEncoding->addItem(langName,langName); + } + SettingsWidget::init(); +} + void resetOptionTabs(Settings::PCompilerSet pSet,QTabWidget* pTab) { while (pTab->count()>0) { diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.h b/RedPandaIDE/settingsdialog/compilersetoptionwidget.h index 47bb473f..4fbba03a 100644 --- a/RedPandaIDE/settingsdialog/compilersetoptionwidget.h +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.h @@ -42,9 +42,12 @@ private: // SettingsWidget interface +public: + void init() override; protected: void doLoad() override; void doSave() override; + private: void reloadCurrentCompilerSet(); void saveCurrentCompilerSet(); @@ -57,6 +60,7 @@ private slots: void on_btnRenameCompilerSet_pressed(); void on_btnRemoveCompilerSet_pressed(); void updateIcons(); + }; #endif // COMPILERSETOPTIONWIDGET_H diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.ui b/RedPandaIDE/settingsdialog/compilersetoptionwidget.ui index 7fed6e6d..19fa4142 100644 --- a/RedPandaIDE/settingsdialog/compilersetoptionwidget.ui +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.ui @@ -121,10 +121,34 @@ - - - Add Charset arguments when calling the compiler - + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Add Charset arguments when calling the compiler + + + + + + + + + + diff --git a/RedPandaIDE/settingsdialog/projectfileswidget.cpp b/RedPandaIDE/settingsdialog/projectfileswidget.cpp index 4eb60727..1d5fe015 100644 --- a/RedPandaIDE/settingsdialog/projectfileswidget.cpp +++ b/RedPandaIDE/settingsdialog/projectfileswidget.cpp @@ -108,6 +108,28 @@ void ProjectFilesWidget::disableFileOptions() ui->txtBuildCommand->setPlainText(""); } +void ProjectFilesWidget::loadUnitEncoding(PProjectUnit unit) +{ + if (unit->encoding() == ENCODING_AUTO_DETECT + || unit->encoding() == ENCODING_SYSTEM_DEFAULT + || unit->encoding() == ENCODING_UTF8) { + ui->cbEncoding->setCurrentText(unit->encoding()); + ui->cbEncodingDetail->clear(); + ui->cbEncodingDetail->setVisible(false); + } else { + QString encoding = unit->encoding(); + QString language = pCharsetInfoManager->findLanguageByCharsetName(encoding); + ui->cbEncoding->setCurrentText(language); + ui->cbEncodingDetail->setVisible(true); + ui->cbEncodingDetail->clear(); + QList infos = pCharsetInfoManager->findCharsetsByLanguageName(language); + foreach (const PCharsetInfo& info, infos) { + ui->cbEncodingDetail->addItem(info->name); + } + ui->cbEncodingDetail->setCurrentText(encoding); + } +} + void ProjectFilesWidget::on_treeProject_doubleClicked(const QModelIndex &index) { if (!index.isValid()) { @@ -130,7 +152,7 @@ void ProjectFilesWidget::on_treeProject_doubleClicked(const QModelIndex &index) ui->chkOverrideBuildCommand->setChecked(unit->overrideBuildCmd()); ui->txtBuildCommand->setPlainText(unit->buildCmd()); ui->txtBuildCommand->setEnabled(ui->chkOverrideBuildCommand->isChecked()); - ui->cbEncoding->setCurrentText(unit->encoding()); + loadUnitEncoding(unit); } else { disableFileOptions(); } @@ -201,7 +223,7 @@ void ProjectFilesWidget::on_cbEncoding_currentTextChanged(const QString &) PProjectUnit unit = currentUnit(); if(!unit) return; - unit->setEncoding(userData.toLocal8Bit()); + unit->setEncoding(userData.toUtf8()); ui->cbEncodingDetail->setVisible(false); ui->cbEncodingDetail->clear(); } else { @@ -241,6 +263,6 @@ void ProjectFilesWidget::on_cbEncodingDetail_currentTextChanged(const QString &) PProjectUnit unit = currentUnit(); if(!unit) return; - unit->setEncoding(ui->cbEncodingDetail->currentText().toLocal8Bit()); + unit->setEncoding(ui->cbEncodingDetail->currentText().toUtf8()); } diff --git a/RedPandaIDE/settingsdialog/projectfileswidget.h b/RedPandaIDE/settingsdialog/projectfileswidget.h index 6f2500a4..49984107 100644 --- a/RedPandaIDE/settingsdialog/projectfileswidget.h +++ b/RedPandaIDE/settingsdialog/projectfileswidget.h @@ -46,6 +46,7 @@ private: PProjectUnit currentUnit(); void copyUnits(); void disableFileOptions(); + void loadUnitEncoding(PProjectUnit unit); private slots: void on_treeProject_doubleClicked(const QModelIndex &index); void on_spinPriority_valueChanged(int arg1);