forked from qt-creator/qt-creator
Haskell: Use ActionBuilder to create action to run ghci
Change-Id: I7bb4064a06e91b580c1d5f72dc4f0ff2ab8ef0cd Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -3,24 +3,27 @@
|
||||
|
||||
#include "haskellmanager.h"
|
||||
|
||||
#include "haskellconstants.h"
|
||||
#include "haskellsettings.h"
|
||||
#include "haskelltr.h"
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/commandline.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/mimeutils.h>
|
||||
#include <utils/process.h>
|
||||
#include <utils/processenums.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
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<MimeType> 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
|
||||
|
||||
@@ -5,17 +5,13 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
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
|
||||
|
||||
@@ -10,30 +10,14 @@
|
||||
#include "haskelltr.h"
|
||||
#include "stackbuildstep.h"
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
|
||||
|
||||
#include <texteditor/snippets/snippetprovider.h>
|
||||
|
||||
#include <QAction>
|
||||
|
||||
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/");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user