Lines 208-219
Link Here
|
208 |
if (shell.getParent() != null) |
208 |
if (shell.getParent() != null) |
209 |
return; |
209 |
return; |
210 |
} |
210 |
} |
|
|
211 |
|
212 |
KeyStroke[] keyStrokes = new KeyStroke[3]; |
213 |
keyStrokes[0] = KeySupport.convertAcceleratorToKeyStroke(KeySupport.convertEventToUnmodifiedAccelerator(event)); |
214 |
keyStrokes[1] = KeySupport.convertAcceleratorToKeyStroke(KeySupport.convertEventToUnshiftedModifiedAccelerator(event)); |
215 |
keyStrokes[2] = KeySupport.convertAcceleratorToKeyStroke(KeySupport.convertEventToModifiedAccelerator(event)); |
211 |
|
216 |
|
212 |
KeyStroke keyStroke = |
217 |
if (press(keyStrokes, event)) { |
213 |
KeySupport.convertAcceleratorToKeyStroke( |
|
|
214 |
KeySupport.convertEventToAccelerator(event)); |
215 |
|
216 |
if (press(keyStroke, event)) { |
217 |
switch (event.type) { |
218 |
switch (event.type) { |
218 |
case SWT.KeyDown : |
219 |
case SWT.KeyDown : |
219 |
event.doit = false; |
220 |
event.doit = false; |
Lines 413-481
Link Here
|
413 |
return true; |
414 |
return true; |
414 |
} |
415 |
} |
415 |
|
416 |
|
416 |
// TODO move this method to CommandManager once getMode() is added to ICommandManager (and triggers and change event) |
417 |
/** |
417 |
// TODO remove event parameter once key-modified actions are removed |
418 |
* Processes a key press with respect to the key binding architecture. This |
418 |
public final boolean press(KeyStroke keyStroke, Event event) { |
419 |
* updates the mode of the command manager, and runs the current handler for |
419 |
final KeySequence modeBeforeKeyStroke = commandManager.getMode(); |
420 |
* the command that matches the key sequence, if any. |
420 |
final List keyStrokes = |
421 |
* |
421 |
new ArrayList(modeBeforeKeyStroke.getKeyStrokes()); |
422 |
* @param potentialKeyStrokes The key strokes that could potentially match, |
422 |
keyStrokes.add(keyStroke); |
423 |
* in the order of priority; must not be <code>null</code>. |
423 |
final KeySequence modeAfterKeyStroke = |
424 |
* @param event The event to pass to the action; may be <code>null</code>. |
424 |
KeySequence.getInstance(keyStrokes); |
425 |
* |
425 |
final Map matchesByKeySequenceForModeBeforeKeyStroke = |
426 |
* @return <code>true</code> if a command is executed; <code>false</code> |
426 |
commandManager.getMatchesByKeySequenceForMode(); |
427 |
* otherwise. |
427 |
commandManager.setMode(modeAfterKeyStroke); |
428 |
*/ |
428 |
final Map matchesByKeySequenceForModeAfterKeyStroke = |
429 |
public boolean press(KeyStroke[] potentialKeyStrokes, Event event) { |
429 |
commandManager.getMatchesByKeySequenceForMode(); |
430 |
// TODO move this method to CommandManager once getMode() is added to ICommandManager (and triggers and change event) |
430 |
boolean consumeKeyStroke = false; |
431 |
// TODO remove event parameter once key-modified actions are removed |
431 |
|
432 |
|
432 |
if (!matchesByKeySequenceForModeAfterKeyStroke.isEmpty()) { |
433 |
// Check every potential key stroke until one matches. |
433 |
// this key stroke is part of one or more possible completions: consume the keystroke |
434 |
for (int i = 0; i < potentialKeyStrokes.length; i++) { |
434 |
updateModeLines(modeAfterKeyStroke); |
435 |
KeySequence modeBeforeKeyStroke = commandManager.getMode(); |
435 |
consumeKeyStroke = true; |
436 |
List keyStrokes = new ArrayList(modeBeforeKeyStroke.getKeyStrokes()); |
436 |
} else { |
437 |
keyStrokes.add(potentialKeyStrokes[i]); |
437 |
// there are no possible longer multi-stroke sequences, allow a completion now if possible |
438 |
KeySequence modeAfterKeyStroke = KeySequence.getInstance(keyStrokes); |
438 |
final Match match = |
439 |
Map matchesByKeySequenceForModeBeforeKeyStroke = commandManager.getMatchesByKeySequenceForMode(); |
439 |
(Match) matchesByKeySequenceForModeBeforeKeyStroke.get( |
440 |
commandManager.setMode(modeAfterKeyStroke); |
440 |
modeAfterKeyStroke); |
441 |
Map matchesByKeySequenceForModeAfterKeyStroke = commandManager.getMatchesByKeySequenceForMode(); |
441 |
|
442 |
boolean consumeKeyStroke = false; |
442 |
if (match != null) { |
443 |
|
443 |
// a completion was found. |
444 |
if (!matchesByKeySequenceForModeAfterKeyStroke.isEmpty()) { |
444 |
final String commandId = match.getCommandId(); |
445 |
// this key stroke is part of one or more possible completions: consume the keystroke |
445 |
final Map actionsById = commandManager.getActionsById(); |
446 |
updateModeLines(modeAfterKeyStroke); |
446 |
org.eclipse.ui.commands.IAction action = |
447 |
consumeKeyStroke = true; |
447 |
(org.eclipse.ui.commands.IAction) actionsById.get( |
448 |
} else { |
448 |
commandId); |
449 |
// there are no possible longer multi-stroke sequences, allow a completion now if possible |
449 |
|
450 |
Match match = (Match) matchesByKeySequenceForModeBeforeKeyStroke.get(modeAfterKeyStroke); |
450 |
if (action != null) { |
451 |
|
451 |
// an action was found corresponding to the completion |
452 |
if (match != null) { |
452 |
|
453 |
// a completion was found. |
453 |
if (action.isEnabled()) { |
454 |
String commandId = match.getCommandId(); |
454 |
updateModeLines(modeAfterKeyStroke); |
455 |
Map actionsById = commandManager.getActionsById(); |
455 |
try { |
456 |
org.eclipse.ui.commands.IAction action = (org.eclipse.ui.commands.IAction) actionsById.get(commandId); |
456 |
action.execute(event); |
457 |
|
457 |
} catch (final Exception e) { |
458 |
if (action != null) { |
458 |
// TODO |
459 |
// an action was found corresponding to the completion |
|
|
460 |
|
461 |
if (action.isEnabled()) { |
462 |
updateModeLines(modeAfterKeyStroke); |
463 |
try { |
464 |
action.execute(event); |
465 |
} catch (Exception e) { |
466 |
// TODO |
467 |
} |
459 |
} |
468 |
} |
|
|
469 |
|
470 |
// consume the keystroke |
471 |
consumeKeyStroke = true; |
460 |
} |
472 |
} |
461 |
|
|
|
462 |
// consume the keystroke |
463 |
consumeKeyStroke = true; |
464 |
} |
473 |
} |
|
|
474 |
|
475 |
// 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. |
476 |
if (modeBeforeKeyStroke.getKeyStrokes().size() >= 1) |
477 |
consumeKeyStroke = true; |
478 |
|
479 |
// clear mode |
480 |
commandManager.setMode(KeySequence.getInstance()); |
481 |
updateModeLines(KeySequence.getInstance()); |
482 |
} |
483 |
|
484 |
// TODO is this necessary? |
485 |
updateActiveContextIds(); |
486 |
|
487 |
if (consumeKeyStroke) { |
488 |
// We found a match, so stop now. |
489 |
return consumeKeyStroke; |
490 |
} else { |
491 |
// Restore the mode, so we can try again. |
492 |
commandManager.setMode(modeBeforeKeyStroke); |
465 |
} |
493 |
} |
466 |
|
|
|
467 |
// 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. |
468 |
if (modeBeforeKeyStroke.getKeyStrokes().size() >= 1) |
469 |
consumeKeyStroke = true; |
470 |
|
471 |
// clear mode |
472 |
commandManager.setMode(KeySequence.getInstance()); |
473 |
updateModeLines(KeySequence.getInstance()); |
474 |
} |
494 |
} |
475 |
|
495 |
|
476 |
// TODO is this necessary? |
496 |
// No key strokes match. |
477 |
updateActiveContextIds(); |
497 |
return false; |
478 |
return consumeKeyStroke; |
|
|
479 |
} |
498 |
} |
480 |
|
499 |
|
481 |
/** |
500 |
/** |