Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2016-01-31 04:33:24 -0500
committerLars Vogel2016-02-09 04:37:10 -0500
commit9e178f2b274b2e8d498ab3c9d86df474fa0ab76a (patch)
tree18cbf65a69ae102a6e742eea0be0c602fa622dac /org.eclipse.text
parent4cffb0013023a237c3d43ffa763649b07f7b61fe (diff)
downloadeclipse.platform.text-9e178f2b274b2e8d498ab3c9d86df474fa0ab76a.tar.gz
eclipse.platform.text-9e178f2b274b2e8d498ab3c9d86df474fa0ab76a.tar.xz
eclipse.platform.text-9e178f2b274b2e8d498ab3c9d86df474fa0ab76a.zip
Bug 486903 - [Templates] Allow specifying a default value in case theI20160209-0800
word_selection is empty Change-Id: I5a5c2e77f65aa45474362838aa71fc351779dcd7 Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
Diffstat (limited to 'org.eclipse.text')
-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.properties4
2 files changed, 27 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 9eb471046..571e6f9a0 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,6 +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
*******************************************************************************/
package org.eclipse.jface.text.templates;
@@ -71,6 +72,30 @@ 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 c7af24b95..d8d6af7b4 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
@@ -20,6 +20,6 @@ GlobalVariables.variable.description.dollar=The dollar symbol
GlobalVariables.variable.description.date=<b>${id\:date[(format[, locale])]}</b><br>Evaluates to the current date in the specified format and locale. 'format' and 'locale' are optional parameters. 'format' is a pattern compatible with java.text.SimpleDateFormat. 'locale' is an RFC 3066 locale ID.<br><br><b>Examples:</b><br><code>${date}</code><br><code>${currentDate:date('yyyy-MM-dd')}</code><br><code>${d:date('EEEE dd MM yyyy', 'fr_CH')}</code>
GlobalVariables.variable.description.year=Current year. Use the 'date' variable if you want to specify the format.
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= The selected word
+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, if specified it is used as default text if the current text selection is empty. <br><br><b>Examples:</b><br><code>${word_selection}</code><br><code>${currentword:word_selection('Press')}</code><br>
GlobalVariables.variable.description.selectedLines= The selected lines

Back to the top