Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2016-02-08 11:52:13 +0000
committerLars Vogel2016-02-10 10:26:43 +0000
commite462c416ddf66bbf893a0f0364be8f88a28963a4 (patch)
tree15e754387e0a39f4e3ffa93aa123b82eb9669212 /org.eclipse.text/src
parent0e1c9f6f7d0f8aa4bf2a25e85272869463a486a5 (diff)
downloadeclipse.platform.text-e462c416ddf66bbf893a0f0364be8f88a28963a4.tar.gz
eclipse.platform.text-e462c416ddf66bbf893a0f0364be8f88a28963a4.tar.xz
eclipse.platform.text-e462c416ddf66bbf893a0f0364be8f88a28963a4.zip
Bug 487327 - [templates] Allow specifying a default value in caseI20160216-1400I20160216-0800
the line_selection is empty Still WIP, awaiting feedback from Dani for https://bugs.eclipse.org/bugs/show_bug.cgi?id=486903#c18 Change-Id: I6868dced6122a5479d9f786be6f8955011fbec82 Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
Diffstat (limited to 'org.eclipse.text/src')
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java25
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties2
2 files changed, 25 insertions, 2 deletions
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java
index 571e6f9a077..087c2986160 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
* Sebastian Davids: sdavids@gmx.de - see bug 25376
* Jeremie Bresson <jbr@bsiag.com> - Allow to specify format for date variable - https://bugs.eclipse.org/75981
- * Lars Vogel <Lars.Vogel@vogella.com> - Bug 486903
+ * Lars Vogel <Lars.Vogel@vogella.com> - Bug 486903, 487327
*******************************************************************************/
package org.eclipse.jface.text.templates;
@@ -120,6 +120,29 @@ public class GlobalTemplateVariables {
return ""; //$NON-NLS-1$
return selection;
}
+
+ @Override
+ public void resolve(TemplateVariable variable, TemplateContext context) {
+ List<String> params= variable.getVariableType().getParams();
+ if (params.size() >= 1 && params.get(0) != null) {
+ resolveWithParams(variable, context, params);
+ } else {
+ // No parameter, use default:
+ super.resolve(variable, context);
+ }
+ }
+
+ private void resolveWithParams(TemplateVariable variable, TemplateContext context, List<String> params) {
+ String selection= context.getVariable(SELECTION);
+ if (selection != null) {
+ variable.setValue(selection);
+ } else {
+ String defaultValue= params.get(0);
+ variable.setValue(defaultValue);
+ }
+ variable.setUnambiguous(true);
+ variable.setResolved(true);
+ }
}
/**
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties b/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties
index 253bb5e7edf..0ef52b8b72e 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties
+++ b/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties
@@ -22,4 +22,4 @@ GlobalVariables.variable.description.year=Current year. Use the 'date' variable
GlobalVariables.variable.description.time=Current time. Use the 'date' variable if you want to specify the format.
GlobalVariables.variable.description.user=User name
GlobalVariables.variable.description.selectedWord= <b>${id\:word_selection[(default)]}</b><br>Evaluates to the selected text. 'default' is an optional parameter, which specifies the text if the selected text is empty. <br><br><b>Examples:</b><br><code>${word_selection}</code><br><code>${currentWord:word_selection(myStringVariable)}</code><br><code>${currentWord:word_selection('"Press me"')}</code><br>
-GlobalVariables.variable.description.selectedLines= The selected lines
+GlobalVariables.variable.description.selectedLines= <b>${id\:line_selection[(default)]}</b><br>Evaluates to the selected text for multiple lines. 'default' is an optional parameter, which specifies the text if the selected text is empty. <br><br><b>Examples:</b><br><code>${line_selection}</code><br><code>${currentLine:line_selection(myStringVariable)}</code><br><code>${currentLine:line_selection('"A default text"')}</code><br> \ No newline at end of file

Back to the top