From 74be7f5d7983035b2dbf8f61ad0390f3d9f439db Mon Sep 17 00:00:00 2001 From: Will Bowers Date: Mon, 17 Feb 2025 16:29:01 -0700 Subject: cmake-gui: Add 'Reload Presets' button, replacing reload timer Previously the presets handler in the GUI was on a timer. Because of this, error messages got suppressed after the first one (even if the error message is different from the one originally suppressed). Add a "reload presets" button which forces the preset to reload, and always provides an error message if the reload failed. Fixes: #26707 --- Source/QtDialog/CMakeSetupDialog.cxx | 2 ++ Source/QtDialog/CMakeSetupDialog.ui | 7 +++++++ Source/QtDialog/QCMake.cxx | 14 +------------- Source/QtDialog/QCMake.h | 6 ++---- Tests/CMakeGUI/CMakeGUITest.cxx | 13 +++++++++---- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index a7ae291..9270d35 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -275,6 +275,8 @@ void CMakeSetupDialog::initialize() QObject::connect(this->BrowseSourceDirectoryButton, &QAbstractButton::clicked, this, &CMakeSetupDialog::doSourceBrowse); + QObject::connect(this->ReloadPresetsButton, &QAbstractButton::clicked, + this->CMakeThread->cmakeInstance(), &QCMake::loadPresets); QObject::connect(this->BrowseBinaryDirectoryButton, &QAbstractButton::clicked, this, &CMakeSetupDialog::doBinaryBrowse); diff --git a/Source/QtDialog/CMakeSetupDialog.ui b/Source/QtDialog/CMakeSetupDialog.ui index c17c414..0289b0a 100644 --- a/Source/QtDialog/CMakeSetupDialog.ui +++ b/Source/QtDialog/CMakeSetupDialog.ui @@ -74,6 +74,13 @@ + + + + Reload &presets + + + diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index dac4f53..f81f107 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -64,17 +64,6 @@ QCMake::QCMake(QObject* p) for (cmake::GeneratorInfo const& gen : generators) { this->AvailableGenerators.push_back(gen); } - - connect(&this->LoadPresetsTimer, &QTimer::timeout, this, [this]() { - this->loadPresets(); - if (!this->PresetName.isEmpty() && - this->CMakePresetsGraph.ConfigurePresets.find( - std::string(this->PresetName.toStdString())) == - this->CMakePresetsGraph.ConfigurePresets.end()) { - this->setPreset(QString{}); - } - }); - this->LoadPresetsTimer.start(1000); } QCMake::~QCMake() = default; @@ -572,13 +561,12 @@ void QCMake::loadPresets() { auto result = this->CMakePresetsGraph.ReadProjectPresets( this->SourceDirectory.toStdString(), true); - if (result != this->LastLoadPresetsResult && !result) { + if (!result) { emit this->presetLoadError( this->SourceDirectory, QString::fromStdString( this->CMakePresetsGraph.parseState.GetErrorMessage(false))); } - this->LastLoadPresetsResult = result; QVector presets; for (auto const& name : this->CMakePresetsGraph.ConfigurePresetOrder) { diff --git a/Source/QtDialog/QCMake.h b/Source/QtDialog/QCMake.h index 71e8656..2bffd70 100644 --- a/Source/QtDialog/QCMake.h +++ b/Source/QtDialog/QCMake.h @@ -124,6 +124,8 @@ public slots: void setWarnUninitializedMode(bool value); /// check if project IDE open is possible and emit openPossible signal void checkOpenPossible(); + /// Reload the preset files and tree + void loadPresets(); public: /// get the list of cache properties @@ -193,8 +195,6 @@ protected: void stderrCallback(std::string const& msg); void setUpEnvironment() const; - void loadPresets(); - bool WarnUninitializedMode; QString SourceDirectory; QString BinaryDirectory; @@ -204,11 +204,9 @@ protected: QString Toolset; std::vector AvailableGenerators; cmCMakePresetsGraph CMakePresetsGraph; - bool LastLoadPresetsResult = true; QString PresetName; QString CMakeExecutable; QAtomicInt InterruptFlag; QProcessEnvironment StartEnvironment; QProcessEnvironment Environment; - QTimer LoadPresetsTimer; }; diff --git a/Tests/CMakeGUI/CMakeGUITest.cxx b/Tests/CMakeGUI/CMakeGUITest.cxx index a3414fd..d4fdfc8 100644 --- a/Tests/CMakeGUI/CMakeGUITest.cxx +++ b/Tests/CMakeGUI/CMakeGUITest.cxx @@ -359,13 +359,15 @@ void CMakeGUITest::changingPresets() QCOMPARE(this->m_window->Preset->isEnabled(), false); writePresets("build1", { "preset" }); - loopSleep(1500); + this->m_window->ReloadPresetsButton->click(); + loopSleep(); QCOMPARE(this->m_window->Preset->presetName(), QString{}); QCOMPARE(this->m_window->Preset->presets().size(), 1); QCOMPARE(this->m_window->BinaryDirectory->currentText(), ""); QCOMPARE(this->m_window->Preset->isEnabled(), true); this->m_window->Preset->setPresetName("preset"); + this->m_window->ReloadPresetsButton->click(); loopSleep(); QCOMPARE(this->m_window->Preset->presetName(), "preset"); QCOMPARE(this->m_window->Preset->presets().size(), 1); @@ -374,7 +376,8 @@ void CMakeGUITest::changingPresets() QCOMPARE(this->m_window->Preset->isEnabled(), true); writePresets("build2", { "preset2", "preset" }); - loopSleep(1500); + this->m_window->ReloadPresetsButton->click(); + loopSleep(); QCOMPARE(this->m_window->Preset->presetName(), "preset"); QCOMPARE(this->m_window->Preset->presets().size(), 2); QCOMPARE(this->m_window->BinaryDirectory->currentText(), @@ -382,7 +385,8 @@ void CMakeGUITest::changingPresets() QCOMPARE(this->m_window->Preset->isEnabled(), true); writePresets("build3", { "preset2" }); - loopSleep(1500); + this->m_window->ReloadPresetsButton->click(); + loopSleep(); QCOMPARE(this->m_window->Preset->presetName(), QString{}); QCOMPARE(this->m_window->Preset->presets().size(), 1); QCOMPARE(this->m_window->BinaryDirectory->currentText(), @@ -420,7 +424,8 @@ void CMakeGUITest::changingPresets() QFile(CMakeGUITest_BINARY_DIR "/changingPresets/src2/CMakePresets.json") .remove(); - loopSleep(1500); + this->m_window->ReloadPresetsButton->click(); + loopSleep(); QCOMPARE(this->m_window->Preset->presetName(), QString{}); QCOMPARE(this->m_window->Preset->presets().size(), 0); QCOMPARE(this->m_window->BinaryDirectory->currentText(), -- cgit v0.12