diff --git a/src/libs/utils/aspects.cpp b/src/libs/utils/aspects.cpp index fc78b7d2d86..b14a429ed92 100644 --- a/src/libs/utils/aspects.cpp +++ b/src/libs/utils/aspects.cpp @@ -3127,6 +3127,11 @@ QList> AspectList::volatileItems() const return d->volatileItems; } +std::shared_ptr AspectList::createAndAddItem() +{ + return addItem(d->createItem()); +} + std::shared_ptr AspectList::addItem(const std::shared_ptr &item) { if (undoStack()) diff --git a/src/libs/utils/aspects.h b/src/libs/utils/aspects.h index d5d47a79d7e..e46ce5ab9b8 100644 --- a/src/libs/utils/aspects.h +++ b/src/libs/utils/aspects.h @@ -1026,6 +1026,7 @@ public: QList> items() const; QList> volatileItems() const; + std::shared_ptr createAndAddItem(); std::shared_ptr addItem(const std::shared_ptr &item); std::shared_ptr actualAddItem(const std::shared_ptr &item); diff --git a/src/plugins/compilerexplorer/compilerexplorereditor.cpp b/src/plugins/compilerexplorer/compilerexplorereditor.cpp index 3e11f667d6c..7946e92b821 100644 --- a/src/plugins/compilerexplorer/compilerexplorereditor.cpp +++ b/src/plugins/compilerexplorer/compilerexplorereditor.cpp @@ -216,7 +216,10 @@ SourceEditorWidget::SourceEditorWidget(const std::shared_ptr &se auto addCompilerButton = new QPushButton; addCompilerButton->setText(Tr::tr("Add compiler")); - connect(addCompilerButton, &QPushButton::clicked, this, &SourceEditorWidget::addCompiler); + connect(addCompilerButton, + &QPushButton::clicked, + &settings->compilers, + &AspectList::createAndAddItem); auto removeSourceButton = new QPushButton; removeSourceButton->setIcon(Utils::Icons::EDIT_CLEAR.icon()); @@ -575,12 +578,6 @@ void EditorWidget::addSourceEditor(const std::shared_ptr &source setupHelpWidget(); }); - connect(sourceEditor, &SourceEditorWidget::addCompiler, this, [sourceSettings]() { - auto newCompiler = std::make_shared(sourceSettings->apiConfigFunction()); - newCompiler->setLanguageId(sourceSettings->languageId()); - sourceSettings->compilers.addItem(newCompiler); - }); - connect(sourceEditor, &SourceEditorWidget::gotFocus, this, [this]() { m_actionHandler.updateCurrentEditor(); }); @@ -725,8 +722,8 @@ QWidget *EditorWidget::createHelpWidget() const auto w = new HelperWidget; connect(w, &HelperWidget::addSource, - m_document->settings(), - &CompilerExplorerSettings::addNewSource); + &m_document->settings()->m_sources, + &AspectList::createAndAddItem); return w; } @@ -792,8 +789,8 @@ QWidget *Editor::toolBar() connect(newSource, &QAction::triggered, - m_document->settings(), - &CompilerExplorerSettings::addNewSource); + &m_document->settings()->m_sources, + &AspectList::createAndAddItem); } return m_toolBar.get(); diff --git a/src/plugins/compilerexplorer/compilerexplorereditor.h b/src/plugins/compilerexplorer/compilerexplorereditor.h index 2db21e4808c..510e5e9eb3c 100644 --- a/src/plugins/compilerexplorer/compilerexplorereditor.h +++ b/src/plugins/compilerexplorer/compilerexplorereditor.h @@ -130,7 +130,6 @@ public: signals: void sourceCodeChanged(); - void addCompiler(); void remove(); void gotFocus(); diff --git a/src/plugins/compilerexplorer/compilerexplorersettings.cpp b/src/plugins/compilerexplorer/compilerexplorersettings.cpp index 94059052d3b..8accdbcc214 100644 --- a/src/plugins/compilerexplorer/compilerexplorersettings.cpp +++ b/src/plugins/compilerexplorer/compilerexplorersettings.cpp @@ -337,10 +337,4 @@ CompilerExplorerSettings::CompilerExplorerSettings() CompilerExplorerSettings::~CompilerExplorerSettings() = default; -void CompilerExplorerSettings::addNewSource() -{ - auto newSource = std::make_shared([this] { return apiConfig(); }); - m_sources.addItem(newSource); -} - } // namespace CompilerExplorer diff --git a/src/plugins/compilerexplorer/compilerexplorersettings.h b/src/plugins/compilerexplorer/compilerexplorersettings.h index fadb03798f6..64f67122fe6 100644 --- a/src/plugins/compilerexplorer/compilerexplorersettings.h +++ b/src/plugins/compilerexplorer/compilerexplorersettings.h @@ -41,8 +41,6 @@ public: return Api::Config(m_networkAccessManager, compilerExplorerUrl()); } - void addNewSource(); - QNetworkAccessManager *networkAccessManager() const { return m_networkAccessManager; } private: