:+: and all that (was Re: Do we need a mouse trap?)

Peter Achten peter88@cs.kun.nl
Mon, 08 Mar 1999 11:05:26 +0100


Dear Ana,

At 02:38 PM 3/5/99 -0300, you wrote:
>We thought about re-writing OpenMenu` in a way that it accepts IODEVICE.
>Is that what you mean?
No, this is not what I mean. I meant something like the following:

// Your type definition of IODEVICE, now with two additional arguments:
::  IODEVICE ls ps
    =   MENU String [String]
    |   MENUMENU String [(String, [String])]
    |   SUBMENUS [(String, [String])]
    |   DEVICEdescriptionERROR String
    |   ITEM String
    |   ITEMS [String]
    |   DUMB
    |   Fail

// Trying to open the MENU alternative:
instance Menus IODEVICE where
    openMenu :: .ls !(IODEVICE .ls (PSt .l .p)) !(PSt .l .p)
                                -> (!ErrorReport,!PSt .l .p)
    openMenu ls (MENU name items) ps
        = openMenu ls 
             (Menu name (ListLS [MenuItem item [] \\ item<-items]) []) ps
    openMenu _ _ ps
        = abort "openMenu applied to inappropriate IODEVICE"
    
    getMenuType :: (IODEVICE .ls .ps) -> MenuType
    getMenuType (MENU _ _) = "MENU"
    getMenuType _          = "not MENU"


>I wonder if you could give me some detailed explanation about
>constructing menu at run-time (which functions I should use, where can I
>find them...). 
You can find all the functions in the module StdMenu.dcl. What you need are:

* Creating menus:
  - the Menus member function openMenu

* Closing menus:
  - the function closeMenu

* If a menu already exists, and it has a valid Id attribute you can add arbitrary menu elements provided they belong to the MenuElements class. This is done with the functions:
  - openMenuElements
  - openSubMenuElements
  - openRadioMenuItems

* Closing menu elements can also be done in several ways. You must always have the Id of the parent Menu. If you have the Id of the menu elements that you want to close, you can use
  - closeMenuElements

  If you know their index position, you can use:
  - closeMenuIndexElements
  - closeSubMenuIndexElements
  - closeRadioMenuIndexElements

* As you can see from these definitions, menus can be modified only if you have given them an Id attribute. Ids are generated by the Ids type constructor class member functions (module StdId.dcl):

class Ids env where
    openId  ::      !*env -> (!Id,  !*env)
    openIds :: !Int !*env -> (![Id],!*env)
instance Ids World
instance Ids (IOSt .l .p)


Greetings, Peter