Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

/Tools/Tidy/Tidy
Function:
Required plugins for this example: MBS Tools Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Tools/Tidy/Tidy
This example is the version from Mon, 22th Nov 2015.
Project "Tidy.rbp"
FileTypes
Filetype text
End FileTypes
Class WindowSimple Inherits Window
Control EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
End Control
Control EditField2 Inherits TextArea
ControlInstance EditField2 Inherits TextArea
End Control
EventHandler Sub Open() dim t as TidyDocumentMBS // the easiest way by just passing strings in and out t=new TidyDocumentMBS t.InstallErrorBuffer Title="Tidy - "+t.ReleaseDate const input="<title>Foo</title><p>Foo!" t.OptionXhtmlOut=True call t.ParseString(input) call t.CleanAndRepair call t.RunDiagnostics t.OptionForceOutput=true EditField1.text=t.SaveString EditField2.text=t.ErrorBuffer End EventHandler
End Class
MenuBar MenuBar1
MenuItem UntitledMenu2 = ""
MenuItem FileMenu = "&File"
MenuItem FileSimple = "Simple"
MenuItem FileWriteEvents = "Write Events"
MenuItem FileReadandWriteEvents = "Read and Write Events"
MenuItem UntitledMenu1 = "-"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
Function FileReadandWriteEvents() As Boolean WindowReadWriteEvents.Show Return true End Function
Function FileSimple() As Boolean WindowSimple.Show Return true End Function
Function FileWriteEvents() As Boolean WindowWriteEvents.Show Return true End Function
End Class
Class WindowWriteEvents Inherits Window
Control EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
End Control
Control EditField2 Inherits TextArea
ControlInstance EditField2 Inherits TextArea
End Control
EventHandler Sub Open() dim t as TidyDocumentMBS // This time we use events to get the output ro=new MyOutput // result output to second editfield ro.e=EditField1 eo=new MyOutput // error output to second editfield eo.e=EditField2 t=new TidyDocumentMBS t.ErrorOutput=eo Title="Tidy - "+t.ReleaseDate const input="<title>Foo</title><p>Foo!" t.OptionXhtmlOut=True call t.ParseString(input) call t.CleanAndRepair call t.RunDiagnostics t.OptionForceOutput=true call t.SaveOutput(ro) End EventHandler
Property eo As myOutput
Property ro As myOutput
End Class
Class MyOutput Inherits TidyOutputMBS
EventHandler Sub WriteByte(value as integer) s=s+chrb(value) // I know it is UTF8, so show a copy e.text=DefineEncoding(s,Encodings.UTF8) End EventHandler
Property e As TextArea
Property s As string
End Class
Class WindowReadWriteEvents Inherits Window
Control EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
End Control
Control EditField2 Inherits TextArea
ControlInstance EditField2 Inherits TextArea
End Control
EventHandler Sub Open() dim t as MyTidyDocument const input="<title>Foo</title><p>Foo!" // This time we use events to get the output and input done ro=new MyOutput // result output to second editfield ro.e=EditField1 eo=new MyOutput // error output to second editfield eo.e=EditField2 inputdata=new MyInput(input) t=new MyTidyDocument t.ErrorOutput=eo Title="Tidy - "+t.ReleaseDate t.OptionXhtmlOut=True call t.ParseSource(inputdata) call t.CleanAndRepair call t.RunDiagnostics t.OptionForceOutput=true call t.SaveOutput(ro) End EventHandler
Property eo As myOutput
Property Private inputdata As myinput
Property ro As myOutput
End Class
Class MyInput Inherits TidyInputMBS
EventHandler Function EndOfFile() As boolean Return index=count End EventHandler
EventHandler Function GetByte() As integer // return one byte index=index+1 Return ascb(midb(data,index,1)) End EventHandler
EventHandler Sub UngetByte(value as integer) index=index-1 // we hope the value is the one from the string End EventHandler
Sub Constructor(s as string) data=s count=lenb(s) index=0 End Sub
Property Private count As integer
Property Private data As string
Property Private index As integer
End Class
Class MyTidyDocument Inherits TidyDocumentMBS
EventHandler Function Filter(level as integer, line as integer, column as integer, message as string) As boolean MsgBox message End EventHandler
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Tools Plugin.




Links
MBS Xojo PDF Plugins