MenuEntry class

One entry of a Menu, added by the addin with Menu.AddEntry. Held WithEvents, it raises Click when the user chooses it, and BeforeShow, when asked for, each time its menu opens.

Private WithEvents CompareEntry As MenuEntry

Private Sub Host_OnProjectLoaded()
    Set CompareEntry = Host.Menus.ProjectExplorerFileViewContextMenu.AddEntry("Compare")
    CompareEntry.BeforeShowEvents = True
End Sub

Private Sub CompareEntry_BeforeShow()
    ' Show the entry for a file only, not for a folder.
    On Error GoTo NotAFile
    CompareEntry.Visible = (Host.FileSystem.ResolvePath(Host.ProjectExplorer.SelectedItemPath).Type <> Folder)
    Exit Sub
NotAFile:
    CompareEntry.Visible = False
End Sub

Private Sub CompareEntry_Click()
    Host.DebugConsole.PrintText "Compare " & Host.ProjectExplorer.SelectedItemPath
End Sub

Properties

BeforeShowEvents

Whether the entry raises BeforeShow. Boolean; False at first. Set it to True for an entry that changes as its menu opens. Each such entry makes the menu wait for its handler, so leave it False for one that does not change.

Syntax: entry.BeforeShowEvents [ = value ]

Caption

The entry’s text. String.

Syntax: entry.Caption [ = value ]

Checked

Whether the entry shows a tick. Boolean. The tick is drawn in place of the entry’s IconData.

Syntax: entry.Checked [ = value ]

Children

The entry’s submenu, for adding entries to it with AddEntry. As Menu, read-only. Once it holds an entry, the entry becomes a submenu: it opens when the pointer is over it, and it raises no Click.

Enabled

Whether the entry can be chosen. Boolean. A disabled entry is drawn grey.

Syntax: entry.Enabled [ = value ]

IconData

The entry’s icon, as the text of an SVG picture that starts with <svg. Variant.

Syntax: entry.IconData [ = value ]

Id

The entry’s identifier, a GUID in braces. String, read-only.

Parent

The menu the entry is in. As Menu, read-only.

Visible

Whether the entry is shown. Boolean.

Syntax: entry.Visible [ = value ]

Methods

Remove

Removes the entry from its menu.

Syntax: entry.Remove

Events

BeforeShow

Raised each time the entry’s menu opens, before it is drawn, while BeforeShowEvents is True. For an entry of a submenu, it is raised as the submenu opens. What the handler changes, the Caption, Visible, Enabled or Checked of any entry, shows in the menu that is opening. So does an entry it adds.

Syntax: entry_BeforeShow()

Use it to fit the entry to what was right-clicked, with ProjectExplorer.SelectedItemPath, as the example above does.

Click

Raised when the user chooses the entry. The menu closes. An entry that has a submenu raises none.

Syntax: entry_Click()

See Also