129
|
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 dwtx.jface.text.templates.GlobalTemplateVariables;
|
|
15
|
131
|
16 import dwtx.jface.text.templates.SimpleTemplateVariableResolver; // packageimport
|
|
17 import dwtx.jface.text.templates.TemplateBuffer; // packageimport
|
|
18 import dwtx.jface.text.templates.TemplateContext; // packageimport
|
|
19 import dwtx.jface.text.templates.TemplateContextType; // packageimport
|
|
20 import dwtx.jface.text.templates.Template; // packageimport
|
|
21 import dwtx.jface.text.templates.TemplateVariable; // packageimport
|
|
22 import dwtx.jface.text.templates.PositionBasedCompletionProposal; // packageimport
|
|
23 import dwtx.jface.text.templates.TemplateException; // packageimport
|
|
24 import dwtx.jface.text.templates.TemplateTranslator; // packageimport
|
|
25 import dwtx.jface.text.templates.DocumentTemplateContext; // packageimport
|
|
26 import dwtx.jface.text.templates.InclusivePositionUpdater; // packageimport
|
|
27 import dwtx.jface.text.templates.TemplateProposal; // packageimport
|
|
28 import dwtx.jface.text.templates.ContextTypeRegistry; // packageimport
|
|
29 import dwtx.jface.text.templates.JFaceTextTemplateMessages; // packageimport
|
|
30 import dwtx.jface.text.templates.TemplateCompletionProcessor; // packageimport
|
|
31 import dwtx.jface.text.templates.TextTemplateMessages; // packageimport
|
|
32 import dwtx.jface.text.templates.TemplateVariableType; // packageimport
|
|
33 import dwtx.jface.text.templates.TemplateVariableResolver; // packageimport
|
|
34
|
|
35
|
129
|
36 import dwt.dwthelper.utils;
|
|
37
|
|
38 import com.ibm.icu.text.DateFormat;
|
|
39 import com.ibm.icu.util.Calendar;
|
|
40
|
|
41 /**
|
|
42 * Global variables which are available in any context.
|
|
43 * <p>
|
|
44 * Clients may instantiate the classes contained within this class.
|
|
45 * </p>
|
|
46 *
|
|
47 * @since 3.0
|
|
48 */
|
|
49 public class GlobalTemplateVariables {
|
|
50
|
|
51 /** The type of the selection variables. */
|
|
52 public static final String SELECTION= "selection"; //$NON-NLS-1$
|
|
53
|
|
54 /**
|
|
55 * The cursor variable determines the cursor placement after template edition.
|
|
56 */
|
|
57 public static class Cursor : SimpleTemplateVariableResolver {
|
|
58
|
|
59 /** Name of the cursor variable, value= {@value} */
|
|
60 public static final String NAME= "cursor"; //$NON-NLS-1$
|
|
61
|
|
62 /**
|
|
63 * Creates a new cursor variable
|
|
64 */
|
|
65 public Cursor() {
|
|
66 super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.cursor")); //$NON-NLS-1$
|
|
67 setEvaluationString(""); //$NON-NLS-1$
|
|
68 }
|
|
69 }
|
|
70
|
|
71 /**
|
|
72 * The word selection variable determines templates that work on a full
|
|
73 * lines selection.
|
|
74 */
|
|
75 public static class WordSelection : SimpleTemplateVariableResolver {
|
|
76
|
|
77 /** Name of the word selection variable, value= {@value} */
|
|
78 public static final String NAME= "word_selection"; //$NON-NLS-1$
|
|
79
|
|
80 /**
|
|
81 * Creates a new word selection variable
|
|
82 */
|
|
83 public WordSelection() {
|
|
84 super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedWord")); //$NON-NLS-1$
|
|
85 }
|
|
86 protected String resolve(TemplateContext context) {
|
|
87 String selection= context.getVariable(SELECTION);
|
|
88 if (selection is null)
|
|
89 return ""; //$NON-NLS-1$
|
|
90 return selection;
|
|
91 }
|
|
92 }
|
|
93
|
|
94 /**
|
|
95 * The line selection variable determines templates that work on selected
|
|
96 * lines.
|
|
97 */
|
|
98 public static class LineSelection : SimpleTemplateVariableResolver {
|
|
99
|
|
100 /** Name of the line selection variable, value= {@value} */
|
|
101 public static final String NAME= "line_selection"; //$NON-NLS-1$
|
|
102
|
|
103 /**
|
|
104 * Creates a new line selection variable
|
|
105 */
|
|
106 public LineSelection() {
|
|
107 super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedLines")); //$NON-NLS-1$
|
|
108 }
|
|
109 protected String resolve(TemplateContext context) {
|
|
110 String selection= context.getVariable(SELECTION);
|
|
111 if (selection is null)
|
|
112 return ""; //$NON-NLS-1$
|
|
113 return selection;
|
|
114 }
|
|
115 }
|
|
116
|
|
117 /**
|
|
118 * The dollar variable inserts an escaped dollar symbol.
|
|
119 */
|
|
120 public static class Dollar : SimpleTemplateVariableResolver {
|
|
121 /**
|
|
122 * Creates a new dollar variable
|
|
123 */
|
|
124 public Dollar() {
|
|
125 super("dollar", TextTemplateMessages.getString("GlobalVariables.variable.description.dollar")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
126 setEvaluationString("$"); //$NON-NLS-1$
|
|
127 }
|
|
128 }
|
|
129
|
|
130 /**
|
|
131 * The date variable evaluates to the current date.
|
|
132 */
|
|
133 public static class Date : SimpleTemplateVariableResolver {
|
|
134 /**
|
|
135 * Creates a new date variable
|
|
136 */
|
|
137 public Date() {
|
|
138 super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
139 }
|
|
140 protected String resolve(TemplateContext context) {
|
|
141 return DateFormat.getDateInstance().format(new java.util.Date());
|
|
142 }
|
|
143 }
|
|
144
|
|
145 /**
|
|
146 * The year variable evaluates to the current year.
|
|
147 */
|
|
148 public static class Year : SimpleTemplateVariableResolver {
|
|
149 /**
|
|
150 * Creates a new year variable
|
|
151 */
|
|
152 public Year() {
|
|
153 super("year", TextTemplateMessages.getString("GlobalVariables.variable.description.year")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
154 }
|
|
155 protected String resolve(TemplateContext context) {
|
|
156 return Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
|
|
157 }
|
|
158 }
|
|
159
|
|
160 /**
|
|
161 * The time variable evaluates to the current time.
|
|
162 */
|
|
163 public static class Time : SimpleTemplateVariableResolver {
|
|
164 /**
|
|
165 * Creates a new time variable
|
|
166 */
|
|
167 public Time() {
|
|
168 super("time", TextTemplateMessages.getString("GlobalVariables.variable.description.time")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
169 }
|
|
170
|
|
171 /**
|
|
172 * {@inheritDoc}
|
|
173 */
|
|
174 protected String resolve(TemplateContext context) {
|
|
175 return DateFormat.getTimeInstance().format(new java.util.Date());
|
|
176 }
|
|
177 }
|
|
178
|
|
179 /**
|
|
180 * The user variable evaluates to the current user.
|
|
181 */
|
|
182 public static class User : SimpleTemplateVariableResolver {
|
|
183 /**
|
|
184 * Creates a new user name variable
|
|
185 */
|
|
186 public User() {
|
|
187 super("user", TextTemplateMessages.getString("GlobalVariables.variable.description.user")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
188 }
|
|
189
|
|
190 /**
|
|
191 * {@inheritDoc}
|
|
192 */
|
|
193 protected String resolve(TemplateContext context) {
|
|
194 return System.getProperty("user.name"); //$NON-NLS-1$
|
|
195 }
|
|
196 }
|
|
197 }
|