diff --git a/share/qtcreator/templates/wizards/files/nim/file.nim b/share/qtcreator/templates/wizards/files/nim/file.nim
new file mode 100644
index 0000000000000000000000000000000000000000..3c23a09b40552e1efec79dbcb3bc6679eda3ad01
--- /dev/null
+++ b/share/qtcreator/templates/wizards/files/nim/file.nim
@@ -0,0 +1,2 @@
+if isMainModule:
+ discard()
diff --git a/share/qtcreator/templates/wizards/files/nim/icon.png b/share/qtcreator/templates/wizards/files/nim/icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..a08e474e6dc4be7e2434851c152d742af3e74716
Binary files /dev/null and b/share/qtcreator/templates/wizards/files/nim/icon.png differ
diff --git a/share/qtcreator/templates/wizards/files/nim/wizard.json b/share/qtcreator/templates/wizards/files/nim/wizard.json
new file mode 100644
index 0000000000000000000000000000000000000000..7d20f7ebbd7cd14d05c4b6a9d88fd93ba59832cf
--- /dev/null
+++ b/share/qtcreator/templates/wizards/files/nim/wizard.json
@@ -0,0 +1,37 @@
+{
+ "version": 1,
+ "kind": "file",
+ "id": "Z.NimSource",
+ "category": "Z.Nim",
+ "trDescription": "Creates an empty Nim file using UTF-8 charset.",
+ "trDisplayName": "Nim File",
+ "trDisplayCategory": "Nim",
+ "icon": "icon.png",
+ "enabled": "%{JS: [ %{Plugins} ].indexOf('Nim') >= 0}",
+
+ "pages" :
+ [
+ {
+ "trDisplayName": "Location",
+ "trShortTitle": "Location",
+ "typeId": "File"
+ },
+ {
+ "trDisplayName": "Project Management",
+ "trShortTitle": "Summary",
+ "typeId": "Summary"
+ }
+ ],
+ "generators" :
+ [
+ {
+ "typeId": "File",
+ "data":
+ {
+ "source": "file.nim",
+ "target": "%{JS: Util.fileName('%{TargetPath}', 'nim')}",
+ "openInEditor": true
+ }
+ }
+ ]
+}
diff --git a/share/qtcreator/templates/wizards/projects/nim/file.nimproject b/share/qtcreator/templates/wizards/projects/nim/file.nimproject
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/share/qtcreator/templates/wizards/projects/nim/icon.png b/share/qtcreator/templates/wizards/projects/nim/icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..a08e474e6dc4be7e2434851c152d742af3e74716
Binary files /dev/null and b/share/qtcreator/templates/wizards/projects/nim/icon.png differ
diff --git a/share/qtcreator/templates/wizards/projects/nim/main.nim b/share/qtcreator/templates/wizards/projects/nim/main.nim
new file mode 100644
index 0000000000000000000000000000000000000000..b8cab1a2fe96f44a993d71ded70022f29033745a
--- /dev/null
+++ b/share/qtcreator/templates/wizards/projects/nim/main.nim
@@ -0,0 +1,5 @@
+proc mainProc =
+ echo "Hello World"
+
+if isMainModule:
+ mainProc()
diff --git a/share/qtcreator/templates/wizards/projects/nim/wizard.json b/share/qtcreator/templates/wizards/projects/nim/wizard.json
new file mode 100644
index 0000000000000000000000000000000000000000..0e86ebee612ed637e63716df32fb5b0272d33854
--- /dev/null
+++ b/share/qtcreator/templates/wizards/projects/nim/wizard.json
@@ -0,0 +1,64 @@
+{
+ "version": 1,
+ "kind": "project",
+ "id": "Z.NimProject",
+ "category": "I.Projects",
+ "trDescription": "Creates a simple Nim application.",
+ "trDisplayName": "Nim Application",
+ "trDisplayCategory": "Non-Qt Project",
+ "icon": "icon.png",
+ "enabled": "%{JS: [ %{Plugins} ].indexOf('Nim') >= 0 }",
+
+ "options":
+ [
+ { "key": "ProjectFile", "value": "%{JS: '%{NimProjectFile}'}" },
+ { "key": "NimProjectFile", "value": "%{JS: Util.fileName('%{ProjectDirectory}/%{ProjectName}', 'nimproject')}" },
+ { "key": "NimFileName", "value": "%{JS: 'main.nim'}" },
+ { "key": "IsTopLevelProject", "value": "%{JS: !'%{Exists:ProjectExplorer.Profile.Ids}'}" }
+ ],
+
+ "pages":
+ [
+ {
+ "trDisplayName": "Project Location",
+ "trShortTitle": "Location",
+ "typeId": "Project"
+ },
+ {
+ "trDisplayName": "Kit Selection",
+ "trShortTitle": "Kits",
+ "typeId": "Kits",
+ "enabled": "%{IsTopLevelProject}",
+ "data": { "projectFilePath": "%{ProjectFile}" }
+ },
+ {
+ "trDisplayName": "Project Management",
+ "trShortTitle": "Summary",
+ "typeId": "Summary"
+ }
+ ],
+ "generators":
+ [
+ {
+ "typeId": "File",
+ "data":
+ [
+ {
+ "source": "file.nimproject",
+ "target": "%{NimProjectFile}",
+ "openAsProject": true
+ },
+ {
+ "source": "main.nim",
+ "target": "%{NimFileName}",
+ "openInEditor": true
+ },
+ {
+ "source": "../git.ignore",
+ "target": "%{ProjectDirectory}/.gitignore",
+ "condition": "%{JS: ! %{IsSubproject} && '%{VersionControl}' === 'G.Git'}"
+ }
+ ]
+ }
+ ]
+}
diff --git a/src/plugins/nim/Nim.json.in b/src/plugins/nim/Nim.json.in
new file mode 100644
index 0000000000000000000000000000000000000000..f31068b821d6a55c8556559eaf0e96d18697d96e
--- /dev/null
+++ b/src/plugins/nim/Nim.json.in
@@ -0,0 +1,20 @@
+{
+ \"Name\" : \"Nim\",
+ \"Version\" : \"$$QTCREATOR_VERSION\",
+ \"CompatVersion\" : \"$$QTCREATOR_COMPAT_VERSION\",
+ \"Vendor\" : \"Filippo Cucchetto\",
+ \"Copyright\" : \"(C) 2015 Filippo Cucchetto\",
+ \"License\" : [ \"Commercial Usage\",
+ \"\",
+ \"Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and The Qt Company.\",
+ \"\",
+ \"GNU Lesser General Public License Usage\",
+ \"\",
+ \"Alternatively, this plugin may be used under the terms of the GNU Lesser General Public License version 2.1 or version 3 as published by the Free Software Foundation. Please review the following information to ensure the GNU Lesser General Public License requirements will be met: https://www.gnu.org/licenses/lgpl.html and http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.\"
+ ],
+ \"Category\" : \"Other Languages\",
+ \"Description\" : \"Plugin for supporting the Nim programming language.\",
+ \"Url\" : \"http://www.qt.io\",
+ \"Experimental\" : true,
+ $$dependencyList
+}
diff --git a/src/plugins/nim/Nim.mimetypes.xml b/src/plugins/nim/Nim.mimetypes.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3e06d398fd8103c1e181d1e519539842c43786ed
--- /dev/null
+++ b/src/plugins/nim/Nim.mimetypes.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+ Nim project file
+
+
+
+
+
+ Nim source file
+
+
+
diff --git a/src/plugins/nim/editor/nimeditorfactory.cpp b/src/plugins/nim/editor/nimeditorfactory.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..dc3a231a93c7a2981acfb189835bc43503aa04a9
--- /dev/null
+++ b/src/plugins/nim/editor/nimeditorfactory.cpp
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "editor/nimeditorfactory.h"
+
+#include "nimconstants.h"
+#include "nimplugin.h"
+#include "editor/nimindenter.h"
+#include "editor/nimhighlighter.h"
+
+#include
+#include
+#include
+#include
+
+using namespace TextEditor;
+using namespace Utils;
+
+namespace Nim {
+
+NimEditorFactory::NimEditorFactory()
+{
+ setId(Constants::C_NIMEDITOR_ID);
+ setDisplayName(tr(Nim::Constants::C_EDITOR_DISPLAY_NAME));
+ addMimeType(QLatin1String(Nim::Constants::C_NIM_MIMETYPE));
+
+ setEditorActionHandlers(TextEditorActionHandler::Format
+ | TextEditorActionHandler::UnCommentSelection
+ | TextEditorActionHandler::UnCollapseAll);
+
+ setEditorWidgetCreator([]{
+ auto result = new TextEditorWidget();
+ result->setLanguageSettingsId(Nim::Constants::C_NIMLANGUAGE_ID);
+ return result;
+ });
+ setDocumentCreator([]() {
+ return new TextDocument(Constants::C_NIMEDITOR_ID);
+ });
+ setIndenterCreator([]() {
+ return new NimIndenter;
+ });
+ setSyntaxHighlighterCreator([]() {
+ return new NimHighlighter;
+ });
+ setCommentStyle(CommentDefinition::HashStyle);
+ setParenthesesMatchingEnabled(true);
+ setMarksVisible(false);
+ setCodeFoldingSupported(true);
+ setMarksVisible(true);
+}
+
+Core::IEditor *NimEditorFactory::createEditor()
+{
+ return TextEditorFactory::createEditor();
+}
+
+}
diff --git a/src/plugins/nim/editor/nimeditorfactory.h b/src/plugins/nim/editor/nimeditorfactory.h
new file mode 100644
index 0000000000000000000000000000000000000000..83758e76e71b5fc6756f2d4f844d2f33eaccb54a
--- /dev/null
+++ b/src/plugins/nim/editor/nimeditorfactory.h
@@ -0,0 +1,42 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace Nim {
+
+class NimEditorFactory : public TextEditor::TextEditorFactory
+{
+ Q_OBJECT
+
+public:
+ NimEditorFactory();
+
+ Core::IEditor *createEditor() override;
+};
+
+}
diff --git a/src/plugins/nim/editor/nimhighlighter.cpp b/src/plugins/nim/editor/nimhighlighter.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..eed765df212a29caa7e2c9964df390c892b550b1
--- /dev/null
+++ b/src/plugins/nim/editor/nimhighlighter.cpp
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "editor/nimhighlighter.h"
+
+#include "tools/nimlexer.h"
+
+#include
+#include
+#include
+
+namespace Nim {
+
+NimHighlighter::NimHighlighter()
+{
+ initTextFormats();
+}
+
+void NimHighlighter::highlightBlock(const QString &text)
+{
+ setCurrentBlockState(highlightLine(text, previousBlockState()));
+}
+
+void NimHighlighter::initTextFormats()
+{
+ static QMap categoryStyle = {
+ {TextCategory, TextEditor::C_TEXT},
+ {KeywordCategory, TextEditor::C_KEYWORD},
+ {CommentCategory, TextEditor::C_COMMENT},
+ {DocumentationCategory, TextEditor::C_DOXYGEN_COMMENT},
+ {TypeCategory, TextEditor::C_TYPE},
+ {StringCategory, TextEditor::C_STRING},
+ {NumberCategory, TextEditor::C_NUMBER},
+ {OperatorCategory, TextEditor::C_OPERATOR},
+ {FunctionCategory, TextEditor::C_FUNCTION},
+ };
+
+ QVector formats;
+ for (const auto &category : categoryStyle.keys())
+ formats << categoryStyle[category];
+ setTextFormatCategories(formats);
+}
+
+NimHighlighter::Category NimHighlighter::categoryForToken(const NimLexer::Token &token,
+ const QString &tokenValue)
+{
+ switch (token.type) {
+ case NimLexer::TokenType::Keyword:
+ return KeywordCategory;
+ case NimLexer::TokenType::Identifier:
+ return categoryForIdentifier(token, tokenValue);
+ case NimLexer::TokenType::Comment:
+ return CommentCategory;
+ case NimLexer::TokenType::Documentation:
+ return DocumentationCategory;
+ case NimLexer::TokenType::StringLiteral:
+ return StringCategory;
+ case NimLexer::TokenType::MultiLineStringLiteral:
+ return StringCategory;
+ case NimLexer::TokenType::Operator:
+ return OperatorCategory;
+ case NimLexer::TokenType::Number:
+ return NumberCategory;
+ default:
+ return TextCategory;
+ }
+}
+
+NimHighlighter::Category NimHighlighter::categoryForIdentifier(const NimLexer::Token &token,
+ const QString &tokenValue)
+{
+ Q_UNUSED(token)
+ QTC_ASSERT(token.type == NimLexer::TokenType::Identifier, return TextCategory);
+
+ static QSet nimBuiltInValues {
+ "true", "false"
+ };
+
+ static QSet nimBuiltInFunctions {
+ "echo", "isMainModule"
+ };
+
+ static QSet nimBuiltInTypes {
+ "bool", "cbool", "string",
+ "cstring", "int", "cint",
+ "uint", "cuint", "long",
+ "clong", "double", "cdouble",
+ "table", "RootObj"
+ };
+
+ if (nimBuiltInFunctions.contains(tokenValue))
+ return TypeCategory;
+ if (nimBuiltInValues.contains(tokenValue))
+ return KeywordCategory;
+ if (nimBuiltInTypes.contains(tokenValue))
+ return TypeCategory;
+ return TextCategory;
+}
+
+int NimHighlighter::highlightLine(const QString &text, int initialState)
+{
+ NimLexer lexer(text.constData(),
+ text.size(),
+ static_cast(initialState));
+
+ NimLexer::Token tk;
+ while ((tk = lexer.next()).type != NimLexer::TokenType::EndOfText) {
+ int category = categoryForToken(tk, text.mid(tk.begin, tk.length));
+ setFormat(tk.begin, tk.length, formatForCategory(category));
+ }
+
+ return lexer.state();
+}
+
+}
diff --git a/src/plugins/nim/editor/nimhighlighter.h b/src/plugins/nim/editor/nimhighlighter.h
new file mode 100644
index 0000000000000000000000000000000000000000..cb563294e98b5d8575abb36f85e9de4da29ed19f
--- /dev/null
+++ b/src/plugins/nim/editor/nimhighlighter.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "tools/nimlexer.h"
+
+#include
+
+namespace Nim {
+
+class NimHighlighter : public TextEditor::SyntaxHighlighter
+{
+ Q_OBJECT
+
+ enum Category {
+ TextCategory = 0,
+ KeywordCategory,
+ CommentCategory,
+ DocumentationCategory,
+ TypeCategory,
+ StringCategory,
+ NumberCategory,
+ OperatorCategory,
+ FunctionCategory
+ };
+
+public:
+ NimHighlighter();
+
+protected:
+ void highlightBlock(const QString &text) override;
+
+private:
+ void initTextFormats();
+
+ Category categoryForToken(const NimLexer::Token &token, const QString &tokenValue);
+ Category categoryForIdentifier(const NimLexer::Token &token, const QString &tokenValue);
+
+ int highlightLine(const QString &text, int initialState);
+};
+
+}
diff --git a/src/plugins/nim/editor/nimindenter.cpp b/src/plugins/nim/editor/nimindenter.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..223294beab84fcadd2f768697c4db83fb3480d01
--- /dev/null
+++ b/src/plugins/nim/editor/nimindenter.cpp
@@ -0,0 +1,175 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "editor/nimindenter.h"
+
+#include "tools/nimlexer.h"
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+namespace Nim {
+
+NimIndenter::NimIndenter()
+{}
+
+bool NimIndenter::isElectricCharacter(const QChar &ch) const
+{
+ return NimIndenter::electricCharacters().contains(ch);
+}
+
+void NimIndenter::indentBlock(QTextDocument *document,
+ const QTextBlock &block,
+ const QChar &typedChar,
+ const TextEditor::TabSettings &settings)
+{
+ Q_UNUSED(document);
+ Q_UNUSED(typedChar);
+
+ const QString currentLine = block.text();
+
+ const QTextBlock previousBlock = block.previous();
+ const QString previousLine = previousBlock.text();
+ const int previousState = previousBlock.userState();
+
+ if (!previousBlock.isValid()) {
+ settings.indentLine(block, 0);
+ return;
+ }
+
+ // Calculate indentation
+ int indentation = 0;
+ if (rightTrimmed(currentLine).isEmpty()) {
+ // Current line is empty so we calculate indentation based on previous line
+ const int indentationDiff = calculateIndentationDiff(previousLine, previousState, settings.m_indentSize);
+ indentation = settings.indentationColumn(previousLine) + indentationDiff;
+ }
+ else {
+ // We don't change indentation if the line is already indented.
+ // This is safer but sub optimal
+ indentation = settings.indentationColumn(block.text());
+ }
+
+ // Sets indentation
+ settings.indentLine(block, std::max(0, indentation));
+}
+
+const QSet &NimIndenter::electricCharacters()
+{
+ static QSet result { QLatin1Char(':'), QLatin1Char('=') };
+ return result;
+}
+
+bool NimIndenter::startsBlock(const QString &line, int state) const
+{
+ NimLexer lexer(line.constData(), line.length(), static_cast(state));
+
+ // Read until end of line and save the last token
+ NimLexer::Token previous;
+ NimLexer::Token current = lexer.next();
+ while (current.type != NimLexer::TokenType::EndOfText) {
+ switch (current.type) {
+ case NimLexer::TokenType::Comment:
+ case NimLexer::TokenType::Documentation:
+ break;
+ default:
+ previous = current;
+ break;
+ }
+ current = lexer.next();
+ }
+
+ // electric characters start a new block, and are operators
+ if (previous.type == NimLexer::TokenType::Operator) {
+ QStringRef ref = line.midRef(previous.begin, previous.length);
+ return ref.isEmpty() ? false : electricCharacters().contains(ref.at(0));
+ }
+
+ // some keywords starts a new block
+ if (previous.type == NimLexer::TokenType::Keyword) {
+ QStringRef ref = line.midRef(previous.begin, previous.length);
+ return ref == QLatin1String("type")
+ || ref == QLatin1String("var")
+ || ref == QLatin1String("let")
+ || ref == QLatin1String("enum")
+ || ref == QLatin1String("object");
+ }
+
+ return false;
+}
+
+bool NimIndenter::endsBlock(const QString &line, int state) const
+{
+ NimLexer lexer(line.constData(), line.length(), static_cast(state));
+
+ // Read until end of line and save the last tokens
+ NimLexer::Token previous;
+ NimLexer::Token current = lexer.next();
+ while (current.type != NimLexer::TokenType::EndOfText) {
+ previous = current;
+ current = lexer.next();
+ }
+
+ // Some keywords end a block
+ if (previous.type == NimLexer::TokenType::Keyword) {
+ QStringRef ref = line.midRef(previous.begin, previous.length);
+ return ref == QLatin1String("return")
+ || ref == QLatin1String("break")
+ || ref == QLatin1String("continue");
+ }
+
+ return false;
+}
+
+int NimIndenter::calculateIndentationDiff(const QString &previousLine, int previousState, int indentSize) const
+{
+ if (previousLine.isEmpty())
+ return 0;
+
+ if (startsBlock(previousLine, previousState))
+ return indentSize;
+
+ if (endsBlock(previousLine, previousState))
+ return -indentSize;
+
+ return 0;
+}
+
+QString NimIndenter::rightTrimmed(const QString &str)
+{
+ int n = str.size() - 1;
+ for (; n >= 0; --n) {
+ if (!str.at(n).isSpace())
+ return str.left(n + 1);
+ }
+ return QString();
+}
+
+}
diff --git a/src/plugins/nim/editor/nimindenter.h b/src/plugins/nim/editor/nimindenter.h
new file mode 100644
index 0000000000000000000000000000000000000000..adf09c6a628bbcbd34b06c6cfdadd34f55c4e9da
--- /dev/null
+++ b/src/plugins/nim/editor/nimindenter.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace TextEditor { class SimpleCodeStylePreferences; }
+
+namespace Nim {
+
+class NimLexer;
+
+class NimIndenter : public TextEditor::Indenter
+{
+public:
+ NimIndenter();
+
+ bool isElectricCharacter(const QChar &ch) const override;
+
+ void indentBlock(QTextDocument *document,
+ const QTextBlock &block,
+ const QChar &typedChar,
+ const TextEditor::TabSettings &settings) override;
+
+private:
+ static const QSet &electricCharacters();
+
+ bool startsBlock(const QString &line, int state) const;
+ bool endsBlock(const QString &line, int state) const;
+
+ int calculateIndentationDiff(const QString &previousLine, int previousState, int indentSize) const;
+
+ static QString rightTrimmed(const QString& other);
+};
+
+}
diff --git a/src/plugins/nim/images/nim.png b/src/plugins/nim/images/nim.png
new file mode 100644
index 0000000000000000000000000000000000000000..a08e474e6dc4be7e2434851c152d742af3e74716
Binary files /dev/null and b/src/plugins/nim/images/nim.png differ
diff --git a/src/plugins/nim/nim.pro b/src/plugins/nim/nim.pro
new file mode 100644
index 0000000000000000000000000000000000000000..35b65add003ddf79de733fed3dbf7dffdb97a8d4
--- /dev/null
+++ b/src/plugins/nim/nim.pro
@@ -0,0 +1,76 @@
+include(../../qtcreatorplugin.pri)
+
+DEFINES += \
+ NIM_LIBRARY
+
+RESOURCES += \
+ nim.qrc
+
+INCLUDEPATH += $$PWD
+
+HEADERS += \
+ nimplugin.h \
+ nimconstants.h \
+ editor/nimhighlighter.h \
+ editor/nimindenter.h \
+ tools/nimlexer.h \
+ tools/sourcecodestream.h \
+ project/nimproject.h \
+ project/nimprojectmanager.h \
+ project/nimprojectnode.h \
+ project/nimbuildconfiguration.h \
+ project/nimbuildconfigurationfactory.h \
+ project/nimbuildinfo.h \
+ project/nimcompilerbuildstep.h \
+ project/nimcompilerbuildstepconfigwidget.h \
+ project/nimcompilercleanstep.h \
+ project/nimcompilercleanstepconfigwidget.h \
+ project/nimrunconfigurationfactory.h \
+ project/nimrunconfiguration.h \
+ project/nimrunconfigurationwidget.h \
+ project/nimcompilerbuildstepfactory.h \
+ project/nimcompilercleanstepfactory.h \
+ project/nimbuildconfigurationwidget.h \
+ project/nimruncontrol.h \
+ project/nimruncontrolfactory.h \
+ editor/nimeditorfactory.h \
+ settings/nimcodestylesettingspage.h \
+ settings/nimcodestylepreferencesfactory.h \
+ settings/nimsettings.h \
+ settings/nimsnippetprovider.h \
+ settings/nimcodestylepreferenceswidget.h
+
+SOURCES += \
+ nimplugin.cpp \
+ editor/nimhighlighter.cpp \
+ editor/nimindenter.cpp \
+ tools/nimlexer.cpp \
+ project/nimproject.cpp \
+ project/nimprojectmanager.cpp \
+ project/nimprojectnode.cpp \
+ project/nimbuildconfiguration.cpp \
+ project/nimbuildconfigurationfactory.cpp \
+ project/nimbuildinfo.cpp \
+ project/nimcompilerbuildstep.cpp \
+ project/nimcompilerbuildstepconfigwidget.cpp \
+ project/nimcompilercleanstep.cpp \
+ project/nimcompilercleanstepconfigwidget.cpp \
+ project/nimrunconfigurationfactory.cpp \
+ project/nimrunconfiguration.cpp \
+ project/nimrunconfigurationwidget.cpp \
+ project/nimcompilerbuildstepfactory.cpp \
+ project/nimcompilercleanstepfactory.cpp \
+ project/nimbuildconfigurationwidget.cpp \
+ project/nimruncontrol.cpp \
+ project/nimruncontrolfactory.cpp \
+ editor/nimeditorfactory.cpp \
+ settings/nimcodestylesettingspage.cpp \
+ settings/nimcodestylepreferencesfactory.cpp \
+ settings/nimsettings.cpp \
+ settings/nimsnippetprovider.cpp \
+ settings/nimcodestylepreferenceswidget.cpp
+
+FORMS += \
+ project/nimcompilerbuildstepconfigwidget.ui \
+ project/nimcompilercleanstepconfigwidget.ui \
+ settings/nimcodestylepreferenceswidget.ui
diff --git a/src/plugins/nim/nim.qbs b/src/plugins/nim/nim.qbs
new file mode 100644
index 0000000000000000000000000000000000000000..69d33ec8d6a0285be2917662416eb852f9043cc1
--- /dev/null
+++ b/src/plugins/nim/nim.qbs
@@ -0,0 +1,81 @@
+import qbs 1.0
+
+QtcPlugin {
+ name: "Nim"
+
+ Depends { name: "Qt.widgets" }
+ Depends { name: "Utils" }
+
+ Depends { name: "Core" }
+ Depends { name: "TextEditor" }
+ Depends { name: "QtSupport" }
+ Depends { name: "ProjectExplorer" }
+ Depends { name: "cpp" }
+
+ cpp.includePaths: ['.']
+
+ Group {
+ name: "General"
+ files: [
+ "nimplugin.cpp", "nimplugin.h",
+ "nimconstants.h",
+ "nim.qrc",
+ ]
+ }
+
+ Group {
+ name: "Editor"
+ prefix: "editor/"
+ files: [
+ "nimeditorfactory.h", "nimeditorfactory.cpp",
+ "nimhighlighter.h", "nimhighlighter.cpp",
+ "nimindenter.h", "nimindenter.cpp"
+ ]
+ }
+
+ Group {
+ name: "Project"
+ prefix: "project/"
+ files: [
+ "nimbuildconfiguration.h", "nimbuildconfiguration.cpp",
+ "nimbuildconfigurationfactory.h", "nimbuildconfigurationfactory.cpp",
+ "nimbuildconfigurationwidget.h", "nimbuildconfigurationwidget.cpp",
+ "nimbuildinfo.h", "nimbuildinfo.cpp",
+ "nimcompilerbuildstep.h", "nimcompilerbuildstep.cpp",
+ "nimcompilerbuildstepconfigwidget.h", "nimcompilerbuildstepconfigwidget.cpp", "nimcompilerbuildstepconfigwidget.ui",
+ "nimcompilerbuildstepfactory.h", "nimcompilerbuildstepfactory.cpp",
+ "nimcompilercleanstep.h", "nimcompilercleanstep.cpp",
+ "nimcompilercleanstepconfigwidget.h", "nimcompilercleanstepconfigwidget.cpp", "nimcompilercleanstepconfigwidget.ui",
+ "nimcompilercleanstepfactory.h", "nimcompilercleanstepfactory.cpp",
+ "nimproject.h", "nimproject.cpp",
+ "nimprojectmanager.h", "nimprojectmanager.cpp",
+ "nimprojectnode.h", "nimprojectnode.cpp",
+ "nimrunconfiguration.h", "nimrunconfiguration.cpp",
+ "nimrunconfigurationfactory.h", "nimrunconfigurationfactory.cpp",
+ "nimrunconfigurationwidget.h", "nimrunconfigurationwidget.cpp",
+ "nimruncontrol.h", "nimruncontrol.cpp",
+ "nimruncontrolfactory.h", "nimruncontrolfactory.cpp"
+ ]
+ }
+
+ Group {
+ name: "Settings"
+ prefix: "settings/"
+ files: [
+ "nimcodestylepreferencesfactory.h", "nimcodestylepreferencesfactory.cpp",
+ "nimcodestylepreferenceswidget.h", "nimcodestylepreferenceswidget.cpp", "nimcodestylepreferenceswidget.ui",
+ "nimcodestylesettingspage.h", "nimcodestylesettingspage.cpp",
+ "nimsettings.h", "nimsettings.cpp",
+ "nimsnippetprovider.h", "nimsnippetprovider.cpp",
+ ]
+ }
+
+ Group {
+ name: "Tools"
+ prefix: "tools/"
+ files: [
+ "nimlexer.h", "nimlexer.cpp",
+ "sourcecodestream.h"
+ ]
+ }
+}
diff --git a/src/plugins/nim/nim.qrc b/src/plugins/nim/nim.qrc
new file mode 100644
index 0000000000000000000000000000000000000000..ca4e8e460cc9c91d6ec1d5dce71369379d4546f3
--- /dev/null
+++ b/src/plugins/nim/nim.qrc
@@ -0,0 +1,6 @@
+
+
+ Nim.mimetypes.xml
+ images/nim.png
+
+
diff --git a/src/plugins/nim/nim_dependencies.pri b/src/plugins/nim/nim_dependencies.pri
new file mode 100644
index 0000000000000000000000000000000000000000..47f6ff43ff25599ed15a4f0fca03dd569193de02
--- /dev/null
+++ b/src/plugins/nim/nim_dependencies.pri
@@ -0,0 +1,8 @@
+QTC_PLUGIN_NAME = Nim
+QTC_LIB_DEPENDS += \
+ extensionsystem \
+ utils
+QTC_PLUGIN_DEPENDS += \
+ coreplugin \
+ texteditor \
+ projectexplorer
diff --git a/src/plugins/nim/nimconstants.h b/src/plugins/nim/nimconstants.h
new file mode 100644
index 0000000000000000000000000000000000000000..7f2dc90d8efa49411e34b6c825a3a3e4ca2e078c
--- /dev/null
+++ b/src/plugins/nim/nimconstants.h
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+#include
+
+namespace Nim {
+namespace Constants {
+
+const char C_NIMPROJECT_ID[] = "Nim.NimProject";
+const char C_NIMEDITOR_ID[] = "Nim.NimEditor";
+const char C_EDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("OpenWith::Editors", "Nim Editor");
+const char C_NIM_ICON_PATH[] = ":/images/nim.png";
+
+// NimRunConfiguration
+const char C_NIMRUNCONFIGURATION_ID[] = "Nim.NimRunConfiguration";
+const char C_NIMRUNCONFIGURATION_DISPLAY[] = QT_TRANSLATE_NOOP("NimRunConfiguration", "Current Build Target");
+const char C_NIMRUNCONFIGURATION_DEFAULT_DISPLAY[] = QT_TRANSLATE_NOOP("NimRunConfiguration", "Current Build Target");
+const QString C_NIMRUNCONFIGURATION_EXECUTABLE_KEY = QStringLiteral("Nim.NimRunConfiguration.Executable");
+const QString C_NIMRUNCONFIGURATION_WORKINGDIRECTORY_KEY = QStringLiteral("Nim.NimRunConfiguration.WorkingDirectory");
+const QString C_NIMRUNCONFIGURATION_COMMANDLINEARGS_KEY = QStringLiteral("Nim.NimRunConfiguration.CommandlineArgs");
+const QString C_NIMRUNCONFIGURATION_RUNMODE_KEY = QStringLiteral("Nim.NimRunConfiguration.RunMode");
+const QString C_NIMRUNCONFIGURATION_WORKINGDIRECTORYASPECT_ID = QStringLiteral("Nim.NimRunConfiguration.WorkingDirectoryAspect");
+const QString C_NIMRUNCONFIGURATION_ARGUMENTASPECT_ID = QStringLiteral("Nim.NimRunConfiguration.ArgumentAspect");
+const QString C_NIMRUNCONFIGURATION_TERMINALASPECT_ID = QStringLiteral("Nim.NimRunConfiguration.TerminalAspect");
+
+
+// NimBuildConfiguration
+const char C_NIMBUILDCONFIGURATION_ID[] = "Nim.NimBuildConfiguration";
+const QString C_NIMBUILDCONFIGURATION_DISPLAY_KEY = QStringLiteral("Nim.NimBuildConfiguration.Display");
+const QString C_NIMBUILDCONFIGURATION_BUILDDIRECTORY_KEY = QStringLiteral("Nim.NimBuildConfiguration.BuildDirectory");
+
+// NimBuildConfigurationWidget
+const char C_NIMBUILDCONFIGURATIONWIDGET_DISPLAY[] = QT_TRANSLATE_NOOP("NimBuildConfigurationWidget","General");
+
+// NimCompilerBuildStep
+const char C_NIMCOMPILERBUILDSTEP_ID[] = "Nim.NimCompilerBuildStep";
+const char C_NIMCOMPILERBUILDSTEP_DISPLAY[] = QT_TRANSLATE_NOOP("NimCompilerBuildStep", "Nim Compiler Build Step");
+const QString C_NIMCOMPILERBUILDSTEP_USERCOMPILEROPTIONS = QStringLiteral("Nim.NimCompilerBuildStep.UserCompilerOptions");
+const QString C_NIMCOMPILERBUILDSTEP_DEFAULTBUILDOPTIONS = QStringLiteral("Nim.NimCompilerBuildStep.DefaultBuildOptions");
+const QString C_NIMCOMPILERBUILDSTEP_TARGETNIMFILE = QStringLiteral("Nim.NimCompilerBuildStep.TargetNimFile");
+
+// NimCompilerBuildStepWidget
+const char C_NIMCOMPILERBUILDSTEPWIDGET_DISPLAY[] = QT_TRANSLATE_NOOP("NimCompilerBuildStepConfigWidget", "Nim build step");
+const char C_NIMCOMPILERBUILDSTEPWIDGET_SUMMARY[] = QT_TRANSLATE_NOOP("NimCompilerBuildStepConfigWidget", "Nim build step");
+
+// NimCompilerCleanStep
+const char C_NIMCOMPILERCLEANSTEP_ID[] = "Nim.NimCompilerCleanStep";
+const char C_NIMCOMPILERCLEANSTEP_DISPLAY[] = QT_TRANSLATE_NOOP("NimCompilerCleanStepFactory", "Nim Compiler Clean Step");
+
+// NimCompilerCleanStepWidget
+const char C_NIMCOMPILERCLEANSTEPWIDGET_DISPLAY[] = QT_TRANSLATE_NOOP("NimCompilerCleanStepWidget", "Nim clean step");
+const char C_NIMCOMPILERCLEANSTEPWIDGET_SUMMARY[] = QT_TRANSLATE_NOOP("NimCompilerCleanStepWidget", "Nim clean step");
+
+const char C_NIMLANGUAGE_ID[] = "Nim";
+const char C_NIMCODESTYLESETTINGSPAGE_ID[] = "Nim.NimCodeStyleSettings";
+const char C_NIMCODESTYLESETTINGSPAGE_DISPLAY[] = QT_TRANSLATE_NOOP("NimCodeStyleSettingsPage", "Code Style");
+const char C_NIMCODESTYLESETTINGSPAGE_CATEGORY[] = "Z.Nim";
+const char C_NIMCODESTYLESETTINGSPAGE_CATEGORY_DISPLAY[] = QT_TRANSLATE_NOOP("NimCodeStyleSettingsPage", "Nim");
+const char C_NIMLANGUAGE_NAME[] = QT_TRANSLATE_NOOP("NimCodeStylePreferencesFactory", "Nim");
+const char C_NIMGLOBALCODESTYLE_ID[] = "NimGlobal";
+const QString C_NIMSNIPPETSGROUP_ID = QStringLiteral("Nim.NimSnippetsGroup");
+const char C_NIMSNIPPETPROVIDER_DISPLAY[] = QT_TRANSLATE_NOOP("NimSnippetProvider", "Nim");
+
+const char C_NIMCODESTYLEPREVIEWSNIPPET[] =
+ "import os\n"
+ "\n"
+ "type Foo = ref object of RootObj\n"
+ " name: string\n"
+ " value: int \n"
+ "\n"
+ "proc newFoo(): Foo =\n"
+ " new(result)\n"
+ "\n"
+ "if isMainModule():\n"
+ " let foo = newFoo()\n"
+ " echo foo.name\n";
+
+/*******************************************************************************
+ * MIME type
+ ******************************************************************************/
+const char C_NIM_MIMETYPE[] = "text/x-nim";
+const char C_NIM_MIME_ICON[] = "text-x-nim";
+const char C_NIM_PROJECT_MIMETYPE[] = "text/x-nim-project";
+
+}
+}
diff --git a/src/plugins/nim/nimplugin.cpp b/src/plugins/nim/nimplugin.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b89676e0eb6218bac4390d79b73b5d95cc4d0657
--- /dev/null
+++ b/src/plugins/nim/nimplugin.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "nimplugin.h"
+
+#include "nimconstants.h"
+#include "editor/nimeditorfactory.h"
+#include "editor/nimhighlighter.h"
+#include "project/nimbuildconfigurationfactory.h"
+#include "project/nimcompilerbuildstepfactory.h"
+#include "project/nimcompilercleanstepfactory.h"
+#include "project/nimprojectmanager.h"
+#include "project/nimrunconfigurationfactory.h"
+#include "project/nimruncontrolfactory.h"
+#include "settings/nimcodestylepreferencesfactory.h"
+#include "settings/nimcodestylesettingspage.h"
+#include "settings/nimsettings.h"
+#include "settings/nimsnippetprovider.h"
+
+#include
+#include
+
+#include
+
+using namespace Utils;
+
+namespace Nim {
+
+static NimPlugin *m_instance = 0;
+
+NimPlugin::NimPlugin()
+{
+ m_instance = this;
+}
+
+NimPlugin::~NimPlugin()
+{
+ m_instance = 0;
+}
+
+bool NimPlugin::initialize(const QStringList &arguments, QString *errorMessage)
+{
+ Q_UNUSED(arguments)
+ Q_UNUSED(errorMessage)
+
+ MimeDatabase::addMimeTypes(QLatin1String(":/Nim.mimetypes.xml"));
+
+ addAutoReleasedObject(new NimSettings);
+ addAutoReleasedObject(new NimSnippetProvider);
+ addAutoReleasedObject(new NimEditorFactory);
+ addAutoReleasedObject(new NimProjectManager);
+ addAutoReleasedObject(new NimBuildConfigurationFactory);
+ addAutoReleasedObject(new NimRunConfigurationFactory);
+ addAutoReleasedObject(new NimCompilerBuildStepFactory);
+ addAutoReleasedObject(new NimCompilerCleanStepFactory);
+ addAutoReleasedObject(new NimRunControlFactory);
+ addAutoReleasedObject(new NimCodeStyleSettingsPage);
+ addAutoReleasedObject(new NimCodeStylePreferencesFactory);
+
+ // Add MIME overlay icons (these icons displayed at Project dock panel)
+ const QIcon icon((QLatin1String(Constants::C_NIM_ICON_PATH)));
+ if (!icon.isNull())
+ Core::FileIconProvider::registerIconOverlayForMimeType(icon, Constants::C_NIM_MIMETYPE);
+
+ return true;
+}
+
+} // namespace Nim
diff --git a/src/plugins/nim/nimplugin.h b/src/plugins/nim/nimplugin.h
new file mode 100644
index 0000000000000000000000000000000000000000..7c83d6a54dc6fae70607125ef7b288d21a937f8a
--- /dev/null
+++ b/src/plugins/nim/nimplugin.h
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace Nim {
+
+class NimPlugin : public ExtensionSystem::IPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Nim.json")
+
+public:
+ NimPlugin();
+
+ ~NimPlugin();
+
+ bool initialize(const QStringList &arguments, QString *errorMessage) override;
+
+ void extensionsInitialized() override {}
+};
+
+}
diff --git a/src/plugins/nim/project/nimbuildconfiguration.cpp b/src/plugins/nim/project/nimbuildconfiguration.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5da368b439617bac594dbb2e8f2eb7956b5d044f
--- /dev/null
+++ b/src/plugins/nim/project/nimbuildconfiguration.cpp
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimbuildconfiguration.h"
+
+#include "nimconstants.h"
+#include "project/nimproject.h"
+#include "project/nimbuildconfigurationwidget.h"
+#include "project/nimcompilerbuildstep.h"
+
+#include
+#include
+#include
+#include
+
+using namespace ProjectExplorer;
+using namespace Utils;
+
+namespace Nim {
+
+NimBuildConfiguration::NimBuildConfiguration(Target *target)
+ : BuildConfiguration(target, Constants::C_NIMBUILDCONFIGURATION_ID)
+{}
+
+NamedWidget *NimBuildConfiguration::createConfigWidget()
+{
+ return new NimBuildConfigurationWidget(this);
+}
+
+BuildConfiguration::BuildType NimBuildConfiguration::buildType() const
+{
+ return BuildConfiguration::Unknown;
+}
+
+void NimBuildConfiguration::setBuildDirectory(const FileName &dir)
+{
+ if (dir == buildDirectory())
+ return;
+ BuildConfiguration::setBuildDirectory(dir);
+}
+
+bool NimBuildConfiguration::fromMap(const QVariantMap &map)
+{
+ if (!BuildConfiguration::fromMap(map))
+ return false;
+
+ if (!canRestore(map))
+ return false;
+
+ const QString displayName = map[Constants::C_NIMBUILDCONFIGURATION_DISPLAY_KEY].toString();
+ const QString buildDirectory = map[Constants::C_NIMBUILDCONFIGURATION_BUILDDIRECTORY_KEY].toString();
+
+ setDisplayName(displayName);
+ setBuildDirectory(FileName::fromString(buildDirectory));
+
+ return true;
+}
+
+QVariantMap NimBuildConfiguration::toMap() const
+{
+ QVariantMap result = BuildConfiguration::toMap();
+ result[Constants::C_NIMBUILDCONFIGURATION_DISPLAY_KEY] = displayName();
+ result[Constants::C_NIMBUILDCONFIGURATION_BUILDDIRECTORY_KEY] = buildDirectory().toString();
+ return result;
+}
+
+FileName NimBuildConfiguration::cacheDirectory() const
+{
+ return buildDirectory().appendPath(QStringLiteral("nimcache"));
+}
+
+FileName NimBuildConfiguration::outFilePath() const
+{
+ const NimCompilerBuildStep *step = nimCompilerBuildStep();
+ QTC_ASSERT(step, return FileName());
+ return step->outFilePath();
+}
+
+bool NimBuildConfiguration::canRestore(const QVariantMap &map)
+{
+ return idFromMap(map) == Constants::C_NIMBUILDCONFIGURATION_ID;
+}
+
+bool NimBuildConfiguration::hasNimCompilerBuildStep() const
+{
+ BuildStepList *steps = stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
+ QTC_ASSERT(steps, return false);
+ return steps->contains(Constants::C_NIMCOMPILERBUILDSTEP_ID);
+}
+
+bool NimBuildConfiguration::hasNimCompilerCleanStep() const
+{
+ BuildStepList *steps = stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
+ QTC_ASSERT(steps, return false);
+ return steps ? steps->contains(Constants::C_NIMCOMPILERCLEANSTEP_ID) : false;
+}
+
+const NimCompilerBuildStep *NimBuildConfiguration::nimCompilerBuildStep() const
+{
+ BuildStepList *steps = stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
+ QTC_ASSERT(steps, return nullptr);
+ foreach (BuildStep *step, steps->steps())
+ if (step->id() == Constants::C_NIMCOMPILERBUILDSTEP_ID)
+ return qobject_cast(step);
+ return nullptr;
+}
+
+}
+
diff --git a/src/plugins/nim/project/nimbuildconfiguration.h b/src/plugins/nim/project/nimbuildconfiguration.h
new file mode 100644
index 0000000000000000000000000000000000000000..a205ae1b18e68de3b63174defcba88c4879718a7
--- /dev/null
+++ b/src/plugins/nim/project/nimbuildconfiguration.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+#include
+
+#include
+
+namespace Nim {
+
+class NimProject;
+class NimCompilerBuildStep;
+
+class NimBuildConfiguration : public ProjectExplorer::BuildConfiguration
+{
+ Q_OBJECT
+
+public:
+ NimBuildConfiguration(ProjectExplorer::Target *target);
+
+ ProjectExplorer::NamedWidget *createConfigWidget() override;
+
+ ProjectExplorer::BuildConfiguration::BuildType buildType() const override;
+
+ void setBuildDirectory(const Utils::FileName &dir) override;
+
+ bool fromMap(const QVariantMap &map) override;
+ QVariantMap toMap() const override;
+
+ Utils::FileName cacheDirectory() const;
+ Utils::FileName outFilePath() const;
+
+ static bool canRestore(const QVariantMap &map);
+
+ bool hasNimCompilerBuildStep() const;
+ bool hasNimCompilerCleanStep() const;
+
+signals:
+ void outFilePathChanged(const Utils::FileName &outFilePath);
+
+private:
+ const NimCompilerBuildStep *nimCompilerBuildStep() const;
+};
+
+}
diff --git a/src/plugins/nim/project/nimbuildconfigurationfactory.cpp b/src/plugins/nim/project/nimbuildconfigurationfactory.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bf396e955171ba5662f1f019f3d98c9d748d52a5
--- /dev/null
+++ b/src/plugins/nim/project/nimbuildconfigurationfactory.cpp
@@ -0,0 +1,207 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimbuildconfigurationfactory.h"
+
+#include "nimconstants.h"
+#include "project/nimbuildconfiguration.h"
+#include "project/nimbuildinfo.h"
+#include "project/nimcompilerbuildstep.h"
+#include "project/nimcompilercleanstep.h"
+#include "project/nimproject.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+using namespace ProjectExplorer;
+using namespace Utils;
+
+namespace Nim {
+
+NimBuildConfigurationFactory::NimBuildConfigurationFactory(QObject *parent)
+ : IBuildConfigurationFactory(parent)
+{}
+
+QList NimBuildConfigurationFactory::availableBuilds(const Target *parent) const
+{
+ // Retrieve the project path
+ auto project = qobject_cast(parent->project());
+ QTC_ASSERT(project, return {});
+
+ // Create the build info
+ NimBuildInfo *info = createBuildInfo(parent->kit(),
+ project->projectFilePath(),
+ BuildConfiguration::Debug);
+
+ info->displayName.clear(); // ask for a name
+ info->buildDirectory.clear(); // This depends on the displayName
+
+ return { info };
+}
+
+QList NimBuildConfigurationFactory::availableSetups(const Kit *k, const QString &projectPath) const
+{
+ NimBuildInfo *debug = createBuildInfo(k, projectPath, BuildConfiguration::Debug);
+ NimBuildInfo *release = createBuildInfo(k, projectPath, BuildConfiguration::Release);
+ return { debug, release };
+}
+
+BuildConfiguration *NimBuildConfigurationFactory::create(Target *parent, const BuildInfo *info) const
+{
+ auto project = qobject_cast(parent->project());
+ QTC_ASSERT(project, return nullptr);
+
+ auto nimInfo = static_cast(info);
+
+ // Create the build configuration and initialize it from build info
+ auto result = new NimBuildConfiguration(parent);
+ result->setDisplayName(nimInfo->displayName);
+ result->setDefaultDisplayName(nimInfo->displayName);
+ result->setBuildDirectory(defaultBuildDirectory(parent->kit(),
+ project->projectFilePath(),
+ nimInfo->displayName,
+ nimInfo->buildType()));
+
+ // Add nim compiler build step
+ {
+ BuildStepList *buildSteps = result->stepList(Core::Id(ProjectExplorer::Constants::BUILDSTEPS_BUILD));
+ auto nimCompilerBuildStep = new NimCompilerBuildStep(buildSteps);
+ NimCompilerBuildStep::DefaultBuildOptions defaultOption;
+ switch (nimInfo->buildType()) {
+ case BuildConfiguration::Release:
+ defaultOption = NimCompilerBuildStep::DefaultBuildOptions::Release;
+ break;
+ case BuildConfiguration::Debug:
+ defaultOption = NimCompilerBuildStep::DefaultBuildOptions::Debug;
+ break;
+ default:
+ defaultOption = NimCompilerBuildStep::DefaultBuildOptions::Empty;
+ break;
+ }
+ nimCompilerBuildStep->setDefaultCompilerOptions(defaultOption);
+ nimCompilerBuildStep->setTargetNimFile(project->nimFiles().first());
+ buildSteps->appendStep(nimCompilerBuildStep);
+ }
+
+ // Add clean step
+ {
+ BuildStepList *cleanSteps = result->stepList(Core::Id(ProjectExplorer::Constants::BUILDSTEPS_CLEAN));
+ cleanSteps->appendStep(new NimCompilerCleanStep(cleanSteps));
+ }
+
+ return result;
+}
+
+bool NimBuildConfigurationFactory::canRestore(const Target *parent, const QVariantMap &map) const
+{
+ Q_UNUSED(parent);
+ return NimBuildConfiguration::canRestore(map);
+}
+
+BuildConfiguration *NimBuildConfigurationFactory::restore(Target *parent, const QVariantMap &map)
+{
+ QTC_ASSERT(canRestore(parent, map), return nullptr);
+
+ // Create the build configuration
+ auto result = new NimBuildConfiguration(parent);
+
+ // Restore from map
+ bool status = result->fromMap(map);
+ QTC_ASSERT(status, return nullptr);
+
+ return result;
+}
+
+bool NimBuildConfigurationFactory::canClone(const Target *parent, BuildConfiguration *product) const
+{
+ QTC_ASSERT(parent, return false);
+ QTC_ASSERT(product, return false);
+ return product->id() == Constants::C_NIMBUILDCONFIGURATION_ID;
+}
+
+BuildConfiguration *NimBuildConfigurationFactory::clone(Target *parent, BuildConfiguration *product)
+{
+ QTC_ASSERT(parent, return nullptr);
+ QTC_ASSERT(product, return nullptr);
+ auto buildConfiguration = qobject_cast(product);
+ QTC_ASSERT(buildConfiguration, return nullptr);
+ std::unique_ptr result(new NimBuildConfiguration(parent));
+ return result->fromMap(buildConfiguration->toMap()) ? result.release() : nullptr;
+}
+
+int NimBuildConfigurationFactory::priority(const Kit *k, const QString &projectPath) const
+{
+ Q_UNUSED(k);
+ Q_UNUSED(projectPath);
+ return 0;
+}
+
+int NimBuildConfigurationFactory::priority(const Target *parent) const
+{
+ Q_UNUSED(parent);
+ return 0;
+}
+
+FileName NimBuildConfigurationFactory::defaultBuildDirectory(const Kit *k,
+ const QString &projectFilePath,
+ const QString &bc,
+ BuildConfiguration::BuildType buildType)
+{
+ QFileInfo projectFileInfo(projectFilePath);
+
+ ProjectMacroExpander expander(projectFileInfo.baseName(), k, bc, buildType);
+ QString buildDirectory = expander.expand(Core::DocumentManager::buildDirectory());
+
+ if (FileUtils::isAbsolutePath(buildDirectory))
+ return FileName::fromString(buildDirectory);
+
+ auto projectDir = FileName::fromString(projectFileInfo.absoluteDir().absolutePath());
+ auto result = projectDir.appendPath(buildDirectory);
+
+ return result;
+}
+
+NimBuildInfo *NimBuildConfigurationFactory::createBuildInfo(const Kit *k,
+ const QString &projectFilePath,
+ BuildConfiguration::BuildType buildType) const
+{
+ auto result = new NimBuildInfo(buildType, this);
+ result->displayName = BuildConfiguration::buildTypeName(buildType);
+ result->buildDirectory = defaultBuildDirectory(k, projectFilePath, result->displayName, buildType);
+ result->kitId = k->id();
+ result->typeName = tr("Build");
+ return result;
+}
+
+}
diff --git a/src/plugins/nim/project/nimbuildconfigurationfactory.h b/src/plugins/nim/project/nimbuildconfigurationfactory.h
new file mode 100644
index 0000000000000000000000000000000000000000..0ba88b05272c18ea1412e37d61152eb5b0a30cc4
--- /dev/null
+++ b/src/plugins/nim/project/nimbuildconfigurationfactory.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace Nim {
+
+class NimBuildInfo;
+
+class NimBuildConfigurationFactory : public ProjectExplorer::IBuildConfigurationFactory
+{
+ Q_OBJECT
+
+public:
+ explicit NimBuildConfigurationFactory(QObject *parent = 0);
+
+ QList availableBuilds(const ProjectExplorer::Target *parent) const override;
+
+ QList availableSetups(const ProjectExplorer::Kit *k,
+ const QString &projectPath) const override;
+
+ ProjectExplorer::BuildConfiguration *create(ProjectExplorer::Target *parent,
+ const ProjectExplorer::BuildInfo *info) const override;
+
+ bool canRestore(const ProjectExplorer::Target *parent,
+ const QVariantMap &map) const override;
+
+ ProjectExplorer::BuildConfiguration *restore(ProjectExplorer::Target *parent,
+ const QVariantMap &map) override;
+
+ bool canClone(const ProjectExplorer::Target *parent,
+ ProjectExplorer::BuildConfiguration *product) const override;
+
+ ProjectExplorer::BuildConfiguration *clone(ProjectExplorer::Target *parent,
+ ProjectExplorer::BuildConfiguration *product) override;
+
+ int priority(const ProjectExplorer::Kit *k, const QString &projectPath) const override;
+
+ int priority(const ProjectExplorer::Target *parent) const override;
+
+private:
+ static Utils::FileName defaultBuildDirectory(const ProjectExplorer::Kit *k,
+ const QString &projectPath,
+ const QString &bc, ProjectExplorer::BuildConfiguration::BuildType buildType);
+
+ NimBuildInfo *createBuildInfo(const ProjectExplorer::Kit *k,
+ const QString &projectPath, ProjectExplorer::BuildConfiguration::BuildType buildType) const;
+};
+
+}
diff --git a/src/plugins/nim/project/nimbuildconfigurationwidget.cpp b/src/plugins/nim/project/nimbuildconfigurationwidget.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b36a344db01bb0867fcb8e8822ca32d055e20a7f
--- /dev/null
+++ b/src/plugins/nim/project/nimbuildconfigurationwidget.cpp
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimbuildconfigurationwidget.h"
+
+#include "nimconstants.h"
+#include "project/nimbuildconfiguration.h"
+
+#include
+#include
+
+#include
+#include
+#include
+
+using namespace ProjectExplorer;
+using namespace Utils;
+
+namespace Nim {
+
+NimBuildConfigurationWidget::NimBuildConfigurationWidget(NimBuildConfiguration *bc)
+ : NamedWidget(nullptr)
+ , m_bc(bc)
+{
+ // Build UI
+ auto mainLayout = new QVBoxLayout(this);
+ mainLayout->setMargin(0);
+
+ auto detailsWidget = new DetailsWidget();
+ detailsWidget->setState(DetailsWidget::NoSummary);
+ mainLayout->addWidget(detailsWidget);
+
+ auto detailsInnerWidget = new QWidget();
+ auto formLayout = new QFormLayout(detailsInnerWidget);
+ detailsWidget->setWidget(detailsInnerWidget);
+
+ m_buildDirectoryChooser = new PathChooser();
+ formLayout->addRow(tr("Build directory:"), m_buildDirectoryChooser);
+
+ // Connect signals
+ connect(bc, &NimBuildConfiguration::buildDirectoryChanged,
+ this, &NimBuildConfigurationWidget::updateUi);
+ connect(m_buildDirectoryChooser, &PathChooser::pathChanged,
+ this, &NimBuildConfigurationWidget::onPathEdited);
+
+ setDisplayName(tr(Constants::C_NIMBUILDCONFIGURATIONWIDGET_DISPLAY));
+ updateUi();
+}
+
+NimBuildConfigurationWidget::~NimBuildConfigurationWidget() = default;
+
+void NimBuildConfigurationWidget::updateUi()
+{
+ m_buildDirectoryChooser->setPath(m_bc->buildDirectory().toUserOutput());
+}
+
+void NimBuildConfigurationWidget::onPathEdited(const QString &path)
+{
+ m_bc->setBuildDirectory(FileName::fromUserInput(path));
+}
+
+
+}
diff --git a/src/plugins/nim/project/nimbuildconfigurationwidget.h b/src/plugins/nim/project/nimbuildconfigurationwidget.h
new file mode 100644
index 0000000000000000000000000000000000000000..cb6251b3ec94224070335f7e55ee559093ef28c5
--- /dev/null
+++ b/src/plugins/nim/project/nimbuildconfigurationwidget.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QLineEdit;
+class QPushButton;
+QT_END_NAMESPACE
+
+namespace Utils { class PathChooser; }
+
+namespace Nim {
+
+class NimBuildConfiguration;
+
+class NimBuildConfigurationWidget : public ProjectExplorer::NamedWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NimBuildConfigurationWidget(NimBuildConfiguration *bc);
+ ~NimBuildConfigurationWidget();
+
+private:
+ void updateUi();
+ void onPathEdited(const QString &path);
+
+ NimBuildConfiguration *m_bc;
+ Utils::PathChooser *m_buildDirectoryChooser;
+};
+
+}
diff --git a/src/plugins/nim/project/nimbuildinfo.cpp b/src/plugins/nim/project/nimbuildinfo.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b6d6eec205e587efb8f2c1cebaebd124b2e20889
--- /dev/null
+++ b/src/plugins/nim/project/nimbuildinfo.cpp
@@ -0,0 +1,46 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimbuildinfo.h"
+
+#include "project/nimbuildconfigurationfactory.h"
+
+using namespace ProjectExplorer;
+
+namespace Nim {
+
+NimBuildInfo::NimBuildInfo(BuildConfiguration::BuildType buildType,
+ const NimBuildConfigurationFactory *factory)
+ : BuildInfo(factory)
+ , m_buildType(buildType)
+{}
+
+BuildConfiguration::BuildType NimBuildInfo::buildType() const
+{
+ return m_buildType;
+}
+
+}
+
diff --git a/src/plugins/nim/project/nimbuildinfo.h b/src/plugins/nim/project/nimbuildinfo.h
new file mode 100644
index 0000000000000000000000000000000000000000..d6b5fe40d16191a5771acd517a8fb109843dd169
--- /dev/null
+++ b/src/plugins/nim/project/nimbuildinfo.h
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+#include
+
+namespace Nim {
+
+class NimBuildConfigurationFactory;
+
+class NimBuildInfo : public ProjectExplorer::BuildInfo
+{
+public:
+ NimBuildInfo(ProjectExplorer::BuildConfiguration::BuildType buildType,
+ const NimBuildConfigurationFactory *factory);
+
+
+ ProjectExplorer::BuildConfiguration::BuildType buildType() const;
+
+private:
+ ProjectExplorer::BuildConfiguration::BuildType m_buildType;
+};
+
+}
diff --git a/src/plugins/nim/project/nimcompilerbuildstep.cpp b/src/plugins/nim/project/nimcompilerbuildstep.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..08973c08aaaf3705817e7fd120ef7a71d1fa7198
--- /dev/null
+++ b/src/plugins/nim/project/nimcompilerbuildstep.cpp
@@ -0,0 +1,206 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimcompilerbuildstep.h"
+
+#include "nimconstants.h"
+#include "project/nimbuildconfiguration.h"
+#include "project/nimcompilerbuildstepconfigwidget.h"
+
+#include
+#include
+
+#include
+
+using namespace ProjectExplorer;
+using namespace Utils;
+
+namespace Nim {
+
+NimCompilerBuildStep::NimCompilerBuildStep(BuildStepList *parentList)
+ : AbstractProcessStep(parentList, Constants::C_NIMCOMPILERBUILDSTEP_ID)
+{
+ setDefaultDisplayName(tr(Constants::C_NIMCOMPILERBUILDSTEP_DISPLAY));
+ setDisplayName(tr(Constants::C_NIMCOMPILERBUILDSTEP_DISPLAY));
+
+ auto bc = qobject_cast(buildConfiguration());
+ connect(bc, &NimBuildConfiguration::buildDirectoryChanged,
+ this, &NimCompilerBuildStep::updateProcessParameters);
+ connect(this, &NimCompilerBuildStep::outFilePathChanged,
+ bc, &NimBuildConfiguration::outFilePathChanged);
+ updateProcessParameters();
+}
+
+BuildStepConfigWidget *NimCompilerBuildStep::createConfigWidget()
+{
+ return new NimCompilerBuildStepConfigWidget(this);
+}
+
+bool NimCompilerBuildStep::fromMap(const QVariantMap &map)
+{
+ AbstractProcessStep::fromMap(map);
+ m_userCompilerOptions = map[Constants::C_NIMCOMPILERBUILDSTEP_USERCOMPILEROPTIONS].toString().split(QLatin1Char('|'));
+ m_defaultOptions = static_cast(map[Constants::C_NIMCOMPILERBUILDSTEP_DEFAULTBUILDOPTIONS].toInt());
+ m_targetNimFile = FileName::fromString(map[Constants::C_NIMCOMPILERBUILDSTEP_TARGETNIMFILE].toString());
+ updateProcessParameters();
+ return true;
+}
+
+QVariantMap NimCompilerBuildStep::toMap() const
+{
+ QVariantMap result = AbstractProcessStep::toMap();
+ result[Constants::C_NIMCOMPILERBUILDSTEP_USERCOMPILEROPTIONS] = m_userCompilerOptions.join(QLatin1Char('|'));
+ result[Constants::C_NIMCOMPILERBUILDSTEP_DEFAULTBUILDOPTIONS] = m_defaultOptions;
+ result[Constants::C_NIMCOMPILERBUILDSTEP_TARGETNIMFILE] = m_targetNimFile.toString();
+ return result;
+}
+
+QStringList NimCompilerBuildStep::userCompilerOptions() const
+{
+ return m_userCompilerOptions;
+}
+
+void NimCompilerBuildStep::setUserCompilerOptions(const QStringList &options)
+{
+ m_userCompilerOptions = options;
+ emit userCompilerOptionsChanged(options);
+ updateProcessParameters();
+}
+
+NimCompilerBuildStep::DefaultBuildOptions NimCompilerBuildStep::defaultCompilerOptions() const
+{
+ return m_defaultOptions;
+}
+
+void NimCompilerBuildStep::setDefaultCompilerOptions(NimCompilerBuildStep::DefaultBuildOptions options)
+{
+ if (m_defaultOptions == options)
+ return;
+ m_defaultOptions = options;
+ emit defaultCompilerOptionsChanged(options);
+ updateProcessParameters();
+}
+
+FileName NimCompilerBuildStep::targetNimFile() const
+{
+ return m_targetNimFile;
+}
+
+void NimCompilerBuildStep::setTargetNimFile(const FileName &targetNimFile)
+{
+ if (targetNimFile == m_targetNimFile)
+ return;
+ m_targetNimFile = targetNimFile;
+ emit targetNimFileChanged(targetNimFile);
+ updateProcessParameters();
+}
+
+FileName NimCompilerBuildStep::outFilePath() const
+{
+ return m_outFilePath;
+}
+
+void NimCompilerBuildStep::setOutFilePath(const FileName &outFilePath)
+{
+ if (outFilePath == m_outFilePath)
+ return;
+ m_outFilePath = outFilePath;
+ emit outFilePathChanged(outFilePath);
+}
+
+void NimCompilerBuildStep::updateProcessParameters()
+{
+ updateOutFilePath();
+ updateCommand();
+ updateArguments();
+ updateWorkingDirectory();
+ updateEnvironment();
+ emit processParametersChanged();
+}
+
+void NimCompilerBuildStep::updateOutFilePath()
+{
+ auto bc = qobject_cast(buildConfiguration());
+ QTC_ASSERT(bc, return);
+ const QString targetName = Utils::HostOsInfo::withExecutableSuffix(m_targetNimFile.toFileInfo().baseName());
+ FileName outFilePath = bc->buildDirectory().appendPath(targetName);
+ setOutFilePath(outFilePath);
+}
+
+void NimCompilerBuildStep::updateCommand()
+{
+ processParameters()->setCommand(QStringLiteral("nim"));
+}
+
+void NimCompilerBuildStep::updateWorkingDirectory()
+{
+ auto bc = qobject_cast(buildConfiguration());
+ QTC_ASSERT(bc, return);
+ processParameters()->setWorkingDirectory(bc->buildDirectory().toString());
+}
+
+void NimCompilerBuildStep::updateArguments()
+{
+ auto bc = qobject_cast(buildConfiguration());
+ QTC_ASSERT(bc, return);
+
+ QStringList arguments;
+ arguments << QStringLiteral("c");
+
+ switch (m_defaultOptions) {
+ case Release:
+ arguments << QStringLiteral("-d:release");
+ break;
+ case Debug:
+ arguments << QStringLiteral("--debugInfo")
+ << QStringLiteral("--lineDir:on");
+ break;
+ default:
+ break;
+ }
+
+ arguments << QStringLiteral("--out:%1").arg(m_outFilePath.toString());
+ arguments << QStringLiteral("--nimCache:%1").arg(bc->cacheDirectory().toString());
+
+ arguments << m_userCompilerOptions;
+ arguments << m_targetNimFile.toString();
+
+ // Remove empty args
+ auto predicate = [](const QString &str) { return str.isEmpty(); };
+ auto it = std::remove_if(arguments.begin(), arguments.end(), predicate);
+ arguments.erase(it, arguments.end());
+
+ processParameters()->setArguments(arguments.join(QChar::Space));
+}
+
+void NimCompilerBuildStep::updateEnvironment()
+{
+ auto bc = qobject_cast(buildConfiguration());
+ QTC_ASSERT(bc, return);
+ processParameters()->setEnvironment(bc->environment());
+}
+
+}
+
diff --git a/src/plugins/nim/project/nimcompilerbuildstep.h b/src/plugins/nim/project/nimcompilerbuildstep.h
new file mode 100644
index 0000000000000000000000000000000000000000..1c22df27073edd2e7b27be5215d601d9f6f729a7
--- /dev/null
+++ b/src/plugins/nim/project/nimcompilerbuildstep.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+#include
+#include
+#include
+
+namespace Nim {
+
+class NimCompilerBuildStep : public ProjectExplorer::AbstractProcessStep
+{
+ Q_OBJECT
+
+public:
+ enum DefaultBuildOptions { Empty = 0, Debug, Release};
+
+ NimCompilerBuildStep(ProjectExplorer::BuildStepList *parentList);
+
+ ProjectExplorer::BuildStepConfigWidget *createConfigWidget() override;
+
+ bool fromMap(const QVariantMap &map) override;
+ QVariantMap toMap() const override;
+
+ QStringList userCompilerOptions() const;
+ void setUserCompilerOptions(const QStringList &options);
+
+ DefaultBuildOptions defaultCompilerOptions() const;
+ void setDefaultCompilerOptions(DefaultBuildOptions options);
+
+ Utils::FileName targetNimFile() const;
+ void setTargetNimFile(const Utils::FileName &targetNimFile);
+
+ Utils::FileName outFilePath() const;
+
+signals:
+ void userCompilerOptionsChanged(const QStringList &options);
+ void defaultCompilerOptionsChanged(DefaultBuildOptions options);
+ void targetNimFileChanged(const Utils::FileName &targetNimFile);
+ void processParametersChanged();
+ void outFilePathChanged(const Utils::FileName &outFilePath);
+
+private:
+ void setOutFilePath(const Utils::FileName &outFilePath);
+
+ void updateOutFilePath();
+ void updateProcessParameters();
+ void updateCommand();
+ void updateWorkingDirectory();
+ void updateArguments();
+ void updateEnvironment();
+
+ DefaultBuildOptions m_defaultOptions;
+ QStringList m_userCompilerOptions;
+ Utils::FileName m_targetNimFile;
+ Utils::FileName m_outFilePath;
+};
+
+}
diff --git a/src/plugins/nim/project/nimcompilerbuildstepconfigwidget.cpp b/src/plugins/nim/project/nimcompilerbuildstepconfigwidget.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..cc7d56bda5c1237a5e72dc462dadc025adf0e0e7
--- /dev/null
+++ b/src/plugins/nim/project/nimcompilerbuildstepconfigwidget.cpp
@@ -0,0 +1,152 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimcompilerbuildstepconfigwidget.h"
+#include "ui_nimcompilerbuildstepconfigwidget.h"
+
+#include "nimconstants.h"
+#include "nimproject.h"
+#include "project/nimbuildconfiguration.h"
+#include "project/nimcompilerbuildstep.h"
+
+#include
+
+using namespace ProjectExplorer;
+using namespace Utils;
+
+namespace Nim {
+
+NimCompilerBuildStepConfigWidget::NimCompilerBuildStepConfigWidget(NimCompilerBuildStep *buildStep)
+ : BuildStepConfigWidget()
+ , m_buildStep(buildStep)
+ , m_ui(new Ui::NimCompilerBuildStepConfigWidget())
+{
+ m_ui->setupUi(this);
+
+ // Connect the project signals
+ auto project = static_cast(m_buildStep->project());
+ connect(project, &NimProject::fileListChanged,
+ this, &NimCompilerBuildStepConfigWidget::updateUi);
+
+ // Connect build step signals
+ connect(m_buildStep, &NimCompilerBuildStep::processParametersChanged,
+ this, &NimCompilerBuildStepConfigWidget::updateUi);
+
+ // Connect UI signals
+ connect(m_ui->targetComboBox, static_cast(&QComboBox::activated),
+ this, &NimCompilerBuildStepConfigWidget::onTargetChanged);
+ connect(m_ui->additionalArgumentsLineEdit, &QLineEdit::textEdited,
+ this, &NimCompilerBuildStepConfigWidget::onAdditionalArgumentsTextEdited);
+ connect(m_ui->defaultArgumentsComboBox, static_cast(&QComboBox::activated),
+ this, &NimCompilerBuildStepConfigWidget::onDefaultArgumentsComboBoxIndexChanged);
+
+ updateUi();
+}
+
+NimCompilerBuildStepConfigWidget::~NimCompilerBuildStepConfigWidget() = default;
+
+QString NimCompilerBuildStepConfigWidget::summaryText() const
+{
+ return tr(Constants::C_NIMCOMPILERBUILDSTEPWIDGET_SUMMARY);
+}
+
+QString NimCompilerBuildStepConfigWidget::displayName() const
+{
+ return tr(Constants::C_NIMCOMPILERBUILDSTEPWIDGET_DISPLAY);
+}
+
+void NimCompilerBuildStepConfigWidget::onTargetChanged(int index)
+{
+ Q_UNUSED(index);
+ auto data = m_ui->targetComboBox->currentData();
+ FileName path = FileName::fromString(data.toString());
+ m_buildStep->setTargetNimFile(path);
+}
+
+void NimCompilerBuildStepConfigWidget::onDefaultArgumentsComboBoxIndexChanged(int index)
+{
+ auto options = static_cast(index);
+ m_buildStep->setDefaultCompilerOptions(options);
+}
+
+void NimCompilerBuildStepConfigWidget::updateUi()
+{
+ updateCommandLineText();
+ updateTargetComboBox();
+ updateAdditionalArgumentsLineEdit();
+ updateDefaultArgumentsComboBox();
+}
+
+void NimCompilerBuildStepConfigWidget::onAdditionalArgumentsTextEdited(const QString &text)
+{
+ m_buildStep->setUserCompilerOptions(text.split(QChar::Space));
+}
+
+void NimCompilerBuildStepConfigWidget::updateCommandLineText()
+{
+ ProcessParameters *parameters = m_buildStep->processParameters();
+
+ QStringList command;
+ command << parameters->command();
+ command << parameters->arguments();
+
+ // Remove empty args
+ auto predicate = [](const QString & str) { return str.isEmpty(); };
+ auto it = std::remove_if(command.begin(), command.end(), predicate);
+ command.erase(it, command.end());
+
+ m_ui->commandTextEdit->setText(command.join(QChar::LineFeed));
+}
+
+void NimCompilerBuildStepConfigWidget::updateTargetComboBox()
+{
+ QTC_ASSERT(m_buildStep, return);
+
+ auto project = qobject_cast(m_buildStep->project());
+ QTC_ASSERT(project, return);
+
+ // Re enter the files
+ m_ui->targetComboBox->clear();
+ foreach (const FileName &file, project->nimFiles())
+ m_ui->targetComboBox->addItem(file.fileName(), file.toString());
+
+ const int index = m_ui->targetComboBox->findData(m_buildStep->targetNimFile().toString());
+ m_ui->targetComboBox->setCurrentIndex(index);
+}
+
+void NimCompilerBuildStepConfigWidget::updateAdditionalArgumentsLineEdit()
+{
+ const QString text = m_buildStep->userCompilerOptions().join(QChar::Space);
+ m_ui->additionalArgumentsLineEdit->setText(text);
+}
+
+void NimCompilerBuildStepConfigWidget::updateDefaultArgumentsComboBox()
+{
+ const int index = m_buildStep->defaultCompilerOptions();
+ m_ui->defaultArgumentsComboBox->setCurrentIndex(index);
+}
+
+}
+
diff --git a/src/plugins/nim/project/nimcompilerbuildstepconfigwidget.h b/src/plugins/nim/project/nimcompilerbuildstepconfigwidget.h
new file mode 100644
index 0000000000000000000000000000000000000000..f2a115b63ed5058bf44736e7ad50b4937763aba0
--- /dev/null
+++ b/src/plugins/nim/project/nimcompilerbuildstepconfigwidget.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace Nim {
+
+class NimCompilerBuildStep;
+
+namespace Ui { class NimCompilerBuildStepConfigWidget; }
+
+class NimCompilerBuildStepConfigWidget : public ProjectExplorer::BuildStepConfigWidget
+{
+ Q_OBJECT
+
+public:
+ NimCompilerBuildStepConfigWidget(NimCompilerBuildStep *buildStep);
+ ~NimCompilerBuildStepConfigWidget();
+
+ QString summaryText() const override;
+ QString displayName() const override;
+
+private:
+ void updateUi();
+ void updateCommandLineText();
+ void updateTargetComboBox();
+ void updateAdditionalArgumentsLineEdit();
+ void updateDefaultArgumentsComboBox();
+
+ void onAdditionalArgumentsTextEdited(const QString &text);
+ void onTargetChanged(int index);
+ void onDefaultArgumentsComboBoxIndexChanged(int index);
+
+ NimCompilerBuildStep *m_buildStep;
+ QScopedPointer m_ui;
+};
+
+}
diff --git a/src/plugins/nim/project/nimcompilerbuildstepconfigwidget.ui b/src/plugins/nim/project/nimcompilerbuildstepconfigwidget.ui
new file mode 100644
index 0000000000000000000000000000000000000000..88bf376aaa36db9490c9da91ac44cbc9512bd19f
--- /dev/null
+++ b/src/plugins/nim/project/nimcompilerbuildstepconfigwidget.ui
@@ -0,0 +1,94 @@
+
+
+ Nim::NimCompilerBuildStepConfigWidget
+
+
+ true
+
+
+
+ 0
+ 0
+ 497
+ 283
+
+
+
+ Form
+
+
+ -
+
+
-
+
+
+ Target:
+
+
+
+ -
+
+
+ -
+
+
+ Extra arguments:
+
+
+
+ -
+
+
+ -
+
+
+ Command:
+
+
+
+ -
+
+
+ false
+
+
+
+ 0
+ 0
+
+
+
+
+ -
+
+
+ Default arguments:
+
+
+
+ -
+
+
-
+
+ None
+
+
+ -
+
+ Debug
+
+
+ -
+
+ Release
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/plugins/nim/project/nimcompilerbuildstepfactory.cpp b/src/plugins/nim/project/nimcompilerbuildstepfactory.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ec8861b5bdb496d3c5e18e2c08dc0e6718a11516
--- /dev/null
+++ b/src/plugins/nim/project/nimcompilerbuildstepfactory.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimcompilerbuildstepfactory.h"
+
+#include "nimconstants.h"
+#include "project/nimbuildconfiguration.h"
+#include "project/nimcompilerbuildstep.h"
+
+#include
+#include
+
+#include
+
+using namespace ProjectExplorer;
+
+namespace Nim {
+
+NimCompilerBuildStepFactory::NimCompilerBuildStepFactory(QObject *parent)
+ : IBuildStepFactory(parent)
+{}
+
+bool NimCompilerBuildStepFactory::canCreate(BuildStepList *parent, Core::Id id) const
+{
+ QTC_ASSERT(parent, return false);
+ if (parent->id() != ProjectExplorer::Constants::BUILDSTEPS_BUILD)
+ return false;
+ if (!qobject_cast(parent->parent()))
+ return false;
+ return id == Constants::C_NIMCOMPILERBUILDSTEP_ID;
+}
+
+BuildStep *NimCompilerBuildStepFactory::create(BuildStepList *parent, Core::Id id)
+{
+ if (!canCreate(parent, id))
+ return nullptr;
+ return new NimCompilerBuildStep(parent);
+}
+
+bool NimCompilerBuildStepFactory::canClone(BuildStepList *parent, BuildStep *buildStep) const
+{
+ QTC_ASSERT(parent, return false);
+ QTC_ASSERT(buildStep, return false);
+ if (parent->id() != ProjectExplorer::Constants::BUILDSTEPS_BUILD)
+ return false;
+ if (!qobject_cast(parent->parent()))
+ return false;
+ return buildStep->id() == Constants::C_NIMCOMPILERBUILDSTEP_ID;
+}
+
+BuildStep *NimCompilerBuildStepFactory::clone(BuildStepList *parent, BuildStep *buildStep)
+{
+ QTC_ASSERT(parent, return nullptr);
+ QTC_ASSERT(buildStep, return nullptr);
+ std::unique_ptr result(new NimCompilerBuildStep(parent));
+ return result->fromMap(buildStep->toMap()) ? result.release() : nullptr;
+}
+
+bool NimCompilerBuildStepFactory::canRestore(BuildStepList *parent, const QVariantMap &map) const
+{
+ return canCreate(parent, idFromMap(map));
+}
+
+BuildStep *NimCompilerBuildStepFactory::restore(BuildStepList *parent, const QVariantMap &map)
+{
+ if (!canRestore(parent, map))
+ return nullptr;
+ std::unique_ptr buildStep(new NimCompilerBuildStep(parent));
+ if (buildStep->fromMap(map))
+ return buildStep.release();
+ return nullptr;
+}
+
+QList NimCompilerBuildStepFactory::availableCreationIds(BuildStepList *parent) const
+{
+ if (parent->id() == ProjectExplorer::Constants::BUILDSTEPS_BUILD)
+ if (auto bc = qobject_cast(parent->parent()))
+ if (!bc->hasNimCompilerBuildStep())
+ return { Constants::C_NIMCOMPILERBUILDSTEP_ID };
+ return {};
+}
+
+QString NimCompilerBuildStepFactory::displayNameForId(Core::Id id) const
+{
+ return id == Constants::C_NIMCOMPILERBUILDSTEP_ID ? tr("Nim Compiler Build Step") : QString();
+}
+
+}
+
diff --git a/src/plugins/nim/project/nimcompilerbuildstepfactory.h b/src/plugins/nim/project/nimcompilerbuildstepfactory.h
new file mode 100644
index 0000000000000000000000000000000000000000..481fd0ddf04c79299b9370e0cbaf06742127f201
--- /dev/null
+++ b/src/plugins/nim/project/nimcompilerbuildstepfactory.h
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace Nim {
+
+class NimCompilerBuildStepFactory : public ProjectExplorer::IBuildStepFactory
+{
+ Q_OBJECT
+
+public:
+ NimCompilerBuildStepFactory(QObject *parent = nullptr);
+
+ bool canCreate(ProjectExplorer::BuildStepList *parent, Core::Id id) const;
+ ProjectExplorer::BuildStep *create(ProjectExplorer::BuildStepList *parent, Core::Id id);
+
+ bool canClone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *product) const;
+ ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *product);
+
+ bool canRestore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) const;
+ ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map);
+
+ QList availableCreationIds(ProjectExplorer::BuildStepList *parent) const;
+ QString displayNameForId(Core::Id id) const;
+};
+
+}
diff --git a/src/plugins/nim/project/nimcompilercleanstep.cpp b/src/plugins/nim/project/nimcompilercleanstep.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..79583634a3288a432c726f536f0e9529bd3327c7
--- /dev/null
+++ b/src/plugins/nim/project/nimcompilercleanstep.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimcompilercleanstep.h"
+
+#include "nimconstants.h"
+#include "project/nimbuildconfiguration.h"
+#include "project/nimcompilercleanstepconfigwidget.h"
+
+#include
+
+#include
+#include
+
+using namespace ProjectExplorer;
+using namespace Utils;
+
+namespace Nim {
+
+NimCompilerCleanStep::NimCompilerCleanStep(BuildStepList *parentList)
+ : BuildStep(parentList, Constants::C_NIMCOMPILERCLEANSTEP_ID)
+{
+ setDefaultDisplayName(tr("Nim Clean Step"));
+ setDisplayName(tr("Nim Clean Step"));
+}
+
+BuildStepConfigWidget *NimCompilerCleanStep::createConfigWidget()
+{
+ return new NimCompilerCleanStepConfigWidget(this);
+}
+
+bool NimCompilerCleanStep::init(QList &)
+{
+ FileName buildDir = buildConfiguration()->buildDirectory();
+ bool result = buildDir.exists();
+ if (result)
+ m_buildDir = buildDir;
+ return result;
+}
+
+void NimCompilerCleanStep::run(QFutureInterface &fi)
+{
+ if (!m_buildDir.exists()) {
+ emit addOutput(tr("Build directory \"%1\" does not exist.").arg(m_buildDir.toUserOutput()), BuildStep::ErrorMessageOutput);
+ reportRunResult(fi, false);
+ return;
+ }
+
+ if (!removeCacheDirectory()) {
+ emit addOutput(tr("Failed to delete the cache directory."), BuildStep::ErrorMessageOutput);
+ reportRunResult(fi, false);
+ return;
+ }
+
+ if (!removeOutFilePath()) {
+ emit addOutput(tr("Failed to delete the out file."), BuildStep::ErrorMessageOutput);
+ reportRunResult(fi, false);
+ return;
+ }
+
+ emit addOutput(tr("Clean step completed successfully."), BuildStep::NormalOutput);
+ reportRunResult(fi, true);
+}
+
+bool NimCompilerCleanStep::removeCacheDirectory()
+{
+ auto bc = qobject_cast(buildConfiguration());
+ QTC_ASSERT(bc, return false);
+ if (!bc->cacheDirectory().exists())
+ return true;
+ QDir dir = QDir::fromNativeSeparators(bc->cacheDirectory().toString());
+ const QString dirName = dir.dirName();
+ if (!dir.cdUp())
+ return false;
+ const QString newName = QStringLiteral("%1.bkp.%2").arg(dirName, QString::number(QDateTime::currentMSecsSinceEpoch()));
+ return dir.rename(dirName, newName);
+}
+
+bool NimCompilerCleanStep::removeOutFilePath()
+{
+ auto bc = qobject_cast(buildConfiguration());
+ QTC_ASSERT(bc, return false);
+ if (!bc->outFilePath().exists())
+ return true;
+ return QFile(bc->outFilePath().toFileInfo().absoluteFilePath()).remove();
+}
+
+}
+
diff --git a/src/plugins/nim/project/nimcompilercleanstep.h b/src/plugins/nim/project/nimcompilercleanstep.h
new file mode 100644
index 0000000000000000000000000000000000000000..9d3e52d1bfa5ea9d9527791d45ba787382d54f93
--- /dev/null
+++ b/src/plugins/nim/project/nimcompilercleanstep.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+#include
+#include
+
+namespace Nim {
+
+class NimCompilerCleanStep : public ProjectExplorer::BuildStep
+{
+ Q_OBJECT
+
+public:
+ NimCompilerCleanStep(ProjectExplorer::BuildStepList *parentList);
+
+ ProjectExplorer::BuildStepConfigWidget *createConfigWidget() override;
+
+ bool init(QList &earlierSteps) override;
+
+ void run(QFutureInterface &fi) override;
+
+private:
+ bool removeCacheDirectory();
+ bool removeOutFilePath();
+
+ Utils::FileName m_buildDir;
+};
+
+}
diff --git a/src/plugins/nim/project/nimcompilercleanstepconfigwidget.cpp b/src/plugins/nim/project/nimcompilercleanstepconfigwidget.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3b8d6f289d27509b88b9f299b1918edd3dc08fd0
--- /dev/null
+++ b/src/plugins/nim/project/nimcompilercleanstepconfigwidget.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimcompilercleanstepconfigwidget.h"
+#include "ui_nimcompilercleanstepconfigwidget.h"
+
+#include "nimconstants.h"
+#include "project/nimcompilercleanstep.h"
+
+#include "projectexplorer/buildconfiguration.h"
+
+using namespace ProjectExplorer;
+
+namespace Nim {
+
+NimCompilerCleanStepConfigWidget::NimCompilerCleanStepConfigWidget(NimCompilerCleanStep *cleanStep)
+ : BuildStepConfigWidget()
+ , m_cleanStep(cleanStep)
+ , m_ui(new Ui::NimCompilerCleanStepConfigWidget())
+{
+ m_ui->setupUi(this);
+ connect(cleanStep->buildConfiguration(), &BuildConfiguration::buildDirectoryChanged,
+ this, &NimCompilerCleanStepConfigWidget::updateUi);
+ updateUi();
+}
+
+NimCompilerCleanStepConfigWidget::~NimCompilerCleanStepConfigWidget() = default;
+
+QString NimCompilerCleanStepConfigWidget::summaryText() const
+{
+ return tr(Constants::C_NIMCOMPILERCLEANSTEPWIDGET_SUMMARY);
+}
+
+QString NimCompilerCleanStepConfigWidget::displayName() const
+{
+ return tr(Constants::C_NIMCOMPILERCLEANSTEPWIDGET_DISPLAY);
+}
+
+void NimCompilerCleanStepConfigWidget::updateUi()
+{
+ auto buildDiretory = m_cleanStep->buildConfiguration()->buildDirectory();
+ m_ui->workingDirectoryLineEdit->setText(buildDiretory.toString());
+}
+
+}
+
diff --git a/src/plugins/nim/project/nimcompilercleanstepconfigwidget.h b/src/plugins/nim/project/nimcompilercleanstepconfigwidget.h
new file mode 100644
index 0000000000000000000000000000000000000000..409f412b842794ab4f72fbd3f70b2345704ddccc
--- /dev/null
+++ b/src/plugins/nim/project/nimcompilercleanstepconfigwidget.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace Nim {
+
+class NimCompilerCleanStep;
+
+namespace Ui { class NimCompilerCleanStepConfigWidget; }
+
+class NimCompilerCleanStepConfigWidget : public ProjectExplorer::BuildStepConfigWidget
+{
+ Q_OBJECT
+
+public:
+ NimCompilerCleanStepConfigWidget(NimCompilerCleanStep *cleanStep);
+
+ ~NimCompilerCleanStepConfigWidget();
+
+ QString summaryText() const override;
+
+ QString displayName() const override;
+
+private:
+ void updateUi();
+
+ NimCompilerCleanStep *m_cleanStep;
+ QScopedPointer m_ui;
+};
+
+}
diff --git a/src/plugins/nim/project/nimcompilercleanstepconfigwidget.ui b/src/plugins/nim/project/nimcompilercleanstepconfigwidget.ui
new file mode 100644
index 0000000000000000000000000000000000000000..f9a7d5dfd99afa9178f847e9e7cfafb23aecfee6
--- /dev/null
+++ b/src/plugins/nim/project/nimcompilercleanstepconfigwidget.ui
@@ -0,0 +1,39 @@
+
+
+ Nim::NimCompilerCleanStepConfigWidget
+
+
+
+ 0
+ 0
+ 400
+ 300
+
+
+
+ Form
+
+
+ -
+
+
-
+
+
+ Working directory:
+
+
+
+ -
+
+
+ true
+
+
+
+
+
+
+
+
+
+
diff --git a/src/plugins/nim/project/nimcompilercleanstepfactory.cpp b/src/plugins/nim/project/nimcompilercleanstepfactory.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..cc7863c30a6a356844d95ff42deb577e2b1cbd4c
--- /dev/null
+++ b/src/plugins/nim/project/nimcompilercleanstepfactory.cpp
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimcompilercleanstepfactory.h"
+
+#include "nimconstants.h"
+#include "project/nimbuildconfiguration.h"
+#include "project/nimcompilercleanstep.h"
+
+#include
+
+#include
+
+using namespace ProjectExplorer;
+
+namespace Nim {
+
+NimCompilerCleanStepFactory::NimCompilerCleanStepFactory(QObject *parent)
+ : IBuildStepFactory(parent)
+{}
+
+bool NimCompilerCleanStepFactory::canCreate(BuildStepList *parent, Core::Id id) const
+{
+ if (parent->id() != ProjectExplorer::Constants::BUILDSTEPS_CLEAN)
+ return false;
+ if (!qobject_cast(parent->parent()))
+ return false;
+ return id == Constants::C_NIMCOMPILERCLEANSTEP_ID;
+}
+
+BuildStep *NimCompilerCleanStepFactory::create(BuildStepList *parent, Core::Id id)
+{
+ if (!canCreate(parent, id))
+ return nullptr;
+ return new NimCompilerCleanStep(parent);
+}
+
+bool NimCompilerCleanStepFactory::canClone(BuildStepList *, BuildStep *) const
+{
+ return false;
+}
+
+BuildStep *NimCompilerCleanStepFactory::clone(BuildStepList *, BuildStep *)
+{
+ return nullptr;
+}
+
+bool NimCompilerCleanStepFactory::canRestore(BuildStepList *parent, const QVariantMap &map) const
+{
+ return canCreate(parent, idFromMap(map));
+}
+
+BuildStep *NimCompilerCleanStepFactory::restore(BuildStepList *parent, const QVariantMap &map)
+{
+ if (!canRestore(parent, map))
+ return nullptr;
+ std::unique_ptr cleanStep(new NimCompilerCleanStep(parent));
+ if (cleanStep->fromMap(map))
+ return cleanStep.release();
+ return nullptr;
+}
+
+QList NimCompilerCleanStepFactory::availableCreationIds(BuildStepList *parent) const
+{
+ if (parent->id() == ProjectExplorer::Constants::BUILDSTEPS_CLEAN)
+ if (auto bc = qobject_cast(parent->parent()))
+ if (!bc->hasNimCompilerCleanStep())
+ return { Constants::C_NIMCOMPILERCLEANSTEP_ID };
+ return {};
+}
+
+QString NimCompilerCleanStepFactory::displayNameForId(Core::Id id) const
+{
+ return id == Constants::C_NIMCOMPILERCLEANSTEP_ID ? tr(Nim::Constants::C_NIMCOMPILERCLEANSTEP_DISPLAY) : QString();
+}
+
+}
diff --git a/src/plugins/nim/project/nimcompilercleanstepfactory.h b/src/plugins/nim/project/nimcompilercleanstepfactory.h
new file mode 100644
index 0000000000000000000000000000000000000000..2025f83affc4f3ee70d8e0d6138c743c01c0f5a9
--- /dev/null
+++ b/src/plugins/nim/project/nimcompilercleanstepfactory.h
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace Nim {
+
+class NimCompilerCleanStepFactory : public ProjectExplorer::IBuildStepFactory
+{
+ Q_OBJECT
+
+public:
+ NimCompilerCleanStepFactory(QObject *parent = nullptr);
+
+ bool canCreate(ProjectExplorer::BuildStepList *parent, Core::Id id) const;
+ ProjectExplorer::BuildStep *create(ProjectExplorer::BuildStepList *parent, Core::Id id);
+
+ bool canClone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *product) const;
+ ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *product);
+
+ bool canRestore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) const;
+ ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map);
+
+ QList availableCreationIds(ProjectExplorer::BuildStepList *parent) const;
+ QString displayNameForId(Core::Id id) const;
+};
+
+}
diff --git a/src/plugins/nim/project/nimproject.cpp b/src/plugins/nim/project/nimproject.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..18e09d6dd1f2d6411a9ff65e78759302e368ecb2
--- /dev/null
+++ b/src/plugins/nim/project/nimproject.cpp
@@ -0,0 +1,242 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimproject.h"
+
+#include "nimconstants.h"
+#include "project/nimbuildconfiguration.h"
+#include "project/nimprojectnode.h"
+#include "project/nimprojectmanager.h"
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+using namespace ProjectExplorer;
+using namespace Utils;
+
+namespace Nim {
+
+const int MIN_TIME_BETWEEN_PROJECT_SCANS = 4500;
+
+NimProject::NimProject(NimProjectManager *projectManager, const QString &fileName)
+ : m_projectManager(projectManager)
+ , m_document(new TextEditor::TextDocument)
+{
+ setDocument(m_document);
+ setId(Constants::C_NIMPROJECT_ID);
+ m_document->setFilePath(FileName::fromString(fileName));
+ m_projectFile = QFileInfo(fileName);
+ m_projectDir = m_projectFile.dir();
+ m_rootNode = new NimProjectNode(FileName::fromString(m_projectDir.absolutePath()));
+ m_rootNode->setDisplayName(m_projectDir.dirName());
+
+ m_projectScanTimer.setSingleShot(true);
+ connect(&m_projectScanTimer, &QTimer::timeout, this, &NimProject::populateProject);
+
+ populateProject();
+
+ connect(&m_fsWatcher, &QFileSystemWatcher::directoryChanged, this, &NimProject::scheduleProjectScan);
+}
+
+QString NimProject::displayName() const
+{
+ return m_projectDir.dirName();
+}
+
+IProjectManager *NimProject::projectManager() const
+{
+ return m_projectManager;
+}
+
+ProjectNode *NimProject::rootProjectNode() const
+{
+ return m_rootNode;
+}
+
+QStringList NimProject::files(FilesMode) const
+{
+ return QStringList(m_files.toList());
+}
+
+bool NimProject::needsConfiguration() const
+{
+ return targets().empty();
+}
+
+QString NimProject::projectDirectoryPath() const
+{
+ return m_projectDir.absolutePath();
+}
+
+QString NimProject::projectFilePath() const
+{
+ return m_projectFile.absoluteFilePath();
+}
+
+void NimProject::scheduleProjectScan()
+{
+ auto elapsedTime = m_lastProjectScan.elapsed();
+ if (elapsedTime < MIN_TIME_BETWEEN_PROJECT_SCANS) {
+ if (!m_projectScanTimer.isActive()) {
+ m_projectScanTimer.setInterval(MIN_TIME_BETWEEN_PROJECT_SCANS - elapsedTime);
+ m_projectScanTimer.start();
+ }
+ } else {
+ populateProject();
+ }
+}
+
+void NimProject::populateProject()
+{
+ m_lastProjectScan.start();
+
+ QSet oldFiles(m_files);
+ m_files.clear();
+
+ recursiveScanDirectory(m_projectDir, m_files);
+
+ QSet removedFiles = oldFiles - m_files;
+ QSet addedFiles = m_files - oldFiles;
+
+ removeNodes(removedFiles);
+ addNodes(addedFiles);
+
+ if (removedFiles.size() || addedFiles.size())
+ emit fileListChanged();
+}
+
+void NimProject::recursiveScanDirectory(const QDir &dir, QSet &container)
+{
+ static const QRegExp projectFilePattern(QLatin1String(".*\\.nimproject(?:\\.user)?$"));
+ for (const QFileInfo &info : dir.entryInfoList(QDir::AllDirs |
+ QDir::Files |
+ QDir::NoDotAndDotDot |
+ QDir::NoSymLinks |
+ QDir::CaseSensitive)) {
+ if (info.isDir())
+ recursiveScanDirectory(QDir(info.filePath()), container);
+ else if (projectFilePattern.indexIn(info.fileName()) == -1)
+ container << info.filePath();
+ }
+ m_fsWatcher.addPath(dir.absolutePath());
+}
+
+void NimProject::addNodes(const QSet &nodes)
+{
+ QStringList path;
+ foreach (const QString &node, nodes) {
+ path = m_projectDir.relativeFilePath(node).split(QDir::separator());
+ path.pop_back();
+ FolderNode *folder = findFolderFor(path);
+ auto fileNode = new FileNode(FileName::fromString(node), SourceType, false);
+ folder->addFileNodes({fileNode});
+ }
+}
+
+void NimProject::removeNodes(const QSet &nodes)
+{
+ QStringList path;
+ foreach (const QString &node, nodes) {
+ path = m_projectDir.relativeFilePath(node).split(QDir::separator());
+ path.pop_back();
+ FolderNode *folder = findFolderFor(path);
+
+ for (FileNode *fileNode : folder->fileNodes()) {
+ if (fileNode->filePath().toString() == node) {
+ folder->removeFileNodes({fileNode});
+ break;
+ }
+ }
+ }
+}
+
+FolderNode *NimProject::findFolderFor(const QStringList &path)
+{
+ FolderNode *folder = m_rootNode;
+
+ QString currentPath = m_projectDir.absolutePath();
+
+ foreach (const QString &part, path) {
+ // Create relative path
+ if (!currentPath.isEmpty())
+ currentPath += QDir::separator();
+ currentPath += part;
+
+ // Find the child with the given name
+ QList subFolderNodes = folder->subFolderNodes();
+ auto predicate = [&part] (const FolderNode * f) {
+ return f->displayName() == part;
+ };
+ auto it = std::find_if(subFolderNodes.begin(), subFolderNodes.end(), predicate);
+
+ if (it != subFolderNodes.end()) {
+ folder = *it;
+ continue;
+ }
+
+ // Folder not found. Add it
+ QString newFolderPath = QDir::cleanPath(currentPath + QDir::separator() + part);
+ auto newFolder = new FolderNode(FileName::fromString(newFolderPath),
+ FolderNodeType,
+ part);
+ folder->addFolderNodes({newFolder});
+ folder = newFolder;
+ }
+ return folder;
+}
+
+bool NimProject::supportsKit(Kit *k, QString *) const
+{
+ return k->isValid();
+}
+
+FileNameList NimProject::nimFiles() const
+{
+ FileNameList result;
+
+ QQueue folders;
+ folders.enqueue(m_rootNode);
+
+ while (!folders.isEmpty()) {
+ FolderNode *folder = folders.takeFirst();
+ for (FileNode *file : folder->fileNodes()) {
+ if (file->displayName().endsWith(QLatin1String(".nim")))
+ result.append(file->filePath());
+ }
+ folders.append(folder->subFolderNodes());
+ }
+
+ return result;
+}
+
+}
diff --git a/src/plugins/nim/project/nimproject.h b/src/plugins/nim/project/nimproject.h
new file mode 100644
index 0000000000000000000000000000000000000000..60688db0627340ee2cab64fd1fb084bb333bc7da
--- /dev/null
+++ b/src/plugins/nim/project/nimproject.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+#include
+
+#include
+#include
+#include
+
+namespace TextEditor { class TextDocument; }
+
+namespace Nim {
+
+class NimProjectManager;
+class NimProjectNode;
+
+class NimProject : public ProjectExplorer::Project
+{
+ Q_OBJECT
+
+public:
+ NimProject(NimProjectManager *projectManager, const QString &fileName);
+
+ QString displayName() const override;
+ ProjectExplorer::IProjectManager *projectManager() const override;
+ ProjectExplorer::ProjectNode *rootProjectNode() const override;
+ QStringList files(FilesMode) const override;
+ bool needsConfiguration() const override;
+ QString projectDirectoryPath() const;
+ QString projectFilePath() const;
+ bool supportsKit(ProjectExplorer::Kit *k, QString *errorMessage) const override;
+ Utils::FileNameList nimFiles() const;
+
+private:
+ void scheduleProjectScan();
+ void populateProject();
+ void recursiveScanDirectory(const QDir &dir, QSet &container);
+ void addNodes(const QSet &nodes);
+ void removeNodes(const QSet &nodes);
+
+ ProjectExplorer::FolderNode *findFolderFor(const QStringList &projectDirectoryPath);
+
+ NimProjectManager *m_projectManager;
+ TextEditor::TextDocument *m_document;
+ NimProjectNode *m_rootNode;
+
+ QDir m_projectDir;
+ QFileInfo m_projectFile;
+ QSet m_files;
+ QFileSystemWatcher m_fsWatcher;
+
+ QElapsedTimer m_lastProjectScan;
+ QTimer m_projectScanTimer;
+};
+
+}
diff --git a/src/plugins/nim/project/nimprojectmanager.cpp b/src/plugins/nim/project/nimprojectmanager.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..323eb513882e35d6c5a514a4ebe978c20c8b8047
--- /dev/null
+++ b/src/plugins/nim/project/nimprojectmanager.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimprojectmanager.h"
+
+#include "nimconstants.h"
+#include "project/nimproject.h"
+
+using namespace ProjectExplorer;
+
+namespace Nim {
+
+QString NimProjectManager::mimeType() const
+{
+ return QLatin1String(Constants::C_NIM_PROJECT_MIMETYPE);
+}
+
+Project *NimProjectManager::openProject(const QString &fileName, QString *errorString)
+{
+ if (!QFileInfo(fileName).isFile()) {
+ *errorString = tr("Failed opening project \"%1\": Project is not a file.").arg(fileName);
+ return nullptr;
+ }
+
+ return new NimProject(this, fileName);
+}
+
+}
diff --git a/src/plugins/nim/project/nimprojectmanager.h b/src/plugins/nim/project/nimprojectmanager.h
new file mode 100644
index 0000000000000000000000000000000000000000..81703d16fd2ef2b10c11194e59e973c167d4ff46
--- /dev/null
+++ b/src/plugins/nim/project/nimprojectmanager.h
@@ -0,0 +1,42 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace Nim {
+
+class NimProjectManager : public ProjectExplorer::IProjectManager
+{
+ Q_OBJECT
+
+public:
+ QString mimeType() const override;
+
+ ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
+};
+
+}
diff --git a/src/plugins/nim/project/nimprojectnode.cpp b/src/plugins/nim/project/nimprojectnode.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c0c33740ae2e64a59af5a97fec79d6a8b1ad5896
--- /dev/null
+++ b/src/plugins/nim/project/nimprojectnode.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimprojectnode.h"
+
+#include "project/nimproject.h"
+
+using namespace ProjectExplorer;
+using namespace Utils;
+
+namespace Nim {
+
+NimProjectNode::NimProjectNode(const FileName &projectFilePath)
+ : ProjectNode(projectFilePath)
+{}
+
+QList NimProjectNode::supportedActions(Node *node) const
+{
+ static const QList fileActions = { ProjectAction::Rename,
+ ProjectAction::RemoveFile
+ };
+ static const QList folderActions = { ProjectAction::AddNewFile,
+ ProjectAction::RemoveFile
+ };
+ switch (node->nodeType()) {
+ case FileNodeType:
+ return fileActions;
+ case FolderNodeType:
+ case ProjectNodeType:
+ return folderActions;
+ default:
+ return ProjectNode::supportedActions(node);
+ }
+}
+
+bool NimProjectNode::addSubProjects(const QStringList &)
+{
+ return false;
+}
+
+bool NimProjectNode::canAddSubProject(const QString &) const
+{
+ return false;
+}
+
+bool NimProjectNode::removeSubProjects(const QStringList &)
+{
+ return false;
+}
+
+bool NimProjectNode::addFiles(const QStringList &, QStringList *)
+{
+ return true;
+}
+
+bool NimProjectNode::removeFiles(const QStringList &, QStringList *)
+{
+ return true;
+}
+
+bool NimProjectNode::deleteFiles(const QStringList &)
+{
+ return true;
+}
+
+bool NimProjectNode::renameFile(const QString &, const QString &)
+{
+ return true;
+}
+
+}
diff --git a/src/plugins/nim/project/nimprojectnode.h b/src/plugins/nim/project/nimprojectnode.h
new file mode 100644
index 0000000000000000000000000000000000000000..c54508e5d6ae79e85ce30eeb87e42caeea63a6f8
--- /dev/null
+++ b/src/plugins/nim/project/nimprojectnode.h
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace Utils { class FileName; }
+
+namespace Nim {
+
+class NimProject;
+
+class NimProjectNode : public ProjectExplorer::ProjectNode
+{
+public:
+ NimProjectNode(const Utils::FileName &projectFilePath);
+
+ QList supportedActions(Node *node) const override;
+ bool canAddSubProject(const QString &) const override;
+ bool addSubProjects(const QStringList &) override;
+ bool removeSubProjects(const QStringList &) override;
+ bool addFiles(const QStringList &, QStringList *) override;
+ bool removeFiles(const QStringList &, QStringList *) override;
+ bool deleteFiles(const QStringList &) override;
+ bool renameFile(const QString &, const QString &) override;
+};
+
+}
diff --git a/src/plugins/nim/project/nimrunconfiguration.cpp b/src/plugins/nim/project/nimrunconfiguration.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6930a6be8242bdcdad1b7b4610b34f606e2900f7
--- /dev/null
+++ b/src/plugins/nim/project/nimrunconfiguration.cpp
@@ -0,0 +1,148 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimrunconfiguration.h"
+
+#include "nimconstants.h"
+#include "project/nimbuildconfiguration.h"
+#include "project/nimrunconfigurationwidget.h"
+
+#include
+#include
+#include
+
+#include
+
+#include
+#include
+#include
+
+using namespace ProjectExplorer;
+using namespace Utils;
+
+namespace Nim {
+
+NimRunConfiguration::NimRunConfiguration(Target *parent, Core::Id id)
+ : RunConfiguration(parent, id)
+ , m_buildConfiguration(nullptr)
+ , m_workingDirectoryAspect(new WorkingDirectoryAspect(this, Nim::Constants::C_NIMRUNCONFIGURATION_WORKINGDIRECTORYASPECT_ID))
+ , m_argumentAspect(new ArgumentsAspect(this, Nim::Constants::C_NIMRUNCONFIGURATION_ARGUMENTASPECT_ID))
+ , m_terminalAspect(new TerminalAspect(this, Nim::Constants::C_NIMRUNCONFIGURATION_TERMINALASPECT_ID))
+ , m_localEnvironmentAspect(new LocalEnvironmentAspect(this, LocalEnvironmentAspect::BaseEnvironmentModifier()))
+{
+ m_terminalAspect->setRunMode(ApplicationLauncher::Gui);
+
+ addExtraAspect(m_argumentAspect);
+ addExtraAspect(m_terminalAspect);
+ addExtraAspect(m_localEnvironmentAspect);
+
+ setDisplayName(tr(Constants::C_NIMRUNCONFIGURATION_DISPLAY));
+ setDefaultDisplayName(tr(Constants::C_NIMRUNCONFIGURATION_DEFAULT_DISPLAY));
+
+ // Connect target signals
+ connect(this->target(), &Target::activeBuildConfigurationChanged,
+ this, &NimRunConfiguration::updateConfiguration);
+
+ updateConfiguration();
+}
+
+QWidget *NimRunConfiguration::createConfigurationWidget()
+{
+ return new NimRunConfigurationWidget(this);
+}
+
+Runnable NimRunConfiguration::runnable() const
+{
+ StandardRunnable result;
+ result.runMode = m_terminalAspect->runMode();
+ result.executable = m_executable;
+ result.commandLineArguments = m_argumentAspect->arguments();
+ result.workingDirectory = m_workingDirectoryAspect->workingDirectory().toString();
+ return result;
+}
+
+
+QVariantMap NimRunConfiguration::toMap() const
+{
+ auto result = RunConfiguration::toMap();
+ result[Constants::C_NIMRUNCONFIGURATION_EXECUTABLE_KEY] = m_executable;
+ return result;
+}
+
+bool NimRunConfiguration::fromMap(const QVariantMap &map)
+{
+ bool result = RunConfiguration::fromMap(map);
+ if (!result)
+ return result;
+ m_executable = map[Constants::C_NIMRUNCONFIGURATION_EXECUTABLE_KEY].toString();
+ return true;
+}
+
+void NimRunConfiguration::setExecutable(const QString &executable)
+{
+ if (m_executable == executable)
+ return;
+ m_executable = executable;
+ emit executableChanged(executable);
+}
+
+void NimRunConfiguration::setWorkingDirectory(const QString &workingDirectory)
+{
+ m_workingDirectoryAspect->setDefaultWorkingDirectory(FileName::fromString(workingDirectory));
+}
+
+void NimRunConfiguration::updateConfiguration()
+{
+ auto buildConfiguration = qobject_cast(activeBuildConfiguration());
+ QTC_ASSERT(buildConfiguration, return);
+ setActiveBuildConfiguration(buildConfiguration);
+ const QFileInfo outFileInfo = buildConfiguration->outFilePath().toFileInfo();
+ setExecutable(outFileInfo.absoluteFilePath());
+ setWorkingDirectory(outFileInfo.absoluteDir().absolutePath());
+}
+
+void NimRunConfiguration::setActiveBuildConfiguration(NimBuildConfiguration *activeBuildConfiguration)
+{
+ if (m_buildConfiguration == activeBuildConfiguration)
+ return;
+
+ if (m_buildConfiguration) {
+ disconnect(m_buildConfiguration, &NimBuildConfiguration::buildDirectoryChanged,
+ this, &NimRunConfiguration::updateConfiguration);
+ disconnect(m_buildConfiguration, &NimBuildConfiguration::outFilePathChanged,
+ this, &NimRunConfiguration::updateConfiguration);
+ }
+
+ m_buildConfiguration = activeBuildConfiguration;
+
+ if (m_buildConfiguration) {
+ connect(m_buildConfiguration, &NimBuildConfiguration::buildDirectoryChanged,
+ this, &NimRunConfiguration::updateConfiguration);
+ connect(m_buildConfiguration, &NimBuildConfiguration::outFilePathChanged,
+ this, &NimRunConfiguration::updateConfiguration);
+ }
+}
+
+}
diff --git a/src/plugins/nim/project/nimrunconfiguration.h b/src/plugins/nim/project/nimrunconfiguration.h
new file mode 100644
index 0000000000000000000000000000000000000000..6769b4f307aa4c52d6325d55ae1afa8b5a806a85
--- /dev/null
+++ b/src/plugins/nim/project/nimrunconfiguration.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace ProjectExplorer {
+class WorkingDirectoryAspect;
+class ArgumentsAspect;
+class TerminalAspect;
+class LocalEnvironmentAspect;
+}
+
+namespace Nim {
+
+class NimBuildConfiguration;
+
+class NimRunConfiguration : public ProjectExplorer::RunConfiguration
+{
+ Q_OBJECT
+
+public:
+ NimRunConfiguration(ProjectExplorer::Target *parent, Core::Id id);
+
+ QWidget *createConfigurationWidget() override;
+ ProjectExplorer::Runnable runnable() const override;
+ QVariantMap toMap() const override;
+ bool fromMap(const QVariantMap &map) override;
+
+signals:
+ void executableChanged(const QString &args);
+ void runModeChanged(ProjectExplorer::ApplicationLauncher::Mode);
+ void workingDirectoryChanged(const QString &workingDirectory);
+ void commandLineArgumentsChanged(const QString &args);
+ void runInTerminalChanged(bool);
+
+private:
+ void setExecutable(const QString &path);
+ void setWorkingDirectory(const QString &path);
+ void setCommandLineArguments(const QString &args);
+ void updateConfiguration();
+ void setActiveBuildConfiguration(NimBuildConfiguration *activeBuildConfiguration);
+
+ QString m_executable;
+ NimBuildConfiguration *m_buildConfiguration;
+ ProjectExplorer::WorkingDirectoryAspect* m_workingDirectoryAspect;
+ ProjectExplorer::ArgumentsAspect* m_argumentAspect;
+ ProjectExplorer::TerminalAspect* m_terminalAspect;
+ ProjectExplorer::LocalEnvironmentAspect* m_localEnvironmentAspect;
+};
+
+}
diff --git a/src/plugins/nim/project/nimrunconfigurationfactory.cpp b/src/plugins/nim/project/nimrunconfigurationfactory.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..24d3dc693e732d313c27371f7d95e3d7d37aad90
--- /dev/null
+++ b/src/plugins/nim/project/nimrunconfigurationfactory.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimrunconfigurationfactory.h"
+
+#include "nimconstants.h"
+#include "project/nimproject.h"
+#include "project/nimrunconfiguration.h"
+
+#include
+#include
+
+#include
+
+using namespace ProjectExplorer;
+
+namespace Nim {
+
+NimRunConfigurationFactory::NimRunConfigurationFactory()
+{
+}
+
+QList NimRunConfigurationFactory::availableCreationIds(Target *parent,
+ IRunConfigurationFactory::CreationMode mode) const
+{
+ Q_UNUSED(mode);
+ if (canHandle(parent))
+ return { Constants::C_NIMRUNCONFIGURATION_ID };
+ return {};
+}
+
+QString NimRunConfigurationFactory::displayNameForId(Core::Id id) const
+{
+ QString result = id.toString() + QStringLiteral("-TempRunConf");
+ return result;
+}
+
+bool NimRunConfigurationFactory::canCreate(Target *parent, Core::Id id) const
+{
+ Q_UNUSED(id);
+ return canHandle(parent);
+}
+
+bool NimRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
+{
+ Q_UNUSED(parent);
+ Q_UNUSED(map);
+ return canHandle(parent);
+}
+
+bool NimRunConfigurationFactory::canClone(Target *parent, RunConfiguration *product) const
+{
+ QTC_ASSERT(parent, return false);
+ QTC_ASSERT(product, return false);
+ return true;
+}
+
+RunConfiguration *NimRunConfigurationFactory::clone(Target *parent, RunConfiguration *product)
+{
+ QTC_ASSERT(parent, return nullptr);
+ QTC_ASSERT(product, return nullptr);
+ std::unique_ptr result(new NimRunConfiguration(parent, Constants::C_NIMRUNCONFIGURATION_ID));
+ return result->fromMap(product->toMap()) ? result.release() : nullptr;
+}
+
+bool NimRunConfigurationFactory::canHandle(Target *parent) const
+{
+ Q_UNUSED(parent);
+ return qobject_cast(parent->project());
+}
+
+RunConfiguration *NimRunConfigurationFactory::doCreate(Target *parent, Core::Id id)
+{
+ Q_UNUSED(id);
+ auto result = new NimRunConfiguration(parent, id);
+ return result;
+}
+
+RunConfiguration *NimRunConfigurationFactory::doRestore(Target *parent, const QVariantMap &map)
+{
+ Q_UNUSED(map);
+ auto result = new NimRunConfiguration(parent, idFromMap(map));
+ result->fromMap(map);
+ return result;
+}
+
+}
diff --git a/src/plugins/nim/project/nimrunconfigurationfactory.h b/src/plugins/nim/project/nimrunconfigurationfactory.h
new file mode 100644
index 0000000000000000000000000000000000000000..262861eed64380343853efbebff4f776932593d0
--- /dev/null
+++ b/src/plugins/nim/project/nimrunconfigurationfactory.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace Nim {
+
+class NimRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFactory
+{
+public:
+ NimRunConfigurationFactory();
+
+ QList availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const override;
+
+ QString displayNameForId(Core::Id id) const override;
+
+ bool canCreate(ProjectExplorer::Target *parent, Core::Id id) const override;
+
+ bool canRestore(ProjectExplorer::Target *parent,
+ const QVariantMap &map) const override;
+
+ bool canClone(ProjectExplorer::Target *parent,
+ ProjectExplorer::RunConfiguration *product) const override;
+
+ ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Target *parent,
+ ProjectExplorer::RunConfiguration *product) override;
+
+private:
+ bool canHandle(ProjectExplorer::Target *parent) const;
+
+ ProjectExplorer::RunConfiguration *doCreate(ProjectExplorer::Target *parent, Core::Id id);
+ ProjectExplorer::RunConfiguration *doRestore(ProjectExplorer::Target *parent, const QVariantMap &map);
+};
+
+}
diff --git a/src/plugins/nim/project/nimrunconfigurationwidget.cpp b/src/plugins/nim/project/nimrunconfigurationwidget.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..57e54442e52f39cc1deb7202428716570600481a
--- /dev/null
+++ b/src/plugins/nim/project/nimrunconfigurationwidget.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimrunconfigurationwidget.h"
+
+#include "project/nimrunconfiguration.h"
+
+#include
+
+#include
+
+using namespace ProjectExplorer;
+
+namespace Nim {
+
+NimRunConfigurationWidget::NimRunConfigurationWidget(NimRunConfiguration *rc,
+ QWidget *parent)
+ : QWidget(parent)
+ , m_rc(rc)
+{
+ QTC_ASSERT(rc, return);
+ auto fl = new QFormLayout(this);
+ fl->setMargin(0);
+ fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
+ rc->extraAspect()->addToMainConfigurationWidget(this, fl);
+ rc->extraAspect()->addToMainConfigurationWidget(this,fl);
+ connect(rc, &NimRunConfiguration::enabledChanged, this, &NimRunConfigurationWidget::updateUi);
+ updateUi();
+}
+
+
+void NimRunConfigurationWidget::updateUi()
+{
+ setEnabled(m_rc->isEnabled());
+}
+
+}
diff --git a/src/plugins/nim/project/nimrunconfigurationwidget.h b/src/plugins/nim/project/nimrunconfigurationwidget.h
new file mode 100644
index 0000000000000000000000000000000000000000..9c47bf1d0674dbb5d9d783278fd673a5be5e6237
--- /dev/null
+++ b/src/plugins/nim/project/nimrunconfigurationwidget.h
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace Nim {
+
+class NimRunConfiguration;
+
+class NimRunConfigurationWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NimRunConfigurationWidget(NimRunConfiguration *rc, QWidget *parent = 0);
+
+private:
+ void updateUi();
+
+ NimRunConfiguration* m_rc;
+};
+
+}
diff --git a/src/plugins/nim/project/nimruncontrol.cpp b/src/plugins/nim/project/nimruncontrol.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ab844fb98a51db2deaad69e6181de1d517a64426
--- /dev/null
+++ b/src/plugins/nim/project/nimruncontrol.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimruncontrol.h"
+
+#include "project/nimrunconfiguration.h"
+
+#include
+#include
+#include
+
+#include
+
+using namespace ProjectExplorer;
+using namespace Utils;
+
+namespace Nim {
+
+NimRunControl::NimRunControl(NimRunConfiguration *rc, Core::Id mode)
+ : RunControl(rc, mode)
+ , m_running(false)
+ , m_runnable(rc->runnable().as())
+{
+ connect(&m_applicationLauncher, &ApplicationLauncher::appendMessage,
+ this, &NimRunControl::slotAppendMessage);
+ connect(&m_applicationLauncher, &ApplicationLauncher::processStarted,
+ this, &NimRunControl::processStarted);
+ connect(&m_applicationLauncher, &ApplicationLauncher::processExited,
+ this, &NimRunControl::processExited);
+ connect(&m_applicationLauncher, &ApplicationLauncher::bringToForegroundRequested,
+ this, &RunControl::bringApplicationToForeground);
+}
+
+void NimRunControl::start()
+{
+ emit started();
+ m_running = true;
+ m_applicationLauncher.start(m_runnable);
+ setApplicationProcessHandle(ProcessHandle(m_applicationLauncher.applicationPID()));
+}
+
+ProjectExplorer::RunControl::StopResult NimRunControl::stop()
+{
+ m_applicationLauncher.stop();
+ return StoppedSynchronously;
+}
+
+bool NimRunControl::isRunning() const
+{
+ return m_running;
+}
+
+void NimRunControl::processStarted()
+{
+ // Console processes only know their pid after being started
+ setApplicationProcessHandle(ProcessHandle(m_applicationLauncher.applicationPID()));
+}
+
+void NimRunControl::processExited(int exitCode, QProcess::ExitStatus status)
+{
+ m_running = false;
+ setApplicationProcessHandle(ProcessHandle());
+ QString msg;
+ if (status == QProcess::CrashExit) {
+ msg = tr("%1 crashed")
+ .arg(QDir::toNativeSeparators(m_runnable.executable));
+ } else {
+ msg = tr("%1 exited with code %2")
+ .arg(QDir::toNativeSeparators(m_runnable.executable)).arg(exitCode);
+ }
+ appendMessage(msg + QLatin1Char('\n'), NormalMessageFormat);
+ emit finished();
+}
+
+void NimRunControl::slotAppendMessage(const QString &err, OutputFormat format)
+{
+ appendMessage(err, format);
+}
+
+}
diff --git a/src/plugins/nim/project/nimruncontrol.h b/src/plugins/nim/project/nimruncontrol.h
new file mode 100644
index 0000000000000000000000000000000000000000..cfc9bb9825ae7bd9829e26c73704678029519b1b
--- /dev/null
+++ b/src/plugins/nim/project/nimruncontrol.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+#include
+
+namespace Nim {
+
+class NimRunConfiguration;
+
+class NimRunControl : public ProjectExplorer::RunControl
+{
+public:
+ NimRunControl(NimRunConfiguration *runConfiguration, Core::Id mode);
+
+ void start() override;
+ StopResult stop() override;
+ bool isRunning() const override;
+
+private:
+ void processStarted();
+ void processExited(int exitCode, QProcess::ExitStatus status);
+ void slotAppendMessage(const QString &err, Utils::OutputFormat isError);
+
+ ProjectExplorer::ApplicationLauncher m_applicationLauncher;
+ bool m_running;
+ ProjectExplorer::StandardRunnable m_runnable;
+};
+
+}
diff --git a/src/plugins/nim/project/nimruncontrolfactory.cpp b/src/plugins/nim/project/nimruncontrolfactory.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..39b588dbb83c4ac5fe504cc00d10e7476df6f319
--- /dev/null
+++ b/src/plugins/nim/project/nimruncontrolfactory.cpp
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "project/nimruncontrolfactory.h"
+
+#include "project/nimrunconfiguration.h"
+#include "project/nimruncontrol.h"
+
+namespace Nim {
+
+bool NimRunControlFactory::canRun(ProjectExplorer::RunConfiguration *runConfiguration, Core::Id mode) const
+{
+ Q_UNUSED(mode)
+ return dynamic_cast(runConfiguration);
+}
+
+ProjectExplorer::RunControl *NimRunControlFactory::create(ProjectExplorer::RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage)
+{
+ Q_UNUSED(errorMessage)
+ QTC_ASSERT(canRun(runConfiguration, mode), return 0);
+ return new NimRunControl(static_cast(runConfiguration), mode);
+}
+
+}
+
diff --git a/src/plugins/nim/project/nimruncontrolfactory.h b/src/plugins/nim/project/nimruncontrolfactory.h
new file mode 100644
index 0000000000000000000000000000000000000000..cee570322b6cd6789282e685ccc9b371bb9c439a
--- /dev/null
+++ b/src/plugins/nim/project/nimruncontrolfactory.h
@@ -0,0 +1,39 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace Nim {
+
+class NimRunControlFactory : public ProjectExplorer::IRunControlFactory
+{
+public:
+ bool canRun(ProjectExplorer::RunConfiguration *runConfiguration, Core::Id mode) const override;
+ ProjectExplorer::RunControl *create(ProjectExplorer::RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage) override;
+};
+
+}
diff --git a/src/plugins/nim/settings/nimcodestylepreferencesfactory.cpp b/src/plugins/nim/settings/nimcodestylepreferencesfactory.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..de5e40d42fc2ecdd0839aedd5c3be442981cd71a
--- /dev/null
+++ b/src/plugins/nim/settings/nimcodestylepreferencesfactory.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "settings/nimcodestylepreferencesfactory.h"
+
+#include "nimconstants.h"
+#include "editor/nimindenter.h"
+#include "settings/nimcodestylepreferenceswidget.h"
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+namespace Nim {
+
+NimCodeStylePreferencesFactory::NimCodeStylePreferencesFactory()
+{
+}
+
+Core::Id NimCodeStylePreferencesFactory::languageId()
+{
+ return Constants::C_NIMLANGUAGE_ID;
+}
+
+QString NimCodeStylePreferencesFactory::displayName()
+{
+ return tr(Constants::C_NIMLANGUAGE_NAME);
+}
+
+TextEditor::ICodeStylePreferences *NimCodeStylePreferencesFactory::createCodeStyle() const
+{
+ return new TextEditor::SimpleCodeStylePreferences();
+}
+
+QWidget *NimCodeStylePreferencesFactory::createEditor(TextEditor::ICodeStylePreferences *preferences,
+ QWidget *parent) const
+{
+ auto result = new NimCodeStylePreferencesWidget(preferences, parent);
+ result->layout()->setMargin(0);
+ return result;
+}
+
+TextEditor::Indenter *NimCodeStylePreferencesFactory::createIndenter() const
+{
+ return new NimIndenter();
+}
+
+TextEditor::ISnippetProvider *NimCodeStylePreferencesFactory::snippetProvider() const
+{
+ return ExtensionSystem::PluginManager::getObject(
+ [](TextEditor::ISnippetProvider *provider) {
+ return provider->groupId() == Nim::Constants::C_NIMSNIPPETSGROUP_ID;
+ });
+}
+
+QString NimCodeStylePreferencesFactory::previewText() const
+{
+ return QLatin1String(Nim::Constants::C_NIMCODESTYLEPREVIEWSNIPPET);
+}
+
+}
diff --git a/src/plugins/nim/settings/nimcodestylepreferencesfactory.h b/src/plugins/nim/settings/nimcodestylepreferencesfactory.h
new file mode 100644
index 0000000000000000000000000000000000000000..b3577a139ade69055cb62896b76189946fa65cc9
--- /dev/null
+++ b/src/plugins/nim/settings/nimcodestylepreferencesfactory.h
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include
+
+namespace Nim {
+
+class NimCodeStylePreferencesFactory : public TextEditor::ICodeStylePreferencesFactory
+{
+ Q_OBJECT
+
+public:
+ NimCodeStylePreferencesFactory();
+
+ Core::Id languageId();
+ QString displayName();
+ TextEditor::ICodeStylePreferences *createCodeStyle() const;
+ QWidget *createEditor(TextEditor::ICodeStylePreferences *settings,
+ QWidget *parent) const;
+ TextEditor::Indenter *createIndenter() const;
+ TextEditor::ISnippetProvider *snippetProvider() const;
+ QString previewText() const;
+};
+
+} // namespace Nim
diff --git a/src/plugins/nim/settings/nimcodestylepreferenceswidget.cpp b/src/plugins/nim/settings/nimcodestylepreferenceswidget.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3482cd476cd84b55685e33eeac5b1b6ee6318f9c
--- /dev/null
+++ b/src/plugins/nim/settings/nimcodestylepreferenceswidget.cpp
@@ -0,0 +1,120 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "nimcodestylepreferenceswidget.h"
+#include "ui_nimcodestylepreferenceswidget.h"
+
+#include "nimconstants.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace TextEditor;
+
+namespace Nim {
+
+NimCodeStylePreferencesWidget::NimCodeStylePreferencesWidget(ICodeStylePreferences *preferences, QWidget *parent)
+ : QWidget(parent)
+ , m_preferences(preferences)
+ , m_ui(new Ui::NimCodeStylePreferencesWidget())
+{
+ m_ui->setupUi(this);
+ m_ui->tabPreferencesWidget->setPreferences(preferences);
+ m_ui->previewTextEdit->setPlainText(Nim::Constants::C_NIMCODESTYLEPREVIEWSNIPPET);
+
+ ISnippetProvider *provider = ExtensionSystem::PluginManager::getObject(
+ [](ISnippetProvider *provider) {
+ return provider->groupId() == Nim::Constants::C_NIMSNIPPETSGROUP_ID;
+ });
+
+ if (provider)
+ provider->decorateEditor(m_ui->previewTextEdit);
+
+ decorateEditor(TextEditorSettings::fontSettings());
+ connect(TextEditorSettings::instance(), &TextEditorSettings::fontSettingsChanged,
+ this, &NimCodeStylePreferencesWidget::decorateEditor);
+
+ connect(m_preferences, &ICodeStylePreferences::currentTabSettingsChanged,
+ this, &NimCodeStylePreferencesWidget::updatePreview);
+
+ setVisualizeWhitespace(true);
+
+ updatePreview();
+}
+
+NimCodeStylePreferencesWidget::~NimCodeStylePreferencesWidget()
+{
+ delete m_ui;
+ m_ui = nullptr;
+}
+
+void NimCodeStylePreferencesWidget::decorateEditor(const FontSettings &fontSettings)
+{
+ const ISnippetProvider *provider = ExtensionSystem::PluginManager::getObject(
+ [](ISnippetProvider *current) {
+ return current->groupId() == Nim::Constants::C_NIMSNIPPETSGROUP_ID;
+ });
+
+ m_ui->previewTextEdit->textDocument()->setFontSettings(fontSettings);
+ if (provider)
+ provider->decorateEditor(m_ui->previewTextEdit);
+}
+
+void NimCodeStylePreferencesWidget::setVisualizeWhitespace(bool on)
+{
+ DisplaySettings displaySettings = m_ui->previewTextEdit->displaySettings();
+ displaySettings.m_visualizeWhitespace = on;
+ m_ui->previewTextEdit->setDisplaySettings(displaySettings);
+}
+
+void NimCodeStylePreferencesWidget::updatePreview()
+{
+ QTextDocument *doc = m_ui->previewTextEdit->document();
+
+ const TabSettings &ts = m_preferences
+ ? m_preferences->currentTabSettings()
+ : TextEditorSettings::codeStyle()->tabSettings();
+ m_ui->previewTextEdit->textDocument()->setTabSettings(ts);
+
+ QTextBlock block = doc->firstBlock();
+ QTextCursor tc = m_ui->previewTextEdit->textCursor();
+ tc.beginEditBlock();
+ while (block.isValid()) {
+ m_ui->previewTextEdit->textDocument()->indenter()
+ ->indentBlock(doc, block, QChar::Null, ts);
+ block = block.next();
+ }
+ tc.endEditBlock();
+}
+
+} // namespace Nim
+
diff --git a/src/plugins/nim/settings/nimcodestylepreferenceswidget.h b/src/plugins/nim/settings/nimcodestylepreferenceswidget.h
new file mode 100644
index 0000000000000000000000000000000000000000..963ff9738b4bbf4fcbef89a7e88b1f524de96364
--- /dev/null
+++ b/src/plugins/nim/settings/nimcodestylepreferenceswidget.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) Filippo Cucchetto