DeployCenter
This commit is contained in:
commit
7c724d475e
14 files changed
+2460
No files matched your search
@@ -0,0 +1,62 @@
|
||||
Set-StrictMode -Version 2.0
|
||||
|
||||
function ConvertFrom-ThemeColor {
|
||||
param([Parameter(Mandatory=$true)][string]$Value)
|
||||
$hex = $Value.Trim().TrimStart('#')
|
||||
if ($hex -notmatch '^[0-9A-Fa-f]{6}$') {
|
||||
throw "Couleur invalide dans un thème : '$Value'. Utiliser #RRGGBB."
|
||||
}
|
||||
return [System.Drawing.Color]::FromArgb(
|
||||
[Convert]::ToInt32($hex.Substring(0,2),16),
|
||||
[Convert]::ToInt32($hex.Substring(2,2),16),
|
||||
[Convert]::ToInt32($hex.Substring(4,2),16)
|
||||
)
|
||||
}
|
||||
|
||||
function Get-DeployCenterThemeNames {
|
||||
param([Parameter(Mandatory=$true)][string]$ThemesRoot)
|
||||
$names = @()
|
||||
foreach ($file in (Get-ChildItem -LiteralPath $ThemesRoot -Filter '*.psd1' -File -ErrorAction SilentlyContinue)) {
|
||||
if ($file.BaseName -match '^[A-Za-z0-9_-]+$') { $names += $file.BaseName }
|
||||
}
|
||||
return @($names | Sort-Object -Unique)
|
||||
}
|
||||
|
||||
function Import-DeployCenterTheme {
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][string]$ThemesRoot,
|
||||
[Parameter(Mandatory=$true)][string]$ThemeName
|
||||
)
|
||||
if ($ThemeName -notmatch '^[A-Za-z0-9_-]+$') { throw "Nom de thème invalide : $ThemeName" }
|
||||
$path = Join-Path $ThemesRoot ($ThemeName + '.psd1')
|
||||
if (-not (Test-Path -LiteralPath $path -PathType Leaf)) { throw "Thème introuvable : $ThemeName" }
|
||||
$data = Import-PowerShellDataFile -LiteralPath $path
|
||||
$required = @('Background','Panel','PanelAlt','Text','Secondary','Accent','Success','Border','Danger')
|
||||
foreach ($key in $required) {
|
||||
if (-not $data.ContainsKey($key)) { throw "Le thème '$ThemeName' ne contient pas la clé '$key'." }
|
||||
}
|
||||
$theme = @{}
|
||||
foreach ($key in $required) { $theme[$key] = ConvertFrom-ThemeColor -Value ([string]$data[$key]) }
|
||||
foreach ($key in @('TableHeader','TableRowEven','TableRowOdd')) {
|
||||
if ($data.ContainsKey($key)) { $theme[$key] = ConvertFrom-ThemeColor -Value ([string]$data[$key]) }
|
||||
else { $theme[$key] = $theme.PanelAlt }
|
||||
}
|
||||
$buttonDefaults = @{
|
||||
Button = @{ Background=$theme.PanelAlt; Foreground=$theme.Text; Border=$theme.Border; HoverBackground=$theme.Panel; PressedBackground=$theme.Border; DisabledBackground=$theme.Panel; DisabledForeground=$theme.Secondary }
|
||||
PrimaryButton = @{ Background=$theme.Accent; Foreground=[System.Drawing.Color]::White; Border=$theme.Accent; HoverBackground=$theme.Accent; PressedBackground=$theme.Accent; DisabledBackground=$theme.PanelAlt; DisabledForeground=$theme.Secondary }
|
||||
DangerButton = @{ Background=$theme.Danger; Foreground=[System.Drawing.Color]::White; Border=$theme.Danger; HoverBackground=$theme.Danger; PressedBackground=$theme.Danger; DisabledBackground=$theme.PanelAlt; DisabledForeground=$theme.Secondary }
|
||||
}
|
||||
foreach ($role in @('Button','PrimaryButton','DangerButton')) {
|
||||
$theme[$role] = @{}
|
||||
$provided = $data[$role]
|
||||
foreach ($property in @('Background','Foreground','Border','HoverBackground','PressedBackground','DisabledBackground','DisabledForeground')) {
|
||||
$raw = $null
|
||||
if ($provided -is [System.Collections.IDictionary] -and $provided.Contains($property)) { $raw = [string]$provided[$property] }
|
||||
if ([string]::IsNullOrWhiteSpace($raw)) { $theme[$role][$property] = $buttonDefaults[$role][$property] }
|
||||
else { $theme[$role][$property] = ConvertFrom-ThemeColor -Value $raw }
|
||||
}
|
||||
}
|
||||
return $theme
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function ConvertFrom-ThemeColor, Get-DeployCenterThemeNames, Import-DeployCenterTheme
|
||||
Reference in new issue
Block a user