Last active
June 7, 2018 10:34
-
-
Save PatrickGrub/8f998c50b9a231c8280d645fa51748dd to your computer and use it in GitHub Desktop.
The coolDialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Show-MessageBox { | |
param( | |
$Title = "The cool Dialog", | |
[Parameter(Mandatory=$true)] | |
$Message, | |
[System.Windows.Forms.MessageBoxIcon]$Icon = "Information", | |
[System.Windows.Forms.MessageBoxButtons]$Buttons = "Ok" | |
) | |
[System.Windows.Forms.MessageBox]::Show($Message, $Title, $Buttons, $Icon) | Out-Null | |
} | |
try { | |
$folderId = $vaultContext.CurrentSelectionSet | select -First 1 -ExpandProperty "Id" | |
if(-not $folderId) { | |
throw "No valid folder selected!" | |
} | |
$fldr = $vault.DocumentService.GetFolderById($folderId) | |
$folder = New-Object Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities.Folder -ArgumentList @($vaultConnection, $fldr) | |
[xml]$xamlContent = Get-Content "$($env:ProgramData)\Autodesk\Vault 2018\Extensions\DataStandard\Vault.Custom\addinVault\Menus\TheCoolDialog.xaml" | |
$theCoolWindow = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader -ArgumentList @($xamlContent))) | |
$theCoolWindow.FindName("StackPanelCoolView").DataContext = $folder | |
$theCoolWindow.FindName("BtnCool").add_Click({ | |
$coolUserInput = $theCoolWindow.FindName("TxtCoolInput").Text | |
if($coolUserInput -notlike "*cool*") { | |
Show-MessageBox -Message "Your input was not cool!`nTry it again!" -Icon "Warning" | |
} else { | |
@(@($theCoolWindow) + $theCoolWindow.FindName("StackPanelCoolView").Children + $theCoolWindow.FindName("StackPanelCoolBtns").Children) | where { $_.GetType() -ne [system.windows.controls.stackpanel] } | foreach { | |
$isTextBox = $_.GetType() -eq [system.windows.controls.TextBox] | |
$_.BorderBrush = "White" | |
$_.Background = if($isTextBox) { "LightGoldenrodYellow" } else { "Orange"} | |
$_.Foreground = if($isTextBox) { "DarkOrange" } else { "White" } | |
} | |
Show-MessageBox -Message "Your input was $coolUserInput!" | |
} | |
}) | |
$theCoolWindow.FindName("BtnCancel").add_Click({ | |
$theCoolWindow.Close() | |
}) | |
$theCoolWindow.ShowDialog() | Out-Null | |
} catch { | |
$errorMessage = "Error message: '$($_.Exception.Message)'`n`n`nSTACKTRACE:`n$($_.InvocationInfo.PositionMessage)`n`n$($_.ScriptStacktrace)" | |
Show-MessageBox -Message $errorMessage -Icon "Error" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:ig="http://schemas.infragistics.com/xaml" | |
SizeToContent="WidthAndHeight" | |
Title="The coolDialog" | |
WindowStartupLocation="CenterScreen"> | |
<Window.Resources> | |
<Style TargetType="{x:Type Button}"> | |
<Setter Property="Margin" | |
Value="10" /> | |
<Setter Property="Height" | |
Value="30" /> | |
<Setter Property="FontSize" | |
Value="14" /> | |
<Setter Property="Width" | |
Value="140" /> | |
</Style> | |
<Style TargetType="{x:Type Label}"> | |
<Setter Property="FontSize" | |
Value="12" /> | |
</Style> | |
<Style TargetType="{x:Type TextBox}"> | |
<Setter Property="FontSize" | |
Value="12" /> | |
<Setter Property="Height" | |
Value="20" /> | |
<Setter Property="Margin" | |
Value="5" /> | |
</Style> | |
</Window.Resources> | |
<StackPanel Name="StackPanelCoolView"> | |
<Label Content="Selected folder:" /> | |
<TextBox Text="{Binding Path=FullName, Mode=OneWay}" | |
IsReadOnly="True" /> | |
<Label Content="Insert a cool text:" /> | |
<TextBox Text="Type something cool" x:Name="TxtCoolInput" /> | |
<StackPanel Orientation="Horizontal" Name="StackPanelCoolBtns"> | |
<Button Content="Make something cool" | |
TabIndex="1" | |
x:Name="BtnCool" /> | |
<Button Content="Close" | |
TabIndex="2" | |
x:Name="BtnCancel" /> | |
</StackPanel> | |
</StackPanel> | |
</Window> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment