'build the source code
Sub btnBuild_Click
SetTitle("Skeleton Source Code")
pnlEmpty.RemoveAllNodes
pnlEmpty.LoadLayout("vCode")
splitter.SetSizeLimits(2,1,1)
SetButtons(False)
Dim sb As StringBuilder
sb.Initialize
sb.Append(BuildEvents)
sb.Append(BuildDesignerProperties)
sb.Append(BuildProperties)
'set the code
jMash.CodeAreaSetText(txtCode,sb.ToString,"1",True)
End Sub
'build code for events, only process active ones
Sub BuildEvents() As String
Dim sb As StringBuilder
sb.Initialize
jMash.AddComment(sb,"This code has been generated with MashSkeletor")
jMash.AddComment(sb,"The Class / CustomView code generated here can be used as a start to create your classes or custom views")
jMash.AddComment(sb,"The idea behind this is encouraging the planning of one's code FIRST")
jMash.AddComment(sb,"*****")
jMash.AddComment(sb,"Conceptualized, created and developed by Mash on [email protected]")
jMash.AddComment(sb,"Powered by B4X from Anywhere Software, www.b4x.com")
jMash.AddComment(sb,jMash.LongDateTimeToday)
jMash.AddComment(sb,"*****")
jMash.AddComment(sb,"***** START OF EVENTS *****")
Dim sb1 As StringBuilder
sb1.Initialize
Dim rEvents As List = DBUtils.ExecuteMaps(prjDB,"select * from events where Active = 1 order by lower(EventName)",Null)
For Each emap As Map In rEvents
Dim sEventName As String = jMash.GetDefault(emap,"EventName","")
Dim sdescription As String = jMash.GetDefault(emap,"description","")
Dim sparameterdef As String = jMash.GetDefault(emap,"parameterdef","")
'add code to build the parameters
If sdescription <> "" Then
jMash.AddComment(sb,sdescription)
End If
sb.Append($"#Event: ${sEventName}()"$).Append(CRLF)
sb1.Append($"#RaisesSynchronousEvents: ${sEventName}"$).Append(CRLF)
Next
jMash.AddComment(sb,"*****")
sb.Append(sb1.ToString)
jMash.AddComment(sb,"***** END OF EVENTS *****")
sb.append(CRLF)
Return sb.tostring
End Sub
'build the code for the designer properties
Sub BuildDesignerProperties() As String
Dim sb As StringBuilder
sb.Initialize
jMash.AddComment(sb,"***** START OF DESIGNER PROPERTIES *****")
Dim rDP As List = DBUtils.ExecuteMaps(prjDB,"select * from DesignerProperties where active = 1 order by lower(KeyName)",Null)
For Each dpmap As Map In rDP
Dim sKeyName As String = jMash.GetDefault(dpmap,"KeyName","")
Dim sDisplayName As String = jMash.GetDefault(dpmap,"DisplayName","")
Dim sFieldType As String = jMash.GetDefault(dpmap,"FieldType","")
Dim sDefaultValue As String = jMash.GetDefault(dpmap,"DefaultValue","")
Dim sDescription As String = jMash.GetDefault(dpmap,"Description","")
Dim sMinRange As String = jMash.getdefault(dpmap,"MinRange","")
Dim sMaxRange As String = jMash.GetDefault(dpmap,"MaxRange","")
Dim sList As String = jMash.GetDefault(dpmap,"List","")
'remove any blank spaces on the name
sKeyName = sKeyName.Replace(" ","").trim
'do we have min and max range
Dim def As String = $"#DesignerProperty: Key: ${sKeyName}, DisplayName: ${sDisplayName}, FieldType: ${sFieldType}, DefaultValue: ${sDefaultValue}"$
If sMinRange <> "" And sMaxRange <> "" Then
Dim minmax As String = $", MinRange: ${sMinRange}, MaxRange: ${sMaxRange}"$
def = def & minmax
End If
If sList <> "" Then
def = def & $", List: ${sList}"$
End If
def = def & $", Description: ${sDescription}"$
'build the def up
sb.Append(def).Append(CRLF)
Next
jMash.AddComment(sb,"***** END OF DESIGNER PROPERTIES *****")
sb.append(CRLF)
Return sb.tostring
End Sub
'build the properties for the class
Sub BuildProperties() As String
Dim sbCG As StringBuilder
sbCG.Initialize
Dim sbPrp As StringBuilder
sbPrp.Initialize
Dim sb As StringBuilder
sb.initialize
Dim pp As List = DBUtils.ExecuteMaps(prjDB,"select * from Properties where active = 1 order by lower(KeyName)",Null)
For Each pmap As Map In pp
Dim sKeyName As String = jMash.GetDefault(pmap,"KeyName","")
Dim sFieldType As String = jMash.GetDefault(pmap,"FieldType","")
Dim sDefaultValue As String = jMash.getdefault(pmap,"DefaultValue","")
Dim sDescription As String = jMash.GetDefault(pmap,"Description","")
Dim sIsConstant As String = jMash.GetDefault(pmap,"IsConstant","0")
Dim sScope As String = jMash.GetDefault(pmap,"Scope","")
Dim sHasGet As String = jMash.GetDefault(pmap,"HasGet","0")
Dim sHasSet As String = jMash.GetDefault(pmap,"HasSet","0")
sKeyName = sKeyName.Replace(" ","").trim
If sIsConstant = "1" Then sIsConstant = "Const"
'if this has no get or set then sit in class globals
If sHasGet = "0" And sHasSet = "0" Then
sbCG.Append($"${sScope} ${sIsConstant} ${sKeyName} As ${sFieldType}"$)
If sDefaultValue <> "" Then
sbCG.Append(" = ")
If sFieldType = "String" Then sbCG.Append(QUOTE)
sbCG.Append(sDefaultValue)
If sFieldType = "String" Then sbCG.Append(QUOTE)
End If
If sDescription <> "" Then
sbCG.Append($" '${sDescription}"$).Append(CRLF)
End If
Else
sbCG.Append($"Private m${sKeyName} As ${sFieldType}"$)
If sDefaultValue <> "" Then
sbCG.Append(" = ")
If sFieldType = "String" Then sbCG.Append(QUOTE)
sbCG.Append(sDefaultValue)
If sFieldType = "String" Then sbCG.Append(QUOTE)
End If
If sDescription <> "" Then
sbCG.Append($" '${sDescription}"$).Append(CRLF)
End If
'this has get or set
If sHasGet = "1" Then
If sDescription <> "" Then
sbPrp.Append($"'Gets ${sDescription}"$).Append(CRLF)
End If
sbPrp.Append($"${sScope} Sub get${sKeyName} As ${sFieldType}
Return m${sKeyName}
End Sub"$).Append(CRLF)
End If
'this has get or set
If sHasSet = "1" Then
If sDescription <> "" Then
sbPrp.Append($"'Sets ${sDescription}"$).Append(CRLF)
End If
sbPrp.Append($"${sScope} Sub set${sKeyName}(${sKeyName} As ${sFieldType})
m${sKeyName} = ${sKeyName}
End Sub"$).Append(CRLF)
End If
End If
Next
jMash.AddComment(sb,"***** START OF PROPERTIES *****")
sb.Append(sbCG.ToString).Append(CRLF)
sb.Append(sbPrp.ToString).Append(CRLF)
jMash.AddComment(sb,"***** END OF PROPERTIES *****")
sb.Append(CRLF)
Return sb.tostring
End Sub