Mercurial > projects > dwt2
comparison org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children | 5feec68b4556 |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2006 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Sebastian Davids: sdavids@gmx.de - see bug 25376 | |
11 * Port to the D programming language: | |
12 * Frank Benoit <benoit@tionex.de> | |
13 *******************************************************************************/ | |
14 module org.eclipse.jface.text.templates.GlobalTemplateVariables; | |
15 | |
16 import org.eclipse.jface.text.templates.SimpleTemplateVariableResolver; // packageimport | |
17 import org.eclipse.jface.text.templates.TemplateBuffer; // packageimport | |
18 import org.eclipse.jface.text.templates.TemplateContext; // packageimport | |
19 import org.eclipse.jface.text.templates.TemplateContextType; // packageimport | |
20 import org.eclipse.jface.text.templates.Template; // packageimport | |
21 import org.eclipse.jface.text.templates.TemplateVariable; // packageimport | |
22 import org.eclipse.jface.text.templates.PositionBasedCompletionProposal; // packageimport | |
23 import org.eclipse.jface.text.templates.TemplateException; // packageimport | |
24 import org.eclipse.jface.text.templates.TemplateTranslator; // packageimport | |
25 import org.eclipse.jface.text.templates.DocumentTemplateContext; // packageimport | |
26 import org.eclipse.jface.text.templates.InclusivePositionUpdater; // packageimport | |
27 import org.eclipse.jface.text.templates.TemplateProposal; // packageimport | |
28 import org.eclipse.jface.text.templates.ContextTypeRegistry; // packageimport | |
29 import org.eclipse.jface.text.templates.JFaceTextTemplateMessages; // packageimport | |
30 import org.eclipse.jface.text.templates.TemplateCompletionProcessor; // packageimport | |
31 import org.eclipse.jface.text.templates.TextTemplateMessages; // packageimport | |
32 import org.eclipse.jface.text.templates.TemplateVariableType; // packageimport | |
33 import org.eclipse.jface.text.templates.TemplateVariableResolver; // packageimport | |
34 | |
35 | |
36 import java.lang.all; | |
37 import java.util.Set; | |
38 | |
39 // import com.ibm.icu.text.DateFormat; | |
40 // import com.ibm.icu.util.Calendar; | |
41 | |
42 /** | |
43 * Global variables which are available in any context. | |
44 * <p> | |
45 * Clients may instantiate the classes contained within this class. | |
46 * </p> | |
47 * | |
48 * @since 3.0 | |
49 */ | |
50 public class GlobalTemplateVariables { | |
51 | |
52 /** The type of the selection variables. */ | |
53 public static const String SELECTION= "selection"; //$NON-NLS-1$ | |
54 | |
55 /** | |
56 * The cursor variable determines the cursor placement after template edition. | |
57 */ | |
58 public static class Cursor : SimpleTemplateVariableResolver { | |
59 | |
60 /** Name of the cursor variable, value= {@value} */ | |
61 public static const String NAME= "cursor"; //$NON-NLS-1$ | |
62 | |
63 /** | |
64 * Creates a new cursor variable | |
65 */ | |
66 public this() { | |
67 super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.cursor")); //$NON-NLS-1$ | |
68 setEvaluationString(""); //$NON-NLS-1$ | |
69 } | |
70 } | |
71 | |
72 /** | |
73 * The word selection variable determines templates that work on a full | |
74 * lines selection. | |
75 */ | |
76 public static class WordSelection : SimpleTemplateVariableResolver { | |
77 | |
78 /** Name of the word selection variable, value= {@value} */ | |
79 public static const String NAME= "word_selection"; //$NON-NLS-1$ | |
80 | |
81 /** | |
82 * Creates a new word selection variable | |
83 */ | |
84 public this() { | |
85 super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedWord")); //$NON-NLS-1$ | |
86 } | |
87 protected String resolve(TemplateContext context) { | |
88 String selection= context.getVariable(SELECTION); | |
89 if (selection is null) | |
90 return ""; //$NON-NLS-1$ | |
91 return selection; | |
92 } | |
93 } | |
94 | |
95 /** | |
96 * The line selection variable determines templates that work on selected | |
97 * lines. | |
98 */ | |
99 public static class LineSelection : SimpleTemplateVariableResolver { | |
100 | |
101 /** Name of the line selection variable, value= {@value} */ | |
102 public static const String NAME= "line_selection"; //$NON-NLS-1$ | |
103 | |
104 /** | |
105 * Creates a new line selection variable | |
106 */ | |
107 public this() { | |
108 super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedLines")); //$NON-NLS-1$ | |
109 } | |
110 protected String resolve(TemplateContext context) { | |
111 String selection= context.getVariable(SELECTION); | |
112 if (selection is null) | |
113 return ""; //$NON-NLS-1$ | |
114 return selection; | |
115 } | |
116 } | |
117 | |
118 /** | |
119 * The dollar variable inserts an escaped dollar symbol. | |
120 */ | |
121 public static class Dollar : SimpleTemplateVariableResolver { | |
122 /** | |
123 * Creates a new dollar variable | |
124 */ | |
125 public this() { | |
126 super("dollar", TextTemplateMessages.getString("GlobalVariables.variable.description.dollar")); //$NON-NLS-1$ //$NON-NLS-2$ | |
127 setEvaluationString("$"); //$NON-NLS-1$ | |
128 } | |
129 } | |
130 | |
131 /** | |
132 * The date variable evaluates to the current date. | |
133 */ | |
134 public static class Date : SimpleTemplateVariableResolver { | |
135 /** | |
136 * Creates a new date variable | |
137 */ | |
138 public this() { | |
139 super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$ | |
140 } | |
141 protected String resolve(TemplateContext context) { | |
142 implMissing(__FILE__,__LINE__); | |
143 return null; | |
144 //return DateFormat.getDateInstance().format(new java.util.Date()); | |
145 } | |
146 } | |
147 | |
148 /** | |
149 * The year variable evaluates to the current year. | |
150 */ | |
151 public static class Year : SimpleTemplateVariableResolver { | |
152 /** | |
153 * Creates a new year variable | |
154 */ | |
155 public this() { | |
156 super("year", TextTemplateMessages.getString("GlobalVariables.variable.description.year")); //$NON-NLS-1$ //$NON-NLS-2$ | |
157 } | |
158 protected String resolve(TemplateContext context) { | |
159 implMissing(__FILE__,__LINE__); | |
160 return null; | |
161 //return Integer.toString(Calendar.getInstance().get(Calendar.YEAR)); | |
162 } | |
163 } | |
164 | |
165 /** | |
166 * The time variable evaluates to the current time. | |
167 */ | |
168 public static class Time : SimpleTemplateVariableResolver { | |
169 /** | |
170 * Creates a new time variable | |
171 */ | |
172 public this() { | |
173 super("time", TextTemplateMessages.getString("GlobalVariables.variable.description.time")); //$NON-NLS-1$ //$NON-NLS-2$ | |
174 } | |
175 | |
176 /** | |
177 * {@inheritDoc} | |
178 */ | |
179 protected String resolve(TemplateContext context) { | |
180 implMissing(__FILE__,__LINE__); | |
181 return null; | |
182 //return DateFormat.getTimeInstance().format(new java.util.Date()); | |
183 } | |
184 } | |
185 | |
186 /** | |
187 * The user variable evaluates to the current user. | |
188 */ | |
189 public static class User : SimpleTemplateVariableResolver { | |
190 /** | |
191 * Creates a new user name variable | |
192 */ | |
193 public this() { | |
194 super("user", TextTemplateMessages.getString("GlobalVariables.variable.description.user")); //$NON-NLS-1$ //$NON-NLS-2$ | |
195 } | |
196 | |
197 /** | |
198 * {@inheritDoc} | |
199 */ | |
200 protected String resolve(TemplateContext context) { | |
201 return System.getProperty("user.name"); //$NON-NLS-1$ | |
202 } | |
203 } | |
204 } |