Skip to content

Commit

Permalink
Move print settings processing to clsSourceParser
Browse files Browse the repository at this point in the history
This keeps the LoadComponentFromText function cleaner and easier to read.
  • Loading branch information
joyfullservice committed Nov 8, 2023
1 parent da9f94a commit 54e070a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 34 deletions.
44 changes: 10 additions & 34 deletions Version Control.accda.src/modules/clsDevMode.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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


Expand Down
33 changes: 33 additions & 0 deletions Version Control.accda.src/modules/clsSourceParser.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Version Control.accda.src/modules/modVCSUtility.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 54e070a

Please sign in to comment.