Mercurial > projects > dwt-addons
annotate dwtx/jface/text/templates/GlobalTemplateVariables.d @ 133:7d818bd32d63
Fix ctors to this with gvim regexp
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 01:29:22 +0200 |
parents | c4fb132a086c |
children | 000f9136b8f7 |
rev | line source |
---|---|
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 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
65 public this() { |
129 | 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 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
83 public this() { |
129 | 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 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
106 public this() { |
129 | 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 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
124 public this() { |
129 | 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 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
137 public this() { |
129 | 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 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
152 public this() { |
129 | 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 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
167 public this() { |
129 | 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 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
186 public this() { |
129 | 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 } |