Re: NetBeans Keycap Listing
Johannes Wahle <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <[email protected]> |
I just stumbled upon the code to convert a KeyStroke to a nice human
readable presentation.
The code is from org.netbeans.modules.quicksearch.SearchResultsRender:
static String getKeyStrokeAsText (KeyStroke keyStroke) {
if (keyStroke == null)
return "";
int modifiers = keyStroke.getModifiers ();
StringBuffer sb = new StringBuffer ();
if ((modifiers & InputEvent.CTRL_DOWN_MASK) > 0)
sb.append ("Ctrl+");
if ((modifiers & InputEvent.ALT_DOWN_MASK) > 0)
sb.append ("Alt+");
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) > 0)
sb.append ("Shift+");
if ((modifiers & InputEvent.META_DOWN_MASK) > 0)
if (Utilities.isMac()) {
// Mac cloverleaf symbol
sb.append ("\u2318+");
} else if (isSolaris()) {
// Sun meta symbol
sb.append ("\u25C6+");
} else {
sb.append ("Meta+");
}
if (keyStroke.getKeyCode () != KeyEvent.VK_SHIFT &&
keyStroke.getKeyCode () != KeyEvent.VK_CONTROL &&
keyStroke.getKeyCode () != KeyEvent.VK_META &&
keyStroke.getKeyCode () != KeyEvent.VK_ALT &&
keyStroke.getKeyCode () != KeyEvent.VK_ALT_GRAPH
)
sb.append (Utilities.keyToString (
KeyStroke.getKeyStroke (keyStroke.getKeyCode (), 0)
));
return sb.toString ();
}
On 11.06.2016 12:03, Johannes Wahle wrote:
> Hi,
>
> this should get you started:
>
> FileObject shortcuts = FileUtil.getConfigFile("Shortcuts");
> for (FileObject shortcut : shortcuts.getChildren()) {
> KeyStroke key = Utilities.stringToKey(shortcut.getName());
> action = shortcut.getAttribute(...)
> }
>
> You still need to figure out, which attribute points to the original
> action, but there should be one (check via shortcut.getAttributes()).
> If the attribute value is a string you might need to look up the
> Action via Actions.forID().
>
> Regards,
> Johannes
>
> On 09.06.2016 17:53, ask.melnyk wrote:
>> I'm write platform plugin for catching shortcuts and showing tips in
>> the status bar. But i need showing action associated with shortcut.
>>
>>
>>
>>
>