Skip to content

Commit

Permalink
Merge pull request IDEMSInternational#9096 from derekagorhom/Allow_fo…
Browse files Browse the repository at this point in the history
…r_Import_Json_File

Added the Option of Loading and Saving Json Files in the R script window
  • Loading branch information
N-thony authored Aug 8, 2024
2 parents 8307206 + df6561f commit 84b1ad9
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions instat/ucrScript.vb
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,10 @@ Public Class ucrScript

Using dlgSave As New SaveFileDialog
dlgSave.Title = "Save " & If(bIsLog, "Log", "Script") & " To File"
dlgSave.Filter = "R Script File (*.R)|*.R|Text File (*.txt)|*.txt"
dlgSave.Filter = "R Script File (*.R)|*.R|Text File (*.txt)|*.txt|JSON File (*.json)|*.json"
dlgSave.FileName = Path.GetFileName(TabControl.SelectedTab.Text)

'Ensure that dialog opens in correct folder.
'In theory, we should be able to use `dlgLoad.RestoreDirectory = True` but this does
'not work (I think a bug in WinForms).So we need to use static variables instead.
' Ensure that dialog opens in the correct folder.
Static strInitialDirectory As String = frmMain.clsInstatOptions.strWorkingDirectory
Static strInitialDirectoryLog As String = frmMain.clsInstatOptions.strWorkingDirectory
dlgSave.InitialDirectory = If(bIsLog, strInitialDirectoryLog, strInitialDirectory)
Expand All @@ -232,15 +230,16 @@ Public Class ucrScript
TabControl.SelectedTab.Text = System.IO.Path.GetFileNameWithoutExtension(dlgSave.FileName)
frmMain.clsRecentItems.addToMenu(Replace(Path.Combine(Path.GetFullPath(strInitialDirectory), System.IO.Path.GetFileName(dlgSave.FileName)), "\", "/"))
frmMain.bDataSaved = True

If bIsLog Then
strInitialDirectoryLog = Path.GetDirectoryName(dlgSave.FileName)
Else
strInitialDirectory = Path.GetDirectoryName(dlgSave.FileName)
End If
Catch
MsgBox("Could not save the " & If(bIsLog, "Log", "Script") & " file." & Environment.NewLine &
"The file may be in use by another program or you may not have access to write to the specified location.",
vbExclamation, "Save " & If(bIsLog, "Log", "Script"))
"The file may be in use by another program or you may not have access to write to the specified location.",
vbExclamation, "Save " & If(bIsLog, "Log", "Script"))
End Try
End If
End Using
Expand Down Expand Up @@ -530,9 +529,9 @@ Public Class ucrScript

Using dlgLoad As New OpenFileDialog
dlgLoad.Title = "Load Script From Text File"
dlgLoad.Filter = "Text & R Script Files (*.txt,*.R)|*.txt;*.R|R Script File (*.R)|*.R|Text File (*.txt)|*.txt"
dlgLoad.Filter = "Text & R Script Files (*.txt, *.R, *.json)|*.txt;*.R;*.json|R Script File (*.R)|*.R|Text File (*.txt)|*.txt|JSON File (*.json)|*.json"

'Ensure that dialog opens in correct folder.
' Ensure that dialog opens in the correct folder.
'In theory, we should be able to use `dlgLoad.RestoreDirectory = True` but this does
'not work (I think a bug in WinForms).So we need to use a static variable instead.
Static strInitialDirectory As String = frmMain.clsInstatOptions.strWorkingDirectory
Expand Down

0 comments on commit 84b1ad9

Please sign in to comment.