diff --git a/src/plugins/nim/CMakeLists.txt b/src/plugins/nim/CMakeLists.txt index 02cf6356f4f..85a3a204ed0 100644 --- a/src/plugins/nim/CMakeLists.txt +++ b/src/plugins/nim/CMakeLists.txt @@ -24,7 +24,6 @@ add_qtc_plugin(Nim project/nimproject.cpp project/nimproject.h project/nimrunconfiguration.cpp project/nimrunconfiguration.h project/nimtoolchain.cpp project/nimtoolchain.h - project/nimtoolchainfactory.cpp project/nimtoolchainfactory.h settings/nimcodestylepreferencesfactory.cpp settings/nimcodestylepreferencesfactory.h settings/nimcodestylepreferenceswidget.cpp settings/nimcodestylepreferenceswidget.h settings/nimcodestylesettingspage.cpp settings/nimcodestylesettingspage.h diff --git a/src/plugins/nim/nim.qbs b/src/plugins/nim/nim.qbs index 34a20473b8f..d1ceb5007c8 100644 --- a/src/plugins/nim/nim.qbs +++ b/src/plugins/nim/nim.qbs @@ -46,7 +46,6 @@ QtcPlugin { "nimproject.h", "nimproject.cpp", "nimrunconfiguration.h", "nimrunconfiguration.cpp", "nimtoolchain.h", "nimtoolchain.cpp", - "nimtoolchainfactory.h", "nimtoolchainfactory.cpp", "nimblebuildstep.h", "nimblebuildstep.cpp", "nimbleproject.h", "nimbleproject.cpp", "nimblerunconfiguration.h", "nimblerunconfiguration.cpp", diff --git a/src/plugins/nim/nimplugin.cpp b/src/plugins/nim/nimplugin.cpp index 09b730c3aba..1b435ae0ebd 100644 --- a/src/plugins/nim/nimplugin.cpp +++ b/src/plugins/nim/nimplugin.cpp @@ -14,7 +14,7 @@ #include "project/nimproject.h" #include "project/nimbleproject.h" #include "project/nimrunconfiguration.h" -#include "project/nimtoolchainfactory.h" +#include "project/nimtoolchain.h" #include "project/nimblebuildstep.h" #include "project/nimbletaskstep.h" #include "settings/nimcodestylepreferencesfactory.h" diff --git a/src/plugins/nim/project/nimtoolchain.cpp b/src/plugins/nim/project/nimtoolchain.cpp index e04efeae8e3..871c4b14c33 100644 --- a/src/plugins/nim/project/nimtoolchain.cpp +++ b/src/plugins/nim/project/nimtoolchain.cpp @@ -4,13 +4,22 @@ #include "nimtoolchain.h" #include "nimconstants.h" -#include "nimtoolchainfactory.h" +#include "nimtoolchain.h" #include "nimtr.h" #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include #include using namespace ProjectExplorer; @@ -70,11 +79,6 @@ QList NimToolChain::createOutputParsers() const return {}; } -std::unique_ptr NimToolChain::createConfigurationWidget() -{ - return std::make_unique(this); -} - QString NimToolChain::compilerVersion() const { return compilerCommand().isEmpty() || m_version == std::make_tuple(-1,-1,-1) @@ -114,4 +118,133 @@ bool NimToolChain::parseVersion(const FilePath &path, std::tuple return true; } +// NimToolChainConfigWidget + +class NimToolChainConfigWidget : public ToolChainConfigWidget +{ +public: + explicit NimToolChainConfigWidget(NimToolChain *tc) + : ToolChainConfigWidget(tc) + , m_compilerCommand(new PathChooser) + , m_compilerVersion(new QLineEdit) + { + // Create ui + const auto gnuVersionArgs = QStringList("--version"); + m_compilerCommand->setExpectedKind(PathChooser::ExistingCommand); + m_compilerCommand->setCommandVersionArguments(gnuVersionArgs); + m_mainLayout->addRow(Tr::tr("&Compiler path:"), m_compilerCommand); + m_compilerVersion->setReadOnly(true); + m_mainLayout->addRow(Tr::tr("&Compiler version:"), m_compilerVersion); + + // Fill + fillUI(); + + // Connect + connect(m_compilerCommand, &PathChooser::validChanged, this, [this] { + const FilePath path = m_compilerCommand->rawFilePath(); + auto tc = static_cast(toolChain()); + QTC_ASSERT(tc, return); + tc->setCompilerCommand(path); + fillUI(); + }); + } + +protected: + void applyImpl() final; + void discardImpl() final; + bool isDirtyImpl() const final; + void makeReadOnlyImpl() final; + +private: + void fillUI(); + + Utils::PathChooser *m_compilerCommand; + QLineEdit *m_compilerVersion; +}; + +void NimToolChainConfigWidget::applyImpl() +{ + auto tc = static_cast(toolChain()); + Q_ASSERT(tc); + if (tc->isAutoDetected()) + return; + tc->setCompilerCommand(m_compilerCommand->filePath()); +} + +void NimToolChainConfigWidget::discardImpl() +{ + fillUI(); +} + +bool NimToolChainConfigWidget::isDirtyImpl() const +{ + auto tc = static_cast(toolChain()); + Q_ASSERT(tc); + return tc->compilerCommand() != m_compilerCommand->filePath(); +} + +void NimToolChainConfigWidget::makeReadOnlyImpl() +{ + m_compilerCommand->setReadOnly(true); +} + +void NimToolChainConfigWidget::fillUI() +{ + auto tc = static_cast(toolChain()); + Q_ASSERT(tc); + m_compilerCommand->setFilePath(tc->compilerCommand()); + m_compilerVersion->setText(tc->compilerVersion()); +} + +std::unique_ptr NimToolChain::createConfigurationWidget() +{ + return std::make_unique(this); +} + +// NimToolChainFactory + +NimToolChainFactory::NimToolChainFactory() +{ + setDisplayName(Tr::tr("Nim")); + setSupportedToolChainType(Constants::C_NIMTOOLCHAIN_TYPEID); + setSupportedLanguages({Constants::C_NIMLANGUAGE_ID}); + setToolchainConstructor([] { return new NimToolChain; }); + setUserCreatable(true); +} + +Toolchains NimToolChainFactory::autoDetect(const ToolchainDetector &detector) const +{ + Toolchains result; + + const FilePath compilerPath = detector.device->searchExecutableInPath("nim"); + if (compilerPath.isEmpty()) + return result; + + result = Utils::filtered(detector.alreadyKnown, [compilerPath](ToolChain *tc) { + return tc->typeId() == Constants::C_NIMTOOLCHAIN_TYPEID + && tc->compilerCommand() == compilerPath; + }); + + if (!result.empty()) + return result; + + auto tc = new NimToolChain; + tc->setDetection(ToolChain::AutoDetection); + tc->setCompilerCommand(compilerPath); + result.append(tc); + return result; +} + +Toolchains NimToolChainFactory::detectForImport(const ToolChainDescription &tcd) const +{ + Toolchains result; + if (tcd.language == Constants::C_NIMLANGUAGE_ID) { + auto tc = new NimToolChain; + tc->setDetection(ToolChain::ManualDetection); // FIXME: sure? + tc->setCompilerCommand(tcd.compilerPath); + result.append(tc); + } + return result; +} + } // Nim diff --git a/src/plugins/nim/project/nimtoolchain.h b/src/plugins/nim/project/nimtoolchain.h index 087f44cd2eb..c86a35a91a2 100644 --- a/src/plugins/nim/project/nimtoolchain.h +++ b/src/plugins/nim/project/nimtoolchain.h @@ -34,4 +34,13 @@ private: std::tuple m_version; }; +class NimToolChainFactory : public ProjectExplorer::ToolChainFactory +{ +public: + NimToolChainFactory(); + + ProjectExplorer::Toolchains autoDetect(const ProjectExplorer::ToolchainDetector &detector) const final; + ProjectExplorer::Toolchains detectForImport(const ProjectExplorer::ToolChainDescription &tcd) const final; +}; + } // Nim diff --git a/src/plugins/nim/project/nimtoolchainfactory.cpp b/src/plugins/nim/project/nimtoolchainfactory.cpp deleted file mode 100644 index 415e7e76962..00000000000 --- a/src/plugins/nim/project/nimtoolchainfactory.cpp +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (C) Filippo Cucchetto -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#include "nimtoolchainfactory.h" - -#include "nimconstants.h" -#include "nimtoolchain.h" -#include "nimtr.h" - -#include - -#include -#include -#include -#include -#include - -#include - -using namespace ProjectExplorer; -using namespace Utils; - -namespace Nim { - -NimToolChainFactory::NimToolChainFactory() -{ - setDisplayName(Tr::tr("Nim")); - setSupportedToolChainType(Constants::C_NIMTOOLCHAIN_TYPEID); - setSupportedLanguages({Constants::C_NIMLANGUAGE_ID}); - setToolchainConstructor([] { return new NimToolChain; }); - setUserCreatable(true); -} - -Toolchains NimToolChainFactory::autoDetect(const ToolchainDetector &detector) const -{ - Toolchains result; - - const FilePath compilerPath = detector.device->searchExecutableInPath("nim"); - if (compilerPath.isEmpty()) - return result; - - result = Utils::filtered(detector.alreadyKnown, [compilerPath](ToolChain *tc) { - return tc->typeId() == Constants::C_NIMTOOLCHAIN_TYPEID - && tc->compilerCommand() == compilerPath; - }); - - if (!result.empty()) - return result; - - auto tc = new NimToolChain; - tc->setDetection(ToolChain::AutoDetection); - tc->setCompilerCommand(compilerPath); - result.append(tc); - return result; -} - -Toolchains NimToolChainFactory::detectForImport(const ToolChainDescription &tcd) const -{ - Toolchains result; - if (tcd.language == Constants::C_NIMLANGUAGE_ID) { - auto tc = new NimToolChain; - tc->setDetection(ToolChain::ManualDetection); // FIXME: sure? - tc->setCompilerCommand(tcd.compilerPath); - result.append(tc); - } - return result; -} - -NimToolChainConfigWidget::NimToolChainConfigWidget(NimToolChain *tc) - : ToolChainConfigWidget(tc) - , m_compilerCommand(new PathChooser) - , m_compilerVersion(new QLineEdit) -{ - // Create ui - const auto gnuVersionArgs = QStringList("--version"); - m_compilerCommand->setExpectedKind(PathChooser::ExistingCommand); - m_compilerCommand->setCommandVersionArguments(gnuVersionArgs); - m_mainLayout->addRow(Tr::tr("&Compiler path:"), m_compilerCommand); - m_compilerVersion->setReadOnly(true); - m_mainLayout->addRow(Tr::tr("&Compiler version:"), m_compilerVersion); - - // Fill - fillUI(); - - // Connect - connect(m_compilerCommand, &PathChooser::validChanged, this, [this] { - const FilePath path = m_compilerCommand->rawFilePath(); - auto tc = static_cast(toolChain()); - QTC_ASSERT(tc, return); - tc->setCompilerCommand(path); - fillUI(); - }); -} - -void NimToolChainConfigWidget::applyImpl() -{ - auto tc = static_cast(toolChain()); - Q_ASSERT(tc); - if (tc->isAutoDetected()) - return; - tc->setCompilerCommand(m_compilerCommand->filePath()); -} - -void NimToolChainConfigWidget::discardImpl() -{ - fillUI(); -} - -bool NimToolChainConfigWidget::isDirtyImpl() const -{ - auto tc = static_cast(toolChain()); - Q_ASSERT(tc); - return tc->compilerCommand() != m_compilerCommand->filePath(); -} - -void NimToolChainConfigWidget::makeReadOnlyImpl() -{ - m_compilerCommand->setReadOnly(true); -} - -void NimToolChainConfigWidget::fillUI() -{ - auto tc = static_cast(toolChain()); - Q_ASSERT(tc); - m_compilerCommand->setFilePath(tc->compilerCommand()); - m_compilerVersion->setText(tc->compilerVersion()); -} - -} diff --git a/src/plugins/nim/project/nimtoolchainfactory.h b/src/plugins/nim/project/nimtoolchainfactory.h deleted file mode 100644 index 96fc55b8e56..00000000000 --- a/src/plugins/nim/project/nimtoolchainfactory.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) Filippo Cucchetto -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#pragma once - -#include -#include - -namespace Utils { class PathChooser; } - -namespace Nim { - -class NimToolChain; - -class NimToolChainFactory : public ProjectExplorer::ToolChainFactory -{ -public: - NimToolChainFactory(); - - ProjectExplorer::Toolchains autoDetect(const ProjectExplorer::ToolchainDetector &detector) const final; - ProjectExplorer::Toolchains detectForImport(const ProjectExplorer::ToolChainDescription &tcd) const final; -}; - -class NimToolChainConfigWidget : public ProjectExplorer::ToolChainConfigWidget -{ - Q_OBJECT - -public: - explicit NimToolChainConfigWidget(NimToolChain *tc); - -protected: - void applyImpl() final; - void discardImpl() final; - bool isDirtyImpl() const final; - void makeReadOnlyImpl() final; - -private: - void fillUI(); - - Utils::PathChooser *m_compilerCommand; - QLineEdit *m_compilerVersion; -}; - -} // Nim