Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 6219 Details for
Bug 43613
Integrate isComplete() work and merge with patches
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
KeySequenceText, KeysPreferencePage, KeySupport, Workbench
org.eclipse.ui.workbench-Bug43613_v1.patch (text/plain), 33.18 KB, created by
Douglas Pollock
on 2003-09-24 16:45:49 EDT
(
hide
)
Description:
KeySequenceText, KeysPreferencePage, KeySupport, Workbench
Filename:
MIME Type:
Creator:
Douglas Pollock
Created:
2003-09-24 16:45:49 EDT
Size:
33.18 KB
patch
obsolete
>Index: Eclipse UI/org/eclipse/ui/internal/Workbench.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java,v >retrieving revision 1.103 >diff -u -r1.103 Workbench.java >--- Eclipse UI/org/eclipse/ui/internal/Workbench.java 24 Sep 2003 18:43:38 -0000 1.103 >+++ Eclipse UI/org/eclipse/ui/internal/Workbench.java 24 Sep 2003 20:40:46 -0000 >@@ -208,12 +208,13 @@ > if (shell.getParent() != null) > return; > } >+ >+ KeyStroke[] keyStrokes = new KeyStroke[3]; >+ keyStrokes[0] = KeySupport.convertAcceleratorToKeyStroke(KeySupport.convertEventToUnmodifiedAccelerator(event)); >+ keyStrokes[1] = KeySupport.convertAcceleratorToKeyStroke(KeySupport.convertEventToUnshiftedModifiedAccelerator(event)); >+ keyStrokes[2] = KeySupport.convertAcceleratorToKeyStroke(KeySupport.convertEventToModifiedAccelerator(event)); > >- KeyStroke keyStroke = >- KeySupport.convertAcceleratorToKeyStroke( >- KeySupport.convertEventToAccelerator(event)); >- >- if (press(keyStroke, event)) { >+ if (press(keyStrokes, event)) { > switch (event.type) { > case SWT.KeyDown : > event.doit = false; >@@ -413,69 +414,87 @@ > return true; > } > >- // TODO move this method to CommandManager once getMode() is added to ICommandManager (and triggers and change event) >- // TODO remove event parameter once key-modified actions are removed >- public final boolean press(KeyStroke keyStroke, Event event) { >- final KeySequence modeBeforeKeyStroke = commandManager.getMode(); >- final List keyStrokes = >- new ArrayList(modeBeforeKeyStroke.getKeyStrokes()); >- keyStrokes.add(keyStroke); >- final KeySequence modeAfterKeyStroke = >- KeySequence.getInstance(keyStrokes); >- final Map matchesByKeySequenceForModeBeforeKeyStroke = >- commandManager.getMatchesByKeySequenceForMode(); >- commandManager.setMode(modeAfterKeyStroke); >- final Map matchesByKeySequenceForModeAfterKeyStroke = >- commandManager.getMatchesByKeySequenceForMode(); >- boolean consumeKeyStroke = false; >- >- if (!matchesByKeySequenceForModeAfterKeyStroke.isEmpty()) { >- // this key stroke is part of one or more possible completions: consume the keystroke >- updateModeLines(modeAfterKeyStroke); >- consumeKeyStroke = true; >- } else { >- // there are no possible longer multi-stroke sequences, allow a completion now if possible >- final Match match = >- (Match) matchesByKeySequenceForModeBeforeKeyStroke.get( >- modeAfterKeyStroke); >- >- if (match != null) { >- // a completion was found. >- final String commandId = match.getCommandId(); >- final Map actionsById = commandManager.getActionsById(); >- org.eclipse.ui.commands.IAction action = >- (org.eclipse.ui.commands.IAction) actionsById.get( >- commandId); >- >- if (action != null) { >- // an action was found corresponding to the completion >- >- if (action.isEnabled()) { >- updateModeLines(modeAfterKeyStroke); >- try { >- action.execute(event); >- } catch (final Exception e) { >- // TODO >+ /** >+ * Processes a key press with respect to the key binding architecture. This >+ * updates the mode of the command manager, and runs the current handler for >+ * the command that matches the key sequence, if any. >+ * >+ * @param potentialKeyStrokes The key strokes that could potentially match, >+ * in the order of priority; must not be <code>null</code>. >+ * @param event The event to pass to the action; may be <code>null</code>. >+ * >+ * @return <code>true</code> if a command is executed; <code>false</code> >+ * otherwise. >+ */ >+ public boolean press(KeyStroke[] potentialKeyStrokes, Event event) { >+ // TODO move this method to CommandManager once getMode() is added to ICommandManager (and triggers and change event) >+ // TODO remove event parameter once key-modified actions are removed >+ >+ // Check every potential key stroke until one matches. >+ for (int i = 0; i < potentialKeyStrokes.length; i++) { >+ KeySequence modeBeforeKeyStroke = commandManager.getMode(); >+ List keyStrokes = new ArrayList(modeBeforeKeyStroke.getKeyStrokes()); >+ keyStrokes.add(potentialKeyStrokes[i]); >+ KeySequence modeAfterKeyStroke = KeySequence.getInstance(keyStrokes); >+ Map matchesByKeySequenceForModeBeforeKeyStroke = commandManager.getMatchesByKeySequenceForMode(); >+ commandManager.setMode(modeAfterKeyStroke); >+ Map matchesByKeySequenceForModeAfterKeyStroke = commandManager.getMatchesByKeySequenceForMode(); >+ boolean consumeKeyStroke = false; >+ >+ if (!matchesByKeySequenceForModeAfterKeyStroke.isEmpty()) { >+ // this key stroke is part of one or more possible completions: consume the keystroke >+ updateModeLines(modeAfterKeyStroke); >+ consumeKeyStroke = true; >+ } else { >+ // there are no possible longer multi-stroke sequences, allow a completion now if possible >+ Match match = (Match) matchesByKeySequenceForModeBeforeKeyStroke.get(modeAfterKeyStroke); >+ >+ if (match != null) { >+ // a completion was found. >+ String commandId = match.getCommandId(); >+ Map actionsById = commandManager.getActionsById(); >+ org.eclipse.ui.commands.IAction action = (org.eclipse.ui.commands.IAction) actionsById.get(commandId); >+ >+ if (action != null) { >+ // an action was found corresponding to the completion >+ >+ if (action.isEnabled()) { >+ updateModeLines(modeAfterKeyStroke); >+ try { >+ action.execute(event); >+ } catch (Exception e) { >+ // TODO >+ } > } >+ >+ // consume the keystroke >+ consumeKeyStroke = true; > } >- >- // consume the keystroke >- consumeKeyStroke = true; > } >+ >+ // possibly no completion was found, or no action was found corresponding to the completion, but if we were already in a mode consume the keystroke anyway. >+ if (modeBeforeKeyStroke.getKeyStrokes().size() >= 1) >+ consumeKeyStroke = true; >+ >+ // clear mode >+ commandManager.setMode(KeySequence.getInstance()); >+ updateModeLines(KeySequence.getInstance()); >+ } >+ >+ // TODO is this necessary? >+ updateActiveContextIds(); >+ >+ if (consumeKeyStroke) { >+ // We found a match, so stop now. >+ return consumeKeyStroke; >+ } else { >+ // Restore the mode, so we can try again. >+ commandManager.setMode(modeBeforeKeyStroke); > } >- >- // possibly no completion was found, or no action was found corresponding to the completion, but if we were already in a mode consume the keystroke anyway. >- if (modeBeforeKeyStroke.getKeyStrokes().size() >= 1) >- consumeKeyStroke = true; >- >- // clear mode >- commandManager.setMode(KeySequence.getInstance()); >- updateModeLines(KeySequence.getInstance()); > } >- >- // TODO is this necessary? >- updateActiveContextIds(); >- return consumeKeyStroke; >+ >+ // No key strokes match. >+ return false; > } > > /** >Index: Eclipse UI/org/eclipse/ui/internal/commands/KeysPreferencePage.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/KeysPreferencePage.java,v >retrieving revision 1.30 >diff -u -r1.30 KeysPreferencePage.java >--- Eclipse UI/org/eclipse/ui/internal/commands/KeysPreferencePage.java 4 Sep 2003 02:48:01 -0000 1.30 >+++ Eclipse UI/org/eclipse/ui/internal/commands/KeysPreferencePage.java 24 Sep 2003 20:40:46 -0000 >@@ -1320,7 +1320,7 @@ > } > > private void setKeySequence(KeySequence keySequence) { >- textKeySequence.setKeySequence(keySequence, null); >+ textKeySequence.setKeySequence(keySequence); > } > > private void update() { >Index: Eclipse UI/org/eclipse/ui/internal/keys/KeySequenceText.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/KeySequenceText.java,v >retrieving revision 1.13 >diff -u -r1.13 KeySequenceText.java >--- Eclipse UI/org/eclipse/ui/internal/keys/KeySequenceText.java 24 Sep 2003 18:43:38 -0000 1.13 >+++ Eclipse UI/org/eclipse/ui/internal/keys/KeySequenceText.java 24 Sep 2003 20:40:46 -0000 >@@ -16,19 +16,18 @@ > import java.util.List; > > import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.FocusEvent; >+import org.eclipse.swt.events.FocusListener; > import org.eclipse.swt.events.ModifyEvent; > import org.eclipse.swt.events.ModifyListener; >-import org.eclipse.swt.events.TraverseEvent; >-import org.eclipse.swt.events.TraverseListener; > import org.eclipse.swt.graphics.Font; > import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Event; > import org.eclipse.swt.widgets.Listener; > import org.eclipse.swt.widgets.Text; >-import org.eclipse.ui.keys.CharacterKey; > import org.eclipse.ui.keys.KeySequence; > import org.eclipse.ui.keys.KeyStroke; >-import org.eclipse.ui.keys.NaturalKey; > import org.eclipse.ui.keys.ParseException; > > /** >@@ -53,8 +52,6 @@ > private KeySequence keySequence = KeySequence.getInstance(); > /** The maximum number of key strokes permitted in the sequence. */ > private int maxStrokes = INFINITE; >- /** The incomplete key stroke, if any. */ >- private KeyStroke temporaryStroke = null; > /** The text widget that is wrapped for this class. */ > private final Text text; > /** The listener that makes sure that the text widget remains up-to-date >@@ -92,14 +89,18 @@ > final Listener keyFilter = new KeyTrapListener(); > text.addListener(SWT.KeyUp, keyFilter); > text.addListener(SWT.KeyDown, keyFilter); >- >- // Add the traversal listener. >- text.addTraverseListener(new FocusTrapListener()); >+ >+ // Add the focus listener that attaches the global traversal filter. >+ text.addFocusListener(new TraversalFilterManager()); > > // Add an internal modify listener. > text.addModifyListener(updateSequenceListener); > } > >+ /** >+ * Changes the font on the underlying text widget. >+ * @param font The new font. >+ */ > public void setFont(Font font) { > text.setFont(font); > } >@@ -117,8 +118,7 @@ > * Clears the text field and resets all the internal values. > */ > public final void clear() { >- keySequence = null; >- temporaryStroke = null; >+ keySequence = KeySequence.getInstance(); > text.setText(EMPTY_STRING); > } > >@@ -131,22 +131,12 @@ > return keySequence; > } > >- /** >- * An accessor for the <code>KeyStroke</code> that is currently held as an >- * incomplete stroke (i.e., one without a natural key). >- * @return The incomplete stroke; may be <code>null</code> if there are no >- * incomplete strokes. >- */ >- final KeyStroke getTemporaryStroke() { >- return temporaryStroke; >- } >- > /** >- * An accessor for the underlying text widget used by this entry field. >- * @return The <code>Text</code> instance; never <code>null</code>. >+ * An accessor for the underlying text widget's contents. >+ * @return The text contents of this entry; never <code>null</code>. > */ >- final Text getText() { >- return text; >+ final String getText() { >+ return text.getText(); > } > > /** >@@ -155,28 +145,7 @@ > * <code>false</code> otherwise. > */ > public final boolean hasIncompleteStroke() { >- return (temporaryStroke != null); >- } >- >- /** >- * Checks whether the given key stroke is a temporary key stroke or not. >- * @param keyStroke The key stroke to check for completion; may be >- * <code>null</code>, which results in <code>false</code>. >- * @return <code>true</code> if the key stroke has no natural key; >- * <code>false</code> otherwise. >- */ >- static final boolean isComplete(final KeyStroke keyStroke) { >- if (keyStroke != null) { >- final NaturalKey naturalKey = keyStroke.getNaturalKey(); >- >- if (naturalKey instanceof CharacterKey) { >- final CharacterKey characterKey = (CharacterKey) naturalKey; >- return (characterKey.getCharacter() != '\0'); >- } else >- return true; >- } >- >- return false; >+ return !keySequence.isComplete(); > } > > /** >@@ -189,10 +158,8 @@ > > /** > * <p> >- * A mutator for the key sequence and incomplete stroke stored within this >- * widget. This does some checking to see if the incomplete stroke is >- * really incomplete; if it is complete, then it is rolled into the key >- * sequence. The text and caret position are updated. >+ * A mutator for the key sequence stored within this widget. The text and >+ * caret position are updated. > * </p> > * <p> > * All sequences are limited to maxStrokes number of strokes in length. >@@ -202,83 +169,34 @@ > * > * @param newKeySequence The new key sequence for this widget; may be > * <code>null</code> if none. >- * @param incompleteStroke The new incomplete stroke for this widget; may be >- * <code>null</code> or incomplete -- both conditions are dealt with. > */ >- public final void setKeySequence(final KeySequence newKeySequence, final KeyStroke incompleteStroke) { >- // Figure out whether the stroke should be rolled in. >- if (isComplete(incompleteStroke)) { >- if (newKeySequence == null) { >- // This is guaranteed to be possible by setMaxStrokes >- keySequence = KeySequence.getInstance(incompleteStroke); >- } else { >- final List keyStrokes = new ArrayList(newKeySequence.getKeyStrokes()); >- keyStrokes.add(incompleteStroke); >- if (maxStrokes != INFINITE) { >- final int keyStrokesSize = keyStrokes.size(); >- for (int i = keyStrokesSize - 1; i >= maxStrokes; i--) { >- keyStrokes.remove(i); >- } >- } >- keySequence = KeySequence.getInstance(keyStrokes); >- } >- temporaryStroke = null; >- } else { >- if ((newKeySequence != null) && (maxStrokes != INFINITE)) { >- final List untrimmedKeyStrokes = newKeySequence.getKeyStrokes(); >- final int keyStrokesSize = untrimmedKeyStrokes.size(); >- if (keyStrokesSize > maxStrokes) { >- final List keyStrokes = new ArrayList(untrimmedKeyStrokes); >- for (int i = keyStrokesSize - 1; i >= maxStrokes; i--) { >- keyStrokes.remove(i); >- } >- keySequence = KeySequence.getInstance(keyStrokes); >- temporaryStroke = null; >- } else if (keyStrokesSize == maxStrokes) { >- keySequence = newKeySequence; >- temporaryStroke = null; >- } else { >- keySequence = newKeySequence; >- temporaryStroke = incompleteStroke; >- } >- } else { >- keySequence = newKeySequence; >- temporaryStroke = incompleteStroke; >- } >- } >- >- /* Create a dummy (and rather invalid) sequence to get localized display >- * formatting >- */ >- final KeySequence dummySequence; >- if (keySequence == null) { >- if (temporaryStroke == null) { >- dummySequence = KeySequence.getInstance(); >- } else { >- dummySequence = KeySequence.getInstance(temporaryStroke); >- } >- } else { >- final List keyStrokes = new ArrayList(keySequence.getKeyStrokes()); >- if (temporaryStroke != null) { >- keyStrokes.add(temporaryStroke); >+ public void setKeySequence(KeySequence newKeySequence) { >+ keySequence = newKeySequence; >+ >+ // Trim any extra strokes. >+ if (maxStrokes != INFINITE) { >+ List keyStrokes = new ArrayList(keySequence.getKeyStrokes()); >+ int keyStrokesSize = keyStrokes.size(); >+ for (int i = keyStrokesSize - 1; i >= maxStrokes; i--) { >+ keyStrokes.remove(i); > } >- dummySequence = KeySequence.getInstance(keyStrokes); >+ keySequence = KeySequence.getInstance(keyStrokes); > } >- >+ > // We need to update the text, but we don't need to synchronize. > text.removeModifyListener(updateSequenceListener); >- text.setText(dummySequence.format()); >+ text.setText(keySequence.format()); > text.addModifyListener(updateSequenceListener); > > // Update the caret position. >- text.setSelection(text.getText().length()); >+ text.setSelection(getText().length()); > } > > /** > * A mutator for the layout information associated with the wrapped widget. > * @param layoutData The layout information; must not be <code>null</code>. > */ >- public final void setLayoutData(final Object layoutData) { >+ public void setLayoutData(Object layoutData) { > text.setLayoutData(layoutData); > } > >@@ -288,61 +206,17 @@ > * @param maximumStrokes The maximum number of strokes; should be a positive > * integer or <code>INFINITE</code>. > */ >- public final void setMaxStrokes(final int maximumStrokes) { >+ public void setMaxStrokes(int maximumStrokes) { > if ((maximumStrokes > 0) || (maximumStrokes == INFINITE)) { > maxStrokes = maximumStrokes; > } > } > > /** >- * A traversal listener that blocks all traversal except for tabs and arrow >- * keys. >- */ >- private final class FocusTrapListener implements TraverseListener { >- >- /** >- * Handles the traverse event on the text field wrapped by this class. >- * It swallows all traverse events example for tab and arrow key >- * navigation. The other forms of navigation can be reached by tabbing >- * off of the control. >- * >- * @param event The trigger event; must not be <code>null</code>. >- */ >- public final void keyTraversed(final TraverseEvent event) { >- switch (event.detail) { >- case SWT.TRAVERSE_ESCAPE : >- case SWT.TRAVERSE_MNEMONIC : >- case SWT.TRAVERSE_NONE : >- case SWT.TRAVERSE_PAGE_NEXT : >- case SWT.TRAVERSE_PAGE_PREVIOUS : >- case SWT.TRAVERSE_RETURN : >- event.doit = false; >- break; >- >- case SWT.TRAVERSE_TAB_NEXT : >- case SWT.TRAVERSE_TAB_PREVIOUS : >- // Check if modifiers other than just 'Shift' were down. >- if ((event.stateMask & (SWT.MODIFIER_MASK ^ SWT.SHIFT)) != 0) { >- // Modifiers other than shift were down. >- event.doit = false; >- break; >- } >- // fall through -- either no modifiers, or just shift. >- >- case SWT.TRAVERSE_ARROW_NEXT : >- case SWT.TRAVERSE_ARROW_PREVIOUS : >- default : >- // Let the traversal happen, but clear the incomplete stroke >- setKeySequence(getKeySequence(), null); >- } >- } >- } >- >- /** > * A key listener that traps incoming events and displays them in the > * wrapped text field. It has no effect on traversal operations. > */ >- private final class KeyTrapListener implements Listener { >+ private class KeyTrapListener implements Listener { > /** > * Handles the key pressed and released events on the wrapped text > * widget. This makes sure to either add the pressed key to the >@@ -353,39 +227,37 @@ > * > * @param event The triggering event; must not be <code>null</code>. > */ >- public final void handleEvent(final Event event) { >+ public void handleEvent(Event event) { >+ List keyStrokes = new ArrayList(getKeySequence().getKeyStrokes()); >+ > if (event.type == SWT.KeyDown) { > if ((event.character == SWT.BS) && (event.stateMask == 0)) { > // Remove the last key stroke. >- if (hasIncompleteStroke()) { >- /* Remove the incomplete stroke. This should not really >- * be possible, but it is better to be safe than sorry. >- */ >- setKeySequence(getKeySequence(), null); >- } else { >- // Remove the last complete stroke. >- final KeySequence sequence = getKeySequence(); >- final List keyStrokes = new ArrayList(sequence.getKeyStrokes()); >- if (!keyStrokes.isEmpty()) { >- keyStrokes.remove(keyStrokes.size() - 1); >- setKeySequence(KeySequence.getInstance(keyStrokes), null); >- } >+ if (!keyStrokes.isEmpty()) { >+ keyStrokes.remove(keyStrokes.size() - 1); > } >+ > } else { > // Handles the key pressed event. >- final int key = KeySupport.convertEventToAccelerator(event); >- final KeyStroke stroke = KeySupport.convertAcceleratorToKeyStroke(key); >- setKeySequence(getKeySequence(), stroke); >+ // Remove the incomplete stroke, if any. >+ if ((hasIncompleteStroke()) && (!keyStrokes.isEmpty())) { >+ keyStrokes.remove(keyStrokes.size() - 1); >+ } >+ >+ // Add the new stroke. >+ int key = KeySupport.convertEventToUnmodifiedAccelerator(event); >+ KeyStroke stroke = KeySupport.convertAcceleratorToKeyStroke(key); >+ keyStrokes.add(stroke); > } > >- } else if (hasIncompleteStroke()) { >+ } else if ((event.type == SWT.KeyUp) && (hasIncompleteStroke())) { > /* Handles the key released event, which is only relevant if > * there is an incomplete stroke. > */ > /* Figure out the SWT integer representation of the remaining > * values. > */ >- final Event mockEvent = new Event(); >+ Event mockEvent = new Event(); > if ((event.keyCode & SWT.MODIFIER_MASK) != 0) { > // This key up is a modifier key being released. > mockEvent.stateMask = event.stateMask - event.keyCode; >@@ -399,16 +271,19 @@ > /* Get a reasonable facsimile of the stroke that is still > * pressed. > */ >- final int key = KeySupport.convertEventToAccelerator(mockEvent); >- final KeyStroke remainingStroke = KeySupport.convertAcceleratorToKeyStroke(key); >- >- if (remainingStroke.getModifierKeys().isEmpty()) { >- setKeySequence(getKeySequence(), null); >- } else { >- setKeySequence(getKeySequence(), remainingStroke); >+ int key = KeySupport.convertEventToUnmodifiedAccelerator(mockEvent); >+ KeyStroke remainingStroke = KeySupport.convertAcceleratorToKeyStroke(key); >+ if (!keyStrokes.isEmpty()) { >+ keyStrokes.remove(keyStrokes.size() - 1); >+ } >+ if (!remainingStroke.getModifierKeys().isEmpty()) { >+ keyStrokes.add(remainingStroke); > } > > } >+ >+ // Update the underlying widget. >+ setKeySequence(KeySequence.getInstance(keyStrokes)); > > // Prevent the event from reaching the widget. > event.doit = false; >@@ -416,45 +291,109 @@ > } > > /** >+ * A traversal listener that blocks all traversal except for tabs and arrow >+ * keys. >+ */ >+ private class TraversalFilter implements Listener { >+ /** >+ * Handles the traverse event on the text field wrapped by this class. >+ * It swallows all traverse events example for tab and arrow key >+ * navigation. The other forms of navigation can be reached by tabbing >+ * off of the control. >+ * >+ * @param event The trigger event; must not be <code>null</code>. >+ */ >+ public void handleEvent(Event event) { >+ switch (event.detail) { >+ case SWT.TRAVERSE_ESCAPE : >+ case SWT.TRAVERSE_MNEMONIC : >+ case SWT.TRAVERSE_NONE : >+ case SWT.TRAVERSE_PAGE_NEXT : >+ case SWT.TRAVERSE_PAGE_PREVIOUS : >+ case SWT.TRAVERSE_RETURN : >+ event.type = SWT.None; >+ event.doit = false; >+ break; >+ >+ case SWT.TRAVERSE_TAB_NEXT : >+ case SWT.TRAVERSE_TAB_PREVIOUS : >+ // Check if modifiers other than just 'Shift' were down. >+ if ((event.stateMask & (SWT.MODIFIER_MASK ^ SWT.SHIFT)) != 0) { >+ // Modifiers other than shift were down. >+ event.type = SWT.None; >+ event.doit = false; >+ break; >+ } >+ // fall through -- either no modifiers, or just shift. >+ >+ case SWT.TRAVERSE_ARROW_NEXT : >+ case SWT.TRAVERSE_ARROW_PREVIOUS : >+ default : >+ // Let the traversal happen, but clear the incomplete stroke >+ if (hasIncompleteStroke()) { >+ List keyStrokes = new ArrayList(getKeySequence().getKeyStrokes()); >+ if (!keyStrokes.isEmpty()) { >+ keyStrokes.remove(keyStrokes.size() - 1); >+ } >+ setKeySequence(KeySequence.getInstance(keyStrokes)); >+ } >+ } >+ >+ } >+ } >+ >+ /** >+ * The manager resposible for installing and removing the traversal filter >+ * when the key sequence entry widget gains and loses focus. >+ */ >+ private class TraversalFilterManager implements FocusListener { >+ /** The managed filter. We only need one instance. */ >+ private TraversalFilter filter = new TraversalFilter(); >+ >+ /** >+ * Attaches the global traversal filter. >+ * @param event Ignored. >+ */ >+ public void focusGained(FocusEvent event) { >+ Display.getCurrent().addFilter(SWT.Traverse, filter); >+ } >+ >+ /** >+ * Detaches the global traversal filter. >+ * @param event Ignored. >+ */ >+ public void focusLost(FocusEvent event) { >+ Display.getCurrent().removeFilter(SWT.Traverse, filter); >+ } >+ } >+ >+ /** > * A modification listener that makes sure that external events to this > * class (i.e., direct modification of the underlying text) do not break > * this class' view of the world. > */ >- private final class UpdateSequenceListener implements ModifyListener { >+ private class UpdateSequenceListener implements ModifyListener { > /** > * Handles the modify event on the underlying text widget. > * @param event The triggering event; ignored. > */ >- public final void modifyText(final ModifyEvent event) { >+ public void modifyText(ModifyEvent event) { > try { > // The original sequence. >- final KeySequence originalSequence = getKeySequence(); >- final List keyStrokes = new ArrayList(originalSequence.getKeyStrokes()); >- if (getTemporaryStroke() != null) { >- keyStrokes.add(getTemporaryStroke()); >- } >- final KeySequence sequenceFromStrokes = KeySequence.getInstance(keyStrokes); >+ KeySequence originalSequence = getKeySequence(); > > // The new sequence drawn from the text. >- final String contents = getText().getText(); >- final KeySequence sequenceFromText = KeySequence.getInstance(contents); >+ String contents = getText(); >+ KeySequence newSequence = KeySequence.getInstance(contents); > > // Check to see if they're the same. >- if (!sequenceFromStrokes.equals(sequenceFromText)) { >- final List strokes = sequenceFromText.getKeyStrokes(); >- final Iterator strokeItr = strokes.iterator(); >- while (strokeItr.hasNext()) { >- // Make sure that it's a valid sequence. >- if (!isComplete((KeyStroke) strokeItr.next())) { >- setKeySequence(getKeySequence(), getTemporaryStroke()); >- return; >- } >- } >- setKeySequence(sequenceFromText, null); >+ if (!originalSequence.equals(newSequence)) { >+ setKeySequence(newSequence); > } >- } catch (final ParseException e) { >+ >+ } catch (ParseException e) { > // Abort any cut/paste-driven modifications >- setKeySequence(getKeySequence(), getTemporaryStroke()); >+ setKeySequence(getKeySequence()); > } > } > } >Index: Eclipse UI/org/eclipse/ui/internal/keys/KeySupport.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/KeySupport.java,v >retrieving revision 1.9 >diff -u -r1.9 KeySupport.java >--- Eclipse UI/org/eclipse/ui/internal/keys/KeySupport.java 24 Sep 2003 18:43:38 -0000 1.9 >+++ Eclipse UI/org/eclipse/ui/internal/keys/KeySupport.java 24 Sep 2003 20:40:46 -0000 >@@ -41,98 +41,133 @@ > if ((accelerator & SWT.SHIFT) != 0) > modifierKeys.add(ModifierKey.SHIFT); > >- accelerator &= SWT.KEY_MASK; >- >- switch (accelerator) { >- case SWT.ARROW_DOWN : >- naturalKey = SpecialKey.ARROW_DOWN; >- break; >- case SWT.ARROW_LEFT : >- naturalKey = SpecialKey.ARROW_LEFT; >- break; >- case SWT.ARROW_RIGHT : >- naturalKey = SpecialKey.ARROW_RIGHT; >- break; >- case SWT.ARROW_UP : >- naturalKey = SpecialKey.ARROW_UP; >- break; >- case SWT.END : >- naturalKey = SpecialKey.END; >- break; >- case SWT.F1 : >- naturalKey = SpecialKey.F1; >- break; >- case SWT.F10 : >- naturalKey = SpecialKey.F10; >- break; >- case SWT.F11 : >- naturalKey = SpecialKey.F11; >- break; >- case SWT.F12 : >- naturalKey = SpecialKey.F12; >- break; >- case SWT.F2 : >- naturalKey = SpecialKey.F2; >- break; >- case SWT.F3 : >- naturalKey = SpecialKey.F3; >- break; >- case SWT.F4 : >- naturalKey = SpecialKey.F4; >- break; >- case SWT.F5 : >- naturalKey = SpecialKey.F5; >- break; >- case SWT.F6 : >- naturalKey = SpecialKey.F6; >- break; >- case SWT.F7 : >- naturalKey = SpecialKey.F7; >- break; >- case SWT.F8 : >- naturalKey = SpecialKey.F8; >- break; >- case SWT.F9 : >- naturalKey = SpecialKey.F9; >- break; >- case SWT.HOME : >- naturalKey = SpecialKey.HOME; >- break; >- case SWT.INSERT : >- naturalKey = SpecialKey.INSERT; >- break; >- case SWT.PAGE_DOWN : >- naturalKey = SpecialKey.PAGE_DOWN; >- break; >- case SWT.PAGE_UP : >- naturalKey = SpecialKey.PAGE_UP; >- break; >- default : >- naturalKey = CharacterKey.getInstance((char) (accelerator & 0xFFFF)); >+ if (((accelerator & SWT.KEY_MASK) == 0) && (accelerator != 0)) { >+ // There were only accelerators >+ naturalKey = null; >+ } else { >+ // There were other keys. >+ accelerator &= SWT.KEY_MASK; >+ >+ switch (accelerator) { >+ case SWT.ARROW_DOWN : >+ naturalKey = SpecialKey.ARROW_DOWN; >+ break; >+ case SWT.ARROW_LEFT : >+ naturalKey = SpecialKey.ARROW_LEFT; >+ break; >+ case SWT.ARROW_RIGHT : >+ naturalKey = SpecialKey.ARROW_RIGHT; >+ break; >+ case SWT.ARROW_UP : >+ naturalKey = SpecialKey.ARROW_UP; >+ break; >+ case SWT.END : >+ naturalKey = SpecialKey.END; >+ break; >+ case SWT.F1 : >+ naturalKey = SpecialKey.F1; >+ break; >+ case SWT.F10 : >+ naturalKey = SpecialKey.F10; >+ break; >+ case SWT.F11 : >+ naturalKey = SpecialKey.F11; >+ break; >+ case SWT.F12 : >+ naturalKey = SpecialKey.F12; >+ break; >+ case SWT.F2 : >+ naturalKey = SpecialKey.F2; >+ break; >+ case SWT.F3 : >+ naturalKey = SpecialKey.F3; >+ break; >+ case SWT.F4 : >+ naturalKey = SpecialKey.F4; >+ break; >+ case SWT.F5 : >+ naturalKey = SpecialKey.F5; >+ break; >+ case SWT.F6 : >+ naturalKey = SpecialKey.F6; >+ break; >+ case SWT.F7 : >+ naturalKey = SpecialKey.F7; >+ break; >+ case SWT.F8 : >+ naturalKey = SpecialKey.F8; >+ break; >+ case SWT.F9 : >+ naturalKey = SpecialKey.F9; >+ break; >+ case SWT.HOME : >+ naturalKey = SpecialKey.HOME; >+ break; >+ case SWT.INSERT : >+ naturalKey = SpecialKey.INSERT; >+ break; >+ case SWT.PAGE_DOWN : >+ naturalKey = SpecialKey.PAGE_DOWN; >+ break; >+ case SWT.PAGE_UP : >+ naturalKey = SpecialKey.PAGE_UP; >+ break; >+ default : >+ naturalKey = CharacterKey.getInstance((char) (accelerator & 0xFFFF)); >+ } > } > > return KeyStroke.getInstance(modifierKeys, naturalKey); > } > >- public static int convertEventToAccelerator(Event event) { >- int key = event.character; >- >- if (key == 0) >- key = event.keyCode; >- else { >- if (0 <= key && key <= 0x1F) { >- if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode != event.character) >- key += 0x40; >- } else { >- if ('a' <= key && key <= 'z') >- key -= 'a' - 'A'; >- } >- } >+ /** >+ * Converts the given event into an SWT accelerator value -- considering >+ * the modified character with the shift modifier. This is the third >+ * accelerator value that should be checked. >+ * >+ * @param event >+ * The event to be converted; must not be <code>null</code>. >+ * @return The combination of the state mask and the unmodified character. >+ */ >+ public static int convertEventToModifiedAccelerator(Event event) { >+ int modifiers = event.stateMask & SWT.MODIFIER_MASK; >+ int modifiedCharacter = topKey(event); >+ return modifiers + modifiedCharacter; >+ } > >+ /** >+ * Converts the given event into an SWT accelerator value -- considering >+ * the unmodified character with all modifier keys. This is the first >+ * accelerator value that should be checked. However, all alphabetic >+ * characters are considered as their uppercase equivalents. >+ * >+ * @param event >+ * The event to be converted; must not be <code>null</code>. >+ * @return The combination of the state mask and the unmodified character. >+ */ >+ public static int convertEventToUnmodifiedAccelerator(Event event) { > int modifiers = event.stateMask & SWT.MODIFIER_MASK; >- return modifiers + key; >+ int unmodifiedCharacter = upperCase(event.keyCode); >+ >+ return modifiers + unmodifiedCharacter; >+ } >+ >+ /** >+ * Converts the given event into an SWT accelerator value -- considering >+ * the modified character without the shift modifier. This is the second >+ * accelerator value that should be checked. >+ * >+ * @param event >+ * The event to be converted; must not be <code>null</code>. >+ * @return The combination of the state mask without shift, and the >+ * modified character. >+ */ >+ public static int convertEventToUnshiftedModifiedAccelerator(Event event) { >+ int modifiers = event.stateMask & (SWT.MODIFIER_MASK ^ SWT.SHIFT); >+ int modifiedCharacter = topKey(event); >+ return modifiers + modifiedCharacter; > } >- >+ > public static final int convertKeyStrokeToAccelerator(final KeyStroke keyStroke) { > if (keyStroke == null) > throw new NullPointerException(); >@@ -205,6 +240,45 @@ > } > > return accelerator; >+ } >+ >+ /** >+ * Makes sure that a fully-modified character is converted to the normal >+ * form. This means that "Ctrl+" key strokes must reverse the modification >+ * caused by control-escaping. Also, all lower case letters are converted >+ * to uppercase. >+ * >+ * @param event >+ * The event from which the fully-modified character should be >+ * pulled. >+ * @return The modified character, uppercase and without control-escaping. >+ */ >+ private static int topKey(Event event) { >+ boolean ctrlDown = (event.stateMask & SWT.CTRL) != 0; >+ char modifiedCharacter; >+ if ((ctrlDown) && (event.character != event.keyCode) && (event.character < 0x20)) { >+ modifiedCharacter = (char) (event.character + 0x40); >+ } else { >+ modifiedCharacter = event.character; >+ } >+ >+ return upperCase(modifiedCharacter); >+ } >+ >+ /** >+ * Makes the given character uppercase if it is a letter. >+ * >+ * @param character >+ * The character to convert. >+ * @return The uppercase equivalent, if any; otherwise, the character >+ * itself. >+ */ >+ private static int upperCase(int character) { >+ if (Character.isLetter((char) character)) { >+ return Character.toUpperCase((char) character); >+ } >+ >+ return character; > } > > private KeySupport() {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 43613
: 6219