From cc711d790363512e9c06fe84e997b8bbb42ea488 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 20 Nov 2023 12:57:46 +0100 Subject: [PATCH] Haskell: Use new setup for HaskellEditorFactory Change-Id: I537248460291d5d649a1dc60a5f495003d76fa8b Reviewed-by: Jarek Kobus Reviewed-by: --- src/plugins/haskell/haskelleditorfactory.cpp | 43 +++++++++++++------- src/plugins/haskell/haskelleditorfactory.h | 8 +--- src/plugins/haskell/haskellplugin.cpp | 2 +- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/plugins/haskell/haskelleditorfactory.cpp b/src/plugins/haskell/haskelleditorfactory.cpp index f3e65ffcd8e..a2ddcb293ab 100644 --- a/src/plugins/haskell/haskelleditorfactory.cpp +++ b/src/plugins/haskell/haskelleditorfactory.cpp @@ -10,38 +10,51 @@ #include #include + #include +#include #include #include +using namespace TextEditor; + namespace Haskell::Internal { static QWidget *createEditorWidget() { - auto widget = new TextEditor::TextEditorWidget; + auto widget = new TextEditorWidget; 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()); }); - widget->insertExtraToolBarWidget(TextEditor::TextEditorWidget::Left, ghciButton); + widget->insertExtraToolBarWidget(TextEditorWidget::Left, ghciButton); return widget; } -HaskellEditorFactory::HaskellEditorFactory() +class HaskellEditorFactory : public TextEditorFactory { - setId(Constants::C_HASKELLEDITOR_ID); - setDisplayName(::Core::Tr::tr("Haskell Editor")); - addMimeType("text/x-haskell"); - setEditorActionHandlers(TextEditor::TextEditorActionHandler::UnCommentSelection - | TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor); - setDocumentCreator([] { return new TextEditor::TextDocument(Constants::C_HASKELLEDITOR_ID); }); - setIndenterCreator([](QTextDocument *doc) { return new TextEditor::TextIndenter(doc); }); - setEditorWidgetCreator(&createEditorWidget); - setCommentDefinition(Utils::CommentDefinition("--", "{-", "-}")); - setParenthesesMatchingEnabled(true); - setMarksVisible(true); - setSyntaxHighlighterCreator([] { return new HaskellHighlighter(); }); +public: + HaskellEditorFactory() + { + setId(Constants::C_HASKELLEDITOR_ID); + setDisplayName(::Core::Tr::tr("Haskell Editor")); + addMimeType("text/x-haskell"); + setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection + | TextEditorActionHandler::FollowSymbolUnderCursor); + setDocumentCreator([] { return new TextDocument(Constants::C_HASKELLEDITOR_ID); }); + setIndenterCreator([](QTextDocument *doc) { return new TextIndenter(doc); }); + setEditorWidgetCreator(&createEditorWidget); + setCommentDefinition(Utils::CommentDefinition("--", "{-", "-}")); + setParenthesesMatchingEnabled(true); + setMarksVisible(true); + setSyntaxHighlighterCreator([] { return new HaskellHighlighter(); }); + } +}; + +void setupHaskellEditor() +{ + static HaskellEditorFactory theHaskellEditorFactory; } } // Haskell::Internal diff --git a/src/plugins/haskell/haskelleditorfactory.h b/src/plugins/haskell/haskelleditorfactory.h index 090a5b12782..6a21ed67a46 100644 --- a/src/plugins/haskell/haskelleditorfactory.h +++ b/src/plugins/haskell/haskelleditorfactory.h @@ -3,14 +3,8 @@ #pragma once -#include - namespace Haskell::Internal { -class HaskellEditorFactory : public TextEditor::TextEditorFactory -{ -public: - HaskellEditorFactory(); -}; +void setupHaskellEditor(); } // Haskell::Internal diff --git a/src/plugins/haskell/haskellplugin.cpp b/src/plugins/haskell/haskellplugin.cpp index 3b6bebdd289..f1285340ac9 100644 --- a/src/plugins/haskell/haskellplugin.cpp +++ b/src/plugins/haskell/haskellplugin.cpp @@ -29,7 +29,6 @@ namespace Haskell::Internal { class HaskellPluginPrivate { public: - HaskellEditorFactory editorFactory; HaskellRunConfigurationFactory runConfigFactory; ProjectExplorer::SimpleTargetRunnerFactory runWorkerFactory{{Constants::C_HASKELL_RUNCONFIG_ID}}; }; @@ -59,6 +58,7 @@ private: setupHaskellStackBuildStep(); setupHaskellBuildConfiguration(); + setupHaskellEditor(); ProjectExplorer::ProjectManager::registerProjectType( Constants::C_HASKELL_PROJECT_MIMETYPE);