Public/Add/Add-ISEThemeMenu.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function Add-ISEThemeMenu {
<#
    .Synopsis
     This is a function that adds more tooling to the ISE for switching themes
  .DESCRIPTION
     This is a function that adds more tooling to the ISE for switching themes making it easier to have a change when required
  .EXAMPLE
     Add-ISEThemeMenu
#>


[cmdletbinding()]
Param()


    Process {
        $parentAdded = $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add('ISE Color Themes',$null,$null)       

        $Functions = @()

        $OutputObj  = New-Object -Type PSObject
        $OutputObj | Add-Member -MemberType NoteProperty -Name FunctionName –Value 'Theme Selector'
        $OutputObj | Add-Member -MemberType NoteProperty -Name 'Scriptblock' –Value 'Select-ISETheme' #ShortcutKey "ALT+SHIFT+W"
        $OutputObj | Add-Member -MemberType NoteProperty -Name ShortcutKey –Value 'CTRL+ALT+SHIFT+T'
        $Functions += $OutputObj 

        $Options = 'darker|lighter|warmer|cooler|greener'
        $OptionArray = $Options.Split('|')

        $ShortcutKey = 0

        $optionArray | ForEach-Object {
            $OutputObj  = New-Object -Type PSObject
            $OutputObj | Add-Member -MemberType NoteProperty -Name FunctionName –Value "Set $_"
            $OutputObj | Add-Member -MemberType NoteProperty -Name 'Scriptblock' –Value "Set-ISEColor -$_" #ShortcutKey "ALT+SHIFT+W"
            $OutputObj | Add-Member -MemberType NoteProperty -Name ShortcutKey –Value "ALT+SHIFT+$ShortcutKey"
            $Functions += $OutputObj 

            $ShortcutKey += 1
        }

        $Functions | Foreach-Object {
            $functionname = $_.FunctionName.ToString()
            $sb=$executioncontext.InvokeCommand.NewScriptBlock($_.Scriptblock)
            $parentAdded.Submenus.Add($functionname,$sb,$_.ShortcutKey) | out-null
        }

        If (!(Test-Path 'HKCU:\Software\Microsoft\PowerShell\3\Hosts\PowerShellISE\ColorThemes')) {
            New-Item -Path 'HKCU:\Software\Microsoft\PowerShell\3\Hosts\PowerShellISE' -Name ColorThemes –Force | out-null
        }

        $ThemeMenu = $ParentAdded.SubMenus.Add('Imported Themes',$null,$null)
        $Themes = @()
        $ImportedThemes = Get-ImportedISETheme        

        $ImportedThemes | ForEach-Object {           
            $OutputObj  = New-Object -Type PSObject
            $OutputObj | Add-Member -MemberType NoteProperty -Name 'FunctionName' –Value $_.ThemeName
            $OutputObj | Add-Member -MemberType NoteProperty -Name 'Scriptblock' –Value "Set-ISETheme -ThemeName '$($_.ThemeName)'"
            $Themes += $OutputObj           
        }

        $OutputObj  = New-Object -Type PSObject
        $OutputObj | Add-Member -MemberType NoteProperty -Name 'FunctionName' –Value 'Import CSE Themes'
        $OutputObj | Add-Member -MemberType NoteProperty -Name 'Scriptblock' –Value 'Import-GroupISETheme'
        $Themes += $OutputObj

        $Themes | Foreach-Object {
            $functionname = $_.FunctionName.ToString()
            $sb=$executioncontext.InvokeCommand.NewScriptBlock($_.Scriptblock)
            $ThemeMenu.Submenus.Add($functionname,$sb,$null) | out-null
        }
    }

}