ISEMenuItem 对象The ISEMenuItem Object

本文内容

ISEMenuItem 对象是 Microsoft.PowerShell.Host.ISE.ISEMenuItem 类的实例。“加载项”菜单上的所有对象都是 Microsoft.PowerShell.Host.ISE.ISEMenuItem 类的实例。

“属性”Properties

DisplayNameDisplayName

在 Windows PowerShell ISE 2.0 和更高版本中受支持。

只读属性,可获取菜单项的显示名称。

1. # Get the display name of the Add-ons menu item
2. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Clear()
3. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('_Process', {Get-Process}, 'Alt+P')
4. $psISE.CurrentPowerShellTab.AddOnsMenu.DisplayName

操作Action

在 Windows PowerShell ISE 2.0 和更高版本中受支持。

只读属性,可获取脚本块。单击菜单项时,它将调用该操作。

1. # Get the action associated with the first submenu item.
2. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Clear()
3. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('_Process', {Get-Process}, 'Alt+P')
4. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus[0].Action

6. # Invoke the script associated with the first submenu item
7. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus[0].Action.Invoke()

快捷方式Shortcut

在 Windows PowerShell ISE 2.0 和更高版本中受支持。

只读属性,可获取菜单项的 Windows 输入键盘快捷方式。

1. # Get the shortcut for the first submenu item.
2. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Clear()
3. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('_Process', {Get-Process}, 'Alt+P')
4. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus[0].Shortcut

在 Windows PowerShell ISE 2.0 和更高版本中受支持。

只读属性,可获取菜单项的子菜单列表。

1. # List the submenus of the Add-ons menu
2. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Clear()
3. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('_Process', {Get-Process}, 'Alt+P')
4. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus

脚本示例Scripting example

若要更好地了解加载项菜单及其可编写脚本属性的使用,请通读下面的脚本示例。

1. # This is a scripting example that shows the use of the Add-ons menu.
2. # Clear the Add-ons menu if any entries currently exist
3. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Clear()

5. # Add an Add-ons menu item with an shortcut and fast access key.
6. # Note the use of “_”  as opposed to the “&” for mapping to the fast access key letter for the menu item.
7. $menuAdded = $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add('_Process', {Get-Process}, 'Alt+P')
8. # Add a nested menu - a parent and a child submenu item.
9. $parentAdded = $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('Parent', $null, $null)
10. $parentAdded.SubMenus.Add('_Dir', {dir}, 'Alt+D')

另请参阅See Also