Satimage Previous | Next
Installing a contextual menu
Home Documentation Smile Customizing Smile Installing a contextual menu  
  • You can install a custom contextual menu in text windows, in dialogs, in graphic windows and in graphic views.
  • Since installing a contextual menu consists in customizing the object's script, the contextual menu is saved if the script is saved with the window. Such is the case for text windows and dialogs. Such is also the case for graphic windows - and for the graphic views that they may contain - provided you select the Bundle format in the Save dialog.
  • Installing a contextual menu consists in installing two handlers in the script of the object: CustomMenuItems, which is called when the user performs a ctrl-click (or right-click) on the window or the object, and do menu, which is called when the user selects an item in a contextual menu.
    • CustomMenuItems(the_object) must return the items to display in the contextual menu, as a list of strings. CustomMenuItems(the_object) receives a reference to the object where the click occurred.

      In the list of strings that CustomMenuItems(the_object) returns, try not to include a string of four characters, as a collision with Smile's own built-in menu commands might result.
    • install a do menu handler to handle the commands. When the user selects an item in the contextual menu, the object's script receives do menu the_cmd to the_object where the_cmd is the command (the selected menu item, as a string) and the_object is a reference to the object where the click occurred.
  • To refer to the default behavior, use the continue keyword. For instance the example below installs a custom list in addition to the built-in contextual menu.
    on CustomMenuItems(the_object)
        set the_list to {"New run", "Stop run", "-"}
        set the_builtin to continue CustomMenuItems(the_object)
        return the_list & the_builtin
    end CustomMenuItems
  • A contextual menu can display sub-menus. To that effect, the list returned by CustomMenuItems may include - in addition to strings - records in the form {name:theSubMenuName, menu:theSubMenuList}.
    on CustomMenuItems(the_object)
        set the_list to {"a", {name:"b", menu:{"1", "2", "3", {name:"4", menu:{"x", "y", "z"}}}}, "c", "-"}
        set the_builtin to continue CustomMenuItems(the_object)
        return the_list & the_builtin
    end CustomMenuItems
  • It is important to call the built-in behavior in the do menu handler since otherwise it may become impossible to save or close a window by the usual means.
    For instance a do menu handler installed in a graphic window should forward the do menu event like in the example below.
    on do menu the_cmd to theView
        if the_cmd is "New run" then
            -- perform new run
        else if the_cmd is "Stop run" then
            -- stop current run
        else
            continue do menu the_cmd to theView
        end if
    end do menu
  • The contextual menu recognizes the conventional metacharacters for menus, which can be anywhere in the string.
    ( (opening parenthesis)
    grays out the menu item
    <B <I <U
    displays the menu item in bold, italic or underlined, respectively
    - (hyphen) alone
    displays a menu separation line
Version française
Copyright ©2008 Paris, Satimage