How do keybindings work?

Keybindings are specified in yet another folder in the system filesystem . The folder Shortcuts/ contains .instance files or .shadow files (shadow files are like symlinks to another file in the system fs) - these map to Actions.

The file name for the action (.instance or .shadow) file in Shortcuts/ is used to specify what keys are bound. This is done using an emacs-like syntax for specifying keybindings - e.g., CA-P equals Ctrl-Alt-P.

For a full listing of the hard-coded and cross-platform prefixes for key definitions, see the javadoc for Utilities.stringToKey() - that and its analogue, Utilities.keyToString() are used to encode and decode these.

There are special modifier characters which map to Command on Mac and Ctrl on PC, Ctrl on Mac and Alt on PC. You should use those unless you're really sure your app will never be used on macintosh or never be used by someone with a non-English macintosh.

Here is an example of what a layer file might look like if you bound the Ctrl+Shift+Equals sequence to the com.tomwheeler.example.fooviewer.FooAction action:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.0//EN"
  <folder name="Actions">
    <folder name="View">
      <folder name="FooViewer">
        <file name="com-tomwheeler-example-fooviewer-FooAction.instance" />
  <folder name="Shortcuts">
        set up a shortcut key for executing the Foo Action:
        Ctrl + Shift + Equals on Linux and MS Windows, but Command + Shift + Equals on a Mac
    <file name="DS-EQUALS.shadow">
      <attr name="originalFile" stringvalue="Actions/View/FooViewer/com-tomwheeler-example-fooviewer-FooAction.instance"/>
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo