Skip to content

Commit

Permalink
- enhancement: Auto detect windows OEM code page in options / compile…
Browse files Browse the repository at this point in the history
…r / compiler set auto convert encoding option combobox.
  • Loading branch information
royqh1979 committed Dec 10, 2024
1 parent c1b3470 commit 2614d14
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions RedPandaIDE/compiler/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions RedPandaIDE/compiler/projectcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
7 changes: 6 additions & 1 deletion RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion RedPandaIDE/settingsdialog/projectcompilerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions libs/redpanda_qt_utils/qt_utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 2614d14

Please sign in to comment.