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