Zooflow: integrate SQLEditor
This commit is contained in:
48
GUIs.Common/SQLEditor/Placeholder.vb
Normal file
48
GUIs.Common/SQLEditor/Placeholder.vb
Normal file
@@ -0,0 +1,48 @@
|
||||
Imports DigitalData.Modules.Patterns
|
||||
|
||||
Namespace SQLEditor
|
||||
Public Class Placeholder
|
||||
''' <summary>
|
||||
''' The internal Category of the placeholder, ie. the INT Part of {#INT#USERNAME}
|
||||
''' </summary>
|
||||
Public Property [Module] As String
|
||||
|
||||
''' <summary>
|
||||
''' The internal Name of the placeholder, ie. the USERNAME Part of {#INT#USERNAME}
|
||||
''' </summary>
|
||||
Public Property Name As String
|
||||
|
||||
''' <summary>
|
||||
''' The Value that this palceholder is replaced by, user entry.
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property Value As String
|
||||
|
||||
''' <summary>
|
||||
''' The internal pattern object
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property Pattern As Pattern
|
||||
|
||||
Public Title As String
|
||||
Public Description As String
|
||||
|
||||
Public Enum PlaceholderType
|
||||
FileFlow
|
||||
End Enum
|
||||
|
||||
Public Sub New(pTitle As String, pDescription As String, pModule As String, pName As String)
|
||||
Title = pTitle
|
||||
Description = pDescription
|
||||
|
||||
Name = pName
|
||||
[Module] = pModule
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Equals(obj As Object) As Boolean
|
||||
Return DirectCast(obj, Placeholder).Module = [Module] And
|
||||
DirectCast(obj, Placeholder).Name = Name
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
137
GUIs.Common/SQLEditor/Placeholders.vb
Normal file
137
GUIs.Common/SQLEditor/Placeholders.vb
Normal file
@@ -0,0 +1,137 @@
|
||||
Imports DevExpress.Utils.Svg
|
||||
Imports DevExpress.XtraBars.Ribbon
|
||||
|
||||
Namespace SQLEditor
|
||||
Public Class Placeholders
|
||||
Public Const AUTO_INDEX_ZOOFLOW = "ATTR_M"
|
||||
Public Const MAN_INDEX_ZOOFLOW = "ATTR_A"
|
||||
|
||||
Public Function GetInternalPlaceholders() As GalleryItemGroup
|
||||
Dim oModule = "INT"
|
||||
Dim oImage = My.Resources.electronics_desktopmac
|
||||
|
||||
Dim oItems As New List(Of GalleryItem)() From {
|
||||
GetGalleryItem(New Placeholder("USERNAME", "Benutzername", oModule, "USERNAME"), oImage),
|
||||
GetGalleryItem(New Placeholder("MACHINE", "Aktuelles Datum", oModule, "MACHINE"), oImage),
|
||||
GetGalleryItem(New Placeholder("DOMAIN", "Email-Adresse", oModule, "DOMAIN"), oImage),
|
||||
GetGalleryItem(New Placeholder("DATE", "Vorname", oModule, "DATE"), oImage)
|
||||
}
|
||||
Dim oGroup1 = New GalleryItemGroup() With {.Caption = "Intern"}
|
||||
|
||||
oGroup1.Items.AddRange(oItems.ToArray)
|
||||
Return oGroup1
|
||||
End Function
|
||||
|
||||
Public Function GetClipboardPlaceholder() As GalleryItemGroup
|
||||
Dim oModule = "CLIP"
|
||||
Dim oImage = My.Resources.electronics_desktopmac
|
||||
|
||||
Dim oItems As New List(Of GalleryItem)() From {
|
||||
GetGalleryItem(New Placeholder("BOARD", "Zwischenablage", oModule, "BOARD"), oImage)
|
||||
}
|
||||
Dim oGroup1 = New GalleryItemGroup() With {.Caption = "Zwischenablage"}
|
||||
|
||||
oGroup1.Items.AddRange(oItems.ToArray)
|
||||
Return oGroup1
|
||||
End Function
|
||||
|
||||
Friend Function GetWindreamPlaceholders(pPlaceholders As List(Of String)) As GalleryItemGroup
|
||||
Dim oImage = My.Resources.bo_contract
|
||||
Dim oItems As New List(Of GalleryItem)()
|
||||
|
||||
If pPlaceholders.Count > 0 Then
|
||||
For Each oWindreamPlaceholder In pPlaceholders
|
||||
Dim oPlaceholder = New Placeholder(oWindreamPlaceholder, "Windream Index", "WMI", oWindreamPlaceholder)
|
||||
oItems.Add(GetGalleryItem(oPlaceholder, oImage))
|
||||
Next
|
||||
Else Return Nothing
|
||||
End If
|
||||
|
||||
Dim oGroup1 = New GalleryItemGroup() With {.Caption = "Windream Indizies"}
|
||||
oGroup1.Items.AddRange(oItems.ToArray)
|
||||
Return oGroup1
|
||||
End Function
|
||||
|
||||
Public Function GetManualPlaceholders(pPlaceholders As List(Of String), pPrefix As String) As GalleryItemGroup
|
||||
Dim oImage As SvgImage = My.Resources.handtool
|
||||
Dim oItems As New List(Of GalleryItem)()
|
||||
Dim oPrefix As String = pPrefix
|
||||
|
||||
If oPrefix Is Nothing Then
|
||||
oPrefix = AUTO_INDEX_ZOOFLOW
|
||||
End If
|
||||
|
||||
If pPlaceholders.Count > 0 Then
|
||||
For Each oManualPlaceholder In pPlaceholders
|
||||
Dim oPlaceholder = New Placeholder(oManualPlaceholder, "Manuelles Attribut", oPrefix, oManualPlaceholder)
|
||||
oItems.Add(GetGalleryItem(oPlaceholder, oImage))
|
||||
Next
|
||||
Else Return Nothing
|
||||
End If
|
||||
|
||||
Dim oGroup1 = New GalleryItemGroup() With {.Caption = "Manuelle Attribute"}
|
||||
oGroup1.Items.AddRange(oItems.ToArray)
|
||||
Return oGroup1
|
||||
End Function
|
||||
|
||||
Public Function GetAutomaticPlaceholders(pPlaceholders As List(Of String), pPrefix As String) As GalleryItemGroup
|
||||
Dim oImage As SvgImage = My.Resources.autoarrange
|
||||
Dim oItems As New List(Of GalleryItem)()
|
||||
Dim oPrefix As String = pPrefix
|
||||
|
||||
If oPrefix Is Nothing Then
|
||||
oPrefix = AUTO_INDEX_ZOOFLOW
|
||||
End If
|
||||
|
||||
If pPlaceholders.Count > 0 Then
|
||||
For Each oManualPlaceholder In pPlaceholders
|
||||
Dim oPlaceholder = New Placeholder(oManualPlaceholder, "Automatisches Attribut", oPrefix, oManualPlaceholder)
|
||||
oItems.Add(GetGalleryItem(oPlaceholder, oImage))
|
||||
Next
|
||||
|
||||
Else Return Nothing
|
||||
End If
|
||||
|
||||
Dim oGroup1 = New GalleryItemGroup() With {.Caption = "Automatisches Attribut"}
|
||||
|
||||
oGroup1.Items.AddRange(oItems.ToArray)
|
||||
Return oGroup1
|
||||
End Function
|
||||
|
||||
Public Function GetUserPlaceholders() As GalleryItemGroup
|
||||
Dim oModule = "USER"
|
||||
Dim oImage = My.Resources.actions_user
|
||||
|
||||
Dim oItems As New List(Of GalleryItem)() From {
|
||||
GetGalleryItem(New Placeholder("PRENAME", "Vorname", oModule, "PRENAME"), oImage),
|
||||
GetGalleryItem(New Placeholder("SURNAME", "Nachname", oModule, "SURNAME"), oImage),
|
||||
GetGalleryItem(New Placeholder("EMAIL", "Email-Adresse", oModule, "EMAIL"), oImage),
|
||||
GetGalleryItem(New Placeholder("USER_ID", "Benutzer-ID", oModule, "USER_ID"), oImage),
|
||||
GetGalleryItem(New Placeholder("PROFILE_ID", "Profil-ID", oModule, "PROFILE_ID"), oImage),
|
||||
GetGalleryItem(New Placeholder("PROFILE_TITLE", "Profil-Name", oModule, "PROFILE_TITLE"), oImage),
|
||||
GetGalleryItem(New Placeholder("LANGUAGE", "Sprache", oModule, "LANGUAGE"), oImage)
|
||||
}
|
||||
Dim oGroup1 = New GalleryItemGroup() With {.Caption = "Benutzer"}
|
||||
|
||||
oGroup1.Items.AddRange(oItems.ToArray)
|
||||
Return oGroup1
|
||||
End Function
|
||||
|
||||
Private Function GetGalleryItem(pPlaceholder As Placeholder) As GalleryItem
|
||||
Return New GalleryItem(Nothing, pPlaceholder.Title, pPlaceholder.Description) With {
|
||||
.Tag = pPlaceholder
|
||||
}
|
||||
End Function
|
||||
|
||||
Private Function GetGalleryItem(pPlaceholder As Placeholder, pImage As SvgImage) As GalleryItem
|
||||
Dim oItem = New GalleryItem(Nothing, pPlaceholder.Title, pPlaceholder.Description) With {
|
||||
.Tag = pPlaceholder
|
||||
}
|
||||
oItem.ImageOptions.SvgImage = pImage
|
||||
|
||||
Return oItem
|
||||
End Function
|
||||
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
165
GUIs.Common/SQLEditor/SQLSyntaxHighlightService.vb
Normal file
165
GUIs.Common/SQLEditor/SQLSyntaxHighlightService.vb
Normal file
@@ -0,0 +1,165 @@
|
||||
Imports System.Collections.Generic
|
||||
Imports System.Drawing
|
||||
Imports System.Windows.Forms
|
||||
Imports DevExpress.Office.Utils
|
||||
Imports DevExpress.XtraRichEdit.API.Native
|
||||
Imports DevExpress.XtraRichEdit.Services
|
||||
Imports System.Linq
|
||||
Imports System.Text.RegularExpressions
|
||||
|
||||
Namespace SQLEditor
|
||||
Public Class SQLSyntaxHighlightService
|
||||
Implements ISyntaxHighlightService
|
||||
|
||||
Private ReadOnly document As Document
|
||||
|
||||
Private _keywords As Regex
|
||||
Private _quotedString As New Regex("'([^']|'')*'")
|
||||
Private _commentedString As New Regex("(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)")
|
||||
Private _placeholderString As New Regex("{#(\w+)#([\:\.\w\s_/-]+)}")
|
||||
|
||||
Private ReadOnly keywords As New List(Of String) From {
|
||||
"INSERT",
|
||||
"SELECT",
|
||||
"CREATE",
|
||||
"TABLE",
|
||||
"USE",
|
||||
"IDENTITY",
|
||||
"JOIN",
|
||||
"ON",
|
||||
"OFF",
|
||||
"NOT",
|
||||
"NULL",
|
||||
"WITH",
|
||||
"SET",
|
||||
"GO",
|
||||
"DECLARE",
|
||||
"EXECUTE",
|
||||
"NVARCHAR",
|
||||
"FROM",
|
||||
"INTO",
|
||||
"VALUES",
|
||||
"WHERE",
|
||||
"AND"
|
||||
}
|
||||
|
||||
Public Sub New(ByVal document As Document)
|
||||
Me.document = document
|
||||
|
||||
Me._keywords = New Regex("\b(" & String.Join("|", keywords.Select(Function(w) Regex.Escape(w))) & ")\b")
|
||||
End Sub
|
||||
Public Sub ForceExecute() Implements ISyntaxHighlightService.ForceExecute
|
||||
Execute()
|
||||
End Sub
|
||||
Public Sub Execute() Implements ISyntaxHighlightService.Execute
|
||||
Dim tSqltokens As List(Of SyntaxHighlightToken) = ParseTokens()
|
||||
document.ApplySyntaxHighlight(tSqltokens)
|
||||
End Sub
|
||||
|
||||
Private Function ParseTokens() As List(Of SyntaxHighlightToken)
|
||||
Dim tokens As New List(Of SyntaxHighlightToken)()
|
||||
Dim ranges() As DocumentRange = Nothing
|
||||
|
||||
' search for quoted strings
|
||||
ranges = TryCast(document.FindAll(_quotedString).GetAsFrozen(), DocumentRange())
|
||||
For i As Integer = 0 To ranges.Length - 1
|
||||
tokens.Add(CreateToken(ranges(i).Start.ToInt(), ranges(i).End.ToInt(), Color.Red))
|
||||
Next i
|
||||
|
||||
'Extract all keywords
|
||||
ranges = TryCast(document.FindAll(_keywords).GetAsFrozen(), DocumentRange())
|
||||
For j As Integer = 0 To ranges.Length - 1
|
||||
If Not IsRangeInTokens(ranges(j), tokens) Then
|
||||
tokens.Add(CreateToken(ranges(j).Start.ToInt(), ranges(j).End.ToInt(), Color.Blue))
|
||||
End If
|
||||
Next j
|
||||
|
||||
'Find all placeholders
|
||||
ranges = TryCast(document.FindAll(_placeholderString).GetAsFrozen(), DocumentRange())
|
||||
For j As Integer = 0 To ranges.Length - 1
|
||||
If Not IsRangeInTokens(ranges(j), tokens) Then
|
||||
tokens.Add(CreateToken(ranges(j).Start.ToInt(), ranges(j).End.ToInt(), Color.DarkTurquoise))
|
||||
End If
|
||||
Next j
|
||||
|
||||
'Find all comments
|
||||
ranges = TryCast(document.FindAll(_commentedString).GetAsFrozen(), DocumentRange())
|
||||
For j As Integer = 0 To ranges.Length - 1
|
||||
If Not IsRangeInTokens(ranges(j), tokens) Then
|
||||
tokens.Add(CreateToken(ranges(j).Start.ToInt(), ranges(j).End.ToInt(), Color.Green))
|
||||
End If
|
||||
Next j
|
||||
|
||||
' order tokens by their start position
|
||||
tokens.Sort(New SyntaxHighlightTokenComparer())
|
||||
|
||||
' fill in gaps in document coverage
|
||||
tokens = CombineWithPlainTextTokens(tokens)
|
||||
Return tokens
|
||||
End Function
|
||||
|
||||
'Parse the remaining text into tokens:
|
||||
Private Function CombineWithPlainTextTokens(ByVal tokens As List(Of SyntaxHighlightToken)) As List(Of SyntaxHighlightToken)
|
||||
Dim result As New List(Of SyntaxHighlightToken)(tokens.Count * 2 + 1)
|
||||
Dim documentStart As Integer = Me.document.Range.Start.ToInt()
|
||||
Dim documentEnd As Integer = Me.document.Range.End.ToInt()
|
||||
If tokens.Count = 0 Then
|
||||
result.Add(CreateToken(documentStart, documentEnd, Color.Black))
|
||||
Else
|
||||
Dim firstToken As SyntaxHighlightToken = tokens(0)
|
||||
If documentStart < firstToken.Start Then
|
||||
result.Add(CreateToken(documentStart, firstToken.Start, Color.Black))
|
||||
End If
|
||||
result.Add(firstToken)
|
||||
For i As Integer = 1 To tokens.Count - 1
|
||||
Dim token As SyntaxHighlightToken = tokens(i)
|
||||
Dim prevToken As SyntaxHighlightToken = tokens(i - 1)
|
||||
If prevToken.End <> token.Start Then
|
||||
result.Add(CreateToken(prevToken.End, token.Start, Color.Black))
|
||||
End If
|
||||
result.Add(token)
|
||||
Next i
|
||||
Dim lastToken As SyntaxHighlightToken = tokens(tokens.Count - 1)
|
||||
If documentEnd > lastToken.End Then
|
||||
result.Add(CreateToken(lastToken.End, documentEnd, Color.Black))
|
||||
End If
|
||||
End If
|
||||
Return result
|
||||
End Function
|
||||
|
||||
'Create a token from the retrieved range and specify its forecolor
|
||||
Private Function CreateToken(ByVal start As Integer, ByVal [end] As Integer, ByVal foreColor As Color) As SyntaxHighlightToken
|
||||
Dim properties As New SyntaxHighlightProperties()
|
||||
properties.ForeColor = foreColor
|
||||
Return New SyntaxHighlightToken(start, [end] - start, properties)
|
||||
End Function
|
||||
|
||||
'Check whether tokens intersect each other
|
||||
Private Function IsRangeInTokens(ByVal range As DocumentRange, ByVal tokens As List(Of SyntaxHighlightToken)) As Boolean
|
||||
Return tokens.Any(Function(t) IsIntersect(range, t))
|
||||
End Function
|
||||
Private Function IsIntersect(ByVal range As DocumentRange, ByVal token As SyntaxHighlightToken) As Boolean
|
||||
Dim start As Integer = range.Start.ToInt()
|
||||
If start >= token.Start AndAlso start < token.End Then
|
||||
Return True
|
||||
End If
|
||||
Dim [end] As Integer = range.End.ToInt() - 1
|
||||
If [end] >= token.Start AndAlso [end] < token.End Then
|
||||
Return True
|
||||
End If
|
||||
If start < token.Start AndAlso [end] >= token.End Then
|
||||
Return True
|
||||
End If
|
||||
Return False
|
||||
End Function
|
||||
End Class
|
||||
|
||||
'Compare token's initial positions to sort them
|
||||
Public Class SyntaxHighlightTokenComparer
|
||||
Implements IComparer(Of SyntaxHighlightToken)
|
||||
|
||||
Public Function Compare(ByVal x As SyntaxHighlightToken, ByVal y As SyntaxHighlightToken) As Integer Implements IComparer(Of SyntaxHighlightToken).Compare
|
||||
Return x.Start - y.Start
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user