diff options
Diffstat (limited to 'org.eclipse.text/src/org/eclipse/jface/text')
-rw-r--r-- | org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java | 25 | ||||
-rw-r--r-- | org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties | 4 |
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 9eb4710464e..571e6f9a077 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 c7af24b9544..d8d6af7b469 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 |