View | Details | Raw Unified | Return to bug 42024
Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/commands/KeysPreferencePage.java (+1 lines)
Lines 607-612 Link Here
607
		gridData.horizontalSpan = 2;		
607
		gridData.horizontalSpan = 2;		
608
		gridData.widthHint = 300;
608
		gridData.widthHint = 300;
609
		textKeySequence.setLayoutData(gridData);
609
		textKeySequence.setLayoutData(gridData);
610
        textKeySequence.setMaxStrokes(4);
610
		
611
		
611
		textKeySequence.addModifyListener(new ModifyListener() {
612
		textKeySequence.addModifyListener(new ModifyListener() {
612
			public void modifyText(ModifyEvent e) {
613
			public void modifyText(ModifyEvent e) {
(-)Eclipse UI/org/eclipse/ui/internal/keys/KeySequenceText.java (-13 / +67 lines)
Lines 37-46 Link Here
37
 */
37
 */
38
public final class KeySequenceText {
38
public final class KeySequenceText {
39
39
40
	/** 
41
	 * The special integer value for the maximum number of strokes indicating
42
	 * that an infinite number should be allowed.
43
	 */
44
	public static final int INFINITE = -1;
40
	/** An empty string instance for use in clearing text values. */
45
	/** An empty string instance for use in clearing text values. */
41
	private static final String EMPTY_STRING = ""; //$NON-NLS-1$
46
	private static final String EMPTY_STRING = ""; //$NON-NLS-1$
47
42
	/** The text of the key sequence -- containing only the complete key strokes. */
48
	/** The text of the key sequence -- containing only the complete key strokes. */
43
	private KeySequence keySequence = null;
49
	private KeySequence keySequence = null;
50
	/** The maximum number of key strokes permitted in the sequence. */
51
	private int maxStrokes = INFINITE;
44
	/** The incomplete key stroke, if any. */
52
	/** The incomplete key stroke, if any. */
45
	private KeyStroke temporaryStroke = null;
53
	private KeyStroke temporaryStroke = null;
46
	/** The text widget that is wrapped for this class. */
54
	/** The text widget that is wrapped for this class. */
Lines 56-67 Link Here
56
	public KeySequenceText(final Composite composite) {
64
	public KeySequenceText(final Composite composite) {
57
		// Set up the text field.
65
		// Set up the text field.
58
		text = new Text(composite, SWT.BORDER);
66
		text = new Text(composite, SWT.BORDER);
59
		
67
60
		/* TODO doug: pls. investigate. works until one backspaces to an empty text field, at which point the font gets changed somehow 
68
		/* TODO doug: pls. investigate. works until one backspaces to an empty text field, at which point the font gets changed somehow 
61
		if ("carbon".equals(SWT.getPlatform())) {
69
		if ("carbon".equals(SWT.getPlatform())) {
62
			// don't worry about this font name here, it is the official menu font and point size on the mac.
70
			// don't worry about this font name here, it is the official menu font and point size on the mac.
63
			final Font font = new Font(text.getDisplay(), "Lucida Grande", 13, SWT.NORMAL); //$NON-NLS-1$
71
			final Font font = new Font(text.getDisplay(), "Lucida Grande", 13, SWT.NORMAL); //$NON-NLS-1$
64
72
		
65
			text.addDisposeListener(new DisposeListener() {
73
			text.addDisposeListener(new DisposeListener() {
66
				public void widgetDisposed(DisposeEvent e) {
74
				public void widgetDisposed(DisposeEvent e) {
67
					font.dispose();
75
					font.dispose();
Lines 142-159 Link Here
142
	}
150
	}
143
151
144
	/**
152
	/**
145
	 * A mutator for the layout information associated with the wrapped widget.
153
	 * <p>
146
	 * @param layoutData The layout information; must not be <code>null</code>.
147
	 */
148
	public final void setLayoutData(final Object layoutData) {
149
		text.setLayoutData(layoutData);
150
	}
151
152
	/**
153
	 * A mutator for the key sequence and incomplete stroke stored within this
154
	 * A mutator for the key sequence and incomplete stroke stored within this
154
	 * widget.  This does some checking to see if the incomplete stroke is 
155
	 * widget.  This does some checking to see if the incomplete stroke is 
155
	 * really incomplete; if it is complete, then it is rolled into the key 
156
	 * really incomplete; if it is complete, then it is rolled into the key 
156
	 * sequence.  The text and caret position are updated.
157
	 * sequence.  The text and caret position are updated.
158
	 * </p>
159
	 * <p>
160
	 * All sequences are limited to maxStrokes number of strokes in length.
161
	 * If there are already that number of strokes, then it does not show
162
	 * incomplete strokes, and does not keep track of them.
163
	 * </p>
157
	 *   
164
	 *   
158
	 * @param newKeySequence The new key sequence for this widget; may be
165
	 * @param newKeySequence The new key sequence for this widget; may be
159
	 * <code>null</code> if none.
166
	 * <code>null</code> if none.
Lines 164-179 Link Here
164
		// Figure out whether the stroke should be rolled in.
171
		// Figure out whether the stroke should be rolled in.
165
		if (isComplete(incompleteStroke)) {
172
		if (isComplete(incompleteStroke)) {
166
			if (newKeySequence == null) {
173
			if (newKeySequence == null) {
174
				// This is guaranteed to be possible by setMaxStrokes
167
				keySequence = KeySequence.getInstance(incompleteStroke);
175
				keySequence = KeySequence.getInstance(incompleteStroke);
168
			} else {
176
			} else {
169
				final List keyStrokes = new ArrayList(newKeySequence.getKeyStrokes());
177
				final List keyStrokes = new ArrayList(newKeySequence.getKeyStrokes());
170
				keyStrokes.add(incompleteStroke);
178
				keyStrokes.add(incompleteStroke);
179
				if (maxStrokes != INFINITE) {
180
					final int keyStrokesSize = keyStrokes.size();
181
					for (int i = keyStrokesSize - 1; i >= maxStrokes; i--) {
182
						keyStrokes.remove(i);
183
					}
184
				}
171
				keySequence = KeySequence.getInstance(keyStrokes);
185
				keySequence = KeySequence.getInstance(keyStrokes);
172
			}
186
			}
173
			temporaryStroke = null;
187
			temporaryStroke = null;
174
		} else {
188
		} else {
175
			keySequence = newKeySequence;
189
			if ((newKeySequence != null) && (maxStrokes != INFINITE)) {
176
			temporaryStroke = incompleteStroke;
190
				final List untrimmedKeyStrokes = newKeySequence.getKeyStrokes();
191
				final int keyStrokesSize = untrimmedKeyStrokes.size();
192
				if (keyStrokesSize > maxStrokes) {
193
					final List keyStrokes = new ArrayList(untrimmedKeyStrokes);
194
					for (int i = keyStrokesSize - 1; i >= maxStrokes; i--) {
195
						keyStrokes.remove(i);
196
					}
197
					keySequence = KeySequence.getInstance(keyStrokes);
198
					temporaryStroke = null;
199
				} else if (keyStrokesSize == maxStrokes) {
200
                    keySequence = newKeySequence;
201
                    temporaryStroke = null;
202
                } else {
203
					keySequence = newKeySequence;
204
					temporaryStroke = incompleteStroke;
205
				}
206
			} else {
207
				keySequence = newKeySequence;
208
				temporaryStroke = incompleteStroke;
209
			}
177
		}
210
		}
178
211
179
		/* Create a dummy (and rather invalid) sequence to get localized display
212
		/* Create a dummy (and rather invalid) sequence to get localized display
Lines 195-204 Link Here
195
			dummySequence = KeySequence.getInstance(keyStrokes);
228
			dummySequence = KeySequence.getInstance(keyStrokes);
196
		}
229
		}
197
230
198
		text.setText(/* TODO "carbon".equals(SWT.getPlatform()) ? KeySupport.formatCarbon(dummySequence) : */ dummySequence.format());
231
		text.setText(/* TODO "carbon".equals(SWT.getPlatform()) ? KeySupport.formatCarbon(dummySequence) : */
232
		dummySequence.format());
199
233
200
		// Update the caret position.
234
		// Update the caret position.
201
		text.setSelection(text.getText().length());
235
		text.setSelection(text.getText().length());
236
	}
237
238
	/**
239
	 * A mutator for the layout information associated with the wrapped widget.
240
	 * @param layoutData The layout information; must not be <code>null</code>.
241
	 */
242
	public final void setLayoutData(final Object layoutData) {
243
		text.setLayoutData(layoutData);
244
	}
245
246
	/**
247
	 * A mutator for the maximum number of strokes that are permitted in this
248
	 * widget at one time.
249
	 * @param maximumStrokes The maximum number of strokes; should be a positive
250
	 * integer or <code>INFINITE</code>.
251
	 */
252
	public final void setMaxStrokes(final int maximumStrokes) {
253
		if ((maximumStrokes > 0) || (maximumStrokes == INFINITE)) {
254
			maxStrokes = maximumStrokes;
255
		}
202
	}
256
	}
203
257
204
	/**
258
	/**

Return to bug 42024