From 6bc943ba9c7aec37a7b8e0ab4327b946f92c36bf Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sat, 8 Jan 2022 11:46:39 +0800 Subject: [PATCH] - enhancement: suppoort localization info in project templates - change: template / project files use utf-8 encoding instead of ANSI --- NEWS.md | 5 +++++ RedPandaIDE/projecttemplate.cpp | 16 +++++++++++++--- RedPandaIDE/utils.cpp | 12 ++++++++++-- RedPandaIDE/widgets/newprojectdialog.cpp | 1 + RedPandaIDE/widgets/newprojectdialog.ui | 6 ++++++ templates/1-WinApp.template | 3 +++ templates/2-ConsoleApp.template | 3 +++ 7 files changed, 41 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 27859649..a31c6efa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +Red Panda C++ Version 0.13.1 + - enhancement: suppoort localization info in project templates + - change: template / project files use utf-8 encoding instead of ANSI + + Red Panda C++ Version 0.12.7 - change: make current build system follow FHS specifications - fix: crash when close settings dialog in Ubuntu 20.04 (but we'll leak memory now...) diff --git a/RedPandaIDE/projecttemplate.cpp b/RedPandaIDE/projecttemplate.cpp index 60b6ba8d..c5215187 100644 --- a/RedPandaIDE/projecttemplate.cpp +++ b/RedPandaIDE/projecttemplate.cpp @@ -18,6 +18,7 @@ #include #include #include "mainwindow.h" +#include "settings.h" ProjectTemplate::ProjectTemplate(QObject *parent) : QObject(parent) { @@ -105,11 +106,20 @@ void ProjectTemplate::readTemplateFile(const QString &fileName) return; } + QString lang = pSettings->environment().language(); // template info - mDescription = fromByteArray(mIni->GetValue("Template", "Description", "")); mIcon = fromByteArray(mIni->GetValue("Template", "Icon", "")); - mCategory = fromByteArray(mIni->GetValue("Template", "Category", "")); - mName = fromByteArray(mIni->GetValue("Template", "Name", "")); + if (!lang.isEmpty()) { + mCategory = fromByteArray(mIni->GetValue("Template", QString("Category[%1]").arg(lang).toUtf8(), "")); + mName = fromByteArray(mIni->GetValue("Template", QString("Name[%1]").arg(lang).toUtf8(), "")); + mDescription = fromByteArray(mIni->GetValue("Template", QString("Description[%1]").arg(lang).toUtf8(), "")); + } + if (mCategory.isEmpty()) + mCategory = fromByteArray(mIni->GetValue("Template", "Category", "")); + if (mName.isEmpty()) + mName = fromByteArray(mIni->GetValue("Template", "Name", "")); + if (mDescription.isEmpty()) + mDescription = fromByteArray(mIni->GetValue("Template", "Description", "")); mOptions.icon = mIni->GetValue("Project", "Icon", ""); mOptions.type = static_cast(mIni->GetLongValue("Project", "Type", 0)); // default = gui diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index e321ddb8..b8171516 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -776,12 +776,20 @@ QString extractFileDir(const QString &fileName) QByteArray toByteArray(const QString &s) { - return s.toLocal8Bit(); + //return s.toLocal8Bit(); + return s.toUtf8(); } QString fromByteArray(const QByteArray &s) { - return QString::fromLocal8Bit(s); + QTextCodec* codec = QTextCodec::codecForName(ENCODING_UTF8); + QTextCodec::ConverterState state; + if (!codec) + return QString(s); + QString tmp = codec->toUnicode(s,s.length(),&state); + if (state.invalidChars>0) + tmp = QString::fromLocal8Bit(s); + return tmp; } QString linesToText(const QStringList &lines) diff --git a/RedPandaIDE/widgets/newprojectdialog.cpp b/RedPandaIDE/widgets/newprojectdialog.cpp index 0fc6362c..e63967cb 100644 --- a/RedPandaIDE/widgets/newprojectdialog.cpp +++ b/RedPandaIDE/widgets/newprojectdialog.cpp @@ -173,6 +173,7 @@ void NewProjectDialog::updateView() icon, t->name()); } + item->setData(Qt::ToolTipRole,t->name()); item->setData(Qt::UserRole,i); ui->lstTemplates->addItem(item); } diff --git a/RedPandaIDE/widgets/newprojectdialog.ui b/RedPandaIDE/widgets/newprojectdialog.ui index d0829218..cd6fef52 100644 --- a/RedPandaIDE/widgets/newprojectdialog.ui +++ b/RedPandaIDE/widgets/newprojectdialog.ui @@ -22,6 +22,12 @@ QListView::IconMode + + true + + + false + Qt::AlignCenter diff --git a/templates/1-WinApp.template b/templates/1-WinApp.template index 81312944..8934e79a 100644 --- a/templates/1-WinApp.template +++ b/templates/1-WinApp.template @@ -1,9 +1,12 @@ [Template] ver=1 Name=Windows Application +Name[zh_CN]=Windows应用程序 Icon=Windows.ico Description=A standard Windows application +Description[zh_CN]=基于Windows API开发的图形界面应用程序 Category=Basic +Category[zh_CN]=基础 [Unit0] CName=main.c diff --git a/templates/2-ConsoleApp.template b/templates/2-ConsoleApp.template index 8ce8216a..16af38da 100644 --- a/templates/2-ConsoleApp.template +++ b/templates/2-ConsoleApp.template @@ -1,9 +1,12 @@ [Template] ver=1 Name=Console Application +Name[zh_CN]=控制台程序 Icon=ConsoleToo.ico Description=A console application (MS-DOS window) +Description[zh_CN]=控制台应用程序 Category=Basic +Category[zh_CN]=基础 [Unit0] CName=main.c