Last active
November 3, 2023 15:55
-
-
Save jordancluts/31bd407f3f85a3557d9308313758625e to your computer and use it in GitHub Desktop.
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 formatfilterstring(filter::NTuple{N,Union{String,Tuple{String,String}}}) where N | |
outarray = String[] | |
for i in eachindex(filter) | |
if typeof(filter[i])==String | |
push!(outarray,"",filter[i]) | |
else | |
push!(outarray,filter[i]...) | |
end | |
end | |
string(outarray[1],"|" .* outarray[2:end]...) | |
end | |
function uigetfile(title::String="Select File",filter::NTuple{N,Union{String,Tuple{String,String}}}=(("All Files","*.*"),);multi::Bool=false,path::String=pwd()) where N | |
if multi | |
MultiSelect="True" | |
else | |
MultiSelect="False" | |
end | |
FiltString=formatfilterstring(filter) | |
result=readlines(`powershell -Command "[System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\") | Out-Null; | |
\$dialog = New-Object System.Windows.Forms.OpenFileDialog; | |
\$dialog.InitialDirectory=\"$path\"; | |
\$dialog.title=\"$title\"; | |
\$dialog.filter = \"$FiltString\"; | |
\$dialog.Multiselect = \$$MultiSelect; | |
\$result=\$dialog.ShowDialog(); | |
\$dialog.FileNames; | |
\$dialog.FilterIndex; | |
\$result"`) | |
if pop!(result)=="Cancel" | |
return nothing | |
end | |
filterindex=pop!(result) | |
if multi | |
return result[2:end] | |
else | |
return pop!(result) | |
end | |
end | |
function uigetdir(title::String="Select Directory";path::String=pwd()) | |
result=readlines(`powershell -Command "[System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\") | Out-Null; | |
\$dialog = New-Object System.Windows.Forms.FolderBrowserDialog; | |
\$dialog.SelectedPath=\"$path\"; | |
\$dialog.Description=\"$title\"; | |
\$result=\$dialog.ShowDialog(); | |
\$dialog.SelectedPath; | |
\$result"`) | |
if pop!(result)=="Cancel" | |
return nothing | |
else | |
return pop!(result) | |
end | |
end | |
function uisavefile(title::String="Save File",filter::NTuple{N,Union{String,Tuple{String,String}}}=(("All Files","*.*"),);path::String=pwd()) where N | |
FiltString=formatfilterstring(filter) | |
result=readlines(`powershell -Command "[System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\") | Out-Null; | |
\$dialog = New-Object System.Windows.Forms.SaveFileDialog; | |
\$dialog.InitialDirectory=\"$path\"; | |
\$dialog.title=\"$title\"; | |
\$dialog.filter = \"$FiltString\"; | |
\$result=\$dialog.ShowDialog(); | |
\$dialog.FileNames; | |
\$result"`) | |
if pop!(result)=="Cancel" | |
return nothing | |
else | |
return result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment