aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/haskell/haskelleditorfactory.cpp
blob: ba87f88ef709fce84d05602123566498e0da1728 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// 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 "haskelleditorfactory.h"

#include "haskellconstants.h"
#include "haskellhighlighter.h"
#include "haskellmanager.h"
#include "haskelltr.h"

#include <coreplugin/actionmanager/commandbutton.h>
#include <coreplugin/coreplugintr.h>
#include <texteditor/textdocument.h>
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/textindenter.h>

namespace Haskell::Internal {

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, guard, [widget] {
        HaskellManager::openGhci(widget->textDocument()->filePath());
    });
    widget->insertExtraToolBarWidget(TextEditor::TextEditorWidget::Left, ghciButton);
    return widget;
}

HaskellEditorFactory::HaskellEditorFactory()
{
    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([this] { return createEditorWidget(this); });
    setCommentDefinition(Utils::CommentDefinition("--", "{-", "-}"));
    setParenthesesMatchingEnabled(true);
    setMarksVisible(true);
    setSyntaxHighlighterCreator([] { return new HaskellHighlighter(); });
}

} // Haskell::Internal