1
General Board / Re: Search for a string (grep) over all CTF base templates?
« on: January 07, 2017, 04:58:21 am »
FWIW, here are the visual basic scripts I'm using to allow for external editing of the code templates. By checking the "use JET 4.0" box in the general preferences of EA and converting the project to be based on the EABase_JET4.eap, you can then open the .eap file with Access 2013. If you save each script below into a separate file you can import them into Access 2013 by going to Database Tools -> Visual Basic -> right click on the project "db2"-> Import File...
You also need to create two macros (Create->Macro), each with one action
export_templates macro: RunCode
Function Name: export_templates()
import_templates macro: RunCode import_templates()
Function Name: import_templates()
The only other trick is that you need to initially touch each template because by default the t_templates table is empty. EA only puts the template into the table if it is modified somehow. You only need to do this once, however, then do Configure->Transfer->ExportReferenceData (in EA13) which will save an XML that has your touched versions. You can later import this into any other project at the start to force all the templates into modified state.
One limitation of these scripts is that they assume the templates for only one language have been modified in EA, and only one stereotype of the template is modified. Extension is needed if you want to save/restore using separate subdirectories for each language and each stereotype. These are already other fields in record set the scripts are already getting from the t_template table so this should be straightforward. Another limitation is that to add new templates you first need to create it in the code template editor.
Attribute VB_Name = "ExportTemplates"
Option Compare Database
Type template_t
filename As String
template As String
End Type
Sub write_template_to_file(t As template_t)
Dim fso As Object
Dim strPath As String
strPath = "C:\path\to\templates\" & t.filename & ".tpl"
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile As Object
Set oFile = fso.CreateTextFile(strPath)
oFile.Write t.template
oFile.Close
Set fso = Nothing
Set oFile = Nothing
End Sub
Public Function export_templates()
Dim rs As Recordset
Dim t As template_t
Set rs = CurrentDb.OpenRecordset("t_template", dbOpenTable)
Do While Not rs.EOF
t.filename = rs(2)
If Not IsNull(rs(5)) Then
t.template = rs(5)
Else
t.template = ""
End If
write_template_to_file t
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Function
--
Attribute VB_Name = "ImportTemplates"
Option Compare Database
Sub read_template_from_file(ByRef t As template_t)
Dim fileNo As Integer
Dim strPath As String
strPath = "C:\path\to\templates\" & t.filename & ".tpl"
fileNo = FreeFile 'Get first free file number
Open strPath For Input As #fileNo
t.template = Input$(LOF(fileNo), fileNo)
Close #fileNo
End Sub
Public Function import_templates()
Dim rs As Recordset
Dim t As template_t
Set rs = CurrentDb.OpenRecordset("t_template", dbOpenTable)
Do While Not rs.EOF
t.filename = rs(2)
read_template_from_file t
rs.Edit
rs(5) = t.template
rs.Update
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Function
You also need to create two macros (Create->Macro), each with one action
export_templates macro: RunCode
Function Name: export_templates()
import_templates macro: RunCode import_templates()
Function Name: import_templates()
The only other trick is that you need to initially touch each template because by default the t_templates table is empty. EA only puts the template into the table if it is modified somehow. You only need to do this once, however, then do Configure->Transfer->ExportReferenceData (in EA13) which will save an XML that has your touched versions. You can later import this into any other project at the start to force all the templates into modified state.
One limitation of these scripts is that they assume the templates for only one language have been modified in EA, and only one stereotype of the template is modified. Extension is needed if you want to save/restore using separate subdirectories for each language and each stereotype. These are already other fields in record set the scripts are already getting from the t_template table so this should be straightforward. Another limitation is that to add new templates you first need to create it in the code template editor.
Attribute VB_Name = "ExportTemplates"
Option Compare Database
Type template_t
filename As String
template As String
End Type
Sub write_template_to_file(t As template_t)
Dim fso As Object
Dim strPath As String
strPath = "C:\path\to\templates\" & t.filename & ".tpl"
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile As Object
Set oFile = fso.CreateTextFile(strPath)
oFile.Write t.template
oFile.Close
Set fso = Nothing
Set oFile = Nothing
End Sub
Public Function export_templates()
Dim rs As Recordset
Dim t As template_t
Set rs = CurrentDb.OpenRecordset("t_template", dbOpenTable)
Do While Not rs.EOF
t.filename = rs(2)
If Not IsNull(rs(5)) Then
t.template = rs(5)
Else
t.template = ""
End If
write_template_to_file t
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Function
--
Attribute VB_Name = "ImportTemplates"
Option Compare Database
Sub read_template_from_file(ByRef t As template_t)
Dim fileNo As Integer
Dim strPath As String
strPath = "C:\path\to\templates\" & t.filename & ".tpl"
fileNo = FreeFile 'Get first free file number
Open strPath For Input As #fileNo
t.template = Input$(LOF(fileNo), fileNo)
Close #fileNo
End Sub
Public Function import_templates()
Dim rs As Recordset
Dim t As template_t
Set rs = CurrentDb.OpenRecordset("t_template", dbOpenTable)
Do While Not rs.EOF
t.filename = rs(2)
read_template_from_file t
rs.Edit
rs(5) = t.template
rs.Update
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Function