Tips_gui   >   Menus   >   Menus Notation

Menus Notation

This section covers examples of notation for various methods dealing with menus.

Install Menu

You can use $open or $openonce to install a menu in the application menu bar.

; Open an instance of the menu class in the application menus.
Do $libs.LibName.$menus.MenuName.$open() Returns rMenu

; Open once an instance of the menu class in the application menus.
Do $libs.LibName.$menus.MenuName.$openonce() Returns rMenu

; Add a window menu to a window instance.
Do rWin.$hasmenus.$assign(kTrue)
Do rWin.$menus.$add($lib.LibName.$menus.MenuName) Returns rMenu

Set Menu Title

Use the $title property to set the menu title.

Do rMenu.$title.$assign('NewTitle') Returns rMenu

Disable/Enable Menu

Use the $enabled property to enable/disable a menu.

; Enable a menu.
Do rMenu.$enabled.$assign(kTrue)

; Disable a menu.
Do rMenu.$enabled.$assign(kFalse)

Remove Menu

You can use $close to remove a menu from the application menu bar or a window menu bar.

; Close the referenced menu instance.
Do rMenu.$close()

Add Menu Item

A menu line is considered an object of the menu instance.

; Add a menu line object.
; $add(cText[,bEnable=kFalse,bCheck=kFalse])
Do rMenu.$objs.$add(Text,kTrue) Returns rLine

Disable/Enable Menu Item

Use the $enabled property to enable/disable a menu line.

; Disable the referenced menu line.
Do rLine.$enabled.$assign(kFalse)

; Enable the referenced menu line.
Do rLine.$enabled.$assign(kTrue)

Remove Menu Item

To remove a menu using notation you need a reference to the menu instance, and you need a reference to the menu item. You can then use the $remove method to remove the menu item.

Set a reference to the menu by using $findname in the menu instances group.
Do $imenus.$findname('MENUNAME') Returns rMenu

Set a reference to the menu item by using $findname in the menu items group.
Do rMenu.$objs.$findname('MENUITEMNAME') Returns rMenuItem

Remove the menu item from the menu
Do rMenu.$objs.$remove(rMenuItem)

Shortcut Keys

To assign a shortcut key combination to a menu using notation you must use the k constant equivalents for the special keys applicable to the platform.

The key equivalents can be found in the F9 Catalog > Constants Tab > Key Modifiers

; Set the menu line shortcut to the function key F5.
Do rLine.$macshortcutkey.$assign(5)
Do rLine.$winshortcutkey.$assign(5)
Do rLine.$unixshortcutkey.$assign(5)

; Set the referenced menu line to the shortcut key combination Ctrl/Cmnd+Shift+P
Do rLine.$macshortcutkey.$assign(kCommand+kShift+asc('P',1))
Do rLine.$winshortcutkey.$assign(kControl+kShift+asc('P',1))
Do rLine.$unixshortcutkey.$assign(kControl+kShift+asc('P',1))

The constants kControl and kCommand are the same value.
The constants kAlt and kOption are the same value.

On the Mac platform the Option key can be used as an additonal modifier key, but not on its own.
On the Win platform the Alt key can be used on its own, but not as an additional modifier.

Cmnd+Opt+K - can be used on the Mac plaform.
Ctrl+Alt+K - can not be used on the Win platform.

Alt+K can be used on the Win platform.
Opt+K can not be used on the Mac platform.

For cross-platform compatabilty use the modifier keys kControl or kControl+kShift. That way you can use the same value for all 3 platforms.

; Set the referenced menu line to the shortcut key combination Ctrl/Cmnd+K
Calculate ShortCutKey as kControl+asc('K',1)
Do rLine.$macshortcutkey.$assign(ShortCutKey)
Do rLine.$winshortcutkey.$assign(ShortCutKey)
Do rLine.$unixshortcutkey.$assign(ShortCutKey)

; Set the referenced menu line to the shortcut key combination Ctrl/Cmnd+Shift+K
Calculate ShortCutKey as kControl+kShift+asc('K',1)
Do rLine.$macshortcutkey.$assign(ShortCutKey)
Do rLine.$winshortcutkey.$assign(ShortCutKey)
Do rLine.$unixshortcutkey.$assign(ShortCutKey)