The easiest way to define commands is to use define-application-frame, which automatically creates a command table for your application. This behavior is controlled by the :command-table
option. It also defines the command-defining macro you will use to define the commands for your application. This is controlled by the :command-definer
option.
This command-definer macro behaves similarly to define-command, but automatically uses your application's command table, so you need not specify one.
Here is a code fragment illustrating the use of define-application-frame, which defines an application named editor
. A command table named editor-command-table
is defined to mediate the user's interactions with the editor
application. define-application-frame also defines a macro named define-editor-command
, which you will use to define commands for the editor
application and install them in the command table editor-command-table
.
(clim:define-application-frame editor () () (:command-table editor-command-table) (:command-definer define-editor-command) ...)
Note that for this particular example, the :command-table
and :command-definer
options are not specified, since the names that they specify are the ones that would be generated by default. Provide these options only when you want different names than the default ones, you don't want a command definer, or you want to specify which command tables the application's command table inherits from. See the macro define-application-frame, in 9.2 Defining CLIM Application Frames for a description of these options.
Every command has a command name, which is a symbol. The symbol names the function that implements the command. The body of the command is the function definition of that symbol.
By convention, commands are named with a com
- prefix, although CLIM does not enforce this convention.
To avoid collisions among command names, each application should live in its own package; for example, there might be several commands named com-show-chart
defined for each of a spreadsheet, a navigation program, and a medical application.
CLIM supports a command line name which is the "command" that the end user sees and uses, as opposed to the construct that is the command's actual name. For example, the command com-show-chart
would have a command-line name of Show Chart
. When defining a command using define-command (or the application's command defining macro), you can have a command line name generated automatically. As you can see from this example, the automatically generated command line name consists of the command's name with the hyphens replaced by spaces and the words capitalized. Any com
- prefix is removed.
The define-editor-command
macro, automatically generated by the define-application-frame code previously, is used to define a command for the editor
application. It is just like define-command, except that you don't need to specify editor-command-table
as the command table in which to define the command. define-editor-command
will automatically use editor-command-table
.
Through the appropriate use of the options to define-editor-command
(see define-command for details), you can provide the command via any number of the previously mentioned interaction styles. For example, you could install the command in the editor
application's menu, as well as specifying a single keystroke command accelerator character for it.
The following example defines a command whose command name is com-save-file
. The com-save-file
command will appear in the application's command menu as Save File. (The command-menu name is derived from the command name in the same way as the command-line name.) The single keystroke CONTROL-s
is also defined to invoke the command.
(define-editor-command (com-save-file :menu t :keystroke (#\s :control)) () ...)
Here, a command line name of Save File is associated with the com-save-file
command. The user can then type Save File to the application's interaction pane to invoke the command.
(define-editor-command (com-save-file :name "Save File") () ...)
Since the command processor works by establishing an input context of presentation type command and executing the resulting input, any displayed presentation can invoke a command, so long as there is a translator defined that translates from the presentation type of the presentation to the presentation type command. In this way, you can associate a command with a pointer gesture when it is applied to a displayed presentation. (8 Presentation Translators in CLIM for details.)
define-presentation-to-command-translator Macro
define-presentation-to-command-translator name (from-type command-name command-table &key (gesture :select) tester documentation pointer-documentation (menu t) priority (echo t)) arglist &body body
Summary: Defines a presentation translator that translates a displayed presentation into a command.
CLIM 2.0 User Guide - 01 Dec 2021 19:38:58