Platforms to show: All Mac Windows Linux Cross-Platform
/Scintilla/ScintillaTest Markdown
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Scintilla/ScintillaTest Markdown
This example is the version from Sat, 20th Jan 2023.
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Scintilla/ScintillaTest Markdown
This example is the version from Sat, 20th Jan 2023.
Project "ScintillaTest Markdown.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
Dim wM As New ScintillaWindow
wM.SetupMarkdown
wM.Title = "Scintilla MarkDown 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 SampleMarkDown = "Test MarkDown\n\n# h1 Heading 8-)\n## h2 Heading\n### h3 Heading\n#### h4 Heading\n##### h5 Heading\n###### h6 Heading\n\n\n## Horizontal Rules\n\n___\n\n---\n\n***\n\n\n## Typographic replacements\n\nEnable typographer option to see result.\n\n(c) (C) (r) (R) (tm) (TM) (p) (P) +-\n\ntest.. test... test..... test?..... test!....\n\n!!!!!! ???? ,, -- ---\n\n""Smartypants, double quotes"" and 'single quotes'\n\n\n## Emphasis\n\n**This is bold text**\n\n__This is bold text__\n\n*This is italic text*\n\n_This is italic text_\n\n~~Strikethrough~~\n\n\n## Blockquotes\n\n\n> Blockquotes can also be nested...\n>> ...by using additional greater-than signs right next to each other...\n> > > ...or with spaces between arrows.\n\n\n## Lists\n\nUnordered\n\n+ Create a list by starting a line with `+`, `-`, or `*`\n+ Sub-lists are made by indenting 2 spaces:\n - Marker character change forces new list start:\n * Ac tristique libero volutpat at\n + Facilisis in pretium nisl aliquet\n - Nulla volutpat aliquam velit\n+ Very easy!\n\nOrdered\n\n1. Lorem ipsum dolor sit amet\n2. Consectetur adipiscing elit\n3. Integer molestie lorem at massa\n\n\n1. You can use sequential numbers...\n1. ...or keep all the numbers as `1.`\n\nStart numbering with offset:\n\n57. foo\n1. bar\n\n\n## Code\n\nInline `code`\n\nIndented code\n\n // Some comments\n line 1 of code\n line 2 of code\n line 3 of code\n\n\nBlock code ""fences""\n\n```\nSample text here...\n```\n\nSyntax highlighting\n\n```\nvar foo = function (bar) {\n return bar++;\n};\n\nconsole.log(foo(5));\n```\n\n## Tables\n\n| Option | Description |\n| ------ | ----------- |\n| data | path to data files to supply the data that will be passed into templates. |\n| engine | engine to be used for processing templates. Handlebars is the default. |\n| ext | extension to be used for dest files. |\n\nRight aligned columns\n\n| Option | Description |\n| ------:| -----------:|\n| data | path to data files to supply the data that will be passed into templates. |\n| engine | engine to be used for processing templates. Handlebars is the default. |\n| ext | extension to be used for dest files. |\n\n\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
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
UpdateTimer.RunMode = timer.RunModes.Single
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
Control HTMLViewer1 Inherits HTMLViewer
ControlInstance HTMLViewer1 Inherits HTMLViewer
End Control
Control UpdateTimer Inherits Timer
ControlInstance UpdateTimer Inherits Timer
EventHandler Sub Action()
UpdateHTML
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 SetupMarkdown()
dim c as ScintillaControlMBS = me.ScintillaControl
c.InitializeLexer "markdown"
const SCE_MARKDOWN_DEFAULT = 0
const SCE_MARKDOWN_LINE_BEGIN = 1
const SCE_MARKDOWN_STRONG1 = 2
const SCE_MARKDOWN_STRONG2 = 3
const SCE_MARKDOWN_EM1 = 4
const SCE_MARKDOWN_EM2 = 5
const SCE_MARKDOWN_HEADER1 = 6
const SCE_MARKDOWN_HEADER2 = 7
const SCE_MARKDOWN_HEADER3 = 8
const SCE_MARKDOWN_HEADER4 = 9
const SCE_MARKDOWN_HEADER5 = 10
const SCE_MARKDOWN_HEADER6 = 11
const SCE_MARKDOWN_PRECHAR = 12
const SCE_MARKDOWN_ULIST_ITEM = 13
const SCE_MARKDOWN_OLIST_ITEM = 14
const SCE_MARKDOWN_BLOCKQUOTE = 15
const SCE_MARKDOWN_STRIKEOUT = 16
const SCE_MARKDOWN_HRULE = 17
const SCE_MARKDOWN_LINK = 18
const SCE_MARKDOWN_CODE = 19
const SCE_MARKDOWN_CODE2 = 20
const SCE_MARKDOWN_CODEBK = 21
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
// SCE_MARKDOWN_DEFAULT: Regular text
// SCE_MARKDOWN_LINE_BEGIN: Special, e.g. end-of-line codes if enabled
// SCE_MARKDOWN_STRONG1: "**" - Strong emphasis (bold)
c.Style(SCE_MARKDOWN_STRONG1).ForeColor = &c224466
c.Style(SCE_MARKDOWN_STRONG1).Bold = true
// SCE_MARKDOWN_STRONG2: "__" - Strong emphasis (bold)
c.Style(SCE_MARKDOWN_STRONG2).ForeColor = &c224466
c.Style(SCE_MARKDOWN_STRONG2).Bold = true
// SCE_MARKDOWN_EM1: '*' - Emphasis (italic)
c.Style(SCE_MARKDOWN_EM1).ForeColor = &c663300
c.Style(SCE_MARKDOWN_EM1).Italic = true
// SCE_MARKDOWN_EM2: '_' - Emphasis (italic)
c.Style(SCE_MARKDOWN_EM2).ForeColor = &c663300
c.Style(SCE_MARKDOWN_EM2).Italic = true
// SCE_MARKDOWN_HEADER1: "#" - Level-one header
c.Style(SCE_MARKDOWN_HEADER1).ForeColor = &c5183C4
c.Style(SCE_MARKDOWN_HEADER1).bold = true
c.Style(SCE_MARKDOWN_HEADER1).Font = "Monaco"
// SCE_MARKDOWN_HEADER2: "##" - Level-two header
c.Style(SCE_MARKDOWN_HEADER2).ForeColor = &c5183C4
c.Style(SCE_MARKDOWN_HEADER2).bold = true
c.Style(SCE_MARKDOWN_HEADER2).Font = "Monaco"
// SCE_MARKDOWN_HEADER3: "###" - Level-three header
c.Style(SCE_MARKDOWN_HEADER3).ForeColor = &c5183C4
c.Style(SCE_MARKDOWN_HEADER3).bold = true
c.Style(SCE_MARKDOWN_HEADER3).Font = "Monaco"
// SCE_MARKDOWN_HEADER4: "####" - Level-four header
c.Style(SCE_MARKDOWN_HEADER4).ForeColor = &c5183C4
c.Style(SCE_MARKDOWN_HEADER4).bold = true
c.Style(SCE_MARKDOWN_HEADER4).Font = "Monaco"
// SCE_MARKDOWN_HEADER5: "#####" - Level-five header
c.Style(SCE_MARKDOWN_HEADER5).ForeColor = &c5183C4
c.Style(SCE_MARKDOWN_HEADER5).bold = true
c.Style(SCE_MARKDOWN_HEADER5).Font = "Monaco"
// SCE_MARKDOWN_HEADER6: "######" - Level-six header
c.Style(SCE_MARKDOWN_HEADER6).ForeColor = &c5183C4
c.Style(SCE_MARKDOWN_HEADER6).bold = true
c.Style(SCE_MARKDOWN_HEADER6).Font = "Monaco"
// SCE_MARKDOWN_PRECHAR: Prechar (up to three indent spaces, e.g. for a second-level list)
c.Style(SCE_MARKDOWN_PRECHAR).BackColor = &cEEEEAA
c.Style(SCE_MARKDOWN_PRECHAR).ForeColor = &c000000
// SCE_MARKDOWN_ULIST_ITEM: "- ", "* ", "+ " - Unordered list item
c.Style(SCE_MARKDOWN_ULIST_ITEM).ForeColor = &c555555
// SCE_MARKDOWN_OLIST_ITEM: "1. " to "9. ", "#. " - Ordered list item
c.Style(SCE_MARKDOWN_OLIST_ITEM).ForeColor = &c555555
// SCE_MARKDOWN_BLOCKQUOTE: "> " - Block quote
c.Style(SCE_MARKDOWN_BLOCKQUOTE).ForeColor = &c000088
// SCE_MARKDOWN_STRIKEOUT: "~~" - Strikeout
c.Style(SCE_MARKDOWN_STRIKEOUT).BackColor = &cA9BA9D
c.Style(SCE_MARKDOWN_STRIKEOUT).ForeColor = &c18453B
c.Style(SCE_MARKDOWN_STRIKEOUT).Font = "Monaco"
// SCE_MARKDOWN_HRULE: "---", "***", "___" - Horizontal rule
c.Style(SCE_MARKDOWN_HRULE).ForeColor = &c555555
c.Style(SCE_MARKDOWN_HRULE).Font = "Monaco"
c.Style(SCE_MARKDOWN_HRULE).bold = true
// SCE_MARKDOWN_LINK: "[]", "![]" - Link or image
c.Style(SCE_MARKDOWN_LINK).ForeColor = &c0000AA
c.Style(SCE_MARKDOWN_LINK).Underline = true
// SCE_MARKDOWN_CODE: '`' - Inline code
c.Style(SCE_MARKDOWN_CODE).BackColor = &cEEEEEE
c.Style(SCE_MARKDOWN_CODE).ForeColor = &c000088
c.Style(SCE_MARKDOWN_CODE).Font = "Monaco"
// SCE_MARKDOWN_CODE2: "``" - Inline code (quotes code containing a single backtick)
c.Style(SCE_MARKDOWN_CODE2).BackColor = &cEEEEEE
c.Style(SCE_MARKDOWN_CODE2).ForeColor = &c000088
c.Style(SCE_MARKDOWN_CODE2).Font = "Monaco"
// SCE_MARKDOWN_CODEBK: "~~~" - Code block
c.Style(SCE_MARKDOWN_CODEBK).BackColor = &cEEEEEE
c.Style(SCE_MARKDOWN_CODEBK).ForeColor = &c000088
c.Style(SCE_MARKDOWN_CODEBK).Font = "Monaco"
// 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 = SampleMarkDown
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 UpdateHTML()
dim t as string = ScintillaControl.text
t = ReplaceLineEndings(t, EndOfLine.UNIX)
dim m as new MarkdownDocumentMBS(t)
if m.Compile then
dim lines() as string
lines.Append "<html>"
lines.Append "<head>"
lines.Append m.CSS
lines.Append "</head>"
lines.Append "<body>"
lines.Append m.Document
lines.Append "</body>"
lines.Append "</head>"
dim s as string = Join(lines,EndOfLine)
HTMLViewer1.LoadPage s, nil
end if
End Sub
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
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.
