Haskell: Use new setup for HaskellEditorFactory

Change-Id: I537248460291d5d649a1dc60a5f495003d76fa8b
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2023-11-20 12:57:46 +01:00
parent f0574fdb9b
commit cc711d7903
3 changed files with 30 additions and 23 deletions

View File

@@ -10,38 +10,51 @@
#include <coreplugin/actionmanager/commandbutton.h> #include <coreplugin/actionmanager/commandbutton.h>
#include <coreplugin/coreplugintr.h> #include <coreplugin/coreplugintr.h>
#include <texteditor/textdocument.h> #include <texteditor/textdocument.h>
#include <texteditor/texteditor.h>
#include <texteditor/texteditoractionhandler.h> #include <texteditor/texteditoractionhandler.h>
#include <texteditor/textindenter.h> #include <texteditor/textindenter.h>
using namespace TextEditor;
namespace Haskell::Internal { namespace Haskell::Internal {
static QWidget *createEditorWidget() static QWidget *createEditorWidget()
{ {
auto widget = new TextEditor::TextEditorWidget; auto widget = new TextEditorWidget;
auto ghciButton = new Core::CommandButton(Constants::A_RUN_GHCI, widget); auto ghciButton = new Core::CommandButton(Constants::A_RUN_GHCI, widget);
ghciButton->setText(Tr::tr("GHCi")); ghciButton->setText(Tr::tr("GHCi"));
QObject::connect(ghciButton, &QToolButton::clicked, widget, [widget] { QObject::connect(ghciButton, &QToolButton::clicked, widget, [widget] {
HaskellManager::openGhci(widget->textDocument()->filePath()); HaskellManager::openGhci(widget->textDocument()->filePath());
}); });
widget->insertExtraToolBarWidget(TextEditor::TextEditorWidget::Left, ghciButton); widget->insertExtraToolBarWidget(TextEditorWidget::Left, ghciButton);
return widget; return widget;
} }
HaskellEditorFactory::HaskellEditorFactory() class HaskellEditorFactory : public TextEditorFactory
{ {
public:
HaskellEditorFactory()
{
setId(Constants::C_HASKELLEDITOR_ID); setId(Constants::C_HASKELLEDITOR_ID);
setDisplayName(::Core::Tr::tr("Haskell Editor")); setDisplayName(::Core::Tr::tr("Haskell Editor"));
addMimeType("text/x-haskell"); addMimeType("text/x-haskell");
setEditorActionHandlers(TextEditor::TextEditorActionHandler::UnCommentSelection setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
| TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor); | TextEditorActionHandler::FollowSymbolUnderCursor);
setDocumentCreator([] { return new TextEditor::TextDocument(Constants::C_HASKELLEDITOR_ID); }); setDocumentCreator([] { return new TextDocument(Constants::C_HASKELLEDITOR_ID); });
setIndenterCreator([](QTextDocument *doc) { return new TextEditor::TextIndenter(doc); }); setIndenterCreator([](QTextDocument *doc) { return new TextIndenter(doc); });
setEditorWidgetCreator(&createEditorWidget); setEditorWidgetCreator(&createEditorWidget);
setCommentDefinition(Utils::CommentDefinition("--", "{-", "-}")); setCommentDefinition(Utils::CommentDefinition("--", "{-", "-}"));
setParenthesesMatchingEnabled(true); setParenthesesMatchingEnabled(true);
setMarksVisible(true); setMarksVisible(true);
setSyntaxHighlighterCreator([] { return new HaskellHighlighter(); }); setSyntaxHighlighterCreator([] { return new HaskellHighlighter(); });
}
};
void setupHaskellEditor()
{
static HaskellEditorFactory theHaskellEditorFactory;
} }
} // Haskell::Internal } // Haskell::Internal

View File

@@ -3,14 +3,8 @@
#pragma once #pragma once
#include <texteditor/texteditor.h>
namespace Haskell::Internal { namespace Haskell::Internal {
class HaskellEditorFactory : public TextEditor::TextEditorFactory void setupHaskellEditor();
{
public:
HaskellEditorFactory();
};
} // Haskell::Internal } // Haskell::Internal

View File

@@ -29,7 +29,6 @@ namespace Haskell::Internal {
class HaskellPluginPrivate class HaskellPluginPrivate
{ {
public: public:
HaskellEditorFactory editorFactory;
HaskellRunConfigurationFactory runConfigFactory; HaskellRunConfigurationFactory runConfigFactory;
ProjectExplorer::SimpleTargetRunnerFactory runWorkerFactory{{Constants::C_HASKELL_RUNCONFIG_ID}}; ProjectExplorer::SimpleTargetRunnerFactory runWorkerFactory{{Constants::C_HASKELL_RUNCONFIG_ID}};
}; };
@@ -59,6 +58,7 @@ private:
setupHaskellStackBuildStep(); setupHaskellStackBuildStep();
setupHaskellBuildConfiguration(); setupHaskellBuildConfiguration();
setupHaskellEditor();
ProjectExplorer::ProjectManager::registerProjectType<HaskellProject>( ProjectExplorer::ProjectManager::registerProjectType<HaskellProject>(
Constants::C_HASKELL_PROJECT_MIMETYPE); Constants::C_HASKELL_PROJECT_MIMETYPE);