# encoding: ascii
# api: powershell
# title: Show-Sample1
# description: A demonstration of how to do menus and commands in ShowUI (it works against the Latest Changeset ‘d7ad095858eb’ right now, so you can just hit the download link on the right of that page).
# version: 0.1
# type: function
# author: Joel Bennett
# license: CC0
# x-poshcode-id: 2669
# x-archived: 2011-05-16T21:23:11
# x-published: 2011-05-10T20:45:00
#
#
if(!(Get-Command New-System.Windows.Input.CommandBinding -ErrorAction SilentlyContinue)) {
Add-UIFunction -Type System.Windows.Input.CommandBinding
}
Show -Width 300 -Height 150 {
DockPanel {
Menu -DockPanel-Dock Top -Height 20 {
MenuItem -Header "_File" {
## Hook up the "New" menuitem to the New command ...
MenuItem -Header "_New" -Command ([system.windows.input.applicationcommands]::new)
MenuItem -Header "_Open"
MenuItem -Header "_Save"
MenuItem -Header "Save _As"
Separator
MenuItem -Header "_Print"
Separator
MenuItem -Header "E_xit"
}
MenuItem -Header "_Edit" {
MenuItem -Header "_Undo"
Separator
MenuItem -Header "Cu_t"
MenuItem -Header "_Copy"
MenuItem -Header "_Paste"
MenuItem -Header "De_lete"
Separator
MenuItem -Header "_Find"
MenuItem -Header "Find _Next"
MenuItem -Header "_Replace"
MenuItem -Header "_Go To"
Separator
MenuItem -Header "Select _All"
MenuItem -Header "Time/_Date"
}
MenuItem -Header "F_ormat" {
MenuItem -Header "_Word Wrap"
MenuItem -Header "_Font"
}
MenuItem -Header "_View" {
MenuItem -Header "_Status Bar"
}
MenuItem -Header "_Help" {
MenuItem -Header "_About"
}
}
TextBox -Name "Content"
}
## Down here you can hook up command bindings as usual...
$this.CommandBindings.Add( (
CommandBinding -Command ([system.windows.input.applicationcommands]::new) `
-On_CanExecute { param($sender, $e) $e.CanExecute = $true } `
-On_Executed { (Select-UIElement $this Content).Text = ""; }
) ) | Out-Null
}