DIAdemヘルプ

Method: Add for MenuPoints

  • 更新日2024-09-12
  • 6分で読める

Method: Add for MenuPoints

Adds a new item to the context menu or the submenu.

Set oMenuPoint = Object.Add(Name, ID)
ObjectMenuPoints
Object with this method
NameString
Specifies the text of the new item in the context menu.
IDLongInteger
Specifies the ID of the new item in the context menu. The ID must between 0 and 22000 and have a unique value. If you assign the value 0 to ID and an empty string to Name, DIAdem creates a hyphen in the context menu.
oMenuPointMenuPoint
Returned object

Note  To test the following example script, you must first save the script and register the script as a user command in the dialog box that opens when you select Settings»Extensions»User Commands.

The following example deletes all entries from the context menu in DIAdem NAVIGATOR and DIAdem VIEW and then adds two new entries to the context menu. In DIAdem NAVIGATOR the second context menu entry contains a submenu. If you click a context menu item, a message displays:

Call AddUserCommandToEvent("Navigator.Events.OnShowingContextMenu", "MyNavigatorOnShowingContextMenu")
Call AddUserCommandToEvent("Navigator.Events.OnContextMenuPointSelected","MyNavigatorOnContextMenuPointSelected")

Sub MyNavigatorOnShowingContextMenu(ParentObj, MenuPoints)
  Dim oMyMenuPoint
  Call MenuPoints.RemoveAll
  Call MenuPoints.Add("MyMenuPoint1", 1)
  Call MenuPoints.Add("", 0)  ' Separator
  Set oMyMenuPoint = MenuPoints.Add("Main", 2) 'Main entry
  Call oMyMenuPoint.MenuPoints.Add("SubMenupoint21", 21) 'Sub entry
  Call oMyMenuPoint.MenuPoints.Add("SubMenupoint22", 22) 'Sub entry
End Sub

Sub MyNavigatorOnContextMenuPointSelected(ParentObj, MenuPoint)
  Select Case MenuPoint.ID
    Case 1    Call MsgBox("DIAdem-NAVIGATOR: MyMenuPoint1 selected")
    Case 2    Call MsgBox("DIAdem-NAVIGATOR: MyMenuPoint2 selected")
    Case 21   Call MsgBox("DIAdem-NAVIGATOR: MyMenuPoint21 selected")
    Case 22   Call MsgBox("DIAdem-NAVIGATOR: MyMenuPoint22 selected")
  End Select
End Sub

'--- For DIAdem-VIEW ------------------------------------------
Call AddUserCommandToEvent("View.Events.OnShowingContextMenu", "MyViewOnShowingContextMenu")
Call AddUserCommandToEvent("View.Events.OnContextMenuPointSelected","MyViewOnContextMenuPointSelected")

Sub MyViewOnShowingContextMenu(Area, MenuPoints)
  Call MenuPoints.RemoveAll
  Call MenuPoints.Add("MyMenuPoint1", 1)
  Call MenuPoints.Add("MyMenuPoint2", 2)
End Sub

Sub MyViewOnContextMenuPointSelected(Area, MenuPoint)
  Select Case MenuPoint.ID
    Case 1    Call MsgBox("DIAdem-VIEW: MyMenuPoint1 selected")
    Case 2    Call MsgBox("DIAdem-VIEW: MyMenuPoint2 selected")
  End Select
End Sub