diff options
author | Tobias Hunger <tobias.hunger@theqtcompany.com> | 2015-09-25 10:31:28 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@theqtcompany.com> | 2015-10-13 09:15:36 +0000 |
commit | 08ca3eb480526bf81e7b9eded7382d32ccca5a66 (patch) | |
tree | 03021cd897a04fec3ab4363abfa47fe3e789ed1e /src/plugins/texteditor/snippets | |
parent | ec2e01faec87e273486b81d0c3bf8ded2619c047 (diff) |
Snippet: Use Template engine to pre-process snippets
This enables macros in snippets as well as if/else to select/deselect
lines to have in the snippet.
Change-Id: Ic88fb3277a0f5ac803bcab486b245c688c00822a
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
Diffstat (limited to 'src/plugins/texteditor/snippets')
-rw-r--r-- | src/plugins/texteditor/snippets/snippet.cpp | 28 | ||||
-rw-r--r-- | src/plugins/texteditor/snippets/snippet.h | 1 |
2 files changed, 19 insertions, 10 deletions
diff --git a/src/plugins/texteditor/snippets/snippet.cpp b/src/plugins/texteditor/snippets/snippet.cpp index 8c63c60911e..03ab97c76c7 100644 --- a/src/plugins/texteditor/snippets/snippet.cpp +++ b/src/plugins/texteditor/snippets/snippet.cpp @@ -32,6 +32,8 @@ #include <coreplugin/id.h> +#include <utils/templateengine.h> + #include <QLatin1Char> #include <QLatin1String> #include <QTextDocument> @@ -192,9 +194,19 @@ Snippet::ParsedSnippet Snippet::parse(const QString &snippet) static TitlecaseMangler tcMangler; Snippet::ParsedSnippet result; - result.success = true; - const int count = snippet.count(); + QString errorMessage; + QString preprocessedSnippet + = Utils::TemplateEngine::processText(Utils::globalMacroExpander(), snippet, + &errorMessage); + + result.success = errorMessage.isEmpty(); + if (!result.success) { + result.errorMessage = errorMessage; + return result; + } + + const int count = preprocessedSnippet.count(); bool success = true; int start = -1; NameMangler *mangler = 0; @@ -202,8 +214,8 @@ Snippet::ParsedSnippet Snippet::parse(const QString &snippet) result.text.reserve(count); for (int i = 0; i < count; ++i) { - QChar current = snippet.at(i); - QChar next = (i + 1) < count ? snippet.at(i + 1) : QChar(); + QChar current = preprocessedSnippet.at(i); + QChar next = (i + 1) < count ? preprocessedSnippet.at(i + 1) : QChar(); if (current == Snippet::kVariableDelimiter) { if (start < 0) { @@ -242,12 +254,8 @@ Snippet::ParsedSnippet Snippet::parse(const QString &snippet) continue; } - if (current == QLatin1Char('\\')) { - if (next.isNull()) { - success = false; - break; - } - result.text.append(next); + if (current == QLatin1Char('\\') && next == QLatin1Char('$')) { + result.text.append(QLatin1Char('$')); ++i; continue; } diff --git a/src/plugins/texteditor/snippets/snippet.h b/src/plugins/texteditor/snippets/snippet.h index 53d61908489..0ee74fcfb52 100644 --- a/src/plugins/texteditor/snippets/snippet.h +++ b/src/plugins/texteditor/snippets/snippet.h @@ -83,6 +83,7 @@ public: class ParsedSnippet { public: QString text; + QString errorMessage; bool success; struct Range { Range(int s, int l, NameMangler *m) : start(s), length(l), mangler(m) { } |