PoshCode Archive  Artifact [3753be8cd2]

Artifact 3753be8cd2f3ebeede85da7544bff25817bcf0a046963336d35abc18c48921ee:

  • File Get-UIChildItem.ps1 — part of check-in [bf31e8c790] at 2018-06-10 13:14:06 on branch trunk — Very simple script that will create file list from -Path in simple UI generated using Show-UI. ToolTip show size and last write time of a file, and once clicked – it will pass fullname down the pipe. It was created mainly as a attempt to use some animated effects in Show-UI. (user: BartekB size: 2898)

# encoding: ascii
# api: powershell
# title: Get-UIChildItem
# description: Very simple script that will create file list from -Path in simple UI generated using Show-UI. ToolTip show size and last write time of a file, and once clicked – it will pass fullname down the pipe. It was created mainly as a attempt to use some animated effects in Show-UI.
# version: 0.5
# type: module
# author: BartekB
# license: CC0
# x-poshcode-id: 2673
# x-archived: 2017-05-16T03:35:02
# x-published: 2011-05-12T15:14:00
#
#
#requires -version 2.0

[CmdletBinding()]
param($Path)

<#
    Quick check to see if we have necessary module...
#>

if (!(Get-Module ShowUI)) {
    try {
        Import-Module ShowUI
    } catch {
        Write-Warning "Can't load ShowUI module. I quit! For more details about error use -Verbose parameter."
        Write-Verbose $_
    }
}   

<#
    Show UI builds UI structure...
#>

Show-UI  -Parameters $Path {
    param ($Path)
    DockPanel -Height 400 {
        ScrollViewer {
            ItemsControl {
                <#
                    Hash that will set common button's options and some effects...
                #>
            
                $Effect = @{
                    Effect = {
                        New-Object Windows.Media.Effects.BlurEffect -Property @{
                            Radius = 3
                        }
                    }
                    On_MouseEnter = {
                        $Clear = DoubleAnimation -From 3 -To 1 -Duration '0:0:0.5'
                        $DependencyRadius = $This.Effect.GetType()::RadiusProperty
                        $This.Effect.BeginAnimation($DependencyRadius,$Clear)
                    }
                    On_MouseLeave = {
                        $Blur = DoubleAnimation -From 1 -To 3 -Duration '0:0:0.5'
                        $DependencyRadius = $This.Effect.GetType()::RadiusProperty
                        $This.Effect.BeginAnimation($DependencyRadius,$Blur)
                    }
                }
                
                <#
                    Time to read our folder. We ignore folders, only files will be listed.
                    As you can see it's pretty easy to pass $Path parameter to UI, and it's not global... :)
                #>
                
                foreach ($File in Get-ChildItem $Path | where { !$_.PSIsContainer } ) {
                    Button @Effect -Content $File.Name -On_Click ([scriptblock]::Create(@"
                        Write-UIOutput $($File.FullName)
                        `$ShowUI.ActiveWindow.Close()
"@)) -ToolTip "File size: $($File.Length) bytes, Last modified: $($File.LastWriteTime.ToShortDateString())"
                    
                }
            } # END ItemsControl
        } # END ScrollViewer
    } # END DockPanel
} # END Show-UI