Generic FunctionPackage: cgToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
Unrevised from 10.0 to 10.1.
10.0 version

shortcut-commands

Arguments: window menu

Returns a list of menu-items to be shown in a pop-up-menu whenever pop-up-shortcut-menu is called on window.

The default mouse-right-down methods for basic-pane and dialog-item call pop-up-shortcut-menu on the window that was clicked. Therefore, a menu of shortcut commands can be implemented for a window or dialog-item subclass simply by writing a shortcut-commands method that specializes on the class. This may be more convenient than the general menu approach of calling open-menu and pop-up-menu. (And this behavior may be overridden by adding a more specific primary mouse-right-down method.)

The default method returns nil, which causes pop-up-shortcut-menu to do nothing.

Generally, the value of each menu-item in the returned list should be a function name, and this function is called with window as the only argument when the user chooses that menu-item. Alternately, the menu-item value may be a window, in which case the window is selected by calling select-window on it. This default behavior may be changed, however, by writing custom shortcut-menu-class methods; see pop-up-shortcut-menu and shortcut-menu-class for details.

window is the window that was passed to pop-up-shortcut-menu, which will be the window that was clicked when called from the default mouse-right-down methods.

menu is the menu to which the returned menu-items will be added. This argument is probably only useful if you customize the on-click behavior by subclassing shortcut-menu and writing shortcut-menu-class methods; you could then specialize on your shortcut-menu subclass here. In the usual case, the argument is ignored (as in the examples below).

Window example:

(defclass my-window (frame-window)())

(defmethod shortcut-commands ((window my-window) menu)
  (declare (ignore menu))
  (list (make-instance 'menu-item
          :title "Beep"
          :value 'beep)
        (make-instance 'menu-item
          :title "Move Down"
          :value #'(lambda (window)
                     (move-window-relative
                      window #.(make-position 0 16))))))

(make-window :foo :class 'my-window
  :width 300 :height 200
  :title "Right-Click Me!")

Widget example

In the example below, the functions that are the values of the returned menu-items will be passed the window of the dialog-item, rather than the dialog-item itself. This requires subclassing both the dialog-item (in the example, a single-item-list) class and the associated widget-window subclass (in the example, a single-item-list-pane), linking them with a widget-device method, and then specializing a shortcut-commands method on the new my-item-list-pane class.

(defclass my-item-list (single-item-list)())

(defclass my-item-list-pane (single-item-list-pane)())

(defmethod widget-device ((dialog-item my-item-list)
                          (dialog dialog))
  'my-item-list-pane)

(defmethod shortcut-commands ((window my-item-list-pane) menu)
  (declare (ignore menu))
  (list (make-instance 'menu-item
           :title "Beep"
           :value 'beep)
        (make-instance 'menu-item
           :title "Change Color"
          :value #'(lambda (window)
                     (setf (background-color
                            (dialog-item window))
                       (make-rgb :red (+ 128 (random 128))
                                 :green (+ 128 (random 128))
                                 :blue (+ 128 (random 128))))))))

(make-window :bar :class 'dialog
  :title "Right-Click the Widget!"
  :width 300 :height 200
  :dialog-items (list (make-instance 'my-item-list
                        :range '(one two three)
                        :left 30 :top 20
                        :value 'one)))

Copyright (c) 1998-2022, Franz Inc. Lafayette, CA., USA. All rights reserved.
This page was not revised from the 10.0 page.
Created 2019.8.20.

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
Unrevised from 10.0 to 10.1.
10.0 version