From 2614d14284eaa0572f1bf3a93cac1bab39581cc3 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 10 Dec 2024 20:08:34 +0800 Subject: [PATCH] - enhancement: Auto detect windows OEM code page in options / compiler / compiler set auto convert encoding option combobox. --- NEWS.md | 2 +- RedPandaIDE/compiler/compiler.cpp | 2 ++ RedPandaIDE/compiler/projectcompiler.cpp | 2 ++ RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp | 7 ++++++- RedPandaIDE/settingsdialog/projectcompilerwidget.cpp | 7 ++++++- libs/redpanda_qt_utils/qt_utils/utils.h | 1 + 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 84a308c16..44169149e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,7 +5,7 @@ Red Panda C++ Version 3.3 - enhancement: Auto scale the main ui & choose theme dialog at the first run. - fix: crash on statements like "x::a x;" - enhancement: support literal operators. - - fix: Use oem code page instead of ANSI code page for compiling. + - enhancement: Auto detect windows OEM code page in options / compiler / compiler set auto convert encoding option combobox. - enhancement: Show oem codpages in compiler setting's encoding combobox. Red Panda C++ Version 3.2 diff --git a/RedPandaIDE/compiler/compiler.cpp b/RedPandaIDE/compiler/compiler.cpp index 0c151ca87..d02871daa 100644 --- a/RedPandaIDE/compiler/compiler.cpp +++ b/RedPandaIDE/compiler/compiler.cpp @@ -393,6 +393,8 @@ QStringList Compiler::getCharsetArgument(const QByteArray& encoding,FileType fil if (forceExecUTF8) { execEncodingName = "UTF-8"; } else if (compilerSetExecCharset == ENCODING_SYSTEM_DEFAULT || compilerSetExecCharset.isEmpty()) { + execEncodingName = systemEncodingName; + } else if (compilerSetExecCharset == ENCODING_OEM_DEFAULT) { execEncodingName = pCharsetInfoManager->getDefaultConsoleEncoding(); } else { execEncodingName = compilerSetExecCharset; diff --git a/RedPandaIDE/compiler/projectcompiler.cpp b/RedPandaIDE/compiler/projectcompiler.cpp index 4baf75676..25dc94d39 100644 --- a/RedPandaIDE/compiler/projectcompiler.cpp +++ b/RedPandaIDE/compiler/projectcompiler.cpp @@ -442,6 +442,8 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file) QByteArray targetEncoding; QByteArray sourceEncoding; if ( encoding == ENCODING_SYSTEM_DEFAULT || encoding.isEmpty()) { + targetEncoding = defaultSystemEncoding; + } else if (encoding == ENCODING_OEM_DEFAULT) { targetEncoding = pCharsetInfoManager->getDefaultConsoleEncoding(); } else if (encoding == ENCODING_UTF8_BOM) { targetEncoding = "UTF-8"; diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp index b08ca640c..59e4e7a96 100644 --- a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp @@ -64,7 +64,10 @@ void CompilerSetOptionWidget::init() { ui->cbEncodingDetails->setVisible(false); ui->cbEncoding->clear(); - ui->cbEncoding->addItem(tr("System Default(%1)").arg(QString(pCharsetInfoManager->getDefaultConsoleEncoding())),ENCODING_SYSTEM_DEFAULT); + ui->cbEncoding->addItem(tr("System Default(%1)").arg(QString(pCharsetInfoManager->getDefaultSystemEncoding())),ENCODING_SYSTEM_DEFAULT); +#ifdef Q_OS_WIN + ui->cbEncoding->addItem(tr("OEM(%1)").arg(QString(pCharsetInfoManager->getDefaultConsoleEncoding())),ENCODING_OEM_DEFAULT); +#endif ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8); foreach (const QString& langName, pCharsetInfoManager->languageNames()) { ui->cbEncoding->addItem(langName,langName); @@ -109,6 +112,7 @@ static void loadCompilerSetSettings(Settings::PCompilerSet pSet, Ui::CompilerSet if (pSet->execCharset() == ENCODING_AUTO_DETECT || pSet->execCharset() == ENCODING_SYSTEM_DEFAULT + || pSet->execCharset() == ENCODING_OEM_DEFAULT || pSet->execCharset() == ENCODING_UTF8) { int index =ui->cbEncoding->findData(pSet->execCharset()); ui->cbEncoding->setCurrentIndex(index); @@ -445,6 +449,7 @@ void CompilerSetOptionWidget::on_cbEncoding_currentTextChanged(const QString &/* QString userData = ui->cbEncoding->currentData().toString(); if (userData == ENCODING_AUTO_DETECT || userData == ENCODING_SYSTEM_DEFAULT + || userData == ENCODING_OEM_DEFAULT || userData == ENCODING_UTF8) { ui->cbEncodingDetails->setVisible(false); ui->cbEncodingDetails->clear(); diff --git a/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp b/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp index 6d480b13e..cfd561373 100644 --- a/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp +++ b/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp @@ -50,6 +50,7 @@ void ProjectCompilerWidget::refreshOptions() QByteArray execEncoding = mExecCharset; if (execEncoding == ENCODING_AUTO_DETECT || execEncoding == ENCODING_SYSTEM_DEFAULT + || execEncoding == ENCODING_OEM_DEFAULT || execEncoding == ENCODING_UTF8) { int index =ui->cbEncoding->findData(execEncoding); ui->cbEncoding->setCurrentIndex(index); @@ -117,7 +118,10 @@ void ProjectCompilerWidget::init() ui->cbCompilerSet->blockSignals(false); ui->cbEncodingDetails->setVisible(false); ui->cbEncoding->clear(); - ui->cbEncoding->addItem(tr("System Default(%1)").arg(QString(pCharsetInfoManager->getDefaultConsoleEncoding())),ENCODING_SYSTEM_DEFAULT); + ui->cbEncoding->addItem(tr("System Default(%1)").arg(QString(pCharsetInfoManager->getDefaultSystemEncoding())),ENCODING_SYSTEM_DEFAULT); +#ifdef Q_OS_WIN + ui->cbEncoding->addItem(tr("OEM(%1)").arg(QString(pCharsetInfoManager->getDefaultConsoleEncoding())),ENCODING_OEM_DEFAULT); +#endif ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8); foreach (const QString& langName, pCharsetInfoManager->languageNames()) { ui->cbEncoding->addItem(langName,langName); @@ -187,6 +191,7 @@ void ProjectCompilerWidget::on_cbEncoding_currentTextChanged(const QString &/*ar QString userData = ui->cbEncoding->currentData().toString(); if (userData == ENCODING_AUTO_DETECT || userData == ENCODING_SYSTEM_DEFAULT + || userData == ENCODING_OEM_DEFAULT || userData == ENCODING_UTF8) { ui->cbEncodingDetails->setVisible(false); ui->cbEncodingDetails->clear(); diff --git a/libs/redpanda_qt_utils/qt_utils/utils.h b/libs/redpanda_qt_utils/qt_utils/utils.h index dffb8c43d..fbde7fd0a 100644 --- a/libs/redpanda_qt_utils/qt_utils/utils.h +++ b/libs/redpanda_qt_utils/qt_utils/utils.h @@ -44,6 +44,7 @@ class QTextStream; #define ENCODING_UTF16_BOM "UTF-16 BOM" #define ENCODING_UTF32_BOM "UTF-32 BOM" #define ENCODING_SYSTEM_DEFAULT "SYSTEM" +#define ENCODING_OEM_DEFAULT "OEM" #define ENCODING_ASCII "ASCII" #define ENCODING_PROJECT "PROJECT"