View | Details | Raw Unified | Return to bug 41962 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/keys/KeySequenceText.java (-4 / +54 lines)
Lines 12-20 Link Here
12
package org.eclipse.ui.internal.keys;
12
package org.eclipse.ui.internal.keys;
13
13
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Iterator;
15
import java.util.List;
16
import java.util.List;
16
17
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.events.ModifyEvent;
18
import org.eclipse.swt.events.ModifyListener;
20
import org.eclipse.swt.events.ModifyListener;
19
import org.eclipse.swt.events.TraverseEvent;
21
import org.eclipse.swt.events.TraverseEvent;
20
import org.eclipse.swt.events.TraverseListener;
22
import org.eclipse.swt.events.TraverseListener;
Lines 26-31 Link Here
26
import org.eclipse.ui.keys.KeySequence;
28
import org.eclipse.ui.keys.KeySequence;
27
import org.eclipse.ui.keys.KeyStroke;
29
import org.eclipse.ui.keys.KeyStroke;
28
import org.eclipse.ui.keys.NaturalKey;
30
import org.eclipse.ui.keys.NaturalKey;
31
import org.eclipse.ui.keys.ParseException;
29
32
30
/**
33
/**
31
 * A wrapper around the SWT text widget that traps literal key presses and 
34
 * A wrapper around the SWT text widget that traps literal key presses and 
Lines 46-52 Link Here
46
	private static final String EMPTY_STRING = ""; //$NON-NLS-1$
49
	private static final String EMPTY_STRING = ""; //$NON-NLS-1$
47
50
48
	/** The text of the key sequence -- containing only the complete key strokes. */
51
	/** The text of the key sequence -- containing only the complete key strokes. */
49
	private KeySequence keySequence = null;
52
	private KeySequence keySequence = KeySequence.getInstance();
50
	/** The maximum number of key strokes permitted in the sequence. */
53
	/** The maximum number of key strokes permitted in the sequence. */
51
	private int maxStrokes = INFINITE;
54
	private int maxStrokes = INFINITE;
52
	/** The incomplete key stroke, if any. */
55
	/** The incomplete key stroke, if any. */
Lines 87-92 Link Here
87
90
88
		// Add the traversal listener.
91
		// Add the traversal listener.
89
		text.addTraverseListener(new FocusTrapListener());
92
		text.addTraverseListener(new FocusTrapListener());
93
94
		// Add an internal modify listener.
95
		text.addModifyListener(new UpdateSequenceListener());
90
	}
96
	}
91
97
92
	/**
98
	/**
Lines 197-205 Link Here
197
					keySequence = KeySequence.getInstance(keyStrokes);
203
					keySequence = KeySequence.getInstance(keyStrokes);
198
					temporaryStroke = null;
204
					temporaryStroke = null;
199
				} else if (keyStrokesSize == maxStrokes) {
205
				} else if (keyStrokesSize == maxStrokes) {
200
                    keySequence = newKeySequence;
206
					keySequence = newKeySequence;
201
                    temporaryStroke = null;
207
					temporaryStroke = null;
202
                } else {
208
				} else {
203
					keySequence = newKeySequence;
209
					keySequence = newKeySequence;
204
					temporaryStroke = incompleteStroke;
210
					temporaryStroke = incompleteStroke;
205
				}
211
				}
Lines 365-370 Link Here
365
371
366
			// Prevent the event from reaching the widget.
372
			// Prevent the event from reaching the widget.
367
			event.doit = false;
373
			event.doit = false;
374
		}
375
	}
376
377
	/**
378
     * A modification listener that makes sure that external events to this 
379
     * class (i.e., direct modification of the underlying text) do not break
380
     * this class' view of the world.
381
     */
382
	private final class UpdateSequenceListener implements ModifyListener {
383
		/**
384
		 * Handles the modify event on the underlying text widget.
385
         * @param event The triggering event; ignored.
386
         */
387
		public final void modifyText(final ModifyEvent event) {
388
			try {
389
				// The original sequence.
390
				final KeySequence originalSequence = getKeySequence();
391
				final List keyStrokes = new ArrayList(originalSequence.getKeyStrokes());
392
				if (temporaryStroke != null) {
393
					keyStrokes.add(temporaryStroke);
394
				}
395
				final KeySequence sequenceFromStrokes = KeySequence.getInstance(keyStrokes);
396
397
				// The new sequence drawn from the text.
398
				final String contents = text.getText();
399
				final KeySequence sequenceFromText = KeySequence.getInstance(contents);
400
401
				// Check to see if they're the same.
402
				if (!sequenceFromStrokes.equals(sequenceFromText)) {
403
					final List strokes = sequenceFromText.getKeyStrokes();
404
					final Iterator strokeItr = strokes.iterator();
405
					while (strokeItr.hasNext()) {
406
						// Make sure that it's a valid sequence.
407
						if (!isComplete((KeyStroke) strokeItr.next())) {
408
							setKeySequence(getKeySequence(), temporaryStroke);
409
							return;
410
						}
411
					}
412
					setKeySequence(sequenceFromText, null);
413
				}
414
			} catch (final ParseException e) {
415
				// Abort any cut/paste-driven modifications
416
				setKeySequence(getKeySequence(), temporaryStroke);
417
			}
368
		}
418
		}
369
	}
419
	}
370
}
420
}

Return to bug 41962