diff options
author | hjk <[email protected]> | 2023-05-15 15:15:17 +0200 |
---|---|---|
committer | hjk <[email protected]> | 2023-05-16 11:19:14 +0000 |
commit | 22fa5f2d3a600f9932a3abc3c71a72cd45c7f3ee (patch) | |
tree | a0846f8fec399cbbc65021176af2623637c114a0 /src/plugins | |
parent | 21cb45e665c2247cdc7abe6c9e002c0900842098 (diff) |
Haskell: More compact settings/manager setup
Use PagedSettings, move related parts Manager interface there, too.
Change-Id: I079dad8bbbea39d2424a25867b08c34ab0234ad5
Reviewed-by: Christian Stenger <[email protected]>
Reviewed-by: Eike Ziller <[email protected]>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/haskell/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/plugins/haskell/haskell.qbs | 2 | ||||
-rw-r--r-- | src/plugins/haskell/haskelleditorfactory.cpp | 14 | ||||
-rw-r--r-- | src/plugins/haskell/haskelleditorfactory.h | 6 | ||||
-rw-r--r-- | src/plugins/haskell/haskellmanager.cpp | 67 | ||||
-rw-r--r-- | src/plugins/haskell/haskellmanager.h | 21 | ||||
-rw-r--r-- | src/plugins/haskell/haskellplugin.cpp | 18 | ||||
-rw-r--r-- | src/plugins/haskell/haskellrunconfiguration.cpp | 4 | ||||
-rw-r--r-- | src/plugins/haskell/haskellsettings.cpp | 63 | ||||
-rw-r--r-- | src/plugins/haskell/haskellsettings.h (renamed from src/plugins/haskell/optionspage.h) | 8 | ||||
-rw-r--r-- | src/plugins/haskell/optionspage.cpp | 51 | ||||
-rw-r--r-- | src/plugins/haskell/stackbuildstep.cpp | 4 |
12 files changed, 95 insertions, 165 deletions
diff --git a/src/plugins/haskell/CMakeLists.txt b/src/plugins/haskell/CMakeLists.txt index 0f43b456999..d45326695cb 100644 --- a/src/plugins/haskell/CMakeLists.txt +++ b/src/plugins/haskell/CMakeLists.txt @@ -12,9 +12,9 @@ add_qtc_plugin(Haskell haskellplugin.cpp haskellplugin.h haskellproject.cpp haskellproject.h haskellrunconfiguration.cpp haskellrunconfiguration.h + haskellsettings.cpp haskellsettings.h haskelltokenizer.cpp haskelltokenizer.h haskelltr.h - optionspage.cpp optionspage.h stackbuildstep.cpp stackbuildstep.h ) diff --git a/src/plugins/haskell/haskell.qbs b/src/plugins/haskell/haskell.qbs index 30eb8328f1a..5c1be115387 100644 --- a/src/plugins/haskell/haskell.qbs +++ b/src/plugins/haskell/haskell.qbs @@ -21,8 +21,8 @@ QtcPlugin { "haskellplugin.cpp", "haskellplugin.h", "haskellproject.cpp", "haskellproject.h", "haskellrunconfiguration.cpp", "haskellrunconfiguration.h", + "haskellsettings.cpp", "haskellsettings.h", "haskelltokenizer.cpp", "haskelltokenizer.h", - "optionspage.cpp", "optionspage.h", "stackbuildstep.cpp", "stackbuildstep.h" ] } diff --git a/src/plugins/haskell/haskelleditorfactory.cpp b/src/plugins/haskell/haskelleditorfactory.cpp index 4053efeba2d..ba87f88ef70 100644 --- a/src/plugins/haskell/haskelleditorfactory.cpp +++ b/src/plugins/haskell/haskelleditorfactory.cpp @@ -14,17 +14,14 @@ #include <texteditor/texteditoractionhandler.h> #include <texteditor/textindenter.h> -#include <QCoreApplication> +namespace Haskell::Internal { -namespace Haskell { -namespace Internal { - -static QWidget *createEditorWidget() +static QWidget *createEditorWidget(QObject *guard) { auto widget = new TextEditor::TextEditorWidget; auto ghciButton = new Core::CommandButton(Constants::A_RUN_GHCI, widget); ghciButton->setText(Tr::tr("GHCi")); - QObject::connect(ghciButton, &QToolButton::clicked, HaskellManager::instance(), [widget] { + QObject::connect(ghciButton, &QToolButton::clicked, guard, [widget] { HaskellManager::openGhci(widget->textDocument()->filePath()); }); widget->insertExtraToolBarWidget(TextEditor::TextEditorWidget::Left, ghciButton); @@ -40,12 +37,11 @@ HaskellEditorFactory::HaskellEditorFactory() | TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor); setDocumentCreator([] { return new TextEditor::TextDocument(Constants::C_HASKELLEDITOR_ID); }); setIndenterCreator([](QTextDocument *doc) { return new TextEditor::TextIndenter(doc); }); - setEditorWidgetCreator(createEditorWidget); + setEditorWidgetCreator([this] { return createEditorWidget(this); }); setCommentDefinition(Utils::CommentDefinition("--", "{-", "-}")); setParenthesesMatchingEnabled(true); setMarksVisible(true); setSyntaxHighlighterCreator([] { return new HaskellHighlighter(); }); } -} // Internal -} // Haskell +} // Haskell::Internal diff --git a/src/plugins/haskell/haskelleditorfactory.h b/src/plugins/haskell/haskelleditorfactory.h index c91f875df29..090a5b12782 100644 --- a/src/plugins/haskell/haskelleditorfactory.h +++ b/src/plugins/haskell/haskelleditorfactory.h @@ -5,8 +5,7 @@ #include <texteditor/texteditor.h> -namespace Haskell { -namespace Internal { +namespace Haskell::Internal { class HaskellEditorFactory : public TextEditor::TextEditorFactory { @@ -14,5 +13,4 @@ public: HaskellEditorFactory(); }; -} // Internal -} // Haskell +} // Haskell::Internal diff --git a/src/plugins/haskell/haskellmanager.cpp b/src/plugins/haskell/haskellmanager.cpp index 78134d4b159..94a03ec659e 100644 --- a/src/plugins/haskell/haskellmanager.cpp +++ b/src/plugins/haskell/haskellmanager.cpp @@ -3,9 +3,9 @@ #include "haskellmanager.h" +#include "haskellsettings.h" #include "haskelltr.h" -#include <coreplugin/messagemanager.h> #include <utils/algorithm.h> #include <utils/commandline.h> #include <utils/hostosinfo.h> @@ -13,33 +13,12 @@ #include <utils/process.h> #include <utils/processenums.h> -#include <QCoreApplication> #include <QDir> #include <QFileInfo> -#include <QSettings> - -#include <unordered_map> - -static const char kStackExecutableKey[] = "Haskell/StackExecutable"; using namespace Utils; -namespace Haskell { -namespace Internal { - -class HaskellManagerPrivate -{ -public: - FilePath stackExecutable; -}; - -Q_GLOBAL_STATIC(HaskellManagerPrivate, m_d) -Q_GLOBAL_STATIC(HaskellManager, m_instance) - -HaskellManager *HaskellManager::instance() -{ - return m_instance; -} +namespace Haskell::Internal { FilePath HaskellManager::findProjectDirectory(const FilePath &filePath) { @@ -57,28 +36,6 @@ FilePath HaskellManager::findProjectDirectory(const FilePath &filePath) return {}; } -FilePath defaultStackExecutable() -{ - // stack from brew or the installer script from https://docs.haskellstack.org - // install to /usr/local/bin. - if (HostOsInfo::isAnyUnixHost()) - return FilePath::fromString("/usr/local/bin/stack"); - return FilePath::fromString("stack"); -} - -FilePath HaskellManager::stackExecutable() -{ - return m_d->stackExecutable; -} - -void HaskellManager::setStackExecutable(const FilePath &filePath) -{ - if (filePath == m_d->stackExecutable) - return; - m_d->stackExecutable = filePath; - emit m_instance->stackExecutableChanged(m_d->stackExecutable); -} - void HaskellManager::openGhci(const FilePath &haskellFile) { const QList<MimeType> mimeTypes = mimeTypesForFileName(haskellFile.toString()); @@ -89,25 +46,9 @@ void HaskellManager::openGhci(const FilePath &haskellFile) + (isHaskell ? QStringList{haskellFile.fileName()} : QStringList()); Process p; p.setTerminalMode(TerminalMode::Detached); - p.setCommand({stackExecutable(), args}); + p.setCommand({settings().stackPath.filePath(), args}); p.setWorkingDirectory(haskellFile.absolutePath()); p.start(); } -void HaskellManager::readSettings(QSettings *settings) -{ - m_d->stackExecutable = FilePath::fromString( - settings->value(kStackExecutableKey, defaultStackExecutable().toString()).toString()); - emit m_instance->stackExecutableChanged(m_d->stackExecutable); -} - -void HaskellManager::writeSettings(QSettings *settings) -{ - if (m_d->stackExecutable == defaultStackExecutable()) - settings->remove(kStackExecutableKey); - else - settings->setValue(kStackExecutableKey, m_d->stackExecutable.toString()); -} - -} // namespace Internal -} // namespace Haskell +} // Haskell::Internal diff --git a/src/plugins/haskell/haskellmanager.h b/src/plugins/haskell/haskellmanager.h index da4018930d1..862f46460f1 100644 --- a/src/plugins/haskell/haskellmanager.h +++ b/src/plugins/haskell/haskellmanager.h @@ -7,30 +7,15 @@ #include <utils/fileutils.h> -QT_BEGIN_NAMESPACE -class QSettings; -QT_END_NAMESPACE +namespace Haskell::Internal { -namespace Haskell { -namespace Internal { - -class HaskellManager : public QObject +class HaskellManager { - Q_OBJECT - public: static HaskellManager *instance(); static Utils::FilePath findProjectDirectory(const Utils::FilePath &filePath); - static Utils::FilePath stackExecutable(); - static void setStackExecutable(const Utils::FilePath &filePath); static void openGhci(const Utils::FilePath &haskellFile); - static void readSettings(QSettings *settings); - static void writeSettings(QSettings *settings); - -signals: - void stackExecutableChanged(const Utils::FilePath &filePath); }; -} // namespace Internal -} // namespace Haskell +} // Haskell::Internal diff --git a/src/plugins/haskell/haskellplugin.cpp b/src/plugins/haskell/haskellplugin.cpp index 334c1049112..84a86f7db48 100644 --- a/src/plugins/haskell/haskellplugin.cpp +++ b/src/plugins/haskell/haskellplugin.cpp @@ -9,8 +9,8 @@ #include "haskellmanager.h" #include "haskellproject.h" #include "haskellrunconfiguration.h" +#include "haskellsettings.h" #include "haskelltr.h" -#include "optionspage.h" #include "stackbuildstep.h" #include <coreplugin/actionmanager/actionmanager.h> @@ -28,8 +28,8 @@ namespace Internal { class HaskellPluginPrivate { public: + HaskellSettings settings; HaskellEditorFactory editorFactory; - OptionsPage optionsPage; HaskellBuildConfigurationFactory buildConfigFactory; StackBuildStepFactory stackBuildStepFactory; HaskellRunConfigurationFactory runConfigFactory; @@ -41,11 +41,11 @@ HaskellPlugin::~HaskellPlugin() delete d; } -static void registerGhciAction() +static void registerGhciAction(QObject *guard) { - QAction *action = new QAction(Tr::tr("Run GHCi"), HaskellManager::instance()); + QAction *action = new QAction(Tr::tr("Run GHCi"), guard); Core::ActionManager::registerAction(action, Constants::A_RUN_GHCI); - QObject::connect(action, &QAction::triggered, HaskellManager::instance(), [] { + QObject::connect(action, &QAction::triggered, guard, [] { if (Core::IDocument *doc = Core::EditorManager::currentDocument()) HaskellManager::openGhci(doc->filePath()); }); @@ -63,13 +63,7 @@ bool HaskellPlugin::initialize(const QStringList &arguments, QString *errorStrin TextEditor::SnippetProvider::registerGroup(Constants::C_HASKELLSNIPPETSGROUP_ID, Tr::tr("Haskell", "SnippetProvider")); - connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested, this, [] { - HaskellManager::writeSettings(Core::ICore::settings()); - }); - - registerGhciAction(); - - HaskellManager::readSettings(Core::ICore::settings()); + registerGhciAction(this); ProjectExplorer::JsonWizardFactory::addWizardPath(":/haskell/share/wizards/"); return true; diff --git a/src/plugins/haskell/haskellrunconfiguration.cpp b/src/plugins/haskell/haskellrunconfiguration.cpp index 45b6e684bc4..9c236c65b5e 100644 --- a/src/plugins/haskell/haskellrunconfiguration.cpp +++ b/src/plugins/haskell/haskellrunconfiguration.cpp @@ -4,9 +4,9 @@ #include "haskellrunconfiguration.h" #include "haskellconstants.h" -#include "haskellmanager.h" #include "haskellproject.h" #include "haskelltr.h" +#include "haskellsettings.h" #include <projectexplorer/buildconfiguration.h> #include <projectexplorer/localenvironmentaspect.h> @@ -68,7 +68,7 @@ Runnable HaskellRunConfiguration::runnable() const r.workingDirectory = projectDirectory; r.environment = aspect<LocalEnvironmentAspect>()->environment(); - r.command = {r.environment.searchInPath(HaskellManager::stackExecutable().toString()), args}; + r.command = {r.environment.searchInPath(settings().stackPath()), args}; return r; } diff --git a/src/plugins/haskell/haskellsettings.cpp b/src/plugins/haskell/haskellsettings.cpp new file mode 100644 index 00000000000..6b0ee170368 --- /dev/null +++ b/src/plugins/haskell/haskellsettings.cpp @@ -0,0 +1,63 @@ +// Copyright (c) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "haskellsettings.h" + +#include "haskellconstants.h" +#include "haskelltr.h" + +#include <coreplugin/icore.h> + +#include <utils/hostosinfo.h> +#include <utils/pathchooser.h> +#include <utils/layoutbuilder.h> + +using namespace Utils; + +namespace Haskell::Internal { + +static HaskellSettings *theSettings; + +HaskellSettings &settings() +{ + return *theSettings; +} + +HaskellSettings::HaskellSettings() +{ + theSettings = this; + + setId(Constants::OPTIONS_GENERAL); + setDisplayName(Tr::tr("General")); + setCategory("J.Z.Haskell"); + setDisplayCategory(Tr::tr("Haskell")); + setCategoryIconPath(":/haskell/images/settingscategory_haskell.png"); + + registerAspect(&stackPath); + stackPath.setSettingsKey("Haskell/StackExecutable"); + stackPath.setDisplayStyle(StringAspect::PathChooserDisplay); + stackPath.setExpectedKind(PathChooser::ExistingCommand); + stackPath.setPromptDialogTitle(Tr::tr("Choose Stack Executable")); + stackPath.setCommandVersionArguments({"--version"}); + + // stack from brew or the installer script from https://docs.haskellstack.org + // install to /usr/local/bin. + stackPath.setDefaultFilePath(HostOsInfo::isAnyUnixHost() + ? FilePath::fromString("/usr/local/bin/stack") + : FilePath::fromString("stack")); + + setLayouter([this](QWidget *widget) { + using namespace Layouting; + Column { + Group { + title(Tr::tr("General")), + Row { Tr::tr("Stack executable:"), stackPath } + }, + st, + }.attachTo(widget); + }); + + readSettings(Core::ICore::settings()); +} + +} // Haskell::Internal diff --git a/src/plugins/haskell/optionspage.h b/src/plugins/haskell/haskellsettings.h index 4328be44e7b..c697a154ee4 100644 --- a/src/plugins/haskell/optionspage.h +++ b/src/plugins/haskell/haskellsettings.h @@ -7,10 +7,14 @@ namespace Haskell::Internal { -class OptionsPage : public Core::IOptionsPage +class HaskellSettings : public Core::PagedSettings { public: - OptionsPage(); + HaskellSettings(); + + Utils::StringAspect stackPath; }; +HaskellSettings &settings(); + } // Haskell::Internal diff --git a/src/plugins/haskell/optionspage.cpp b/src/plugins/haskell/optionspage.cpp deleted file mode 100644 index 48e5159da5a..00000000000 --- a/src/plugins/haskell/optionspage.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#include "optionspage.h" - -#include "haskellconstants.h" -#include "haskellmanager.h" -#include "haskelltr.h" - -#include <utils/pathchooser.h> -#include <utils/layoutbuilder.h> - -using namespace Utils; - -namespace Haskell::Internal { - -class HaskellOptionsPageWidget : public Core::IOptionsPageWidget -{ -public: - HaskellOptionsPageWidget() - { - auto stackPath = new PathChooser; - stackPath->setExpectedKind(PathChooser::ExistingCommand); - stackPath->setPromptDialogTitle(Tr::tr("Choose Stack Executable")); - stackPath->setFilePath(HaskellManager::stackExecutable()); - stackPath->setCommandVersionArguments({"--version"}); - - setOnApply([stackPath] { HaskellManager::setStackExecutable(stackPath->rawFilePath()); }); - - using namespace Layouting; - Column { - Group { - title(Tr::tr("General")), - Row { Tr::tr("Stack executable:"), stackPath } - }, - st, - }.attachTo(this); - } -}; - -OptionsPage::OptionsPage() -{ - setId(Constants::OPTIONS_GENERAL); - setDisplayName(Tr::tr("General")); - setCategory("J.Z.Haskell"); - setDisplayCategory(Tr::tr("Haskell")); - setCategoryIconPath(":/haskell/images/settingscategory_haskell.png"); - setWidgetCreator([] { return new HaskellOptionsPageWidget; }); -} - -} // Haskell::Internal diff --git a/src/plugins/haskell/stackbuildstep.cpp b/src/plugins/haskell/stackbuildstep.cpp index 084ba8af4a7..860ef458c5f 100644 --- a/src/plugins/haskell/stackbuildstep.cpp +++ b/src/plugins/haskell/stackbuildstep.cpp @@ -4,7 +4,7 @@ #include "stackbuildstep.h" #include "haskellconstants.h" -#include "haskellmanager.h" +#include "haskellsettings.h" #include "haskelltr.h" #include <projectexplorer/buildconfiguration.h> @@ -38,7 +38,7 @@ bool StackBuildStep::init() if (AbstractProcessStep::init()) { const auto projectDir = QDir(project()->projectDirectory().toString()); processParameters()->setCommandLine( - {HaskellManager::stackExecutable(), + {settings().stackPath.filePath(), {"build", "--work-dir", projectDir.relativeFilePath(buildDirectory().toString())}}); processParameters()->setEnvironment(buildEnvironment()); } |