public/Add/Add-ISEThemeMenu.ps1

function Add-ISEThemeMenu {
    <#
    .SYNOPSIS
        Adds a color theme management menu to the PowerShell ISE Add-Ons menu.
 
    .DESCRIPTION
        The Add-ISEThemeMenu function creates a nested menu structure within the PowerShell ISE's Add-Ons menu.
        It includes options for adjusting theme appearance (e.g., darker, lighter), importing/exporting themes,
        selecting from installed themes, and resetting to defaults.
 
        Optional keyboard shortcuts can be added for quick access to each item.
 
    .PARAMETER AddShortcuts
        If specified, adds keyboard shortcuts to the menu items to enable faster theme management via hotkeys.
 
    .EXAMPLE
        Add-ISEThemeMenu
 
        Creates the ISE Color Themes menu with default options and no keyboard shortcuts.
 
    .EXAMPLE
        Add-ISEThemeMenu -AddShortcuts
 
        Creates the ISE Color Themes menu and adds keyboard shortcuts to each menu item for quicker access.
 
    .NOTES
        Author: Jeff Pollock
        Module: ISEColorTheme.Cmdlets
        Repository: https://pxlabs.info
        PowerShell Gallery: https://www.powershellgallery.com/packages/ISEColorTheme.Cmdlets
 
    .LINK
        Get-ImportedISETheme
        Set-ISETheme
        Set-ISEColor
        Reset-ISETheme
        Import-ISEThemeFile
        Export-ISEThemeFile
    #>


    [CmdletBinding()]
    param (
        [Parameter()]
        [switch]$AddShortcuts
    )

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

        # Import/export menu
        $ImportExportMenu = $parentMenu.SubMenus.Add('Import/Export', $null, $null)
        $importExportfunctions = @()

        $importExportHash = @{
            'Import Theme File'       = 'Import-ISEThemeFile'
            'Import Theme Directory'  = 'Import-GroupISETheme'
            'Export Current Theme'    = 'Export-ISEThemeFile'
            'Export All Themes'       = 'Export-GroupISETheme'
        }

        $importExportHash.GetEnumerator() | ForEach-Object {
            $importExportfunctions += [PSCustomObject]@{
                FunctionName = $_.Key
                Scriptblock  = $_.Value
                ShortcutKey  = $null # No shortcut key for import/export functions
            }
        }

        foreach ($fn in $importExportfunctions) {
            $sb = [scriptblock]::Create($fn.Scriptblock)
            try {
                $ImportExportMenu.Submenus.Add($fn.FunctionName, $sb, $fn.ShortcutKey) | out-null
            } catch {
                # Silently continue on error
            }
        }

        # Add adjustments menu
        $AdjustmentMenu = $parentMenu.SubMenus.Add('Adjustments', $null, $null)
        $functions = @()

        $options = 'darker','lighter','warmer','cooler','greener'
        for ($i = 0; $i -lt $options.Count; $i++) {
            $shortcut = if ($AddShortcuts) { "ALT+SHIFT+$i" } else { $null }

            $functions += [PSCustomObject]@{
                FunctionName = "Set $($options[$i])"
                Scriptblock  = "Set-ISEColor -$($options[$i])"
                ShortcutKey  = $shortcut
            }
        }

        $shortcut = if ($AddShortcuts) { "CTRL+ALT+SHIFT+R" } else { $null }        
        $functions += [PSCustomObject]@{
            FunctionName = 'Reset Theme'
            Scriptblock  = 'Reset-ISETheme'
            ShortcutKey  = $shortcut
        }

        foreach ($fn in $functions) {
            $sb = [scriptblock]::Create($fn.Scriptblock)
            try {
                $AdjustmentMenu.Submenus.Add($fn.FunctionName, $sb, $fn.ShortcutKey) | out-null
            } catch {
                # Silently continue on error
            }
        }

        # Add Theme Selector
        $shortcut = if ($AddShortcuts) { "CTRL+ALT+SHIFT+T" } else { $null }
        $ThemeSelector = [PSCustomObject]@{
                FunctionName = 'Theme Selector'
                Scriptblock  = 'Select-ISETheme'
                ShortcutKey  = $shortcut
            }        

        $ThemeSelectorScriptBlock = [scriptblock]::Create($ThemeSelector.Scriptblock)
        Try {
            $parentMenu.Submenus.Add($ThemeSelector.FunctionName, $ThemeSelectorScriptBlock, $ThemeSelector.ShortcutKey) | Out-Null
        } catch {
            # If the menu already exists, we can ignore the error
            Write-Verbose "Theme Selector menu already exists."
        }

        #Add themes from the registry
        $themes = @()
        
        # Ensure registry path exists
        $regPath = 'HKey_Current_User\Software\Microsoft\PowerShell\3\Hosts\PowerShellISE\ColorThemes'
        if (-not (Test-Path registry::"$regPath")) {
            New-Item -Path registry::"$regPath" -Force | Out-Null
        }

        # import themes from the registry
        $importedThemes = Get-ImportedISETheme | Sort-Object -Property ThemeName
        foreach ($theme in $importedThemes) {
            $themes += [PSCustomObject]@{
                FunctionName = $theme.ThemeName
                Scriptblock  = "Set-ISETheme -ThemeName '$($theme.ThemeName)'"
            }
        }

        foreach ($theme in $themes) {
            $sb = [scriptblock]::Create($theme.Scriptblock)
            $parentMenu.Submenus.Add($theme.FunctionName, $sb, $null) | Out-Null
        }

        Write-Verbose "ISE Color Theme menu added with $($functions.Count + $themes.Count) entries."
    }
}