Skip to content

Commit

Permalink
Update itt.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
emadadel4 committed Sep 7, 2024
1 parent 7e932aa commit 7fff221
Showing 1 changed file with 71 additions and 73 deletions.
144 changes: 71 additions & 73 deletions itt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add-Type -AssemblyName WindowsBase
$itt = [Hashtable]::Synchronized(@{
database = @{}
ProcessRunning = $false
lastupdate = "09/06/2024"
lastupdate = "09/07/2024"
github = "https://github.com/emadadel4"
telegram = "https://t.me/emadadel4"
website = "https://emadadel4.github.io"
Expand Down Expand Up @@ -15623,78 +15623,76 @@ function Check-Date {
function DisablePopup {
Set-ItemProperty -Path $itt.registryPath -Name "PopupWindow" -Value "off" -Force
}
#===========================================================================
#region Select elements with a Name attribute using XPath and iterate over them
#===========================================================================

# Select elements with a Name attribute and iterate
$xaml.SelectNodes("//*[@Name]") | ForEach-Object {
$name = $_.Name
$element = $itt["window"].FindName($name)

if ($element) {
$itt[$name] = $element

# Add event handlers based on element type
switch ($element.GetType().Name) {
"Button" {
$element.Add_Click({ Invoke-Button $args[0].Name })
}
"MenuItem" {
$element.Add_Click({ Invoke-Button $args[0].Name })
}
"TextBox" {
$element.Add_TextChanged({ Invoke-Button $args[0].Name })
$element.Add_GotFocus({ Invoke-Button $args[0].Name })
}
"Ellipse" {
$element.add_MouseLeftButtonDown({ Invoke-Button $args[0].Name })
}
"ComboBox" {
$element.add_SelectionChanged({ Invoke-Button $args[0].Name })
}
"TabControl" {
$element.add_SelectionChanged({ Invoke-Button $args[0].Name })
}
"CheckBox" {
$element.IsChecked = Get-ToggleStatus -ToggleSwitch $name
$element.Add_Click({ Invoke-Toogle $args[0].Name })
}
}
}
}
#===========================================================================
#endregion Select elements with a Name attribute using XPath and iterate over them
#===========================================================================

# Define OnClosing event handler
$onClosingEvent = {
param($s, $c)

$exitDialog = $itt.database.locales.Controls.$($itt.Language).exit

# Show confirmation message box
$result = [System.Windows.MessageBox]::Show($exitDialog, "Confirmation", [System.Windows.MessageBoxButton]::YesNo, [System.Windows.MessageBoxImage]::Question)

# Check user's choice
if ($result -eq [System.Windows.MessageBoxResult]::Yes) {
StopAllRunspace
} else {
$c.Cancel = $true
}
}

# Handle the Loaded event
$itt["window"].Add_Loaded({
Startup
Check-Date
})

# Close Event handler
$itt["window"].add_Closing($onClosingEvent)

# Show Window
$itt["window"].ShowDialog() | Out-Null
#===========================================================================
#region Select elements with a Name attribute using XPath and iterate over them
#===========================================================================
$xaml.SelectNodes("//*[@Name]") | ForEach-Object {
$name = $_.Name
$element = $itt["window"].FindName($name)

if ($element) {
$itt[$name] = $element

# Add event handlers based on element type
switch ($element.GetType().Name) {
"Button" {
$element.Add_Click({ Invoke-Button $args[0].Name })
}
"MenuItem" {
$element.Add_Click({ Invoke-Button $args[0].Name })
}
"TextBox" {
$element.Add_TextChanged({ Invoke-Button $args[0].Name })
$element.Add_GotFocus({ Invoke-Button $args[0].Name })
}
"Ellipse" {
$element.add_MouseLeftButtonDown({ Invoke-Button $args[0].Name })
}
"ComboBox" {
$element.add_SelectionChanged({ Invoke-Button $args[0].Name })
}
"TabControl" {
$element.add_SelectionChanged({ Invoke-Button $args[0].Name })
}
"CheckBox" {
$element.IsChecked = Get-ToggleStatus -ToggleSwitch $name
$element.Add_Click({ Invoke-Toogle $args[0].Name })
}
}
}
}
#===========================================================================
#endregion Select elements with a Name attribute using XPath and iterate over them
#===========================================================================

# Define OnClosing event handler
$onClosingEvent = {
param($s, $c)

$exitDialog = $itt.database.locales.Controls.$($itt.Language).exit

# Show confirmation message box
$result = [System.Windows.MessageBox]::Show($exitDialog, "Confirmation", [System.Windows.MessageBoxButton]::YesNo, [System.Windows.MessageBoxImage]::Question)

# Check user's choice
if ($result -eq [System.Windows.MessageBoxResult]::Yes) {
StopAllRunspace
} else {
$c.Cancel = $true
}
}

# Handle the Loaded event
$itt["window"].Add_Loaded({
Startup
Check-Date
})

# Close Event handler
$itt["window"].add_Closing($onClosingEvent)

# Show Window
$itt["window"].ShowDialog() | Out-Null

#===========================================================================
#endregion End Main Functions
Expand Down

0 comments on commit 7fff221

Please sign in to comment.