11.2 Defining Commands the Easy Way

11.2.2 The Command-Defining Macro

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 iscom-save-file. The com-save-filecommand will appear in the application's command menu asSave File. (The command-menu name is derived from the command name in the same way as the command-line name.) The single keystrokeCONTROL-s is also defined to invoke the command.

(define-editor-command 
  (com-save-file :menu t                                 
                 :keystroke #\c-\s) () ...) 
Here, a command line name ofSave File is associated with the com-save-filecommand. The user can then typeSave 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. (See Chapter 8, "Presentation Translators in CLIM," for details.)

define-presentation-to-command-translator [Macro]

Arguments:
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's Guide - OCT 1998

Generated with Harlequin WebMaker