Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Text.RegularExpressions
- Imports FastColoredTextBoxNS
- Imports System.Windows.Forms
- Public Class Editor
- Public Property Styles As New Dictionary(Of String, Style)
- Public Property Foldings As New Dictionary(Of String, String)
- Public Property Keywords As New List(Of SyntaxItem)
- Public Property CompletionItems As New List(Of AutocompleteItem)
- Sub New(tb As FastColoredTextBox, imglist As imagelist)
- Dim Intelisense As AutocompleteMenu = New AutocompleteMenu(tb)
- Intelisense.SearchPattern = "[\w\.:=!<>]"
- CompletionItems.Add(New InsertSpaceSnippet())
- CompletionItems.Add(New InsertSpaceSnippet("^(\w+)([=<>!:]+)(\w+)$"))
- CompletionItems.Add(New InsertEnterSnippet())
- 'set as autocomplete source
- Intelisense.Items.SetAutocompleteItems(CompletionItems)
- Intelisense.ShowItemToolTips = True
- Intelisense.ImageList = imglist
- End Sub
- Public Function getStyle(key As String) As Style
- For Each l In From l1 In Styles Where l1.Key = key
- Return l.Value
- Next
- End Function
- Public Sub TextChanged(e As FastColoredTextBoxNS.TextChangedEventArgs)
- e.ChangedRange.ClearFoldingMarkers()
- For Each Style In Styles
- e.ChangedRange.ClearStyle(Style.Value)
- Next
- For Each folder In Foldings
- e.ChangedRange.SetFoldingMarkers(folder.Key, folder.Value)
- Next
- For Each keyword In Keywords
- e.ChangedRange.SetStyle(keyword.Value, keyword.Key, keyword.Option)
- Next
- End Sub
- Public Sub AutoIndentNeeded(args As FastColoredTextBoxNS.AutoIndentEventArgs)
- If Regex.IsMatch(args.LineText, "^[^""""']*\{.*\}[^""""']*$") Then
- Return
- End If
- 'start of block {}
- If Regex.IsMatch(args.LineText, "^[^""""']*\{") Then
- args.ShiftNextLines = args.TabLength
- Return
- End If
- 'end of block {}
- If Regex.IsMatch(args.LineText, "}[^""""']*$") Then
- args.Shift = (args.TabLength * -1)
- args.ShiftNextLines = (args.TabLength * -1)
- Return
- End If
- 'label
- If (Regex.IsMatch(args.LineText, "^\s*\w+\s*:\s*($|//)") _
- AndAlso Not Regex.IsMatch(args.LineText, "^\s*default\s*:")) Then
- args.Shift = (args.TabLength * -1)
- Return
- End If
- 'some statements: case, default
- If Regex.IsMatch(args.LineText, "^\s*(case|default)\b.*:\s*($|//)") Then
- args.Shift = ((args.TabLength / 2) _
- * -1)
- Return
- End If
- 'is unclosed operator in previous line ?
- If Regex.IsMatch(args.PrevLineText, "^\s*(if|for|foreach|while|[\}\s]*else)\b[^{]*$") Then
- If Not Regex.IsMatch(args.PrevLineText, "(;\s*$)|(;\s*//)") Then
- args.Shift = args.TabLength
- Return
- End If
- End If
- End Sub
- End Class
- Public Class SyntaxItem
- Public Property Key As String
- Public Property Value As Style
- Public Property [Option] As RegexOptions
- Sub New(key As String, value As Style, Optional [Option] As RegexOptions = RegexOptions.IgnoreCase)
- MyClass.Key = key
- MyClass.Option = [Option]
- MyClass.Value = value
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement