当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] ISEmenuItem 对象

作者:精品下载站 日期:2024-12-14 02:59:46 浏览:14 分类:玩电脑

ISEmenuItem 对象


ISEMenuItem 对象是 Microsoft.PowerShell.Host.ISE.ISEMenuItem 类的实例。 Add-ons 菜单上的所有菜单对象都是 Microsoft.PowerShell.Host.ISE.ISEMenuItem 类的实例。

特性

DisplayName

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

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

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

行动

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

获取脚本块的只读属性。当您单击菜单项时,它会调用该操作。

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

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

捷径

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

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

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

子菜单

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

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

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

脚本示例

为了更好地了解附加组件菜单的使用及其可编写脚本的属性,请阅读以下脚本示例。

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

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

参见

  • ISEmenuItemCollection 对象
  • Windows PowerShell ISE 脚本对象模型的用途
  • ISE 对象模型层次结构

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯