Platforms to show: All Mac Windows Linux Cross-Platform
/Scintilla/ScintillaTest
Function:
Required plugins for this example: MBS Scintilla Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Scintilla/ScintillaTest
This example is the version from Fri, 29th Sep 2022.
Function:
Required plugins for this example: MBS Scintilla Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Scintilla/ScintillaTest
This example is the version from Fri, 29th Sep 2022.
Project "ScintillaTest.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
Dim wM As New ScintillaWindow
wM.SetupMySQL
wM.Title = "Scintilla MySQL Example"
Dim wH As New ScintillaWindow
wH.SetupHTML
wH.Title = "Scintilla HTML Example"
Dim wX As New ScintillaWindow
wX.SetupXojo
wX.Title = "Scintilla Xojo Example"
End EventHandler
Sub LoadLIbs()
#If True Then
// we use built-in for macOS and Windows!
#ElseIf TargetMacOS Then
Dim ExecutableFolder As FolderItem = app.ExecutableFile.Parent
Dim ContentsFolder As FolderItem = ExecutableFolder.Parent
Dim FrameworksFolder As FolderItem = ContentsFolder.Child("Frameworks")
Dim libFile As FolderItem = FrameworksFolder.Child("liblexilla.dylib")
If ScintillaControlMBS.LoadLibrary(libFile) Then
'MessageBox "OK"
Else
MessageBox "Failed to load Lexilla."
End If
Dim FrameworkFile As FolderItem = FrameworksFolder.Child("Scintilla.framework")
If ScintillaControlMBS.LoadFramework(FrameworkFile) Then
'MessageBox "OK"
Else
MessageBox "Failed to load Scintilla."
End If
#ElseIf TargetWindows Then
Const libPath = "Lexilla.dll"
Dim libFile As FolderItem = New FolderItem(libPath)
System.DebugLog "LibFile: "+libFile.NativePath
If ScintillaControlMBS.LoadLibrary(libFile) Then
'MessageBox "OK"
Else
MessageBox "Failed to load Lexilla."
End If
Const ScintillaPath = "Scintilla.dll"
Dim ScintillaFile As FolderItem = New FolderItem(ScintillaPath)
System.DebugLog "ScintillaFile: "+ScintillaFile.NativePath
If ScintillaControlMBS.LoadLibrary(ScintillaFile) Then
'MessageBox "OK"
Else
MessageBox "Failed to load Scintilla."
End If
#EndIf
End Sub
End Class
Class ScintillaWindow Inherits Window
Const SampleHTML = "<!DOCTYPE html>\n<html>\n<head>\n\t<title>Hello World</title>\n</head>\n<body>\n\n<div test=123>\n<P>Hello World</P>\n</div>\n\n<!-- some comment -->\n\n<script>\nif (i + 5 == 6)\n{\n\talert('hello');\n}\n</script>\n\n</body>\n</html>\n"
Control ScintillaControl Inherits ScintillaControlMBS
ControlInstance ScintillaControl Inherits ScintillaControlMBS
EventHandler Sub AutoCompleteCancelled()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub AutoCompleteCharacterDeleted()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub AutoCompleteCompleted(Position as Integer, Character as Integer, Text as String, listCompletionMethod as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub AutoCompleteSelection(Position as Integer, Character as Integer, Text as String, listCompletionMethod as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub AutoCompleteSelectionChange(Position as Integer, Text as String, listType as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub CallTipClick(Position as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub CharacterAdded(Character as Integer, CharacterSource as Integer)
System.DebugLog CurrentMethodName
// new line -> let's indent the text a bit
If Character = 13 Or Character = 10 Then
Dim CurrentPosition As Integer = Me.Position
Dim curLine As Integer = Me.LineFromPosition(CurrentPosition)
Dim lineLength As Integer = Me.LineLength(curLine)
If curLine > 0 And lineLength < 2 Then
// beginning on a new line
Dim prevLine As String = Me.Line(curLine-1)
Dim Len As Integer = 0
For i As Integer = 1 To prevLine.Len
Dim ch As String = prevLine.Mid(i, 1)
If Asc(ch) = 9 Or Asc(ch) = 32 Then
// we take that
Len = i
Else
// start of text, so exit
Exit
End If
Next
Dim prefix As String = prevLine.Left(Len)
Me.ReplaceSelection(prefix)
return
End If
End If
// no selection?
If Me.SelectionEnd = Me.SelectionStart Then
If Me.SelectionStart > 0 Then
// already active?
If Me.AutoCompleteActive Then
Else
StartAutoComplete
End If
End If
End If
End EventHandler
EventHandler Sub Close()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub DWellEnd(Position as Integer, X as Integer, Y as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub DWellStart(Position as Integer, X as Integer, Y as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub DoubleClick(Position as Integer, line as integer, modifiers as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Function DragEnter(obj As DragItem, action As Integer) As Boolean
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub DragExit(obj As DragItem, action As Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Function DragOver(x As Integer, y As Integer, obj As DragItem, action As Integer) As Boolean
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub DropObject(obj As DragItem, action As Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub FocusIn()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub FocusOut()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub FolderToggled(Line as Integer, Position as Integer, Margin as ScintillaMarginMBS)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub HotSpotClick(Position as Integer, modifiers as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub HotSpotDoubleCLick(Position as Integer, modifiers as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub HotspotReleaseClick(Position as Integer, modifiers as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub IndicatorClick(Position as Integer, modifiers as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub IndicatorRelease(Position as Integer, modifiers as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub Key(Character as Integer, modifiers as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub MacroRecord(Message as Integer, wParam as Integer, lParam as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub MarginClick(Position as Integer, modifiers as Integer, Margin as ScintillaMarginMBS)
System.DebugLog CurrentMethodName
dim line as integer = me.LineFromPosition(Position)
if margin.Margin = 1 then // bookmark
dim old as integer = me.MarkerGet(line)
if old = 2 then // bit 2 is set for marker element 1
me.MarkerDelete(line, 1)
else
call me.MarkerAdd(line, 1)
end if
end if
End EventHandler
EventHandler Sub MarginRightClick(Position as Integer, modifiers as Integer, Margin as ScintillaMarginMBS)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub Modified(Position as Integer, modificationType as Integer, Text as String, length as Integer, linesAdded as Integer, line as Integer, foldLevelNow as Integer, foldLevelPrev as Integer, token as Integer, annotationLinesAdded as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub ModifyAttemptReadOnly()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub MouseEnter()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub MouseExit()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub MouseMove(X As Integer, Y As Integer)
'System.DebugLog CurrentMethodName
End EventHandler
EventHandler Function MouseWheel(X As Integer, Y As Integer, deltaX as Integer, deltaY as Integer) As Boolean
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub NeedsShown(Position as Integer, length as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub Open()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub Painted()
'System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub SavePointLeft()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub SavePointReached()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub ScaleFactorChanged(NewFactor as double)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub SelectionChanged(updated as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub StyleNeeded(Position as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub TextChanged(Position as Integer, modificationType as Integer, Text as String, length as Integer, linesAdded as Integer, line as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub URIDropped(text as String)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub UpdateUI(updated as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub UserListSelection(Position as Integer, Character as Integer, Text as String, listType as Integer, listCompletionMethod as Integer)
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub Zoom()
System.DebugLog CurrentMethodName
End EventHandler
End Control
Function EditFind() As Boolean
ShowFind
Return True
End Function
Function FileLoadBigText() As Boolean
// for small text, you can just assign text for control.
// but the ScintillaLoaderMBS class lets you load several Megabytes of text without blocking GUI
dim file as FolderItem = GetOpenFolderitem("")
if file <> nil then
dim loader as ScintillaLoaderMBS = ScintillaControl.CreateLoader
dim b as BinaryStream = BinaryStream.Open(file)
// you could do this in a thread via timer...
while not b.EndOfFile
dim t as string = b.Read(1000000)
dim e as integer = loader.AddData(t)
if e < 0 then
Break
MessageBox "Out of memory!"
return true
end if
wend
// finally
if loader.Finished then
dim LineCount as integer = ScintillaControl.LineCount
// make more room for bigger line numbers
if LineCount > 999999 then
ScintillaControl.Margin(0).Width = 35 + 27
elseif LineCount > 99999 then
ScintillaControl.Margin(0).Width = 35 + 18
elseif LineCount > 9999 then
ScintillaControl.Margin(0).Width = 35 + 9
end if
else
MessageBox "Failed?"
end if
end if
Return True
End Function
Sub AddWordsForAutoComplete(list as string)
Dim words() As String = Split(list, " ")
For Each word As String In words
AutoCompleteWords.Append word
Next
End Sub
Sub SetupHTML()
dim c as ScintillaControlMBS = me.ScintillaControl
c.InitializeLexer "hypertext" // HTML lexer does hypertext, xml and phpscript
// a ton of styles for html, JavaScript, VBScript, phyton and php
// we adapt styles from html.properties
// https://fossies.org/linux/gscite/html.properties
// https://searchcode.com/file/77957307/lexers/LexHTML.cxx/
Const SCE_H_DEFAULT = 0 // default Text
Const SCE_H_TAG = 1 // tag Tags
Const SCE_H_ERRORTAGUNKNOWN = 2 // error tag Unknown Tags
Const SCE_H_ATTRIBUTE = 3 // attribute Attributes
Const SCE_H_ATTRIBUTEUNKNOWN = 4 // error attribute Unknown Attributes
Const SCE_H_NUMBER = 5 // literal numeric Numbers
Const SCE_H_DOUBLESTRING = 6 // literal string Double quoted strings
Const SCE_H_SINGLESTRING = 7 // literal string Single quoted strings
Const SCE_H_OTHER = 8 // tag operator Other inside tag, including space and '='
Const SCE_H_COMMENT = 9 // comment Comment
Const SCE_H_ENTITY = 10 // literal Entities
Const SCE_H_TAGEND = 11 // tag XML style tag ends '/>'
Const SCE_H_XMLSTART = 12 // identifier XML identifier start '<?'
Const SCE_H_XMLEND = 13 // identifier XML identifier end '?>'
Const SCE_H_SCRIPT = 14 // error Internal state which should never be visible
Const SCE_H_ASP = 15 // preprocessor ASP <% ... %>
Const SCE_H_ASPAT = 16 // preprocessor ASP <% ... %>
Const SCE_H_CDATA = 17 // literal CDATA
Const SCE_H_QUESTION = 18 // preprocessor PHP
Const SCE_H_VALUE = 19 // literal string Unquoted values
Const SCE_H_XCCOMMENT = 20 // comment JSP Comment <%-- ... --%>
Const SCE_H_SGML_DEFAULT = 21 // default SGML tags <! ... >
Const SCE_H_SGML_COMMAND = 22 // preprocessor SGML command
Const SCE_H_SGML_1ST_PARAM = 23 // preprocessor SGML 1st param
Const SCE_H_SGML_DOUBLESTRING = 24 // literal string SGML double string
Const SCE_H_SGML_SIMPLESTRING = 25 // literal string SGML single string
Const SCE_H_SGML_ERROR = 26 // error SGML error
Const SCE_H_SGML_SPECIAL = 27 // literal SGML special (#XXXX type)
Const SCE_H_SGML_ENTITY = 28 // literal SGML entity
Const SCE_H_SGML_COMMENT = 29 // comment SGML comment
Const SCE_H_SGML_1ST_PARAM_COMMENT = 30 // error comment SGML first parameter - lexer internal. It is an error if any text is in this style.
Const SCE_H_SGML_BLOCK_DEFAULT = 31 // default SGML block
Const SCE_HJ_START = 40 // client javascript default JS Start - allows eol filled background to not start on same line as SCRIPT tag
Const SCE_HJ_DEFAULT = 41 // client javascript default JS Default
Const SCE_HJ_COMMENT = 42 // client javascript comment JS Comment
Const SCE_HJ_COMMENTLINE = 43 // client javascript comment line JS Line Comment
Const SCE_HJ_COMMENTDOC = 44 // client javascript comment documentation JS Doc comment
Const SCE_HJ_NUMBER = 45 // client javascript literal numeric JS Number
Const SCE_HJ_WORD = 46 // client javascript identifier JS Word
Const SCE_HJ_KEYWORD = 47 // client javascript keyword JS Keyword
Const SCE_HJ_DOUBLESTRING = 48 // client javascript literal string JS Double quoted string
Const SCE_HJ_SINGLESTRING = 49 // client javascript literal string JS Single quoted string
Const SCE_HJ_SYMBOLS = 50 // client javascript operator JS Symbols
Const SCE_HJ_STRINGEOL = 51 // client javascript error literal string JavaScript EOL
Const SCE_HJ_REGEX = 52 // JavaScript RegEx
Const SCE_HJA_START = 55 // server javascript default JS Start - allows eol filled background to not start on same line as SCRIPT tag
Const SCE_HJA_DEFAULT = 56 // server javascript default JS Default
Const SCE_HJA_COMMENT = 57 // server javascript comment JS Comment
Const SCE_HJA_COMMENTLINE = 58 // server javascript comment line JS Line Comment
Const SCE_HJA_COMMENTDOC = 59 // server javascript comment documentation JS Doc comment
Const SCE_HJA_NUMBER = 60 // server javascript literal numeric JS Number
Const SCE_HJA_WORD = 61 // server javascript identifier JS Word
Const SCE_HJA_KEYWORD = 62 // server javascript keyword JS Keyword
Const SCE_HJA_DOUBLESTRING = 63 // server javascript literal string JS Double quoted string
Const SCE_HJA_SINGLESTRING = 64 // server javascript literal string JS Single quoted string
Const SCE_HJA_SYMBOLS = 65 // server javascript operator JS Symbols
Const SCE_HJA_STRINGEOL = 66 // server javascript error literal string JavaScript EOL
Const SCE_HJA_REGEX = 67 // server javascript literal regex JavaScript RegEx
Const SCE_HB_START = 70 // client basic default Start
Const SCE_HB_DEFAULT = 71 // client basic default Default
Const SCE_HB_COMMENTLINE = 72 // client basic comment line Comment
Const SCE_HB_NUMBER = 73 // client basic literal numeric Number
Const SCE_HB_WORD = 74 // client basic keyword KeyWord
Const SCE_HB_STRING = 75 // client basic literal string String
Const SCE_HB_IDENTIFIER = 76 // client basic identifier Identifier
Const SCE_HB_STRINGEOL = 77 // client basic literal string Unterminated string
Const SCE_HBA_START = 80 // server basic default Start
Const SCE_HBA_DEFAULT = 81 // server basic default Default
Const SCE_HBA_COMMENTLINE = 82 // server basic comment line Comment
Const SCE_HBA_NUMBER = 83 // server basic literal numeric Number
Const SCE_HBA_WORD = 84 // server basic keyword KeyWord
Const SCE_HBA_STRING = 85 // server basic literal string String
Const SCE_HBA_IDENTIFIER = 86 // server basic identifier Identifier
Const SCE_HBA_STRINGEOL = 87 // server basic literal string Unterminated string
Const SCE_HP_START = 90 // client python default Embedded Python
Const SCE_HP_DEFAULT = 91 // client python default Embedded Python
Const SCE_HP_COMMENTLINE = 92 // client python comment line Comment
Const SCE_HP_NUMBER = 93 // client python literal numeric Number
Const SCE_HP_STRING = 94 // client python literal string String
Const SCE_HP_CHARACTER = 95 // client python literal string character Single quoted string
Const SCE_HP_WORD = 96 // client python keyword Keyword
Const SCE_HP_TRIPLE = 97 // client python literal string Triple quotes
Const SCE_HP_TRIPLEDOUBLE = 98 // client python literal string Triple double quotes
Const SCE_HP_CLASSNAME = 99 // client python identifier Class name definition
Const SCE_HP_DEFNAME = 100 // client python identifier Function or method name definition
Const SCE_HP_OPERATOR = 101 // client python operator Operators
Const SCE_HP_IDENTIFIER = 102 // client python identifier Identifiers
Const SCE_HPHP_COMPLEX_VARIABLE = 104 // server php identifier PHP complex variable
Const SCE_HPA_START = 105 // server python default ASP Python
Const SCE_HPA_DEFAULT = 106 // server python default ASP Python
Const SCE_HPA_COMMENTLINE = 107 // server python comment line Comment
Const SCE_HPA_NUMBER = 108 // server python literal numeric Number
Const SCE_HPA_STRING = 109 // server python literal string String
Const SCE_HPA_CHARACTER = 110 // server python literal string character Single quoted string
Const SCE_HPA_WORD = 111 // server python keyword Keyword
Const SCE_HPA_TRIPLE = 112 // server python literal string Triple quotes
Const SCE_HPA_TRIPLEDOUBLE = 113 // server python literal string Triple double quotes
Const SCE_HPA_CLASSNAME = 114 // server python identifier Class name definition
Const SCE_HPA_DEFNAME = 115 // server python identifier Function or method name definition
Const SCE_HPA_OPERATOR = 116 // server python operator Operators
Const SCE_HPA_IDENTIFIER = 117 // server python identifier Identifiers
Const SCE_HPHP_DEFAULT = 118 // server php default Default
Const SCE_HPHP_HSTRING = 119 // server php literal string Double quoted String
Const SCE_HPHP_SIMPLESTRING = 120 // server php literal string Single quoted string
Const SCE_HPHP_WORD = 121 // server php keyword Keyword
Const SCE_HPHP_NUMBER = 122 // server php literal numeric Number
Const SCE_HPHP_VARIABLE = 123 // server php identifier Variable
Const SCE_HPHP_COMMENT = 124 // server php comment Comment
Const SCE_HPHP_COMMENTLINE = 125 // server php comment line One line comment
Const SCE_HPHP_HSTRING_VARIABLE = 126 // server php literal string identifier PHP variable in double quoted string
Const SCE_HPHP_OPERATOR = 127 // server php operator PHP operator
Const hypertextElements = "a abbr acronym address applet area b base basefont bdo bgsound big blink blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em fieldset Font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img Input ins isindex kbd label legend li link listing map marquee menu menuitem meta multicol nobr noembed noframes noscript Object ol optgroup option p param plaintext pre q s samp script Select small spacer span strike strong style Sub sup table tbody td textarea tfoot th thead title tr tt u ul var xml xmlns xmp "
Const hypertextAttributes = "abbr accept-charset accept accesskey action align alink allowtransparency alt archive axis background bgcolor border bordercolor bottommargin cellpadding cellspacing char charoff charset checked cite class classid clear codebase codetype color cols colspan compact content coords data datafld dataformatas datapagesize datasrc datetime declare defer dir disabled enctype event face for frame frameborder framespacing headers height href hreflang hspace http-equiv id is ismap itemid itemprop itemref itemscope itemtype label lang language leftmargin link longdesc lowsrc marginwidth marginheight maxlength media method methods multiple name nohref noresize noshade nowrap object onblur onchange onclick ondblclick onfocus onkeydown onkeypress onkeyup onload onmousedown onmousemove onmouseover onmouseout onmouseup onreset onselect onsubmit onunload profile prompt readonly rel rev rightmargin rows rowspan rules scheme scope scrolling selected shape size span src standby start style summary tabindex target text title topmargin type usemap urn valign value valuetype version vlink vspace width text password checkbox radio submit reset file hidden image ^data- "
Const html5elements = "address article aside audio base bdi canvas command details datalist dialog embed figure figcaption footer header hgroup keygen main mark menu meter nav output picture progress ruby rb rt rtc rp section source template track time video wbr "
Const html5attributes = "allowfullscreen allowpaymentrequest async autocomplete autofocus autoplay controls contenteditable contextmenu crossorigin default dirname download draggable form formaction formenctype formmethod formnovalidate formtarget high kind list low loop manifest max muted min minlength nonce novalidate open optimum onabort onaddtrack onafterprint onauxclick onbeforeprint onbeforeunload oncancel oncanplay oncanplaythrough onclose oncopy oncuechange oncut ondrag ondragend ondragenter ondragexit ondragleave ondragover ondragstart ondrop ondurationchange onemptied onended onerror onenter onexit onhashchange oninput oninvalid onlanguagechange onloadeddata onloadedmetadata onloadend onloadstart onmessage onmouseenter onmouseleave onoffline ononline onpagehide onpageshow onpaste onpause onplay onplaying onprogress onpopstate onratechange onremovetrack onresize onrejectionhandled onresize onscroll onseeked onseeking onshow onstalled onstorage onsuspend ontimeupdate ontoggle onunhandledrejection onvolumechange onwaiting onwheel pattern placeholder poster preload referrerpolicy required reversed role sandbox scoped seamless sizes spellcheck srcdoc srclang srcset step translate typemustmatch wrap "
Const keywordclassHypertext = hypertextElements+hypertextAttributes+html5elements+html5attributes+"public !doctype"
Const keywordclassJavascript = "abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends final finally float for function goto if implements import in instanceof int interface long native new package private protected public return short static super switch synchronized this throw throws transient try typeof var void volatile while with "
// we skip VBScript, PHP, SGML and Python here.
// we could also do html
AddWordsForAutoComplete keywordclassHypertext
AddWordsForAutoComplete keywordclassJavascript
// Keywords to highlight. Indices are:
// 0: HTML elements and attributes
// 1: JavaScript keywords
// 2: VBScript keywords
// 3: Python keywords
// 4: PHP keywords
// 5: SGML and DTD keywords
c.KeyWords(0) = keywordclassHypertext
c.KeyWords(1) = keywordclassJavascript
Dim Factor As Double = 1
Dim style As ScintillaStyleMBS = c.Style(ScintillaStyleMBS.kStylesCommonDefault)
// Colors and styles for various syntactic elements. First the default style.
style.Font = "Helvetica"
// c.StyleFont(c.kStylesCommonDefault) = "Monospac821 BT" // Very pleasing programmer's font.
#If TargetWindows Then
style.size = 10 // on Windows it is 96 dpi insteasd of 72dpi
Factor = Self.ScaleFactor // and we have to do margins *2
#Else
Factor = 1
style.size = 14
#EndIf
style.ForeColor = &c000000
c.StyleClearAll
// normal Text
c.Style(SCE_H_DEFAULT).ForeColor = &c000000
// Tags
c.Style(SCE_H_TAG).ForeColor = &c000080
// Unknown Tags
c.Style(SCE_H_ERRORTAGUNKNOWN).ForeColor = &cFF0000
// Attributes
c.Style(SCE_H_ATTRIBUTE).ForeColor = &c008080
// Unknown Attributes
c.Style(SCE_H_ATTRIBUTEUNKNOWN).BackColor = &cFF0000
// Numbers
c.Style(SCE_H_NUMBER).ForeColor = &c378EA5
// Double/single quoted strings
c.Style(SCE_H_DOUBLESTRING).ForeColor = &cFFAA3E
c.Style(SCE_H_SINGLESTRING).ForeColor = &cFFAA3E
// Other inside tag, including space and '='
c.Style(SCE_H_OTHER).ForeColor = &c800080
// Comment
c.Style(SCE_H_COMMENT).ForeColor = &c808000
// Entities
c.Style(SCE_H_ENTITY).ForeColor = &c800080
// XML style tag ends '/>'
c.Style(SCE_H_TAGEND).ForeColor = &c000080
// XML identifier start '<?'
c.Style(SCE_H_XMLSTART).ForeColor = &c0000FF
// XML identifier end '?>'
c.Style(SCE_H_XMLEND).ForeColor = &c0000FF
// Line number style.
c.Style(ScintillaStyleMBS.kStylesCommonLineNumber).ForeColor = &cF0F0F0
c.Style(ScintillaStyleMBS.kStylesCommonLineNumber).BackColor = &c808080
c.Margin(0).Type = ScintillaMarginMBS.kMarginTypeNumber
c.Margin(0).Width = 35 * Factor
// Marker for bookmark
c.Margin(1).Width = 16 * Factor
c.Margin(1).Sensitive = true // allow click
// Some special lexer properties.
c.PropertyValue("fold") = "1"
c.PropertyValue("fold.html") = "1"
c.PropertyValue("fold.hypertext.comment") = "1"
// you can query property name list for this lexer
Dim PropertyNames() As String = c.PropertyNames.Split(EndOfLine.UNIX)
// and learn what keyword sets do
Dim DescribeKeyWordSets() As String = c.DescribeKeyWordSets.Split(EndOfLine.UNIX)
// and query details on each property
Dim FoldHTMLPropertyDescription As String = c.DescribeProperty("fold.html")
'Break // stop here to read properties
// Folder setup.
c.Margin(2).Width = 16
c.Margin(2).Mask = c.kMaskFolders
c.Margin(2).Sensitive = True
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderOpen).Symbol = ScintillaMarkerMBS.kMarkerSymbolBoxMinus
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolder).Symbol = ScintillaMarkerMBS.kMarkerSymbolBoxPlus
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderSub).Symbol = ScintillaMarkerMBS.kMarkerSymbolVLine
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderTail).Symbol = ScintillaMarkerMBS.kMarkerSymbolLCorner
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderEnd).Symbol = ScintillaMarkerMBS.kMarkerSymbolBoxPlusConnected
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderOpenMid).Symbol = ScintillaMarkerMBS.kMarkerSymbolBoxMinusConnected
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderMidTail).Symbol = ScintillaMarkerMBS.kMarkerSymbolTCorner
For n As Integer = 25 To 31
// Markers 25..31 are reserved for folding.
c.Marker(n).ForeColor = &cFFFFFF
c.Marker(n).BackColor = &c000000
Next
// Init markers & indicators for highlighting of syntax errors.
c.Indicator(0).ForeColor = &cFF0000
c.Indicator(0).Under = True
c.Indicator(0).Style = ScintillaIndicatorMBS.kIndicatorStyleSquiggle
c.Marker(0).BackColor = &cB1151C
c.SetSelBackColor(True, Color.HighlightColor)
// define the marker for breakpoint
c.Marker(1).ForeColor = &cFF0000
c.Marker(1).Symbol = ScintillaMarkerMBS.kMarkerSymbolBookmark
c.AutoCompleteIgnoreCase = True
// Uncomment if you wanna see auto wrapping in action.
// c.WrapMode = c.kWrapWord
c.setStatusText "Operation complete"
c.Text = SampleHTML
End Sub
Sub SetupMySQL()
dim c as ScintillaControlMBS = me.ScintillaControl
c.InitializeLexer "mysql"
Const SCE_MYSQL_DEFAULT = 0
Const SCE_MYSQL_COMMENT = 1
Const SCE_MYSQL_COMMENTLINE = 2
Const SCE_MYSQL_VARIABLE = 3
Const SCE_MYSQL_SYSTEMVARIABLE = 4
Const SCE_MYSQL_KNOWNSYSTEMVARIABLE = 5
Const SCE_MYSQL_NUMBER = 6
Const SCE_MYSQL_MAJORKEYWORD = 7
Const SCE_MYSQL_KEYWORD = 8
Const SCE_MYSQL_DATABASEOBJECT = 9
Const SCE_MYSQL_PROCEDUREKEYWORD = 10
Const SCE_MYSQL_STRING = 11
Const SCE_MYSQL_SQSTRING = 12
Const SCE_MYSQL_DQSTRING = 13
Const SCE_MYSQL_OPERATOR = 14
Const SCE_MYSQL_FUNCTION = 15
Const SCE_MYSQL_IDENTIFIER = 16
Const SCE_MYSQL_QUOTEDIDENTIFIER = 17
Const SCE_MYSQL_USER1 = 18
Const SCE_MYSQL_USER2 = 19
Const SCE_MYSQL_USER3 = 20
Const SCE_MYSQL_HIDDENCOMMAND = 21
Const SCE_MYSQL_PLACEHOLDER = 22
Dim major_keywords As String = _
"accessible add all alter analyze and as asc asensitive "+_
"before between bigint binary blob both by "+_
"call cascade case change char character check collate column condition connection constraint "+_
"continue convert create cross current_date current_time current_timestamp current_user cursor "+_
"database databases day_hour day_microsecond day_minute day_second dec decimal declare default "+_
"delayed delete desc describe deterministic distinct distinctrow div double drop dual "+_
"each else elseif enclosed escaped exists exit explain "+_
"false fetch float float4 float8 for force foreign from fulltext "+_
"goto grant group "+_
"having high_priority hour_microsecond hour_minute hour_second "+_
"if ignore in index infile inner inout insensitive insert int int1 int2 int3 int4 int8 integer "+_
"interval into is iterate "+_
"join "+_
"key keys kill "+_
"label leading leave left like limit linear lines load localtime localtimestamp lock long "+_
"longblob longtext loop low_priority "+_
"master_ssl_verify_server_cert match mediumblob mediumint mediumtext middleint minute_microsecond "+_
"minute_second mod modifies "+_
"natural not no_write_to_binlog null numeric "+_
"on optimize option optionally or order out outer outfile "+_
"precision primary procedure purge "+_
"range read reads read_only read_write real references regexp release rename repeat replace "+_
"require restrict return revoke right rlike "+_
"schema schemas second_microsecond select sensitive separator set show smallint spatial specific "+_
"sql sqlexception sqlstate sqlwarning sql_big_result sql_calc_found_rows sql_small_result ssl "+_
"starting straight_join "+_
"table terminated then tinyblob tinyint tinytext to trailing trigger true "+_
"undo union unique unlock unsigned update upgrade usage use using utc_date utc_time utc_timestamp "+_
"values varbinary varchar varcharacter varying "+_
"when where while with write "+_
"xor "+_
"year_month "+_
"zerofill"
// Not reserved words but intrinsic part of procedure definitions.
Dim procedure_keywords As String = "begin comment end"
// Definition of keywords only used by clients, not the server itself.
Dim client_keywords As String = "delimiter"
// Definition of own keywords, not used by MySQL.
Dim user_keywords As String = "edit"
AddWordsForAutoComplete major_keywords
AddWordsForAutoComplete procedure_keywords
AddWordsForAutoComplete client_keywords
AddWordsForAutoComplete user_keywords
// Keywords to highlight. Indices are:
// 0 - Major keywords (reserved keywords)
// 1 - Normal keywords (everything not reserved but integral part of the language)
// 2 - Database objects
// 3 - Function keywords
// 4 - System variable keywords
// 5 - Procedure keywords (keywords used in procedures like "begin" and "end")
// 6..8 - User keywords 1..3
c.KeyWords(0) = major_keywords
c.KeyWords(5) = procedure_keywords
c.KeyWords(6) = client_keywords
c.KeyWords(7) = user_keywords
Dim Factor As Double = 1
Dim style As ScintillaStyleMBS = c.Style(ScintillaStyleMBS.kStylesCommonDefault)
// Colors and styles for various syntactic elements. First the default style.
style.Font = "Helvetica"
// c.StyleFont(c.kStylesCommonDefault) = "Monospac821 BT" // Very pleasing programmer's font.
#If TargetWindows Then
style.size = 10 // on Windows it is 96 dpi insteasd of 72dpi
Factor = Self.ScaleFactor // and we have to do margins *2
#Else
Factor = 1
style.size = 14
#EndIf
style.ForeColor = &c000000
c.StyleClearAll
c.Style(SCE_MYSQL_DEFAULT).ForeColor = &c000000
c.Style(SCE_MYSQL_COMMENT).ForeColor = &c097BF7
c.Style(SCE_MYSQL_COMMENTLINE).ForeColor = &c097BF7
c.Style(SCE_MYSQL_HIDDENCOMMAND).ForeColor = &c097BF7
c.Style(SCE_MYSQL_HIDDENCOMMAND).BackColor = &cF0F0F0
c.Style(SCE_MYSQL_VARIABLE).ForeColor = &c378EA5
c.Style(SCE_MYSQL_SYSTEMVARIABLE).ForeColor = &c378EA5
c.Style(SCE_MYSQL_KNOWNSYSTEMVARIABLE).ForeColor = &c3A37A5
c.Style(SCE_MYSQL_NUMBER).ForeColor = &c7F7F00
c.Style(SCE_MYSQL_SQSTRING).ForeColor = &cFFAA3E
// Note: if we were using ANSI quotes we would set the DQSTRING to the same color as the
// the back tick string.
c.Style(SCE_MYSQL_DQSTRING).ForeColor = &c274A6D
// Keyword highlighting.
c.Style(SCE_MYSQL_MAJORKEYWORD).ForeColor = &c007F00
c.Style(SCE_MYSQL_MAJORKEYWORD).bold = True
c.Style(SCE_MYSQL_KEYWORD).ForeColor = &c007F00
c.Style(SCE_MYSQL_KEYWORD).bold = True
c.Style(SCE_MYSQL_PROCEDUREKEYWORD).ForeColor = &c56007F
c.Style(SCE_MYSQL_PROCEDUREKEYWORD).bold = True
c.Style(SCE_MYSQL_USER1).ForeColor = &c808080
c.Style(SCE_MYSQL_USER2).ForeColor = &c808080
c.Style(SCE_MYSQL_USER2).BackColor = &cF0E0E0
// The following 3 styles have no impact as we did not set a keyword list for any of them.
c.Style(SCE_MYSQL_DATABASEOBJECT).ForeColor = &cFF0000
c.Style(SCE_MYSQL_FUNCTION).ForeColor = &cFF0000
c.Style(SCE_MYSQL_IDENTIFIER).ForeColor = &c000000
c.Style(SCE_MYSQL_QUOTEDIDENTIFIER).ForeColor = &c274A6D
c.Style(SCE_MYSQL_OPERATOR).Bold = True
// Line number style.
c.Style(ScintillaStyleMBS.kStylesCommonLineNumber).ForeColor = &cF0F0F0
c.Style(ScintillaStyleMBS.kStylesCommonLineNumber).BackColor = &c808080
c.Margin(0).Type = ScintillaMarginMBS.kMarginTypeNumber
c.Margin(0).Width = 35 * Factor
// Marker for bookmark
c.Margin(1).Width = 16 * Factor
c.Margin(1).Sensitive = true // allow click
// Some special lexer properties.
c.PropertyValue("fold") = "1"
c.PropertyValue("fold.compact") = "0"
c.PropertyValue("fold.comment") = "1"
c.PropertyValue("fold.preprocessor") = "1"
// Folder setup.
c.Margin(2).Width = 16
c.Margin(2).Mask = c.kMaskFolders
c.Margin(2).Sensitive = True
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderOpen).Symbol = ScintillaMarkerMBS.kMarkerSymbolBoxMinus
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolder).Symbol = ScintillaMarkerMBS.kMarkerSymbolBoxPlus
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderSub).Symbol = ScintillaMarkerMBS.kMarkerSymbolVLine
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderTail).Symbol = ScintillaMarkerMBS.kMarkerSymbolLCorner
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderEnd).Symbol = ScintillaMarkerMBS.kMarkerSymbolBoxPlusConnected
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderOpenMid).Symbol = ScintillaMarkerMBS.kMarkerSymbolBoxMinusConnected
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderMidTail).Symbol = ScintillaMarkerMBS.kMarkerSymbolTCorner
For n As Integer = 25 To 31
// Markers 25..31 are reserved for folding.
c.Marker(n).ForeColor = &cFFFFFF
c.Marker(n).BackColor = &c000000
Next
// Init markers & indicators for highlighting of syntax errors.
c.Indicator(0).ForeColor = &cFF0000
c.Indicator(0).Under = True
c.Indicator(0).Style = ScintillaIndicatorMBS.kIndicatorStyleSquiggle
c.Marker(0).BackColor = &cB1151C
c.SetSelBackColor(True, Color.HighlightColor)
// define the marker for breakpoint
c.Marker(1).ForeColor = &cFF0000
c.Marker(1).Symbol = ScintillaMarkerMBS.kMarkerSymbolBookmark
c.AutoCompleteIgnoreCase = True
// Uncomment if you wanna see auto wrapping in action.
// c.WrapMode = c.kWrapWord
c.setStatusText "Operation complete"
c.Text = TestData
End Sub
Sub SetupXojo()
dim c as ScintillaControlMBS = me.ScintillaControl
// there is no built-in xojo lexer, so we utility a close matching one, e.g. the one for Visual Basic
'c.InitializeLexer "freebasic"
'c.InitializeLexer "purebasic" // misses ' and #pragma
'c.InitializeLexer "blitzbasic" // misses ' and #pragma
'c.InitializeLexer "vb" // does #pragma
'c.InitializeLexer "vbscript"
// if you got newer lexer with Xojo
c.InitializeLexer "xojo"
// all miss the // comments, so we may eventually need to make an extra one.
Const SCLEX_VB = 8
Const SCLEX_VBSCRIPT = 28
Const SCLEX_POWERBASIC = 51
Const SCLEX_BLITZBASIC = 66
Const SCLEX_FREEBASIC = 75
Const SCE_B_DEFAULT = 0
Const SCE_B_COMMENT = 1
Const SCE_B_NUMBER = 2
Const SCE_B_KEYWORD = 3
Const SCE_B_STRING = 4
Const SCE_B_PREPROCESSOR = 5
Const SCE_B_OPERATOR = 6
Const SCE_B_IDENTIFIER = 7
Const SCE_B_DATE = 8
Const SCE_B_STRINGEOL = 9
Const SCE_B_KEYWORD2 = 10
Const SCE_B_KEYWORD3 = 11
Const SCE_B_KEYWORD4 = 12
Const SCE_B_CONSTANT = 13
Const SCE_B_ASM = 14
Const SCE_B_LABEL = 15
Const SCE_B_ERROR = 16
Const SCE_B_HEXNUMBER = 17
Const SCE_B_BINNUMBER = 18
Const SCE_B_COMMENTBLOCK = 19
Const SCE_B_DOCLINE = 20
Const SCE_B_DOCBLOCK = 21
Const SCE_B_DOCKEYWORD = 22
Dim Factor As Double = 1
Dim ReservedWords As String = "addhandler addressof aggregates and array as assigns async attributes await break byref byval call case catch class const continue ctype declare delegate dim do downto each else elseif end enum event exception exit extends false finally for function global goto handles if implements in inherits interface is isa lib loop me mod module namespace new next nil not object of optional or paramarray private property [[protected] public raise raiseevent redim rem removehandler return select self shared soft static step structure sub super then to true try until using var weakaddressof wend while with xor"
Dim DataTypes As String = "string integer double"
AddWordsForAutoComplete ReservedWords
AddWordsForAutoComplete DataTypes
// Keywords to highlight.
c.KeyWords(0) = ReservedWords
c.KeyWords(1) = DataTypes
Dim style As ScintillaStyleMBS = c.Style(ScintillaStyleMBS.kStylesCommonDefault)
// Colors and styles for various syntactic elements. First the default style.
style.Font = "Helvetica"
// c.StyleFont(c.kStylesCommonDefault) = "Monospac821 BT" // Very pleasing programmer's font.
#If TargetWindows Then
style.size = 10 // on Windows it is 96 dpi insteasd of 72dpi
Factor = Self.ScaleFactor // and we have to do margins *2
#Else
Factor = 1
style.size = 14
#endif
style.ForeColor = &c000000
c.StyleClearAll
c.Style(SCE_B_DEFAULT).ForeColor = &c000000
c.Style(SCE_B_KEYWORD).ForeColor = &c0A5FFE
c.Style(SCE_B_KEYWORD).bold = True
c.Style(SCE_B_KEYWORD2).ForeColor = &c1A5FFE
c.Style(SCE_B_KEYWORD2).bold = True
c.Style(SCE_B_STRING).ForeColor = &c9D33D5
c.Style(SCE_B_NUMBER).ForeColor = &c28C732
c.Style(SCE_B_COMMENT).ForeColor = &c7D1012
c.Style(SCE_B_COMMENTBLOCK).ForeColor = &c7D1012
c.Style(SCE_B_IDENTIFIER).ForeColor = &c333333
c.Style(SCE_B_OPERATOR).ForeColor = &c333333
c.Style(SCE_B_OPERATOR).bold = True
c.Style(SCE_B_PREPROCESSOR).ForeColor = &c3A37A5
c.Style(SCE_B_DATE).ForeColor = &c9D33D5 // same as string
c.Style(SCE_B_STRINGEOL).ForeColor = &c9D33D5 // same as string
c.Style(SCE_B_HEXNUMBER).ForeColor = &c28C732 // same as number
c.Style(SCE_B_BINNUMBER).ForeColor = &c28C732 // same as number
// Line number style.
c.Style(ScintillaStyleMBS.kStylesCommonLineNumber).ForeColor = &cF0F0F0
c.Style(ScintillaStyleMBS.kStylesCommonLineNumber).BackColor = &c808080
c.Margin(0).Type = ScintillaMarginMBS.kMarginTypeNumber
c.Margin(0).Width = 35 * Factor
// Markers.
c.Margin(1).Width = 16 * Factor
c.Margin(1).Sensitive = true // allow click
// Some special lexer properties.
c.PropertyValue("fold") = "1"
c.PropertyValue("fold.compact") = "0"
c.PropertyValue("fold.comment") = "1"
c.PropertyValue("fold.preprocessor") = "1"
// Folder setup.
c.Margin(2).Width = 16
c.Margin(2).Mask = c.kMaskFolders
c.Margin(2).Sensitive = True
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderOpen).Symbol = ScintillaMarkerMBS.kMarkerSymbolBoxMinus
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolder).Symbol = ScintillaMarkerMBS.kMarkerSymbolBoxPlus
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderSub).Symbol = ScintillaMarkerMBS.kMarkerSymbolVLine
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderTail).Symbol = ScintillaMarkerMBS.kMarkerSymbolLCorner
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderEnd).Symbol = ScintillaMarkerMBS.kMarkerSymbolBoxPlusConnected
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderOpenMid).Symbol = ScintillaMarkerMBS.kMarkerSymbolBoxMinusConnected
c.Marker(ScintillaMarkerMBS.kMarkerOutlineFolderMidTail).Symbol = ScintillaMarkerMBS.kMarkerSymbolTCorner
For n As Integer = 25 To 31
// Markers 25..31 are reserved for folding.
c.Marker(n).ForeColor = &cFFFFFF
c.Marker(n).BackColor = &c000000
Next
// Init markers & indicators for highlighting of syntax errors.
c.Indicator(0).ForeColor = &cFF0000
c.Indicator(0).Under = True
c.Indicator(0).Style = ScintillaIndicatorMBS.kIndicatorStyleSquiggle
c.Marker(0).BackColor = &cB1151C
c.SetSelBackColor(True, Color.HighlightColor)
// define the marker for breakpoint
c.Marker(1).ForeColor = &cFF0000
c.Marker(1).Symbol = ScintillaMarkerMBS.kMarkerSymbolBookmark
// more possible options
c.AutoCompleteIgnoreCase = True
If False Then
c.EOLMode = c.kEndOfLineLf // Unix
c.ViewEOL = True
c.Zoom = 4
End If
If False Then
// custom line wrapping
// Set the Text wrapping mode To word wrap
c.WrapMode = c.kWrapWord
// Set the Text wrapping mode visual indication
c.WrapVisualFlagsLocation = c.kWrapVisualLocationEndByText
// Set the Text wrapping To indent the wrapped lines
c.WrapIndentMode = c.kWrapIndentModeSame
End If
If False Then
// custom edge marker
// Set the edge marker's position and set it to color the background
// when a line goes over the limit Of 50 characters
c.EdgeMode = c.kEdgeVisualStyleBackground
c.EdgeColumn = 50
c.EdgeColor = &cff00ff00
End If
If False Then
// custom indentation
//Set indentation With spaces instead Of tabs
c.UseTabs = False
// Set the tab width To 4 spaces
c.TabWidth = 4
// Set tab indent mode
c.TabIndents = true
// Set autoindentation mode To maintain the indentation
// level Of the previous line (the editor's lexer HAS
// To be disabled)
c.Indent = 4
// Make the backspace jump back To the tab width guides
// instead Of deleting one character, but only when
// there are ONLY whitespaces on the Left side Of the
// cursor
c.BackSpaceUnIndents = True
// Set indentation guides To be visible
c.IndentationGuides = c.kIndentViewLookBoth
End If
If False Then
// Customization - CARET (the blinking cursor indicator)
// Set the caret color to red
c.CaretForeColor = &cffff0000
// Enable and set the caret line background color to slightly transparent blue
c.CaretLineVisible = True
c.CaretLineBackColor = &c7f0000ff
// Set the caret width of 4 pixels
c.CaretWidth = 4
end if
// now put in some text
'c.ReadOnly = true
c.setStatusText "Operation complete"
c.Text = testXojo
End Sub
Sub ShowFind()
if myFindWindow <> nil then
myFindWindow.show
else
dim w as new FindWindow
w.parent = self
w.control = self.ScintillaControl
w.top = self.top + 100
w.Left = self.left + self.Width - 100
w.show
self.myFindWindow = w
end if
End Sub
Sub StartAutoComplete()
Dim editor As ScintillaControlMBS = ScintillaControl
'Dim CurrentPosition As Integer = editor.Position
'Dim lineCurrentPos As Integer = editor.LineFromPosition(CurrentPosition)
'Dim lineStart As Integer = editor.LineStart(lineCurrentPos)
'Dim lineEnd As Integer = editor.LineStart(lineCurrentPos + 1)
Dim line As String = editor.CurrentLine
Dim positon As Integer = editor.GetCaretInLine
Dim wordCharacters As String = editor.WordChars
Dim startword As Integer = positon
// Autocompletion of pure numbers is mostly an annoyance
Dim allNumber As Boolean = True
Dim Numbers As String = "0123456789"
While (startword > 0 And wordCharacters.IndexOfBytes(line.MiddleBytes(startword-1, 1)) >= 0)
startword = startword - 1
Dim c As String = line.MiddleBytes(startword, 1)
If Numbers.IndexOf(c) < 0 Then
// not a number
allNumber = False
End If
Wend
If startword = positon Or allNumber Then
// nothing to do
Return
End If
// build word list
Dim root As String = line.MiddleBytes(startword, positon - startword)
Dim rootLength As Integer = root.Bytes
// simple auto complete based on key words
Dim words() As String
For Each n As String In AutoCompleteWords
If n.Bytes > rootLength And n.LeftB(rootLength) = root Then
words.Append n
End If
Next
If words.Ubound = -1 Then
// no words
editor.AutoCompleteCancel
Return
Else
Const autoCompleteVisibleItemCount = 9
Dim wordList As String = Join(Words, " ")
editor.AutoCompleteMaxHeight = autoCompleteVisibleItemCount
editor.AutoCompleteSeparator = 32
editor.AutoCompleteShow(rootLength, wordList)
End If
End Sub
Property AutoCompleteWords() As string
Property myFindWindow As FindWindow
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileLoadBigText = "Load Big Text..."
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
MenuItem UntitledSeparator = "-"
MenuItem EditFind = "Find"
End MenuBar
ExternalFile TestData
End ExternalFile
ExternalFile testXojo
End ExternalFile
Module Utils
Function GetCaretInLine(extends editor As ScintillaControlMBS) As Integer
// find position within line
Dim caret As Integer = editor.Position
Dim line As Integer = editor.LineFromPosition(caret)
Dim lineStart As Integer = editor.LineStart(line)
Return caret - lineStart
End Function
End Module
Class FindWindow Inherits Window
Control SearchLabel Inherits Label
ControlInstance SearchLabel Inherits Label
End Control
Control FindField Inherits TextField
ControlInstance FindField Inherits TextField
EventHandler Function KeyDown(Key As String) As Boolean
if asc(key) = 3 or asc(key) = 13 then
if me.Text.Length > 0 then
find
return true
end if
end if
End EventHandler
EventHandler Sub TextChange()
FindButton.Enabled = me.Text.Length > 0
ReplaceButton.Enabled = me.Text.Length > 0
End EventHandler
End Control
Control ReplaceLabel Inherits Label
ControlInstance ReplaceLabel Inherits Label
End Control
Control ReplaceField Inherits TextField
ControlInstance ReplaceField Inherits TextField
End Control
Control CheckMatchCase Inherits CheckBox
ControlInstance CheckMatchCase Inherits CheckBox
EventHandler Sub Action()
dim Flag as Integer = ScintillaControlMBS.kFindOptionMatchCase
if me.Value then
SearchFlags = Bitwise.BitOr(SearchFlags, Flag)
else
SearchFlags = Bitwise.BitAnd(SearchFlags, Bitwise.OnesComplement(Flag))
end if
End EventHandler
End Control
Control CheckWholeWord Inherits CheckBox
ControlInstance CheckWholeWord Inherits CheckBox
EventHandler Sub Action()
dim Flag as Integer = ScintillaControlMBS.kFindOptionWholeWord
if me.Value then
SearchFlags = Bitwise.BitOr(SearchFlags, Flag)
else
SearchFlags = Bitwise.BitAnd(SearchFlags, Bitwise.OnesComplement(Flag))
end if
End EventHandler
End Control
Control CheckWordStart Inherits CheckBox
ControlInstance CheckWordStart Inherits CheckBox
EventHandler Sub Action()
dim Flag as Integer = ScintillaControlMBS.kFindOptionWordStart
if me.Value then
SearchFlags = Bitwise.BitOr(SearchFlags, Flag)
else
SearchFlags = Bitwise.BitAnd(SearchFlags, Bitwise.OnesComplement(Flag))
end if
End EventHandler
End Control
Control CheckRegEx Inherits CheckBox
ControlInstance CheckRegEx Inherits CheckBox
EventHandler Sub Action()
dim Flag as Integer = ScintillaControlMBS.kFindOptionRegExp
if me.Value then
SearchFlags = Bitwise.BitOr(SearchFlags, Flag)
else
SearchFlags = Bitwise.BitAnd(SearchFlags, Bitwise.OnesComplement(Flag))
end if
End EventHandler
End Control
Control FindButton Inherits PushButton
ControlInstance FindButton Inherits PushButton
EventHandler Sub Action()
NextPos = 0
Find
End EventHandler
End Control
Control NextButton Inherits PushButton
ControlInstance NextButton Inherits PushButton
EventHandler Sub Action()
Find
End EventHandler
End Control
Control ReplaceButton Inherits PushButton
ControlInstance ReplaceButton Inherits PushButton
EventHandler Sub Action()
control.TargetStart = control.SelectionStart
control.TargetEnd = control.SelectionEnd
control.SearchFlags = SearchFlags
dim pos as integer
if CheckRegEx.Value then
pos = control.ReplaceTargetRE(ReplaceField.Text)
else
pos = control.ReplaceTarget(ReplaceField.Text)
end if
me.Enabled = false
dim RangeStart as integer = control.TargetStart
dim RangeEnd as integer = control.TargetEnd
control.SelectionStart = RangeStart
control.SelectionEnd = RangeEnd
NextPos = RangeEnd
End EventHandler
End Control
EventHandler Sub Close()
if parent <> nil then
parent.myFindWindow = nil
end if
parent = nil
control = nil
End EventHandler
EventHandler Sub Open()
End EventHandler
Sub Find()
dim RangeStart as integer = NextPos
dim RangeEnd as integer = control.Length
dim pos as integer = control.FindText(SearchFlags, FindField.Text, RangeStart, RangeEnd)
if pos < 0 then
// failed
beep
NextButton.Enabled = False
ReplaceButton.Enabled = false
else
// found
control.SetSelection RangeEnd, RangeStart
// scroll to make sure this is visible
'control.ScrollCaret
control.ScrollRange RangeEnd, RangeStart
NextPos = RangeEnd
NextButton.Enabled = true
ReplaceButton.Enabled = true
end if
End Sub
Property NextPos As Integer
Property Parent As ScintillaWindow
Property SearchFlags As Integer
Property control As ScintillaControlMBS
End Class
End Project
See also:
The items on this page are in the following plugins: MBS Scintilla Plugin.
