27.4 Keystroke Accelerators

Each command table may have a mapping from keystroke accelerator gesture names to command menu items. When a user types a key on the keyboard that corresponds to the gesture for keystroke accelerator, the corresponding command menu item will be invoked. Note that command menu items are shared among the command table's menu and the accelerator table. There are several reasons for this. One is that it is common to have menus display the keystroke associated with a particular item, if there is one. [annotate]

Note that, despite the fact the keystroke accelerators are specified using keyboard gesture names rather than characters, the conventions for typed characters vary widely from one platform to another. Therefore the programmer must be careful in choosing keystroke accelerators. Some sort of per-platform conditionalization is to be expected. [annotate]

add-keystroke-to-command-table  command-table gesture type value &key documentation (errorp t) [Function]
          

Adds a command menu item to command-table's keystroke accelerator table. gesture is a keyboard gesture name to be used as the accelerator. type and value are as in add-menu-item-to-command-table, except that type must be either :command, :function or :menu. command-table is a command table designator. [annotate]

Minor issue: Should we allow gesture to be a gesture specification as well as just a gesture name? It simplifies its use by avoiding a profusion of defined gesture names, but we may want to encourage the use of gesture names. --- SWM [annotate]

documentation is a documentation string, which can be used as documentation for the keystroke accelerator. [annotate]

If the command menu item associated with gesture is already present in the command table's accelerator table and errorp is true, then the command-already-present error will be signalled. When the item is already present in the command table's accelerator table and errorp is false, the old item will first be removed. [annotate]

[annotate]

remove-keystroke-from-command-table  command-table gesture &key (errorp t) [Function]
          

Removes the command menu item named by keyboard gesture name gesture from command-table's accelerator table. command-table is a command table designator. [annotate]

If the command menu item associated with gesture is not present in the command table's menu and errorp is true, then the command-not-present error will be signalled. [annotate]

[annotate]

map-over-command-table-keystrokes  function command-table [Function]
          

Applies function to all of the keystroke accelerators in command-table's accelerator table. function must be a function of three arguments, the menu name (which will be nil if there is none), the keystroke accelerator, and the command menu item; it has dynamic extent. command-table is a command table designator. [annotate]

map-over-command-table-keystrokes does not descend into sub-menus. If the programmer requires this behavior, he should examine the type of the command menu item to see if it is :menu. [annotate]

[annotate]

find-keystroke-item  gesture command-table &key test (errorp t) [Function]
          

Given a keyboard gesture gesture and a command table, returns two values, the command menu item associated with the gesture and the command table in which it was found. (Since keystroke accelerators are not inherited, the second returned value will always be command-table.) [annotate]

This function returns objects that reveal CLIM's internal state; do not modify those objects. [annotate]

test is the test used to compare the supplied gesture to the gesture name in the command table. The supplied gesture will generally be an event object, so the default for test is event-matches-gesture-name-p. [annotate]

If the keystroke accelerator is not present in command-table and errorp is true, then the command-not-present error will be signalled. command-table is a command table designator. [annotate]

[annotate]

lookup-keystroke-item  gesture command-table &key test [Function]
          

Given a keyboard gesture gesture and a command table, returns two values, the command menu item associated with the gesture and the command table in which it was found. Note that gesture may be either a keyboard gesture name of a gesture object, and is handled in the same way as in find-keystroke-item. This function returns objects that reveal CLIM's internal state; do not modify those objects. [annotate]

Unlike find-keystroke-item, this follows the sub-menu chains that can be created with add-menu-item-to-command-table. If the keystroke accelerator cannot be found in the command table or any of the command tables from which it inherits, lookup-keystroke-item will return nil. command-table is a command table designator. [annotate]

Note: This part of the specification is silly: are we talking about inheritance or about menu items? Sub-chains are specified with :menu option while inheritance with :inherit-from. [edit]-- DK 2020-10-15 15:00Z
 

test is the test used to compare the supplied gesture to the gesture name in the command table. The supplied gesture will generally be an event object, so the default for test is event-matches-gesture-name-p. [annotate]

[annotate]

lookup-keystroke-command-item  gesture command-table &key test numeric-arg [Function]
          

Given a keyboard gesture gesture and a command table, returns the command associated with the keystroke, or gesture if no command is found. Note that gesture may be either a keyboard gesture name of a gesture object, and is handled in the same way as in find-keystroke-item. This function returns objects that reveal CLIM's internal state; do not modify those objects. [annotate]

This is like find-keystroke-item, except that only keystrokes that map to an enabled application command will be matched. command-table is a command table designator. [annotate]

test is the test used to compare the supplied gesture to the gesture name in the command table. The supplied gesture will generally be an event object, so the default for test is event-matches-gesture-name-p. [annotate]

numeric-arg (which defaults to 1) is substituted into the resulting command for any occurrence of *numeric-argument-marker* in the command. This is intended to allow programmers to define keystroke accelerators that take simple numeric arguments, which will be passed on by the input editor. [annotate]

Minor issue: Do the above three functions need to have their hands on the port? If event-matches-gesture-name-p needs the port, then the answer is yes. Otherwise, if gesture names are "global" across all ports, then these don't need the port. --- SWM [annotate]

[annotate]

substitute-numeric-argument-marker  command numeric-arg [Function]
          

Given a command object command, this substitutes the value of numeric-arg for all occurrences of the value of *numeric-argument-marker* in the command, and returns a command object with those substitutions. [annotate]

[annotate]