work save: fix project file encoding setting

compiler set - exec charset setting
This commit is contained in:
royqh1979@gmail.com 2022-01-24 01:08:47 +08:00
parent 8cffef2cb6
commit d9f36ae3cd
9 changed files with 101 additions and 9 deletions

View File

@ -68,8 +68,7 @@ QList<PCharsetInfo> CharsetInfoManager::findCharsetsByLanguageName(const QString
{
QList<PCharsetInfo> 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<PCharsetInfo> 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<CharsetInfo>(37,"IBM037","",false));

View File

@ -42,6 +42,7 @@ public:
PCharsetInfo findCharsetByCodepage(int codepage);
QStringList languageNames();
QList<PCharsetInfo> findCharsetsByLanguageName(const QString& languageName);
QString findLanguageByCharsetName(const QString& encodingName);
private:
QList<PCharsetInfo> mCodePages;
};

View File

@ -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());

View File

@ -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

View File

@ -22,6 +22,7 @@
#include <QMessageBox>
#include "../utils.h"
#include "../iconsmanager.h"
#include "../platform.h"
#include <QDebug>
#include <QFileDialog>
#include <QInputDialog>
@ -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) {

View File

@ -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

View File

@ -121,10 +121,34 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="chkAutoAddCharset">
<property name="text">
<string>Add Charset arguments when calling the compiler</string>
</property>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="chkAutoAddCharset">
<property name="text">
<string>Add Charset arguments when calling the compiler</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbEncoding"/>
</item>
<item>
<widget class="QComboBox" name="cbEncodingDetails"/>
</item>
</layout>
</widget>
</item>
<item>

View File

@ -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<PCharsetInfo> 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());
}

View File

@ -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);