diff options
author | Eike Ziller <git@eikeziller.de> | 2017-07-02 15:33:25 +0200 |
---|---|---|
committer | Eike Ziller <git@eikeziller.de> | 2017-10-01 20:11:08 +0200 |
commit | 224815da1c03c2ad82900d1354590b8f678c672a (patch) | |
tree | 6a1255a4d8ba72f2d6121d805a6dd91483446059 /plugins/haskell/haskellmanager.cpp | |
parent | d1c0bd6491e9ff5a2d9ce31d523901640eadbb66 (diff) |
Add options page for stack executable
Diffstat (limited to 'plugins/haskell/haskellmanager.cpp')
-rw-r--r-- | plugins/haskell/haskellmanager.cpp | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/plugins/haskell/haskellmanager.cpp b/plugins/haskell/haskellmanager.cpp index 275c921..0867edf 100644 --- a/plugins/haskell/haskellmanager.cpp +++ b/plugins/haskell/haskellmanager.cpp @@ -27,11 +27,16 @@ #include "ghcmod.h" +#include <utils/hostosinfo.h> + #include <QDir> #include <QFileInfo> +#include <QSettings> #include <unordered_map> +static const char kStackExecutableKey[] = "Haskell/StackExecutable"; + using namespace Utils; namespace Haskell { @@ -41,9 +46,16 @@ class HaskellManagerPrivate { public: std::unordered_map<FileName, std::weak_ptr<AsyncGhcMod>> ghcModCache; + FileName stackExecutable; }; -Q_GLOBAL_STATIC(HaskellManagerPrivate, m_d); +Q_GLOBAL_STATIC(HaskellManagerPrivate, m_d) +Q_GLOBAL_STATIC(HaskellManager, m_instance) + +HaskellManager *HaskellManager::instance() +{ + return m_instance; +} FileName HaskellManager::findProjectDirectory(const FileName &filePath) { @@ -76,5 +88,43 @@ std::shared_ptr<AsyncGhcMod> HaskellManager::ghcModForFile(const FileName &fileP return ghcmod; } +FileName defaultStackExecutable() +{ + // stack from brew or the installer script from https://docs.haskellstack.org + // install to /usr/local/bin. + if (HostOsInfo::isAnyUnixHost()) + return FileName::fromString("/usr/local/bin/stack"); + return FileName::fromString("stack"); +} + +FileName HaskellManager::stackExecutable() +{ + return m_d->stackExecutable; +} + +void HaskellManager::setStackExecutable(const FileName &filePath) +{ + if (filePath == m_d->stackExecutable) + return; + m_d->stackExecutable = filePath; + emit m_instance->stackExecutableChanged(m_d->stackExecutable); +} + +void HaskellManager::readSettings(QSettings *settings) +{ + m_d->stackExecutable = FileName::fromString( + settings->value(kStackExecutableKey, + defaultStackExecutable().toString()).toString()); + emit m_instance->stackExecutableChanged(m_d->stackExecutable); +} + +void HaskellManager::writeSettings(QSettings *settings) +{ + if (m_d->stackExecutable == defaultStackExecutable()) + settings->remove(kStackExecutableKey); + else + settings->setValue(kStackExecutableKey, m_d->stackExecutable.toString()); +} + } // namespace Internal } // namespace Haskell |