diff --git a/src/plugins/haskell/haskellconstants.h b/src/plugins/haskell/haskellconstants.h index 7561a53a040..b632eb6ac9c 100644 --- a/src/plugins/haskell/haskellconstants.h +++ b/src/plugins/haskell/haskellconstants.h @@ -3,8 +3,7 @@ #pragma once -namespace Haskell { -namespace Constants { +namespace Haskell::Constants { const char C_HASKELLEDITOR_ID[] = "Haskell.HaskellEditor"; const char C_HASKELLSNIPPETSGROUP_ID[] = "Haskell"; @@ -15,5 +14,4 @@ const char C_STACK_BUILD_STEP_ID[] = "Haskell.Stack.Build"; const char OPTIONS_GENERAL[] = "Haskell.A.General"; const char A_RUN_GHCI[] = "Haskell.RunGHCi"; -} // namespace Haskell -} // namespace Constants +} // Haskell::Constants diff --git a/src/plugins/haskell/haskelleditorfactory.cpp b/src/plugins/haskell/haskelleditorfactory.cpp index a2ddcb293ab..3371a8734c9 100644 --- a/src/plugins/haskell/haskelleditorfactory.cpp +++ b/src/plugins/haskell/haskelleditorfactory.cpp @@ -26,7 +26,7 @@ static QWidget *createEditorWidget() auto ghciButton = new Core::CommandButton(Constants::A_RUN_GHCI, widget); ghciButton->setText(Tr::tr("GHCi")); QObject::connect(ghciButton, &QToolButton::clicked, widget, [widget] { - HaskellManager::openGhci(widget->textDocument()->filePath()); + openGhci(widget->textDocument()->filePath()); }); widget->insertExtraToolBarWidget(TextEditorWidget::Left, ghciButton); return widget; diff --git a/src/plugins/haskell/haskellmanager.cpp b/src/plugins/haskell/haskellmanager.cpp index cc91ae7f816..bd0fe2d2cdb 100644 --- a/src/plugins/haskell/haskellmanager.cpp +++ b/src/plugins/haskell/haskellmanager.cpp @@ -3,24 +3,27 @@ #include "haskellmanager.h" +#include "haskellconstants.h" #include "haskellsettings.h" #include "haskelltr.h" +#include +#include + #include #include -#include #include #include -#include #include #include +using namespace Core; using namespace Utils; namespace Haskell::Internal { -FilePath HaskellManager::findProjectDirectory(const FilePath &filePath) +FilePath findProjectDirectory(const FilePath &filePath) { if (filePath.isEmpty()) return {}; @@ -36,7 +39,7 @@ FilePath HaskellManager::findProjectDirectory(const FilePath &filePath) return {}; } -void HaskellManager::openGhci(const FilePath &haskellFile) +void openGhci(const FilePath &haskellFile) { const QList mimeTypes = mimeTypesForFileName(haskellFile.toString()); const bool isHaskell = Utils::anyOf(mimeTypes, [](const MimeType &mt) { @@ -51,4 +54,14 @@ void HaskellManager::openGhci(const FilePath &haskellFile) p.start(); } +void setupHaskellActions(QObject *guard) +{ + ActionBuilder runGhci(guard, Haskell::Constants::A_RUN_GHCI); + runGhci.setText(Tr::tr("Run GHCi")); + runGhci.setOnTriggered(guard, [] { + if (IDocument *doc = EditorManager::currentDocument()) + openGhci(doc->filePath()); + }); +} + } // Haskell::Internal diff --git a/src/plugins/haskell/haskellmanager.h b/src/plugins/haskell/haskellmanager.h index 862f46460f1..ad540d86e97 100644 --- a/src/plugins/haskell/haskellmanager.h +++ b/src/plugins/haskell/haskellmanager.h @@ -5,17 +5,13 @@ #include -#include +namespace Utils { class FilePath; } namespace Haskell::Internal { -class HaskellManager -{ -public: - static HaskellManager *instance(); +Utils::FilePath findProjectDirectory(const Utils::FilePath &filePath); +void openGhci(const Utils::FilePath &haskellFile); - static Utils::FilePath findProjectDirectory(const Utils::FilePath &filePath); - static void openGhci(const Utils::FilePath &haskellFile); -}; +void setupHaskellActions(QObject *guard); } // Haskell::Internal diff --git a/src/plugins/haskell/haskellplugin.cpp b/src/plugins/haskell/haskellplugin.cpp index 632b9514a98..f8c32dc288d 100644 --- a/src/plugins/haskell/haskellplugin.cpp +++ b/src/plugins/haskell/haskellplugin.cpp @@ -10,30 +10,14 @@ #include "haskelltr.h" #include "stackbuildstep.h" -#include -#include -#include - #include #include #include -#include - namespace Haskell::Internal { -static void registerGhciAction(QObject *guard) -{ - QAction *action = new QAction(Tr::tr("Run GHCi"), guard); - Core::ActionManager::registerAction(action, Constants::A_RUN_GHCI); - QObject::connect(action, &QAction::triggered, guard, [] { - if (Core::IDocument *doc = Core::EditorManager::currentDocument()) - HaskellManager::openGhci(doc->filePath()); - }); -} - class HaskellPlugin final : public ExtensionSystem::IPlugin { Q_OBJECT @@ -54,7 +38,7 @@ public: TextEditor::SnippetProvider::registerGroup(Constants::C_HASKELLSNIPPETSGROUP_ID, Tr::tr("Haskell", "SnippetProvider")); - registerGhciAction(this); + setupHaskellActions(this); ProjectExplorer::JsonWizardFactory::addWizardPath(":/haskell/share/wizards/"); }