Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge branch 'key-shortcut-aliases' into integration/master
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Jul 6, 2012
2 parents 6c3ffbd + c243afa commit 51aefae
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 82 deletions.
Expand Up @@ -184,20 +184,20 @@ public void onKeyShortcut(KeyShortcutEvent event)
};

// Register shortcut CTRL+ALT+1 to copy result from TM result 1
keyShortcutPresenter.register(new KeyShortcut(Keys.CTRL_ALT_KEYS, Keys.KEY_1, ShortcutContext.Edit, messages.copyFromTM(1), copyTM1Handler));
keyShortcutPresenter.register(new KeyShortcut(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_1, ShortcutContext.Edit, KeyShortcut.DO_NOT_DISPLAY_DESCRIPTION, copyTM1Handler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_1), ShortcutContext.Edit, messages.copyFromTM(1), copyTM1Handler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_1), ShortcutContext.Edit, KeyShortcut.DO_NOT_DISPLAY_DESCRIPTION, copyTM1Handler));

// Register shortcut CTRL+ALT+2 to copy result from TM result 2
keyShortcutPresenter.register(new KeyShortcut(Keys.CTRL_ALT_KEYS, Keys.KEY_2, ShortcutContext.Edit, messages.copyFromTM(2), copyTM2Handler));
keyShortcutPresenter.register(new KeyShortcut(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_2, ShortcutContext.Edit, KeyShortcut.DO_NOT_DISPLAY_DESCRIPTION, copyTM2Handler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_2), ShortcutContext.Edit, messages.copyFromTM(2), copyTM2Handler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_2), ShortcutContext.Edit, KeyShortcut.DO_NOT_DISPLAY_DESCRIPTION, copyTM2Handler));

// Register shortcut CTRL+ALT+3 to copy result from TM result 3
keyShortcutPresenter.register(new KeyShortcut(Keys.CTRL_ALT_KEYS, Keys.KEY_3, ShortcutContext.Edit, messages.copyFromTM(3), copyTM3Handler));
keyShortcutPresenter.register(new KeyShortcut(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_3, ShortcutContext.Edit, KeyShortcut.DO_NOT_DISPLAY_DESCRIPTION, copyTM3Handler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_3), ShortcutContext.Edit, messages.copyFromTM(3), copyTM3Handler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_3), ShortcutContext.Edit, KeyShortcut.DO_NOT_DISPLAY_DESCRIPTION, copyTM3Handler));

// Register shortcut CTRL+ALT+4 to copy result from TM result 4
keyShortcutPresenter.register(new KeyShortcut(Keys.CTRL_ALT_KEYS, Keys.KEY_4, ShortcutContext.Edit, messages.copyFromTM(4), copyTM4Handler));
keyShortcutPresenter.register(new KeyShortcut(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_4, ShortcutContext.Edit, KeyShortcut.DO_NOT_DISPLAY_DESCRIPTION, copyTM4Handler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_4), ShortcutContext.Edit, messages.copyFromTM(4), copyTM4Handler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_4), ShortcutContext.Edit, KeyShortcut.DO_NOT_DISPLAY_DESCRIPTION, copyTM4Handler));

KeyShortcutEventHandler moveNextKeyHandler = new KeyShortcutEventHandler()
{
Expand All @@ -220,16 +220,16 @@ public void onKeyShortcut(KeyShortcutEvent event)
};

// Register shortcut ALT+(Down/K) to move next row and open editor
keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, KeyCodes.KEY_DOWN, ShortcutContext.Edit, messages.moveToNextRow(), moveNextKeyHandler));
keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, Keys.KEY_K, ShortcutContext.Edit, messages.moveToNextRow(), moveNextKeyHandler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, KeyCodes.KEY_DOWN), ShortcutContext.Edit, messages.moveToNextRow(), moveNextKeyHandler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, 'K'), ShortcutContext.Edit, messages.moveToNextRow(), moveNextKeyHandler));

// Register shortcut ALT+(Up/J) to move previous row and open editor
keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, KeyCodes.KEY_UP, ShortcutContext.Edit, messages.moveToPreviousRow(), movePreviousKeyHandler));
keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, Keys.KEY_J, ShortcutContext.Edit, messages.moveToPreviousRow(), movePreviousKeyHandler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, KeyCodes.KEY_UP), ShortcutContext.Edit, messages.moveToPreviousRow(), movePreviousKeyHandler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, 'J'), ShortcutContext.Edit, messages.moveToPreviousRow(), movePreviousKeyHandler));

// Register shortcut ALT+(PageDown) to move next state entry - if modal
// navigation is enabled
keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, KeyCodes.KEY_PAGEDOWN, ShortcutContext.Edit, messages.moveToNextStateRow(), new KeyShortcutEventHandler()
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, KeyCodes.KEY_PAGEDOWN), ShortcutContext.Edit, messages.moveToNextStateRow(), new KeyShortcutEventHandler()
{
@Override
public void onKeyShortcut(KeyShortcutEvent event)
Expand All @@ -243,7 +243,7 @@ public void onKeyShortcut(KeyShortcutEvent event)

// Register shortcut ALT+(PageUp) to move previous state entry - if modal
// navigation is enabled
keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, KeyCodes.KEY_PAGEUP,
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, KeyCodes.KEY_PAGEUP),
ShortcutContext.Edit, messages.moveToPreviousStateRow(), new KeyShortcutEventHandler()
{
@Override
Expand All @@ -257,7 +257,7 @@ public void onKeyShortcut(KeyShortcutEvent event)
}));

// Register shortcut CTRL+S to save as fuzzy
keyShortcutPresenter.register(new KeyShortcut(Keys.CTRL_KEY, Keys.KEY_S,
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.CTRL_KEY, 'S'),
ShortcutContext.Edit, messages.saveAsFuzzy(), KeyEvent.KEY_DOWN, true, true, new KeyShortcutEventHandler()
{
@Override
Expand All @@ -276,15 +276,15 @@ public void onKeyShortcut(KeyShortcutEvent event)
}
};

ctrlEnterSavesApprovedShortcut = new KeyShortcut(Keys.CTRL_KEY, KeyCodes.KEY_ENTER,
ctrlEnterSavesApprovedShortcut = new KeyShortcut(new Keys(Keys.CTRL_KEY, KeyCodes.KEY_ENTER),
ShortcutContext.Edit, messages.saveAsApproved(), KeyEvent.KEY_DOWN, true, true,
saveAsApprovedKeyShortcutHandler);

enterSavesApprovedShortcut = new KeyShortcut(Keys.NO_MODIFIER, KeyCodes.KEY_ENTER,
enterSavesApprovedShortcut = new KeyShortcut(new Keys(Keys.NO_MODIFIER, KeyCodes.KEY_ENTER),
ShortcutContext.Edit, messages.saveAsApproved(), KeyEvent.KEY_DOWN, true, true,
saveAsApprovedKeyShortcutHandler);

enterTriggersAutoSizeShortcut = new KeyShortcut(Keys.NO_MODIFIER, KeyCodes.KEY_ENTER,
enterTriggersAutoSizeShortcut = new KeyShortcut(new Keys(Keys.NO_MODIFIER, KeyCodes.KEY_ENTER),
ShortcutContext.Edit, KeyShortcut.DO_NOT_DISPLAY_DESCRIPTION, KeyEvent.KEY_DOWN, false, false, new KeyShortcutEventHandler()
{
@Override
Expand Down Expand Up @@ -316,7 +316,7 @@ public void onKeyShortcut(KeyShortcutEvent event)
}
}));

escClosesEditorShortcut = new KeyShortcut(Keys.NO_MODIFIER, KeyCodes.KEY_ESCAPE,
escClosesEditorShortcut = new KeyShortcut(new Keys(Keys.NO_MODIFIER, KeyCodes.KEY_ESCAPE),
ShortcutContext.Edit, messages.closeEditor(), new KeyShortcutEventHandler()
{
@Override
Expand All @@ -338,7 +338,7 @@ public void onKeyShortcut(KeyShortcutEvent event)
escClosesEditorRegistered = false;
}

keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, Keys.KEY_G, ShortcutContext.Edit, "Copy from source", new KeyShortcutEventHandler()
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, 'G'), ShortcutContext.Edit, "Copy from source", new KeyShortcutEventHandler()
{
@Override
public void onKeyShortcut(KeyShortcutEvent event)
Expand Down
Expand Up @@ -92,10 +92,10 @@ public enum KeyEvent {
* @param handler activated for a registered {@link KeyShortcut} when context is active
* and a user inputs the correct key combination
*/
public KeyShortcut(int modifiers, int keyCode, ShortcutContext context, String description,
public KeyShortcut(Keys shortcutKeys, ShortcutContext context, String description,
KeyEvent keyEvent, boolean stopPropagation, boolean preventDefault, KeyShortcutEventHandler handler)
{
this.keys = new Keys(modifiers, keyCode);
this.keys = shortcutKeys;
this.context = context;
this.description = description;
this.handler = handler;
Expand All @@ -109,28 +109,16 @@ public KeyShortcut(int modifiers, int keyCode, ShortcutContext context, String d
*
* @see #KeyShortcut(int, int, ShortcutContext, String, KeyShortcutEventHandler, String, boolean, boolean, boolean)
*/
public KeyShortcut(int modifiers, int keyCode, ShortcutContext context, String description, KeyShortcutEventHandler handler)
public KeyShortcut(Keys shortcutKeys, ShortcutContext context, String description, KeyShortcutEventHandler handler)
{
this(modifiers, keyCode, context, description, KeyEvent.KEY_DOWN, false, false, handler);
this(shortcutKeys, context, description, KeyEvent.KEY_DOWN, false, false, handler);
}

public Keys getKeys()
{
return keys;
}

// TODO remove (use Keys.getModifiers)
public int getModifiers()
{
return keys.getModifiers();
}

// TODO remove (use Keys.getKeyCode)
public int getKeyCode()
{
return keys.getKeyCode();
}

public ShortcutContext getContext()
{
return context;
Expand Down Expand Up @@ -166,18 +154,6 @@ public boolean isPreventDefault()
return preventDefault;
}

//TODO remove this and just inline body for any usages
/**
* Return a hash for just the user input part of the shortcut, without
* context.
*
* @return a hash that is unique for a set of modifiers + key code
*/
public int keysHash()
{
return keys.hashCode();
}

// TODO update to deal with list of key combinations
@Override
public int hashCode()
Expand Down
Expand Up @@ -38,11 +38,6 @@ public class Keys implements Comparable<Keys>
public static final int SHIFT_ALT_KEYS = ALT_KEY | SHIFT_KEY;
public static final int CTRL_ALT_KEYS = CTRL_KEY | ALT_KEY;

public static final int KEY_G = 'G';
public static final int KEY_J = 'J';
public static final int KEY_K = 'K';
public static final int KEY_S = 'S';

public static final int KEY_1 = 49;
public static final int KEY_2 = 50;
public static final int KEY_3 = 51;
Expand Down
Expand Up @@ -303,7 +303,7 @@ public void onPresenterRevealed(PresenterRevealedEvent event)
}));

keyShortcutPresenter.register(new KeyShortcut(
Keys.ALT_KEY, 'L',
new Keys(Keys.ALT_KEY, 'L'),
ShortcutContext.Application,
messages.showDocumentListKeyShortcut(),
new KeyShortcutEventHandler()
Expand All @@ -318,7 +318,7 @@ public void onKeyShortcut(KeyShortcutEvent event)
}));

keyShortcutPresenter.register(new KeyShortcut(
Keys.ALT_KEY, 'O',
new Keys(Keys.ALT_KEY, 'O'),
ShortcutContext.Application,
messages.showEditorKeyShortcut(),
new KeyShortcutEventHandler()
Expand All @@ -340,7 +340,7 @@ public void onKeyShortcut(KeyShortcutEvent event)
}));

keyShortcutPresenter.register(new KeyShortcut(
Keys.ALT_KEY, 'P',
new Keys(Keys.ALT_KEY, 'P'),
ShortcutContext.Application,
messages.showProjectWideSearch(),
new KeyShortcutEventHandler()
Expand Down
Expand Up @@ -77,7 +77,7 @@ public interface Display extends WidgetDisplay
}

/**
* Key uses {@link KeyShortcut#keysHash()}
* Key uses {@link Keys#hashCode()}
*/
private Map<Integer, Set<KeyShortcut>> shortcutMap;

Expand Down Expand Up @@ -115,7 +115,7 @@ public void onPreviewNativeEvent(NativePreviewEvent event)
}
});

register(new KeyShortcut(Keys.NO_MODIFIER, KeyCodes.KEY_ESCAPE, ShortcutContext.Application,
register(new KeyShortcut(new Keys(Keys.NO_MODIFIER, KeyCodes.KEY_ESCAPE), ShortcutContext.Application,
messages.closeShortcutView(), KeyEvent.KEY_UP, true, true, new KeyShortcutEventHandler()
{
@Override
Expand All @@ -130,7 +130,7 @@ public void onKeyShortcut(KeyShortcutEvent event)

// could try to use ?, although this is not as simple as passing character
// '?'
register(new KeyShortcut(Keys.ALT_KEY, 'Y', ShortcutContext.Application,
register(new KeyShortcut(new Keys(Keys.ALT_KEY, 'Y'), ShortcutContext.Application,
messages.showAvailableKeyShortcuts(), new KeyShortcutEventHandler()
{
@Override
Expand Down Expand Up @@ -188,12 +188,12 @@ public void setContextActive(ShortcutContext context, boolean active)
*/
public HandlerRegistration register(KeyShortcut shortcut)
{
Log.debug("registering key shortcut. key: " + shortcut.getKeyCode() + " modifier: " + shortcut.getModifiers() + " keyhash: " + shortcut.keysHash());
Set<KeyShortcut> shortcuts = ensureShortcutMap().get(shortcut.keysHash());
Log.debug("registering key shortcut. key: " + shortcut.getKeys().getKeyCode() + " modifier: " + shortcut.getKeys().getModifiers() + " key hash: " + shortcut.getKeys().hashCode());
Set<KeyShortcut> shortcuts = ensureShortcutMap().get(shortcut.getKeys().hashCode());
if (shortcuts == null)
{
shortcuts = new HashSet<KeyShortcut>();
ensureShortcutMap().put(shortcut.keysHash(), shortcuts);
ensureShortcutMap().put(shortcut.getKeys().hashCode(), shortcuts);
}
shortcuts.add(shortcut);
return new KeyShortcutHandlerRegistration(shortcut);
Expand Down Expand Up @@ -283,11 +283,11 @@ private void processKeyEvent(NativeEvent evt)
}

/**
* Calculate a hash that should match {@link KeyShortcut#keysHash()}.
* Calculate a hash that should match {@link Keys#hashCode()}.
*
* @param evt
* @return
* @see KeyShortcut#keysHash()
* @see Keys#hashCode()
*/
private int calculateKeyHash(int modifiers, int keyCode)
{
Expand Down Expand Up @@ -337,7 +337,7 @@ public KeyShortcutHandlerRegistration(KeyShortcut shortcut)
@Override
public void removeHandler()
{
Set<KeyShortcut> shortcuts = ensureShortcutMap().get(shortcut.keysHash());
Set<KeyShortcut> shortcuts = ensureShortcutMap().get(shortcut.getKeys().hashCode());
if (shortcuts != null)
{
shortcuts.remove(shortcut);
Expand Down
Expand Up @@ -391,7 +391,7 @@ else if (info.getReplaceInfo() == null)
}
}));

keyShortcutPresenter.register(new KeyShortcut(Keys.SHIFT_ALT_KEYS, 'A', ShortcutContext.ProjectWideSearch, messages.selectAllTextFlowsKeyShortcut(), new KeyShortcutEventHandler()
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.SHIFT_ALT_KEYS, 'A'), ShortcutContext.ProjectWideSearch, messages.selectAllTextFlowsKeyShortcut(), new KeyShortcutEventHandler()
{
@Override
public void onKeyShortcut(KeyShortcutEvent event)
Expand All @@ -400,7 +400,7 @@ public void onKeyShortcut(KeyShortcutEvent event)
}
}));

keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, 'P', ShortcutContext.ProjectWideSearch, messages.focusSearchPhraseKeyShortcut(), new KeyShortcutEventHandler()
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, 'P'), ShortcutContext.ProjectWideSearch, messages.focusSearchPhraseKeyShortcut(), new KeyShortcutEventHandler()
{
@Override
public void onKeyShortcut(KeyShortcutEvent event)
Expand All @@ -409,7 +409,7 @@ public void onKeyShortcut(KeyShortcutEvent event)
}
}));

keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, 'C', ShortcutContext.ProjectWideSearch, messages.focusReplacementPhraseKeyShortcut(), new KeyShortcutEventHandler()
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, 'C'), ShortcutContext.ProjectWideSearch, messages.focusReplacementPhraseKeyShortcut(), new KeyShortcutEventHandler()
{
@Override
public void onKeyShortcut(KeyShortcutEvent event)
Expand All @@ -418,7 +418,7 @@ public void onKeyShortcut(KeyShortcutEvent event)
}
}));

keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, 'R', ShortcutContext.ProjectWideSearch, messages.replaceSelectedKeyShortcut(), new KeyShortcutEventHandler()
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, 'R'), ShortcutContext.ProjectWideSearch, messages.replaceSelectedKeyShortcut(), new KeyShortcutEventHandler()
{
@Override
public void onKeyShortcut(KeyShortcutEvent event)
Expand All @@ -429,7 +429,7 @@ public void onKeyShortcut(KeyShortcutEvent event)

// TODO Alt+R for replace, Alt+C to focus replace field

keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, 'W', ShortcutContext.ProjectWideSearch, messages.toggleRowActionButtons(), new KeyShortcutEventHandler()
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, 'W'), ShortcutContext.ProjectWideSearch, messages.toggleRowActionButtons(), new KeyShortcutEventHandler()
{
@Override
public void onKeyShortcut(KeyShortcutEvent event)
Expand Down
Expand Up @@ -281,15 +281,15 @@ public void onKeyShortcut(KeyShortcutEvent event)
};

// Register shortcut ALT+(UP/J) for previous row navigation
keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, KeyCodes.KEY_UP, ShortcutContext.Navigation, messages.navigateToNextRow(), KeyEvent.KEY_DOWN, true, true, gotoPreRowHandler));
keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, Keys.KEY_J, ShortcutContext.Navigation, messages.navigateToNextRow(), KeyEvent.KEY_DOWN, true, true, gotoPreRowHandler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, KeyCodes.KEY_UP), ShortcutContext.Navigation, messages.navigateToNextRow(), KeyEvent.KEY_DOWN, true, true, gotoPreRowHandler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, 'J'), ShortcutContext.Navigation, messages.navigateToNextRow(), KeyEvent.KEY_DOWN, true, true, gotoPreRowHandler));

// Register shortcut ALT+(Down/K) for next row navigation
keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, KeyCodes.KEY_DOWN, ShortcutContext.Navigation, messages.navigateToPreviousRow(), KeyEvent.KEY_DOWN, true, true, gotoNextRowHandler));
keyShortcutPresenter.register(new KeyShortcut(Keys.ALT_KEY, Keys.KEY_K, ShortcutContext.Navigation, messages.navigateToPreviousRow(), KeyEvent.KEY_DOWN, true, true, gotoNextRowHandler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, KeyCodes.KEY_DOWN), ShortcutContext.Navigation, messages.navigateToPreviousRow(), KeyEvent.KEY_DOWN, true, true, gotoNextRowHandler));
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.ALT_KEY, 'K'), ShortcutContext.Navigation, messages.navigateToPreviousRow(), KeyEvent.KEY_DOWN, true, true, gotoNextRowHandler));

// Register shortcut Enter to open editor in selected row - if no other input field is in focus
keyShortcutPresenter.register(new KeyShortcut(Keys.NO_MODIFIER, KeyCodes.KEY_ENTER, ShortcutContext.Navigation, messages.openEditorInSelectedRow(), KeyEvent.KEY_UP, true, true, new KeyShortcutEventHandler()
keyShortcutPresenter.register(new KeyShortcut(new Keys(Keys.NO_MODIFIER, KeyCodes.KEY_ENTER), ShortcutContext.Navigation, messages.openEditorInSelectedRow(), KeyEvent.KEY_UP, true, true, new KeyShortcutEventHandler()
{
@Override
public void onKeyShortcut(KeyShortcutEvent event)
Expand Down

0 comments on commit 51aefae

Please sign in to comment.