textfield custom name for shortcut

This commit is contained in:
duffyduck 2026-01-07 16:16:04 +01:00
parent 9abe201389
commit 347ffa1c2e
1 changed files with 90 additions and 30 deletions

View File

@ -127,7 +127,7 @@ function Show-UserSelectionDialog {
$form = New-Object System.Windows.Forms.Form $form = New-Object System.Windows.Forms.Form
$form.Text = "Benutzer ausw$([char]0x00E4)hlen - Freigabe" $form.Text = "Benutzer ausw$([char]0x00E4)hlen - Freigabe"
$form.Size = New-Object System.Drawing.Size(450, 530) $form.Size = New-Object System.Drawing.Size(450, 570)
$form.StartPosition = "CenterScreen" $form.StartPosition = "CenterScreen"
$form.FormBorderStyle = "FixedDialog" $form.FormBorderStyle = "FixedDialog"
$form.MaximizeBox = $false $form.MaximizeBox = $false
@ -165,24 +165,63 @@ function Show-UserSelectionDialog {
} }
}) })
$chkFullPath = New-Object System.Windows.Forms.CheckBox # Gruppierung fuer Verknuepfungsname
$chkFullPath.Text = "Kompletten Pfad in Verkn$([char]0x00FC)pfungsname schreiben" $grpName = New-Object System.Windows.Forms.GroupBox
$chkFullPath.Location = New-Object System.Drawing.Point(10, 385) $grpName.Text = "Verkn$([char]0x00FC)pfungsname"
$chkFullPath.Size = New-Object System.Drawing.Size(410, 25) $grpName.Location = New-Object System.Drawing.Point(10, 380)
$chkFullPath.Font = New-Object System.Drawing.Font("Segoe UI", 9) $grpName.Size = New-Object System.Drawing.Size(410, 105)
$form.Controls.Add($chkFullPath) $grpName.Font = New-Object System.Drawing.Font("Segoe UI", 9)
$form.Controls.Add($grpName)
$lblExample = New-Object System.Windows.Forms.Label # Radio: Standard (Ordnername)
$lblExample.Text = "(z.B. 'Mandanten - S - Schmidt - Lohn' statt nur 'Lohn')" $rbStandard = New-Object System.Windows.Forms.RadioButton
$lblExample.Location = New-Object System.Drawing.Point(27, 408) $rbStandard.Text = "Ordnername (Standard)"
$lblExample.Size = New-Object System.Drawing.Size(400, 20) $rbStandard.Location = New-Object System.Drawing.Point(10, 20)
$lblExample.ForeColor = [System.Drawing.Color]::Gray $rbStandard.Size = New-Object System.Drawing.Size(180, 22)
$lblExample.Font = New-Object System.Drawing.Font("Segoe UI", 8) $rbStandard.Checked = $true
$form.Controls.Add($lblExample) $grpName.Controls.Add($rbStandard)
# Radio: Kompletter Pfad
$rbFullPath = New-Object System.Windows.Forms.RadioButton
$rbFullPath.Text = "Kompletter Pfad"
$rbFullPath.Location = New-Object System.Drawing.Point(200, 20)
$rbFullPath.Size = New-Object System.Drawing.Size(180, 22)
$grpName.Controls.Add($rbFullPath)
# Radio: Eigener Name
$rbCustom = New-Object System.Windows.Forms.RadioButton
$rbCustom.Text = "Eigener Name:"
$rbCustom.Location = New-Object System.Drawing.Point(10, 50)
$rbCustom.Size = New-Object System.Drawing.Size(110, 22)
$grpName.Controls.Add($rbCustom)
# Textfeld fuer eigenen Namen
$txtCustomName = New-Object System.Windows.Forms.TextBox
$txtCustomName.Location = New-Object System.Drawing.Point(125, 50)
$txtCustomName.Size = New-Object System.Drawing.Size(270, 22)
$txtCustomName.Enabled = $false
$grpName.Controls.Add($txtCustomName)
# Hinweistext
$lblHint = New-Object System.Windows.Forms.Label
$lblHint.Text = "Kompletter Pfad: z.B. 'Mandanten - S - Schmidt - Lohn'"
$lblHint.Location = New-Object System.Drawing.Point(10, 78)
$lblHint.Size = New-Object System.Drawing.Size(390, 18)
$lblHint.ForeColor = [System.Drawing.Color]::Gray
$lblHint.Font = New-Object System.Drawing.Font("Segoe UI", 8)
$grpName.Controls.Add($lblHint)
# Event: Textfeld aktivieren wenn "Eigener Name" gewaehlt
$rbCustom.Add_CheckedChanged({
$txtCustomName.Enabled = $rbCustom.Checked
if ($rbCustom.Checked) {
$txtCustomName.Focus()
}
})
$okBtn = New-Object System.Windows.Forms.Button $okBtn = New-Object System.Windows.Forms.Button
$okBtn.Text = "Freigeben" $okBtn.Text = "Freigeben"
$okBtn.Location = New-Object System.Drawing.Point(240, 450) $okBtn.Location = New-Object System.Drawing.Point(240, 495)
$okBtn.Size = New-Object System.Drawing.Size(85, 30) $okBtn.Size = New-Object System.Drawing.Size(85, 30)
$okBtn.Enabled = $false $okBtn.Enabled = $false
$okBtn.DialogResult = [System.Windows.Forms.DialogResult]::OK $okBtn.DialogResult = [System.Windows.Forms.DialogResult]::OK
@ -191,7 +230,7 @@ function Show-UserSelectionDialog {
$cancelBtn = New-Object System.Windows.Forms.Button $cancelBtn = New-Object System.Windows.Forms.Button
$cancelBtn.Text = "Abbrechen" $cancelBtn.Text = "Abbrechen"
$cancelBtn.Location = New-Object System.Drawing.Point(335, 450) $cancelBtn.Location = New-Object System.Drawing.Point(335, 495)
$cancelBtn.Size = New-Object System.Drawing.Size(85, 30) $cancelBtn.Size = New-Object System.Drawing.Size(85, 30)
$cancelBtn.DialogResult = [System.Windows.Forms.DialogResult]::Cancel $cancelBtn.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelBtn $form.CancelButton = $cancelBtn
@ -209,17 +248,25 @@ function Show-UserSelectionDialog {
}) })
$script:selectedUser = $null $script:selectedUser = $null
$script:useFullPath = $false $script:nameMode = "standard"
$script:customName = ""
if ($form.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK -and $listBox.SelectedIndex -ge 0) { if ($form.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK -and $listBox.SelectedIndex -ge 0) {
$selectedText = $listBox.SelectedItem $selectedText = $listBox.SelectedItem
$script:selectedUser = $script:allUsers | Where-Object { $_.FullName -eq $selectedText } | Select-Object -First 1 $script:selectedUser = $script:allUsers | Where-Object { $_.FullName -eq $selectedText } | Select-Object -First 1
$script:useFullPath = $chkFullPath.Checked
if ($rbFullPath.Checked) {
$script:nameMode = "fullpath"
} elseif ($rbCustom.Checked) {
$script:nameMode = "custom"
$script:customName = $txtCustomName.Text.Trim()
}
} }
return @{ return @{
User = $script:selectedUser User = $script:selectedUser
UseFullPath = $script:useFullPath NameMode = $script:nameMode
CustomName = $script:customName
} }
} }
@ -315,7 +362,8 @@ try {
} }
$selectedUser = $dialogResult.User $selectedUser = $dialogResult.User
$useFullPath = $dialogResult.UseFullPath $nameMode = $dialogResult.NameMode
$customName = $dialogResult.CustomName
$userName = $selectedUser.SamAccountName $userName = $selectedUser.SamAccountName
$userFolder = Join-Path $basePath $userName $userFolder = Join-Path $basePath $userName
@ -327,7 +375,8 @@ try {
$uncPath = Get-UNCPath -LocalPath $Path $uncPath = Get-UNCPath -LocalPath $Path
# Verknuepfungsname erstellen # Verknuepfungsname erstellen
if ($useFullPath) { switch ($nameMode) {
"fullpath" {
# Kompletten Pfad verwenden: \\server\Mandanten\S\Schmidt\Lohn -> Mandanten - S - Schmidt - Lohn # Kompletten Pfad verwenden: \\server\Mandanten\S\Schmidt\Lohn -> Mandanten - S - Schmidt - Lohn
$pathForName = $uncPath $pathForName = $uncPath
# UNC-Prefix und Servernamen entfernen # UNC-Prefix und Servernamen entfernen
@ -336,8 +385,19 @@ try {
} }
# Backslashes durch " - " ersetzen # Backslashes durch " - " ersetzen
$itemName = $pathForName -replace '\\', ' - ' $itemName = $pathForName -replace '\\', ' - '
} else { }
"custom" {
# Eigener Name vom Benutzer
if ([string]::IsNullOrWhiteSpace($customName)) {
$itemName = Split-Path -Path $Path -Leaf $itemName = Split-Path -Path $Path -Leaf
} else {
$itemName = $customName
}
}
default {
# Standard: nur Ordnername
$itemName = Split-Path -Path $Path -Leaf
}
} }
# Ungueltige Zeichen fuer Dateinamen entfernen/ersetzen # Ungueltige Zeichen fuer Dateinamen entfernen/ersetzen