Advertisement
filmee24

manager

Dec 17th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.38 KB | None | 0 0
  1. Imports System.Text.RegularExpressions
  2. Imports FastColoredTextBoxNS
  3. Imports System.Windows.Forms
  4.  
  5. Public Class Editor
  6.  
  7.     Public Property Styles As New Dictionary(Of String, Style)
  8.     Public Property Foldings As New Dictionary(Of String, String)
  9.     Public Property Keywords As New List(Of SyntaxItem)
  10.     Public Property CompletionItems As New List(Of AutocompleteItem)
  11.  
  12.  
  13.  
  14.     Sub New(tb As FastColoredTextBox, imglist As imagelist)
  15.         Dim Intelisense As AutocompleteMenu = New AutocompleteMenu(tb)
  16.  
  17.         Intelisense.SearchPattern = "[\w\.:=!<>]"
  18.  
  19.         CompletionItems.Add(New InsertSpaceSnippet())
  20.         CompletionItems.Add(New InsertSpaceSnippet("^(\w+)([=<>!:]+)(\w+)$"))
  21.         CompletionItems.Add(New InsertEnterSnippet())
  22.  
  23.         'set as autocomplete source
  24.         Intelisense.Items.SetAutocompleteItems(CompletionItems)
  25.         Intelisense.ShowItemToolTips = True
  26.         Intelisense.ImageList = imglist
  27.     End Sub
  28.  
  29.     Public Function getStyle(key As String) As Style
  30.         For Each l In From l1 In Styles Where l1.Key = key
  31.             Return l.Value
  32.         Next
  33.     End Function
  34.  
  35.     Public Sub TextChanged(e As FastColoredTextBoxNS.TextChangedEventArgs)
  36.         e.ChangedRange.ClearFoldingMarkers()
  37.  
  38.         For Each Style In Styles
  39.             e.ChangedRange.ClearStyle(Style.Value)
  40.         Next
  41.         For Each folder In Foldings
  42.             e.ChangedRange.SetFoldingMarkers(folder.Key, folder.Value)
  43.         Next
  44.  
  45.         For Each keyword In Keywords
  46.             e.ChangedRange.SetStyle(keyword.Value, keyword.Key, keyword.Option)
  47.         Next
  48.     End Sub
  49.  
  50.     Public Sub AutoIndentNeeded(args As FastColoredTextBoxNS.AutoIndentEventArgs)
  51.         If Regex.IsMatch(args.LineText, "^[^""""']*\{.*\}[^""""']*$") Then
  52.             Return
  53.         End If
  54.         'start of block {}
  55.         If Regex.IsMatch(args.LineText, "^[^""""']*\{") Then
  56.             args.ShiftNextLines = args.TabLength
  57.             Return
  58.         End If
  59.         'end of block {}
  60.         If Regex.IsMatch(args.LineText, "}[^""""']*$") Then
  61.             args.Shift = (args.TabLength * -1)
  62.             args.ShiftNextLines = (args.TabLength * -1)
  63.             Return
  64.         End If
  65.         'label
  66.         If (Regex.IsMatch(args.LineText, "^\s*\w+\s*:\s*($|//)") _
  67.                     AndAlso Not Regex.IsMatch(args.LineText, "^\s*default\s*:")) Then
  68.             args.Shift = (args.TabLength * -1)
  69.             Return
  70.         End If
  71.         'some statements: case, default
  72.         If Regex.IsMatch(args.LineText, "^\s*(case|default)\b.*:\s*($|//)") Then
  73.             args.Shift = ((args.TabLength / 2) _
  74.                         * -1)
  75.             Return
  76.         End If
  77.         'is unclosed operator in previous line ?
  78.         If Regex.IsMatch(args.PrevLineText, "^\s*(if|for|foreach|while|[\}\s]*else)\b[^{]*$") Then
  79.             If Not Regex.IsMatch(args.PrevLineText, "(;\s*$)|(;\s*//)") Then
  80.                 args.Shift = args.TabLength
  81.                 Return
  82.             End If
  83.         End If
  84.     End Sub
  85.  
  86. End Class
  87. Public Class SyntaxItem
  88.  
  89.     Public Property Key As String
  90.     Public Property Value As Style
  91.     Public Property [Option] As RegexOptions
  92.  
  93.     Sub New(key As String, value As Style, Optional [Option] As RegexOptions = RegexOptions.IgnoreCase)
  94.         MyClass.Key = key
  95.         MyClass.Option = [Option]
  96.         MyClass.Value = value
  97.     End Sub
  98.  
  99. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement