allow compiler sets persist in auto-find (#170)

This commit is contained in:
Cyano Hao 2024-01-18 10:41:18 +08:00 committed by GitHub
parent f9028ab70f
commit 69872c6f0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 70 additions and 30 deletions

View File

@ -1675,6 +1675,7 @@ Settings::CompilerSet::CompilerSet():
mAutoAddCharsetParams{false}, mAutoAddCharsetParams{false},
mExecCharset{ENCODING_SYSTEM_DEFAULT}, mExecCharset{ENCODING_SYSTEM_DEFAULT},
mStaticLink{false}, mStaticLink{false},
mPersistInAutoFind{false},
mPreprocessingSuffix{DEFAULT_PREPROCESSING_SUFFIX}, mPreprocessingSuffix{DEFAULT_PREPROCESSING_SUFFIX},
mCompilationProperSuffix{DEFAULT_COMPILATION_SUFFIX}, mCompilationProperSuffix{DEFAULT_COMPILATION_SUFFIX},
mAssemblingSuffix{DEFAULT_ASSEMBLING_SUFFIX}, mAssemblingSuffix{DEFAULT_ASSEMBLING_SUFFIX},
@ -1689,6 +1690,7 @@ Settings::CompilerSet::CompilerSet(const QString& compilerFolder, const QString&
mAutoAddCharsetParams{true}, mAutoAddCharsetParams{true},
mExecCharset{ENCODING_SYSTEM_DEFAULT}, mExecCharset{ENCODING_SYSTEM_DEFAULT},
mStaticLink{true}, mStaticLink{true},
mPersistInAutoFind{false},
mPreprocessingSuffix{DEFAULT_PREPROCESSING_SUFFIX}, mPreprocessingSuffix{DEFAULT_PREPROCESSING_SUFFIX},
mCompilationProperSuffix{DEFAULT_COMPILATION_SUFFIX}, mCompilationProperSuffix{DEFAULT_COMPILATION_SUFFIX},
mAssemblingSuffix{DEFAULT_ASSEMBLING_SUFFIX}, mAssemblingSuffix{DEFAULT_ASSEMBLING_SUFFIX},
@ -1754,6 +1756,7 @@ Settings::CompilerSet::CompilerSet(const Settings::CompilerSet &set):
mAutoAddCharsetParams{set.mAutoAddCharsetParams}, mAutoAddCharsetParams{set.mAutoAddCharsetParams},
mExecCharset{set.mExecCharset}, mExecCharset{set.mExecCharset},
mStaticLink{set.mStaticLink}, mStaticLink{set.mStaticLink},
mPersistInAutoFind{set.mPersistInAutoFind},
mPreprocessingSuffix{set.mPreprocessingSuffix}, mPreprocessingSuffix{set.mPreprocessingSuffix},
mCompilationProperSuffix{set.mCompilationProperSuffix}, mCompilationProperSuffix{set.mCompilationProperSuffix},
@ -2779,6 +2782,16 @@ QByteArray Settings::CompilerSet::getCompilerOutput(const QString &binDir, const
return result.trimmed(); return result.trimmed();
} }
bool Settings::CompilerSet::persistInAutoFind() const
{
return mPersistInAutoFind;
}
void Settings::CompilerSet::setPersistInAutoFind(bool newPersistInAutoFind)
{
mPersistInAutoFind = newPersistInAutoFind;
}
Settings::CompilerSet::CompilationStage Settings::CompilerSet::compilationStage() const Settings::CompilerSet::CompilationStage Settings::CompilerSet::compilationStage() const
{ {
return mCompilationStage; return mCompilationStage;
@ -3102,20 +3115,24 @@ bool Settings::CompilerSets::addSets(const QString &folder)
return found; return found;
} }
void Settings::CompilerSets::clearSets() Settings::CompilerSetList Settings::CompilerSets::clearSets()
{ {
CompilerSetList persisted;
for (size_t i=0;i<mList.size();i++) { for (size_t i=0;i<mList.size();i++) {
mSettings->mSettings.beginGroup(QString(SETTING_COMPILTER_SET).arg(i)); mSettings->mSettings.beginGroup(QString(SETTING_COMPILTER_SET).arg(i));
mSettings->mSettings.remove(""); mSettings->mSettings.remove("");
mSettings->mSettings.endGroup(); mSettings->mSettings.endGroup();
if (mList[i]->persistInAutoFind())
persisted.push_back(std::move(mList[i]));
} }
mList.clear(); mList.clear();
mDefaultIndex = -1; mDefaultIndex = -1;
return persisted;
} }
void Settings::CompilerSets::findSets() void Settings::CompilerSets::findSets()
{ {
clearSets(); CompilerSetList persisted = clearSets();
QSet<QString> searched; QSet<QString> searched;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
@ -3152,6 +3169,8 @@ void Settings::CompilerSets::findSets()
} }
#endif #endif
for (PCompilerSet &set: persisted)
addSet(set);
} }
void Settings::CompilerSets::saveSets() void Settings::CompilerSets::saveSets()
@ -3241,7 +3260,6 @@ void Settings::CompilerSets::loadSets()
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
return; return;
} }
clearSets();
findSets(); findSets();
pCurrentSet = defaultSet(); pCurrentSet = defaultSet();
if (!pCurrentSet) { if (!pCurrentSet) {
@ -3370,6 +3388,7 @@ void Settings::CompilerSets::saveSet(int index)
mSettings->mSettings.setValue("AddCharset", pSet->autoAddCharsetParams()); mSettings->mSettings.setValue("AddCharset", pSet->autoAddCharsetParams());
mSettings->mSettings.setValue("StaticLink", pSet->staticLink()); mSettings->mSettings.setValue("StaticLink", pSet->staticLink());
mSettings->mSettings.setValue("ExecCharset", pSet->execCharset()); mSettings->mSettings.setValue("ExecCharset", pSet->execCharset());
mSettings->mSettings.setValue("PersistInAutoFind", pSet->persistInAutoFind());
mSettings->mSettings.setValue("preprocessingSuffix", pSet->preprocessingSuffix()); mSettings->mSettings.setValue("preprocessingSuffix", pSet->preprocessingSuffix());
mSettings->mSettings.setValue("compilationProperSuffix", pSet->compilationProperSuffix()); mSettings->mSettings.setValue("compilationProperSuffix", pSet->compilationProperSuffix());
@ -3457,6 +3476,7 @@ Settings::PCompilerSet Settings::CompilerSets::loadSet(int index)
pSet->setCustomLinkParams(mSettings->mSettings.value("customLinkParams").toString()); pSet->setCustomLinkParams(mSettings->mSettings.value("customLinkParams").toString());
pSet->setAutoAddCharsetParams(mSettings->mSettings.value("AddCharset", true).toBool()); pSet->setAutoAddCharsetParams(mSettings->mSettings.value("AddCharset", true).toBool());
pSet->setStaticLink(mSettings->mSettings.value("StaticLink", false).toBool()); pSet->setStaticLink(mSettings->mSettings.value("StaticLink", false).toBool());
pSet->setPersistInAutoFind(mSettings->mSettings.value("PersistInAutoFind", false).toBool());
pSet->setExecCharset(mSettings->mSettings.value("ExecCharset", ENCODING_SYSTEM_DEFAULT).toString()); pSet->setExecCharset(mSettings->mSettings.value("ExecCharset", ENCODING_SYSTEM_DEFAULT).toString());
if (pSet->execCharset().isEmpty()) { if (pSet->execCharset().isEmpty()) {

View File

@ -1468,6 +1468,9 @@ public:
bool forceUTF8() const; bool forceUTF8() const;
bool isCompilerInfoUsingUTF8() const; bool isCompilerInfoUsingUTF8() const;
bool persistInAutoFind() const;
void setPersistInAutoFind(bool newPersistInAutoFind);
private: private:
void setGCCProperties(const QString& binDir, const QString& c_prog); void setGCCProperties(const QString& binDir, const QString& c_prog);
void setDirectories(const QString& binDir); void setDirectories(const QString& binDir);
@ -1518,6 +1521,7 @@ public:
bool mAutoAddCharsetParams; bool mAutoAddCharsetParams;
QString mExecCharset; QString mExecCharset;
bool mStaticLink; bool mStaticLink;
bool mPersistInAutoFind;
QString mPreprocessingSuffix; QString mPreprocessingSuffix;
QString mCompilationProperSuffix; QString mCompilationProperSuffix;
@ -1538,7 +1542,7 @@ public:
explicit CompilerSets(Settings* settings); explicit CompilerSets(Settings* settings);
PCompilerSet addSet(); PCompilerSet addSet();
bool addSets(const QString& folder); bool addSets(const QString& folder);
void clearSets(); CompilerSetList clearSets();
void findSets(); void findSets();
void saveSets(); void saveSets();
void loadSets(); void loadSets();

View File

@ -95,6 +95,7 @@ static void loadCompilerSetSettings(Settings::PCompilerSet pSet, Ui::CompilerSet
ui->txtCustomLinkParams->setEnabled(pSet->useCustomLinkParams()); ui->txtCustomLinkParams->setEnabled(pSet->useCustomLinkParams());
ui->chkAutoAddCharset->setChecked(pSet->autoAddCharsetParams()); ui->chkAutoAddCharset->setChecked(pSet->autoAddCharsetParams());
ui->chkStaticLink->setChecked(pSet->staticLink()); ui->chkStaticLink->setChecked(pSet->staticLink());
ui->chkPersistInAutoFind->setChecked(pSet->persistInAutoFind());
//rest tabs in the options widget //rest tabs in the options widget
ui->optionTabs->resetUI(pSet,pSet->compileOptions()); ui->optionTabs->resetUI(pSet,pSet->compileOptions());
@ -240,6 +241,7 @@ void CompilerSetOptionWidget::saveCurrentCompilerSet()
pSet->setCustomLinkParams(ui->txtCustomLinkParams->toPlainText().trimmed()); pSet->setCustomLinkParams(ui->txtCustomLinkParams->toPlainText().trimmed());
pSet->setAutoAddCharsetParams(ui->chkAutoAddCharset->isChecked()); pSet->setAutoAddCharsetParams(ui->chkAutoAddCharset->isChecked());
pSet->setStaticLink(ui->chkStaticLink->isChecked()); pSet->setStaticLink(ui->chkStaticLink->isChecked());
pSet->setPersistInAutoFind(ui->chkPersistInAutoFind->isChecked());
pSet->setCCompiler(ui->txtCCompiler->text().trimmed()); pSet->setCCompiler(ui->txtCCompiler->text().trimmed());
pSet->setCppCompiler(ui->txtCppCompiler->text().trimmed()); pSet->setCppCompiler(ui->txtCppCompiler->text().trimmed());
@ -296,13 +298,13 @@ QString CompilerSetOptionWidget::getBinDir()
void CompilerSetOptionWidget::on_btnFindCompilers_clicked() void CompilerSetOptionWidget::on_btnFindCompilers_clicked()
{ {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QString msg = tr("Red Panda C++ will clear current compiler list and search" QString msg = tr("Red Panda C++ will clear previously found compiler list and search"
" for compilers in the following locations:<br /> '%1'<br /> '%2'<br />Are you really want to continue?") " for compilers in the following locations:<br /> '%1'<br /> '%2'<br />Do you really want to continue?")
.arg(includeTrailingPathDelimiter(pSettings->dirs().appDir()) + "MinGW32") .arg(includeTrailingPathDelimiter(pSettings->dirs().appDir()) + "MinGW32")
.arg(includeTrailingPathDelimiter(pSettings->dirs().appDir()) + "MinGW64"); .arg(includeTrailingPathDelimiter(pSettings->dirs().appDir()) + "MinGW64");
#else #else
QString msg = tr("Red Panda C++ will clear current compiler list and search" QString msg = tr("Red Panda C++ will clear previously found compiler list and search"
" for compilers in the the PATH. <br />Are you really want to continue?"); " for compilers in the the PATH. <br />Do you really want to continue?");
#endif #endif
if (QMessageBox::warning(this,tr("Confirm"),msg, if (QMessageBox::warning(this,tr("Confirm"),msg,
QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok ) QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok )
@ -315,14 +317,12 @@ void CompilerSetOptionWidget::on_btnFindCompilers_clicked()
pMainWindow); pMainWindow);
progressDlg.setWindowModality(Qt::WindowModal); progressDlg.setWindowModality(Qt::WindowModal);
progressDlg.setMaximum(3); progressDlg.setMaximum(2);
progressDlg.setLabelText(tr("Searching...")); progressDlg.setLabelText(tr("Searching..."));
pSettings->compilerSets().clearSets();
progressDlg.setValue(1);
pSettings->compilerSets().findSets(); pSettings->compilerSets().findSets();
progressDlg.setValue(2); progressDlg.setValue(1);
doLoad(); doLoad();
progressDlg.setValue(3); progressDlg.setValue(2);
setSettingsChanged(); setSettingsChanged();
if (pSettings->compilerSets().size()==0) { if (pSettings->compilerSets().size()==0) {
QMessageBox::warning(this,tr("Failed"),tr("Can't find any compiler.")); QMessageBox::warning(this,tr("Failed"),tr("Can't find any compiler."));
@ -332,9 +332,10 @@ void CompilerSetOptionWidget::on_btnFindCompilers_clicked()
void CompilerSetOptionWidget::on_btnAddBlankCompilerSet_clicked() void CompilerSetOptionWidget::on_btnAddBlankCompilerSet_clicked()
{ {
QString name = QInputDialog::getText(this,tr("Compiler Set Name"),tr("Name")); QString name = QInputDialog::getText(this,tr("Compiler Set Name"),tr("Name"));
pSettings->compilerSets().addSet(); Settings::PCompilerSet set = pSettings->compilerSets().addSet();
pSettings->compilerSets().setDefaultIndex(pSettings->compilerSets().size()-1); pSettings->compilerSets().setDefaultIndex(pSettings->compilerSets().size()-1);
pSettings->compilerSets().defaultSet()->setName(name); set->setName(name);
set->setPersistInAutoFind(true);
doLoad(); doLoad();
} }

View File

@ -166,6 +166,13 @@
<item> <item>
<widget class="QPlainTextEdit" name="txtCustomLinkParams"/> <widget class="QPlainTextEdit" name="txtCustomLinkParams"/>
</item> </item>
<item>
<widget class="QCheckBox" name="chkPersistInAutoFind">
<property name="text">
<string>Survive auto-finds</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tabSettings"> <widget class="QWidget" name="tabSettings">
@ -492,6 +499,6 @@
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../icons.qrc"/> <include location="../icons.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -692,12 +692,12 @@
<translation>UTF-8</translation> <translation>UTF-8</translation>
</message> </message>
<message> <message>
<source>Red Panda C++ will clear current compiler list and search for compilers in the following locations:&lt;br /&gt; &apos;%1&apos;&lt;br /&gt; &apos;%2&apos;&lt;br /&gt;Are you really want to continue?</source> <source>Red Panda C++ will clear previously found compiler list and search for compilers in the following locations:&lt;br /&gt; &apos;%1&apos;&lt;br /&gt; &apos;%2&apos;&lt;br /&gt;Do you really want to continue?</source>
<translation>Red Panda C++ irá limpar a atual lista de compiladores e irá procurar por compiladores em &lt;br /&gt; &apos;%1&apos;&lt;br /&gt; &apos;%2&apos;&lt;br /&gt;Quer mesmo continuar?</translation> <translation>Red Panda C++ irá limpar a atual lista de compiladores encontrada anteriormente e irá procurar por compiladores em &lt;br /&gt; &apos;%1&apos;&lt;br /&gt; &apos;%2&apos;&lt;br /&gt;Quer mesmo continuar?</translation>
</message> </message>
<message> <message>
<source>Red Panda C++ will clear current compiler list and search for compilers in the the PATH. &lt;br /&gt;Are you really want to continue?</source> <source>Red Panda C++ will clear previously found compiler list and search for compilers in the the PATH. &lt;br /&gt;Do you really want to continue?</source>
<translation>Red Panda C++ irá limpar a atual lista de compiladores e irá procurar por compiladores no PATH. &lt;br /&gt;Quer mesmo continuar</translation> <translation>Red Panda C++ irá limpar a atual lista de compiladores encontrada anteriormente e irá procurar por compiladores no PATH. &lt;br /&gt;Quer mesmo continuar</translation>
</message> </message>
<message> <message>
<source>Confirm</source> <source>Confirm</source>
@ -811,6 +811,10 @@
<source>Binary suffix</source> <source>Binary suffix</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Survive auto-finds</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>CppRefacter</name> <name>CppRefacter</name>

View File

@ -1030,12 +1030,8 @@ p, li { white-space: pre-wrap; }
</message> </message>
<message> <message>
<location filename="../settingsdialog/compilersetoptionwidget.cpp" line="299"/> <location filename="../settingsdialog/compilersetoptionwidget.cpp" line="299"/>
<source>Red Panda C++ will clear current compiler list and search for compilers in the following locations:&lt;br /&gt; &apos;%1&apos;&lt;br /&gt; &apos;%2&apos;&lt;br /&gt;Are you really want to continue?</source> <source>Red Panda C++ will clear previously found compiler list and search for compilers in the following locations:&lt;br /&gt; &apos;%1&apos;&lt;br /&gt; &apos;%2&apos;&lt;br /&gt;Do you really want to continue?</source>
<oldsource>Red Panda C++ will clear current compiler list and search for compilers in the following locations: <translation>C++ :&lt;br/&gt; &apos;%1&apos;&lt;br/&gt; &apos;%2&apos;&lt;br /&gt;</translation>
&apos;%1&apos;
&apos;%2&apos;
Are you really want to continue?</oldsource>
<translation>C++ :&lt;br/&gt; &apos;%1&apos;&lt;br/&gt; &apos;%2&apos;&lt;br /&gt;</translation>
</message> </message>
<message> <message>
<location filename="../settingsdialog/compilersetoptionwidget.cpp" line="68"/> <location filename="../settingsdialog/compilersetoptionwidget.cpp" line="68"/>
@ -1049,8 +1045,8 @@ Are you really want to continue?</oldsource>
</message> </message>
<message> <message>
<location filename="../settingsdialog/compilersetoptionwidget.cpp" line="304"/> <location filename="../settingsdialog/compilersetoptionwidget.cpp" line="304"/>
<source>Red Panda C++ will clear current compiler list and search for compilers in the the PATH. &lt;br /&gt;Are you really want to continue?</source> <source>Red Panda C++ will clear previously found compiler list and search for compilers in the the PATH. &lt;br /&gt;Do you really want to continue?</source>
<translation>C++ PATH路径中搜索gcc编译器.&lt;br /&gt;</translation> <translation>C++ PATH路径中搜索gcc编译器.&lt;br /&gt;</translation>
</message> </message>
<message> <message>
<location filename="../settingsdialog/compilersetoptionwidget.cpp" line="311"/> <location filename="../settingsdialog/compilersetoptionwidget.cpp" line="311"/>
@ -1148,6 +1144,10 @@ Are you really want to continue?</oldsource>
<source>Locate nasm</source> <source>Locate nasm</source>
<translation type="vanished">nasm程序</translation> <translation type="vanished">nasm程序</translation>
</message> </message>
<message>
<source>Survive auto-finds</source>
<translation></translation>
</message>
</context> </context>
<context> <context>
<name>CppRefacter</name> <name>CppRefacter</name>

View File

@ -589,11 +589,11 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Red Panda C++ will clear current compiler list and search for compilers in the following locations:&lt;br /&gt; &apos;%1&apos;&lt;br /&gt; &apos;%2&apos;&lt;br /&gt;Are you really want to continue?</source> <source>Red Panda C++ will clear previously found compiler list and search for compilers in the following locations:&lt;br /&gt; &apos;%1&apos;&lt;br /&gt; &apos;%2&apos;&lt;br /&gt;Do you really want to continue?</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Red Panda C++ will clear current compiler list and search for compilers in the the PATH. &lt;br /&gt;Are you really want to continue?</source> <source>Red Panda C++ will clear previously found compiler list and search for compilers in the the PATH. &lt;br /&gt;Do you really want to continue?</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
@ -700,6 +700,10 @@
<source>Binary suffix</source> <source>Binary suffix</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Survive auto-finds</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>CppRefacter</name> <name>CppRefacter</name>