From ccfb786f74c8171c5c483d34b76876b7d72483c0 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 5 Apr 2024 20:43:04 +0800 Subject: [PATCH] - fix: Project options -> file doesn't work. --- .../compilersetoptionwidget.cpp | 2 -- .../settingsdialog/projectcompilerwidget.cpp | 21 ++++++++++++------- .../settingsdialog/projectcompilerwidget.h | 1 - .../settingsdialog/projectfileswidget.cpp | 13 ++++++++++-- .../settingsdialog/projectfileswidget.h | 1 + RedPandaIDE/settingsdialog/settingswidget.cpp | 10 ++++++++- RedPandaIDE/settingsdialog/settingswidget.h | 1 + 7 files changed, 35 insertions(+), 14 deletions(-) diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp index 57edf046..3ae56149 100644 --- a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp @@ -177,7 +177,6 @@ static void loadCompilerSetSettings(Settings::PCompilerSet pSet, Ui::CompilerSet void CompilerSetOptionWidget::doLoad() { - disconnectInputs(); ui->cbCompilerSet->clear(); if (pSettings->compilerSets().size()<=0) { ui->btnRenameCompilerSet->setEnabled(false); @@ -196,7 +195,6 @@ void CompilerSetOptionWidget::doLoad() } ui->cbCompilerSet->setCurrentIndex(index); reloadCurrentCompilerSet(); - connectInputs(); } void CompilerSetOptionWidget::doSave() diff --git a/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp b/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp index 75386138..3ceb5d24 100644 --- a/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp +++ b/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp @@ -26,7 +26,6 @@ ProjectCompilerWidget::ProjectCompilerWidget(const QString &name, const QString SettingsWidget(name,group,parent), ui(new Ui::ProjectCompilerWidget) { - mInitialized=false; ui->setupUi(this); } @@ -76,10 +75,12 @@ void ProjectCompilerWidget::refreshOptions() void ProjectCompilerWidget::doLoad() { mOptions = pMainWindow->project()->options().compilerOptions; + ui->cbCompilerSet->blockSignals(true); ui->cbCompilerSet->setCurrentIndex(pMainWindow->project()->options().compilerSet); + ui->cbCompilerSet->blockSignals(false); ui->chkAddCharset->setChecked(pMainWindow->project()->options().addCharset); ui->chkStaticLink->setChecked(pMainWindow->project()->options().staticLink); - mInitialized=true; + refreshOptions(); } void ProjectCompilerWidget::doSave() @@ -87,7 +88,6 @@ void ProjectCompilerWidget::doSave() Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(ui->cbCompilerSet->currentIndex()); if (!pSet) return; - pMainWindow->project()->setCompilerSet(ui->cbCompilerSet->currentIndex()); pMainWindow->project()->options().compilerOptions = ui->tabOptions->arguments(true); if (pSet->compilerType()!=CompilerType::Clang) @@ -104,10 +104,12 @@ void ProjectCompilerWidget::doSave() void ProjectCompilerWidget::init() { + ui->cbCompilerSet->blockSignals(true); ui->cbCompilerSet->clear(); for (size_t i=0;icompilerSets().size();i++) { ui->cbCompilerSet->addItem(pSettings->compilerSets().getSet(i)->name()); } + ui->cbCompilerSet->blockSignals(false); ui->cbEncodingDetails->setVisible(false); ui->cbEncoding->clear(); ui->cbEncoding->addItem(tr("ANSI"),ENCODING_SYSTEM_DEFAULT); @@ -120,15 +122,17 @@ void ProjectCompilerWidget::init() void ProjectCompilerWidget::on_cbCompilerSet_currentIndexChanged(int index) { + if (index<0) + return; std::shared_ptr project = pMainWindow->project(); + clearSettingsChanged(); + disconnectInputs(); + ui->cbCompilerSet->blockSignals(true); auto action = finally([this]{ - disconnectInputs(); + ui->cbCompilerSet->blockSignals(false); refreshOptions(); connectInputs(); }); - if (!mInitialized || index==project->options().compilerSet) { - return; - } Settings::PCompilerSet pSet=pSettings->compilerSets().getSet(index); #ifdef ENABLE_SDCC if (pSet) { @@ -165,7 +169,8 @@ void ProjectCompilerWidget::on_cbCompilerSet_currentIndexChanged(int index) return; } project->setCompilerSet(index); - project->saveOptions(); + setSettingsChanged(); + //project->saveOptions(); } void ProjectCompilerWidget::on_cbEncoding_currentTextChanged(const QString &/*arg1*/) diff --git a/RedPandaIDE/settingsdialog/projectcompilerwidget.h b/RedPandaIDE/settingsdialog/projectcompilerwidget.h index bfdf1faf..eb831e19 100644 --- a/RedPandaIDE/settingsdialog/projectcompilerwidget.h +++ b/RedPandaIDE/settingsdialog/projectcompilerwidget.h @@ -37,7 +37,6 @@ private: private: Ui::ProjectCompilerWidget *ui; QMap mOptions; - bool mInitialized; // SettingsWidget interface protected: diff --git a/RedPandaIDE/settingsdialog/projectfileswidget.cpp b/RedPandaIDE/settingsdialog/projectfileswidget.cpp index 128e92d1..20423a63 100644 --- a/RedPandaIDE/settingsdialog/projectfileswidget.cpp +++ b/RedPandaIDE/settingsdialog/projectfileswidget.cpp @@ -57,6 +57,11 @@ void ProjectFilesWidget::doSave() ui->treeProject->clicked(ui->treeProject->currentIndex()); } +void ProjectFilesWidget::onLoaded() +{ + disconnectAbstractItemView(ui->treeProject); +} + PProjectUnit ProjectFilesWidget::currentUnit() { QModelIndex index = ui->treeProject->currentIndex(); @@ -142,8 +147,9 @@ void ProjectFilesWidget::on_treeProject_doubleClicked(const QModelIndex &index) disableFileOptions(); return; } - PProjectUnit unit = node->pUnit.lock(); + PProjectUnit unit = currentUnit(); if (unit) { + disconnectInputs(); ui->grpFileOptions->setEnabled(true); ui->spinPriority->setValue(unit->priority()); ui->chkCompile->setChecked(unit->compile()); @@ -153,6 +159,8 @@ void ProjectFilesWidget::on_treeProject_doubleClicked(const QModelIndex &index) ui->txtBuildCommand->setPlainText(unit->buildCmd()); ui->txtBuildCommand->setEnabled(ui->chkOverrideBuildCommand->isChecked()); loadUnitEncoding(unit); + connectInputs(); + disconnectAbstractItemView(ui->treeProject); } else { disableFileOptions(); } @@ -266,7 +274,7 @@ void ProjectFilesWidget::init() SettingsWidget::init(); } -void ProjectFilesWidget::showEvent(QShowEvent */*event*/) +void ProjectFilesWidget::showEvent(QShowEvent *event) { if (ui->cbEncoding->count()>0) { if (pMainWindow->project()->options().encoding==ENCODING_SYSTEM_DEFAULT) { @@ -275,6 +283,7 @@ void ProjectFilesWidget::showEvent(QShowEvent */*event*/) ui->cbEncoding->setItemText(0,tr("Project(%1)").arg(QString(pMainWindow->project()->options().encoding))); } } + SettingsWidget::showEvent(event); } diff --git a/RedPandaIDE/settingsdialog/projectfileswidget.h b/RedPandaIDE/settingsdialog/projectfileswidget.h index 608a0216..ee929cd2 100644 --- a/RedPandaIDE/settingsdialog/projectfileswidget.h +++ b/RedPandaIDE/settingsdialog/projectfileswidget.h @@ -42,6 +42,7 @@ private: protected: void doLoad() override; void doSave() override; + void onLoaded() override; private: PProjectUnit currentUnit(); void copyUnits(); diff --git a/RedPandaIDE/settingsdialog/settingswidget.cpp b/RedPandaIDE/settingsdialog/settingswidget.cpp index 80f8376e..86a16b4f 100644 --- a/RedPandaIDE/settingsdialog/settingswidget.cpp +++ b/RedPandaIDE/settingsdialog/settingswidget.cpp @@ -45,14 +45,17 @@ void SettingsWidget::init() this, &SettingsWidget::onUpdateIcons); onUpdateIcons(); //load(); - connectInputs(); + clearSettingsChanged(); } void SettingsWidget::load() { try { + disconnectInputs(); doLoad(); clearSettingsChanged(); + connectInputs(); + onLoaded(); } catch (FileError & e) { QMessageBox::warning(nullptr, tr("Load Error"), @@ -210,3 +213,8 @@ void SettingsWidget::onUpdateIcons() { updateIcons(pIconsManager->actionIconSize()); } + +void SettingsWidget::onLoaded() +{ + +} diff --git a/RedPandaIDE/settingsdialog/settingswidget.h b/RedPandaIDE/settingsdialog/settingswidget.h index 185f09eb..e01d2fb4 100644 --- a/RedPandaIDE/settingsdialog/settingswidget.h +++ b/RedPandaIDE/settingsdialog/settingswidget.h @@ -38,6 +38,7 @@ public slots: protected: virtual void doLoad() = 0; virtual void doSave() = 0; + virtual void onLoaded(); void connectAbstractItemView(QAbstractItemView* pView); void disconnectAbstractItemView(QAbstractItemView* pView); virtual void updateIcons(const QSize &size) ;