diff --git a/Version Control.accda.src/modules/clsDevMode.cls b/Version Control.accda.src/modules/clsDevMode.cls index 7482fbdb..c8b1f821 100644 --- a/Version Control.accda.src/modules/clsDevMode.cls +++ b/Version Control.accda.src/modules/clsDevMode.cls @@ -216,7 +216,7 @@ End Function ' Purpose : Load sections from export file '--------------------------------------------------------------------------------------- ' -Public Sub LoadFromExportFile(strFile As String) +Public Sub LoadFromExportFile(strFileContent As String) Dim varLines As Variant Dim lngLine As Long @@ -240,17 +240,11 @@ Public Sub LoadFromExportFile(strFile As String) ' Clear existing structures and create block classes. ClearStructures - If Not FSO.FileExists(strFile) Then Exit Sub - - ' Open the export file, checking to see if it is in UCS format - If HasUcs2Bom(strFile) Then - varLines = Split(ReadFile(strFile, "Unicode"), vbCrLf) - Else - varLines = Split(ReadFile(strFile), vbCrLf) - End If + If Not Len(strFileContent) Then Exit Sub ' Read the text file line by line, loading the block data Perf.OperationStart "Read File DevMode" + varLines = Split(strFileContent, vbCrLf) For lngLine = 0 To UBound(varLines) strLine = Trim$(varLines(lngLine)) ' Look for header if not inside block @@ -315,7 +309,7 @@ Public Sub LoadFromExportFile(strFile As String) Next intBlock Perf.OperationEnd - CatchAny eelError, "Error loading printer settings from file: " & strFile, _ + CatchAny eelError, "Error loading printer settings from file content.", _ ModuleName(Me) & ".LoadFromExportFile", True, True End Sub @@ -1007,18 +1001,6 @@ Public Sub ApplySettings(dSettings As Dictionary) End Sub -'--------------------------------------------------------------------------------------- -' Procedure : GetPrintSettingsFileName -' Author : Adam Waller -' Date : 1/14/2021 -' Purpose : Return the file name for the print vars json file. -'--------------------------------------------------------------------------------------- -' -Public Function GetPrintSettingsFileName(cDbObject As IDbComponent) As String - GetPrintSettingsFileName = cDbObject.BaseFolder & GetSafeFileName(cDbObject.Name) & ".json" -End Function - - '--------------------------------------------------------------------------------------- ' Procedure : AddToExportFile ' Author : Adam Waller @@ -1028,7 +1010,7 @@ End Function ' : file for import into the database using the loaded print settings. '--------------------------------------------------------------------------------------- ' -Public Function AddToExportFile(strFile As String) As String +Public Function AddToExportFile(strFileContent As String) As String Dim strTempFile As String Dim strLine As String @@ -1040,15 +1022,12 @@ Public Function AddToExportFile(strFile As String) As String If DebugMode(True) Then On Error GoTo 0 Else On Error Resume Next - ' Load data from export file - strData = ReadFile(strFile) - varLines = Split(strData, vbCrLf) - ' Use concatenation class for performance reasons. With New clsConcat .AppendOnAdd = vbCrLf ' Loop through lines in file, searching for location to insert blocks. + varLines = Split(strFileContent, vbCrLf) For lngLine = LBound(varLines) To UBound(varLines) ' Get single line @@ -1088,16 +1067,13 @@ Public Function AddToExportFile(strFile As String) As String End If Next lngLine - ' Write to new file - strTempFile = GetTempFile - WriteFile .GetStr, strTempFile - + ' Return content + AddToExportFile = .GetStr End With - ' Return path to temp file - AddToExportFile = strTempFile - CatchAny eelError, "Error adding to export file: " & strFile, _ + CatchAny eelError, "Error adding print settings to export file.", _ ModuleName(Me) & ".AddToExportFile", True, True + End Function diff --git a/Version Control.accda.src/modules/clsSourceParser.cls b/Version Control.accda.src/modules/clsSourceParser.cls index 7f73ee67..d158b225 100644 --- a/Version Control.accda.src/modules/clsSourceParser.cls +++ b/Version Control.accda.src/modules/clsSourceParser.cls @@ -164,6 +164,39 @@ Public Sub MergeVBA(strVbaCode As String) End Sub +'--------------------------------------------------------------------------------------- +' Procedure : MergePrintSettings +' Author : Adam Waller +' Date : 11/8/2023 +' Purpose : Merge print settings into the current source file. +'--------------------------------------------------------------------------------------- +' +Public Sub MergePrintSettings(strJson As String) + + Dim dSettings As Dictionary + + ' Make sure we have some output + If Not Len(this.strOutput) Then this.strOutput = this.strInput + + ' Don't try to parse an empty string + If strJson = vbNullString Then Exit Sub + + ' Read settings from JSON + Set dSettings = ParseJson(strJson) + If dSettings.Exists("Items") Then + With New clsDevMode + ' Load default printer settings, then overlay + ' settings saved with report. + .ApplySettings dSettings("Items") + ' Write the printer settings to the output content + this.strOutput = .AddToExportFile(this.strOutput) + this.blnOutputModified = True + End With + End If + +End Sub + + '--------------------------------------------------------------------------------------- ' Procedure : SaveObjectVBA ' Author : Adam Waller diff --git a/Version Control.accda.src/modules/modVCSUtility.bas b/Version Control.accda.src/modules/modVCSUtility.bas index b90ba8ee..9dbafb62 100644 --- a/Version Control.accda.src/modules/modVCSUtility.bas +++ b/Version Control.accda.src/modules/modVCSUtility.bas @@ -562,6 +562,13 @@ Public Sub LoadComponentFromText(intType As AcObjectType, _ End If End With End If + + ' Check for print settings file + strAltFile = SwapExtension(strFile, "json") + If FSO.FileExists(strAltFile) Then + ' Merge the print settings into the source file content + .MergePrintSettings ReadFile(strAltFile) + End If End Select ' Check UCS-2-LE requirement for the current database.