View Full Version : Next thinBasic: template dialog
ErosOlmi
22-01-2012, 13:33
I'm few weeks I'm working on next thinBasic version: 1.9
Among other many enhancements, one of the things I'm working on is a new template dialog, the dialog used to create a new thinBasic script (see image)
So far I've almost completely re-coded it keeping as possible inspiration the new project dialog present in Microsoft Visual Studio
There will be 4 areas in the dialog (see image):
the repository tree structure used to store thinBasic script templates
the list of templates present in a certain directory
general info about templates like: author, date, version, ...
a preview of the template
I'm now working on area 3 and 4
In area 3 I'm trying to find a way to add that info inside template source code in order to get them during preview
In area 4 I'm working on adding Scintilla Text Editor (http://www.scintilla.org/index.html) as possible editor making experience with it in order to consider as possible future thinAir editor control.
What I need?
I need some advice on what you think about this new dialog layout
I need some possible ideas to enhance this dialog
I need idea on how to insert into template source code the template info: author, description short, description long, version, ...
Maybe we can think to use XML as template structure. In this way it will be very easy to implement additional specifications
I need some new templates from general one to complex one in order to present thinBasic programmers a quite rich set of templates to start from
Any help will be very much appreciated.
Ciao
Eros
Hi, in vb6 i am using it sometimes for a hurry calc, i draw quickly textbox and a button then dblclick on the button to write textbox1=some operation, i prefer this than console or msgbox. so a template for textbox with a button for a hurry calc will be useful, because it is not easy to remember the complex syntax of the related windows api functions. such a template can make use of the attached example i have found on my hard disk made by one of the users, i have edited it slightly.
i suggest also a simple template for a form with a canvas, with a one instruction to draw an ellipse,circle, line, pixel.
Petr Schreiber
22-01-2012, 17:43
Hi Eros,
few ideas from my side:
Template file format
I would move the template file format completely to XML, having the following structure:
<ThinAIRTemplate version="1.0"> // Version of template file format
<Header>
<DescriptionShort>Simple dialog</DescriptionShort> // Name to be displayed in the templates listing instead of filename of this template
<DescriptionLong>This template generates code for single modal dialog with button and callback</DescriptionLong> // Description to be displayed
<Author>Petr Schreiber</Author> // Person responsible for the template
<Contact>Drop user "Petr Schreiber" a personal message on ThinBASIC forumor email me at...</Contact> // Contact information in case of trouble, link to source of latest version and such
<Version>1.1<Version> // Version of this particular template
</Header>
<Files count="1"> // In future it could be multifile, for projects and such
<File>
<Name>Dialog_</Name> // Gets pre-filled in the name for new file in New thinBasic script dialog, can be left empty, to give user more freedom
<Extension>tBasic</Extension> // This is quite important, it could be tBasic, tBasicC, tBasicI, tBasicU, Txt
<Code>
uses "UI"
... here goes thinBasic code of the file ...
</Code>
</File>
</Files>
</ThinAIRTemplate>
I am sorry, but I didn't managed to display it indented
"New" dialog
I like the new layout, but have few "highlevelization" ideas to make the dialog more intuitive to users:
Area 1
I am not sure what is the experience of other users, but I personally do not nest the template directories. There could be simple list of directories under Templates/ instead of treeview.
The list of templates could get more human readable format, like in Visual Studio. It could be realised with WebControl, having a look of "Listbox on steroids" realised via HTML one column table:
each template would have his name in bold
author, version and other minor metadata would be listed below
description in italics below
tooltip would tell the file name for anyone interested, but most users won't need to know it I guess
So one item would look like:
Simple modal dialog
author: Petr Schreiber, version: 1.1
This template creates code for single modal dialog, with button and callback predefined
It is a bit of space waste, but from my experience I do not use more than 6 templates in total, so this number would still fit on the screen.
It could erase the need for Area 3.
The gray area above is look to far future, it would take a lot of time.
Petr
Petr Schreiber
22-01-2012, 18:14
The XML template idea still valid, for the dialog layout I have new idea, more realisable.
For a newcomer, I think it would be good to add some visual guides, because what he will see will be 3 window areas - where he should click first?
On the other side the code listing will be not needed for the ol' coders knowing the template well. This leads to new layout in the attachement.
It has visual guides for new comer and expandable area with code listing.
Petr
ErosOlmi
22-01-2012, 18:32
Petr,
as usual great ideas! Thanks.
What is field "File name" used for?
Eros
ErosOlmi
22-01-2012, 18:35
Hi, in vb6 i am using it sometimes for a hurry calc, i draw quickly textbox and a button then dblclick on the button to write textbox1=some operation, i prefer this than console or msgbox. so a template for textbox with a button for a hurry calc will be useful, because it is not easy to remember the complex syntax of the related windows api functions. such a template can make use of the attached example i have found on my hard disk made by one of the users, i have edited it slightly.
i suggest also a simple template for a form with a canvas, with a one instruction to draw an ellipse,circle, line, pixel.
Thanks zak.
All templates I will receive will be valuated for the next version.
I want to create a rich set of templates because I have the doubt that the many thinBasic script examples are not much visible to users while if we will create them as templates I think they will be much more visible.
Ciao
Eros
Petr Schreiber
22-01-2012, 19:21
Thanks :)
Currently, the file is always created as Untitled?.tBasic after pressing Use button.
The file name field could be used to name the file since the beginning somehow, and the extension would be detected from the template XML File.Extension tag.
The file name could be prefilled based on value in File.Name tag, but filling this tag in would be optional (could be left empty).
What is this good for? For example in case of code units. As I use frequently the TBGL actor template, the new XML version of it would:
force tBasicU extension, as it is not standalone
the name would be suggested to start "actor_" to keep clear what the file is about
Of course user can ignore this suggestion and name it as he wants.
Petr
Petr,
as usual great ideas! Thanks.
What is field "File name" used for?
Eros
ErosOlmi
22-01-2012, 19:27
I think is a great solution.
I just need to change thinAir internal identification of new files never saved in order to ask user to save them
At the moment "untitled" is used to identify them.
Anyway quite simple change
ErosOlmi
22-01-2012, 21:12
Petr,
I've created a test program to load a template XML file following your example.
I've used Don Dickinson XML parser in order to avoid un-needed dependencies connections to big libraries or COM dependencies.
Attached full source code and example template.
I think I will go this way unless you have a better XML parser.
Ciao
Eros
Petr Schreiber
22-01-2012, 21:54
Hi Eros,
I have developed very basic XML parser. It should work for our case. The usage is very simple (referencing tag directly with path), but on the other side it is not really the gold piece of code, as it could be slow for big XMLs and it is a bit hacky.
Please try it on your PC, save it to the same directory as "_Template_.xml" to see it processed. The code relies on GRAB$ heavily, the rest is PB compatible I guess :)
So... here comes the spaghetti code :D:
Uses "Console", "File"
$ProcessedFile = APP_SourcePath+"_Template_.XML"
Function TBMain()
If FILE_Exists($ProcessedFile) = FALSE Then
MsgBox 0, "This example needs the file " + $ProcessedFile + " to work"
Stop
End If
String sXMLBuffer = FILE_Load(APP_SourcePath+"_Template_.XML")
PrintL "Version : ", XML_GetTagParameter(sXMLBuffer, "ThinAIRTemplate", "version")
' -- The error catching is a bit silly, but should work
' If Len(XML_LastError) Then
' PrintL "Error occurred:"
' PrintL XML_LastError
' WaitKey
' Stop
' End If
PrintL "Type : ", XML_GetTagParameter(sXMLBuffer, "ThinAIRTemplate", "type")
PrintL
PrintL "DescriptionShort: ", XML_GetString(sXMLBuffer, "ThinAIRTemplate.Header.DescriptionShort")
PrintL "DescriptionLong : ", XML_GetString(sXMLBuffer, "ThinAIRTemplate.Header.DescriptionLong")
PrintL "Author : ", XML_GetString(sXMLBuffer, "ThinAIRTemplate.Header.Author")
PrintL "Contact : ", XML_GetString(sXMLBuffer, "ThinAIRTemplate.Header.Contact")
PrintL "Version : ", XML_GetString(sXMLBuffer, "ThinAIRTemplate.Header.Version")
PrintL
PrintL "Count : ", XML_GetTagParameter(sXMLBuffer, "ThinAIRTemplate.Files", "count")
PrintL
PrintL "Name : ", XML_GetString(sXMLBuffer, "ThinAIRTemplate.Files.Name")
PrintL "Extension : ", XML_GetString(sXMLBuffer, "ThinAIRTemplate.Files.Extension")
PrintL "Code : ", XML_GetString(sXMLBuffer, "ThinAIRTemplate.Files.Code")
WaitKey
End Function
String XML_LastError
' -- Retrieves string from passed tag
Function XML_GetString(sFile As String, sXPath As String) As String
Return XML_GetString_NthOccurence(sFile, sXPath, 1)
End Function
' -- Retrieves parameter of given tag
Function XML_GetTagParameter(sFile As String, sXPath As String, sParameter As String) As String
' -- By bypassing purge we retrieve the part after tag name
String sBuffer = XML_GetString_NthOccurence(sFile, sXPath, 1, FALSE)
' -- This gives us string of the params, like: type="template" version="1.0"
sBuffer = RTrim$(Extract$(sBuffer, ">"), ">")
' -- This chops each param to single array item
String sParams()
Long nParams = Parse(sBuffer, sParams, " ")
' -- Now we seek for match, and if we do, we return the thing between quotes
Long i
For i = 1 To nParams
If StartsWith(sParams(i)+"=", sParameter) Then
Return Parse$(sParams(i), $DQ, 2)
End If
Next
XML_LastError = "The parameter " + $DQ + sParameter + $DQ + " could not be found for tag " + sXPath
End Function
' -- Retrieves string from nth occurrence of passed tag
Function XML_GetString_NthOccurence(sFile As String, sXPath As String, occurence As Long, Optional purge As Long = TRUE) As String
' -- This makes sure we can process both string buffer or file from disk
String sBuffer
If InStr(sFile, ":") = 2 Then
sBuffer = Acode$(UTF8ToWideChar$(FILE_Load(sFile)))
Else
sBuffer = sFile
End If
' -- Some XMLs have odd tags with > on another line
sBuffer = Replace$(sBuffer, $LF+">", ">")
' -- Here we chop the XML tag path to pieces
String sPathElement()
Long i
Long pathElements = Parse(sXPath, sPathElement, ".")
' -- Here ve linearly chop the original string by tags till we get the result
For i = 1 To pathElements
If i = pathElements-1 Then
If InStr(sBuffer, "<"+sPathElement(i)+">") Then
sBuffer = Grab$(sBuffer, "<"+sPathElement(i)+">", "</"+sPathElement(i)+">", occurence) ' -- For tags without parameters
ElseIf InStr(sBuffer, "<"+sPathElement(i)+" ") Then
sBuffer = Grab$(sBuffer, "<"+sPathElement(i)+" ", "</"+sPathElement(i)+">", occurence) ' -- and for those with
If purge Then
sBuffer = Remain$(sBuffer, ">")
End If
Else
XML_LastError = "Tag " + $DQ + sPathElement(i) + $DQ + " was not found in the path " + sXPath
End If
Else
If InStr(sBuffer, "<"+sPathElement(i)+">") Then
sBuffer = Grab$(sBuffer, "<"+sPathElement(i)+">", "</"+sPathElement(i)+">")
ElseIf InStr(sBuffer, "<"+sPathElement(i)+" ") Then
sBuffer = Grab$(sBuffer, "<"+sPathElement(i)+" ", "</"+sPathElement(i)+">")
If purge Then
sBuffer = Remain$(sBuffer, ">")
End If
Else
XML_LastError = "Tag " + $DQ + sPathElement(i) + $DQ + " was not found in the path " + sXPath
End If
End If
Next
Return sBuffer
End Function
Petr
ErosOlmi
22-01-2012, 22:44
Petr,
your code is working as T90 Tank (https://www.google.com/#hl=en&sugexp=pfwl&tok=JMDvU4ovTLrb5Dn2NcOJCg&cp=5&gs_id=i&xhr=t&q=t90+tank&gs_sm=&gs_upl=&um=1&ie=UTF-8&tbo=u&tbm=vid&source=og&sa=N&tab=wv&ei=x3McT62LPKel4gS2zriPDQ&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=df761dfb19304051&biw=1918&bih=1019) :cool:
I think that we need to add a CDATA inside <code>...</code> in order to avoid character misinterpretation (http://www.w3schools.com/xml/xml_cdata.asp):
My code is not able to interpret CDATA and it just hangs
Your code seems just ignoring and returned source code is the code plus CDATA so your code is much better.
I will see what I can do.
Eros
ErosOlmi
23-01-2012, 02:02
I forgot I have a MSXML wrapper: #INCLUDE "%APP_INCLUDEPATH%\TB_XML60.INC"
Will see what I can get from it.
I like the layout Eros. About section 3, how about keeping the data in a SQL database on the server. This way there are no xml files to distribute and information is up to date all the time. In fact, the templates themselves could come from the server. So only templates people need are downloaded and your distribution file remains small.
ErosOlmi
23-01-2012, 08:13
Thanks Kent
Maybe on a second step I will add server side templates but at first they will be distributed with setup. They are just text files so the space they occupy on a compressed distribution is just minimum.
Eros
Petr Schreiber
23-01-2012, 21:42
The CDATA note is important. I think even my T90 routines :p would have problem in case the text between <Code></Code> would contain </Code> for example in string.
Petr
largo_winch
24-01-2012, 15:33
1)
Template file format
I would move the template file format completely to XML, having the following structure:
petr, does this mean your are only taking this xml for header import? Not for whole dialog code example content I am not sure what's your intention, better to ask here for it. the dialog code example content doesn't need this xml text format? if that's the case ist true I can't read nor more this code format with adding colors and styles formats or java script enhancements in xml text ;)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<verzeichnis>
<titel>Wikipedia Städteverzeichnis</titel>
<eintrag>
<stichwort>Genf</stichwort>
<eintragstext>Genf ist der Sitz von ...</eintragstext>
</eintrag>
<eintrag>
<stichwort>Köln</stichwort>
<eintragstext>Köln ist eine Stadt, die ...</eintragstext>
</eintrag>
</verzeichnis>
2) a dialog should have a
a) simple list/combobox for thinbasic *tmplate too
b) and I like to add the color of a dialog window parameters with simple adding at the end two commands ( rgb(100,0,200), rgb(255,160,255) or/and "gradient style" ) of dialog parameter
c) dialog with menu (and perhaps toolbar)
I shall write that for you?
I generally like the idea for new dialog format/template.
bye, largo
ErosOlmi
24-01-2012, 17:39
Largo,
just to be sure ...
we are talking about improving thinAir/File/New dialog
and improving the <template> file structure transforming it from plain text to xml code for better handling and future enhancements
Ciao
Eros
ErosOlmi
24-01-2012, 23:40
Below code is parsing XML thinAir template idea of Petr using thinBasic native XML wrapper.
I think I will go this way for thinAir parser.
Attached thinBasic source and template
Code
Uses "Console"
#INCLUDE "%APP_INCLUDEPATH%\TB_XML60.INC"
$XMLFile = APP_SourcePath+"_Template_.xml"
Function TBMain()
Local pXmlDoc As DWord
Local pRoot As DWord
Local pRootName As String
Local pRootVersion As Variant
Local pRootType As Variant
Local pHeader As DWord
Local pFiles As DWord
Local pFile As DWord
Local FileCount As Long
Local pFileInfo As DWord
Local pNode As DWord
pXmlDoc = XmlCreateObject("Msxml2.DOMDocument")'.6.0")
IXMLDOMDocument_put_async pXmlDoc, %FALSE
IXMLDOMDocument_load(pXmlDoc, $XMLFile)
If XmlParseError_get_errorCode(pXmlDoc) <> 0 Then
PrintL XmlParseError_get_reason(pXmlDoc)
Else
'------------------------------------------------------------
'---Get thinAirTemplate Root
'------------------------------------------------------------
PrintL "-[Root Info]------------------------------------"
pRoot = IXMLDOMDocument_get_documentElement(pXmlDoc)
pRootName = IXMLDOMDocument_get_nodeName(pRoot)
IXMLDOMElement_getAttribute(pRoot, "version", pRootVersion)
IXMLDOMElement_getAttribute(pRoot, "type", pRootType)
PrintL "Root name : " & pRootName
PrintL "Root version: " & pRootVersion
PrintL "Root type : " & pRootType
PrintL "------------------------------------------------"
PrintL
'------------------------------------------------------------
'---Get Header info
'------------------------------------------------------------
PrintL "-[Header ]------------------------------------"
pHeader = IXMLDOMElement_get_firstChild(pRoot)
PrintL "Node name: " & IXMLDOMDocument_get_nodeName(pHeader)
pNode = IXMLDOMElement_get_FirstChild(pHeader)
While pNode
Print IXMLDOMDocument_get_nodeName(pNode) & ": "
PrintL IXMLDOMDocument_get_text(pNode)
pNode = IXMLDOMElement_get_NextSibling(pNode)
Wend
PrintL
'------------------------------------------------------------
'---Files info
'------------------------------------------------------------
' <Any note here. Breakpoint will be set to line following this statement>
PrintL "-[Files ]------------------------------------"
pFiles = IXMLDOMElement_get_NextSibling(pHeader)
PrintL "Node name: " & IXMLDOMDocument_get_nodeName(pFiles)
'---Loop for each file
pFile = IXMLDOMElement_get_FirstChild(pFiles)
While pFile
Incr FileCount
PrintL IXMLDOMDocument_get_nodeName(pFile) & " " & FileCount
'---Loop for each file info
pFileInfo = IXMLDOMElement_get_FirstChild(pFile)
While pFileInfo
Print IXMLDOMDocument_get_nodeName(pFileInfo) & ": "
PrintL IXMLDOMDocument_get_text(pFileInfo)
pFileInfo = IXMLDOMElement_get_NextSibling(pFileInfo)
Wend
pFile = IXMLDOMElement_get_NextSibling(pFile)
Wend
PrintL
PrintL
End If
' cleanup
XmlRelease pRoot
XmlRelease pHeader
XmlRelease pFiles
XmlRelease pFile
XmlRelease pFileInfo
XmlRelease pNode
XmlRelease pXmlDoc
PrintL "--- Press any key to finish ---"
WaitKey
End Function
[B]Template Example:
<?xml version='1.0'?>
<thinAirTemplate version="1.0" type="template">
<Header>
<DescriptionShort>Simple dialog</DescriptionShort>
<DescriptionLong>This template generates code for single modal dialog</DescriptionLong>
<Author>Petr Schreiber</Author>
<Contact>Drop user "Petr Schreiber" a message on ThinBASIC forum</Contact>
<Version>1.1</Version>
</Header>
<Files>
<File>
<Name>Dialog_</Name>
<Extension>tBasic</Extension>
<Code>
<![CDATA[
uses "UI"
... here goes thinBasic code of the file ...
]]>
</Code>
<Signature>hello</Signature>
</File>
</Files>
</thinAirTemplate>
Petr Schreiber
18-02-2012, 15:27
Hi Eros,
the template dialog in beta has one little problem - when I click the templates, their code appears correctly. But when I use arrow keys to choose the template, the right panel with code does not update at all.
It is probably not an issue, if the code section will be expandable as we discussed earlier.
Petr