Sonntag, 14. Februar 2010

1st improvement to Add-IseMenu

I hope that all users of Powershell V2 did try ISEpack from the PowerShellPack.

In the ISEpack module there is a function Add-IseMenu for creating addon menus.

On of its shortcomings is that it is not tolerant in case when a short-cut is alredy in use.

Just replace
$m = $iseMenu.Submenus.Add($itemName, $scriptBlock, $_.ShortcutKey)            

with
try {            
$m = $iseMenu.Submenus.Add($itemName, $scriptBlock, $_.ShortcutKey)
}
catch
{
Write-Host "Shortcut $($_.ShortcutKey) already in use. Menu item created without shortcut"
$m = $iseMenu.Submenus.Add($itemName, $scriptBlock, $null)
}

and that know-all behaviour is past. Now in case of clashes, it just creates the menu item without the short cut and emits a message.

For the second shortcoming, no control about the order of the items, I have not yet a compatible idea.

Bernd

Keine Kommentare:

Kommentar veröffentlichen