mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-05-24 00:07:24 -05:00
Refactor Hotkey Handling (#3299)
* Refactor Hotkey Handling to improve readability and fix a bug * Remove unnecessary $_.Handled Properties
This commit is contained in:
parent
91365d50b5
commit
14943e3c55
@ -271,51 +271,34 @@ $sync.SearchBarClearButton.Add_Click({
|
|||||||
|
|
||||||
# add some shortcuts for people that don't like clicking
|
# add some shortcuts for people that don't like clicking
|
||||||
$commonKeyEvents = {
|
$commonKeyEvents = {
|
||||||
|
# Prevent shortcuts from executing if a process is already running
|
||||||
if ($sync.ProcessRunning -eq $true) {
|
if ($sync.ProcessRunning -eq $true) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_.Key -eq "Escape") {
|
# Handle key presses of single keys
|
||||||
$sync.SearchBar.SelectAll()
|
switch ($_.Key) {
|
||||||
$sync.SearchBar.Text = ""
|
"Escape" { $sync.SearchBar.Text = "" }
|
||||||
$sync.SearchBarClearButton.Visibility = "Collapsed"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
# don't ask, I know what I'm doing, just go...
|
|
||||||
if (($_.Key -eq "Q" -and $_.KeyboardDevice.Modifiers -eq "Ctrl")) {
|
|
||||||
$this.Close()
|
|
||||||
}
|
}
|
||||||
|
# Handle Alt key combinations for navigation
|
||||||
if ($_.KeyboardDevice.Modifiers -eq "Alt") {
|
if ($_.KeyboardDevice.Modifiers -eq "Alt") {
|
||||||
if ($_.SystemKey -eq "I") {
|
$keyEventArgs = $_
|
||||||
Invoke-WPFButton "WPFTab1BT"
|
switch ($_.SystemKey) {
|
||||||
}
|
"I" { Invoke-WPFButton "WPFTab1BT"; $keyEventArgs.Handled = $true } # Navigate to Install tab and suppress Windows Warning Sound
|
||||||
if ($_.SystemKey -eq "T") {
|
"T" { Invoke-WPFButton "WPFTab2BT"; $keyEventArgs.Handled = $true } # Navigate to Tweaks tab
|
||||||
Invoke-WPFButton "WPFTab2BT"
|
"C" { Invoke-WPFButton "WPFTab3BT"; $keyEventArgs.Handled = $true } # Navigate to Config tab
|
||||||
}
|
"U" { Invoke-WPFButton "WPFTab4BT"; $keyEventArgs.Handled = $true } # Navigate to Updates tab
|
||||||
if ($_.SystemKey -eq "C") {
|
"M" { Invoke-WPFButton "WPFTab5BT"; $keyEventArgs.Handled = $true } # Navigate to MicroWin tab
|
||||||
Invoke-WPFButton "WPFTab3BT"
|
|
||||||
}
|
|
||||||
if ($_.SystemKey -eq "U") {
|
|
||||||
Invoke-WPFButton "WPFTab4BT"
|
|
||||||
}
|
|
||||||
if ($_.SystemKey -eq "M") {
|
|
||||||
Invoke-WPFButton "WPFTab5BT"
|
|
||||||
}
|
|
||||||
if ($_.SystemKey -eq "P") {
|
|
||||||
Write-Host "Your Windows Product Key: $((Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey)"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# shortcut for the filter box
|
# Handle Ctrl key combinations for specific actions
|
||||||
if ($_.Key -eq "F" -and $_.KeyboardDevice.Modifiers -eq "Ctrl") {
|
if ($_.KeyboardDevice.Modifiers -eq "Ctrl") {
|
||||||
if ($sync.SearchBar.Text -eq "Ctrl-F to filter") {
|
switch ($_.Key) {
|
||||||
$sync.SearchBar.SelectAll()
|
"F" { $sync.SearchBar.Focus() } # Focus on the search bar
|
||||||
$sync.SearchBar.Text = ""
|
"Q" { $this.Close() } # Close the application
|
||||||
}
|
}
|
||||||
$sync.SearchBar.Focus()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sync["Form"].Add_PreViewKeyDown($commonKeyEvents)
|
$sync["Form"].Add_PreViewKeyDown($commonKeyEvents)
|
||||||
|
|
||||||
$sync["Form"].Add_MouseLeftButtonDown({
|
$sync["Form"].Add_MouseLeftButtonDown({
|
||||||
@ -483,44 +466,36 @@ $sync["Form"].Add_Activated({
|
|||||||
$sync["ThemeButton"].Add_Click({
|
$sync["ThemeButton"].Add_Click({
|
||||||
Write-Debug "ThemeButton clicked"
|
Write-Debug "ThemeButton clicked"
|
||||||
Invoke-WPFPopup -PopupActionTable @{ "Settings" = "Hide"; "Theme" = "Toggle" }
|
Invoke-WPFPopup -PopupActionTable @{ "Settings" = "Hide"; "Theme" = "Toggle" }
|
||||||
$_.Handled = $false
|
|
||||||
})
|
})
|
||||||
$sync["AutoThemeMenuItem"].Add_Click({
|
$sync["AutoThemeMenuItem"].Add_Click({
|
||||||
Write-Debug "About clicked"
|
Write-Debug "About clicked"
|
||||||
Invoke-WPFPopup -Action "Hide" -Popups @("Theme")
|
Invoke-WPFPopup -Action "Hide" -Popups @("Theme")
|
||||||
Invoke-WinutilThemeChange -theme "Auto"
|
Invoke-WinutilThemeChange -theme "Auto"
|
||||||
$_.Handled = $false
|
|
||||||
})
|
})
|
||||||
$sync["DarkThemeMenuItem"].Add_Click({
|
$sync["DarkThemeMenuItem"].Add_Click({
|
||||||
Write-Debug "Dark Theme clicked"
|
Write-Debug "Dark Theme clicked"
|
||||||
Invoke-WPFPopup -Action "Hide" -Popups @("Theme")
|
Invoke-WPFPopup -Action "Hide" -Popups @("Theme")
|
||||||
Invoke-WinutilThemeChange -theme "Dark"
|
Invoke-WinutilThemeChange -theme "Dark"
|
||||||
$_.Handled = $false
|
|
||||||
})
|
})
|
||||||
$sync["LightThemeMenuItem"].Add_Click({
|
$sync["LightThemeMenuItem"].Add_Click({
|
||||||
Write-Debug "Light Theme clicked"
|
Write-Debug "Light Theme clicked"
|
||||||
Invoke-WPFPopup -Action "Hide" -Popups @("Theme")
|
Invoke-WPFPopup -Action "Hide" -Popups @("Theme")
|
||||||
Invoke-WinutilThemeChange -theme "Light"
|
Invoke-WinutilThemeChange -theme "Light"
|
||||||
$_.Handled = $false
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
$sync["SettingsButton"].Add_Click({
|
$sync["SettingsButton"].Add_Click({
|
||||||
Write-Debug "SettingsButton clicked"
|
Write-Debug "SettingsButton clicked"
|
||||||
Invoke-WPFPopup -PopupActionTable @{ "Settings" = "Toggle"; "Theme" = "Hide" }
|
Invoke-WPFPopup -PopupActionTable @{ "Settings" = "Toggle"; "Theme" = "Hide" }
|
||||||
$_.Handled = $false
|
|
||||||
})
|
})
|
||||||
$sync["ImportMenuItem"].Add_Click({
|
$sync["ImportMenuItem"].Add_Click({
|
||||||
Write-Debug "Import clicked"
|
Write-Debug "Import clicked"
|
||||||
Invoke-WPFPopup -Action "Hide" -Popups @("Settings")
|
Invoke-WPFPopup -Action "Hide" -Popups @("Settings")
|
||||||
Invoke-WPFImpex -type "import"
|
Invoke-WPFImpex -type "import"
|
||||||
$_.Handled = $false
|
|
||||||
})
|
})
|
||||||
$sync["ExportMenuItem"].Add_Click({
|
$sync["ExportMenuItem"].Add_Click({
|
||||||
Write-Debug "Export clicked"
|
Write-Debug "Export clicked"
|
||||||
Invoke-WPFPopup -Action "Hide" -Popups @("Settings")
|
Invoke-WPFPopup -Action "Hide" -Popups @("Settings")
|
||||||
Invoke-WPFImpex -type "export"
|
Invoke-WPFImpex -type "export"
|
||||||
$_.Handled = $false
|
|
||||||
})
|
})
|
||||||
$sync["AboutMenuItem"].Add_Click({
|
$sync["AboutMenuItem"].Add_Click({
|
||||||
Write-Debug "About clicked"
|
Write-Debug "About clicked"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user