Skip to content

Commit de6107e

Browse files
DevExpressExampleBotDevExpressExampleBot
DevExpressExampleBot
authored and
DevExpressExampleBot
committed
Source auto update [skip ci]
1 parent d969d82 commit de6107e

16 files changed

+593
-9
lines changed

CS/DXRichEditSyntaxExample/App.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Application x:Class="DXRichEditSyntaxExample.App"
1+
<Application x:Class="DXRichEditSyntaxExample.App"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:local="clr-namespace:DXRichEditSyntaxExample"

CS/DXRichEditSyntaxExample/DXRichEditSyntaxExample.csproj

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
@@ -34,11 +34,12 @@
3434
<WarningLevel>4</WarningLevel>
3535
</PropertyGroup>
3636
<ItemGroup>
37-
<Reference Include="DevExpress.Data.v18.1, Version=18.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
38-
<Reference Include="DevExpress.Office.v18.1.Core, Version=18.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
39-
<Reference Include="DevExpress.RichEdit.v18.1.Core, Version=18.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
40-
<Reference Include="DevExpress.Xpf.Core.v18.1, Version=18.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
41-
<Reference Include="DevExpress.Xpf.RichEdit.v18.1, Version=18.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
37+
<Reference Include="DevExpress.Data.v18.1, Version=18.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
38+
<Reference Include="DevExpress.Office.v18.1.Core, Version=18.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
39+
<Reference Include="DevExpress.RichEdit.v18.1.Core, Version=18.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
40+
<Reference Include="DevExpress.Mvvm.v18.1, Version=18.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
41+
<Reference Include="DevExpress.Xpf.Core.v18.1, Version=18.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
42+
<Reference Include="DevExpress.Xpf.RichEdit.v18.1, Version=18.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
4243
<Reference Include="System" />
4344
<Reference Include="System.Data" />
4445
<Reference Include="System.Drawing" />
@@ -106,4 +107,4 @@
106107
</Content>
107108
</ItemGroup>
108109
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
109-
</Project>
110+
</Project>

CS/DXRichEditSyntaxExample/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Window x:Class="DXRichEditSyntaxExample.MainWindow"
1+
<Window x:Class="DXRichEditSyntaxExample.MainWindow"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

VB/DXRichEditSyntaxExample.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio 15
3+
VisualStudioVersion = 15.0.27703.2042
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "DXRichEditSyntaxExample", "DXRichEditSyntaxExample\DXRichEditSyntaxExample.vbproj", "{52F77B1E-BCAE-4B11-BFC9-51E70ADE1FB1}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{52F77B1E-BCAE-4B11-BFC9-51E70ADE1FB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{52F77B1E-BCAE-4B11-BFC9-51E70ADE1FB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{52F77B1E-BCAE-4B11-BFC9-51E70ADE1FB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{52F77B1E-BCAE-4B11-BFC9-51E70ADE1FB1}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {ACA91C17-2C39-4A04-966C-D5A072862C0B}
23+
EndGlobalSection
24+
EndGlobal

VB/DXRichEditSyntaxExample/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
</configuration>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="DXRichEditSyntaxExample.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:DXRichEditSyntaxExample"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Imports System
2+
Imports System.Collections.Generic
3+
Imports System.Configuration
4+
Imports System.Data
5+
Imports System.Linq
6+
Imports System.Threading.Tasks
7+
Imports System.Windows
8+
9+
Namespace DXRichEditSyntaxExample
10+
''' <summary>
11+
''' Interaction logic for App.xaml
12+
''' </summary>
13+
Partial Public Class App
14+
Inherits Application
15+
16+
End Class
17+
End Namespace
Binary file not shown.
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{52F77B1E-BCAE-4B11-BFC9-51E70ADE1FB1}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace></RootNamespace>
10+
<AssemblyName>DXRichEditSyntaxExample</AssemblyName>
11+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
<OptionExplicit>On</OptionExplicit>
16+
<OptionCompare>Binary</OptionCompare>
17+
<OptionStrict>Off</OptionStrict>
18+
<OptionInfer>On</OptionInfer>
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<PlatformTarget>AnyCPU</PlatformTarget>
22+
<DebugSymbols>true</DebugSymbols>
23+
<DebugType>full</DebugType>
24+
<Optimize>false</Optimize>
25+
<OutputPath>bin\Debug\</OutputPath>
26+
<DefineDebug>true</DefineDebug>
27+
<DefineTrace>true</DefineTrace>
28+
<ErrorReport>prompt</ErrorReport>
29+
</PropertyGroup>
30+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
31+
<PlatformTarget>AnyCPU</PlatformTarget>
32+
<DebugType>pdbonly</DebugType>
33+
<Optimize>true</Optimize>
34+
<OutputPath>bin\Release\</OutputPath>
35+
<DefineDebug>false</DefineDebug>
36+
<DefineTrace>true</DefineTrace>
37+
<ErrorReport>prompt</ErrorReport>
38+
</PropertyGroup>
39+
<ItemGroup>
40+
<Import Include="Microsoft.VisualBasic" />
41+
<Import Include="System.Collections.Generic" />
42+
<Import Include="System.Collections" />
43+
<Import Include="System.Diagnostics" />
44+
<Import Include="System.Linq" />
45+
<Import Include="System.Xml.Linq" />
46+
<Import Include="System.Data" />
47+
<Import Include="System.Drawing" />
48+
<Import Include="System.Windows.Forms" />
49+
<Import Include="System.Windows.Controls" />
50+
<Import Include="System.Windows.Data" />
51+
<Import Include="System.Windows.Shapes" />
52+
<Import Include="System.Windows.Documents" />
53+
<Import Include="System.Windows.Input" />
54+
<Import Include="System.Windows.Media.Imaging" />
55+
<Import Include="System.Windows.Media" />
56+
<Import Include="System.Windows.Navigation" />
57+
<Import Include="System.Windows" />
58+
<Import Include="System" />
59+
</ItemGroup>
60+
<ItemGroup>
61+
<Reference Include="DevExpress.Data.v18.1, Version=18.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
62+
<Reference Include="DevExpress.Office.v18.1.Core, Version=18.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
63+
<Reference Include="DevExpress.RichEdit.v18.1.Core, Version=18.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
64+
<Reference Include="DevExpress.Mvvm.v18.1, Version=18.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
65+
<Reference Include="DevExpress.Xpf.Core.v18.1, Version=18.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
66+
<Reference Include="DevExpress.Xpf.RichEdit.v18.1, Version=18.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
67+
<Reference Include="System" />
68+
<Reference Include="System.Data" />
69+
<Reference Include="System.Drawing" />
70+
<Reference Include="System.Windows.Forms" />
71+
<Reference Include="System.Xml" />
72+
<Reference Include="Microsoft.CSharp" />
73+
<Reference Include="System.Core" />
74+
<Reference Include="System.Xml.Linq" />
75+
<Reference Include="System.Data.DataSetExtensions" />
76+
<Reference Include="System.Net.Http" />
77+
<Reference Include="System.Xaml">
78+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
79+
</Reference>
80+
<Reference Include="WindowsBase" />
81+
<Reference Include="PresentationCore" />
82+
<Reference Include="PresentationFramework" />
83+
</ItemGroup>
84+
<ItemGroup>
85+
<ApplicationDefinition Include="Application.xaml">
86+
<Generator>MSBuild:Compile</Generator>
87+
<SubType>Designer</SubType>
88+
</ApplicationDefinition>
89+
<Page Include="MainWindow.xaml">
90+
<Generator>MSBuild:Compile</Generator>
91+
<SubType>Designer</SubType>
92+
</Page>
93+
<Compile Include="Application.xaml.vb">
94+
<DependentUpon>Application.xaml</DependentUpon>
95+
<SubType>Code</SubType>
96+
</Compile>
97+
<Compile Include="MainWindow.xaml.vb">
98+
<DependentUpon>MainWindow.xaml</DependentUpon>
99+
<SubType>Code</SubType>
100+
</Compile>
101+
</ItemGroup>
102+
<ItemGroup>
103+
<Compile Include="My Project\AssemblyInfo.vb">
104+
<SubType>Code</SubType>
105+
</Compile>
106+
<Compile Include="My Project\Resources.Designer.vb">
107+
<AutoGen>True</AutoGen>
108+
<DesignTime>True</DesignTime>
109+
<DependentUpon>Resources.resx</DependentUpon>
110+
</Compile>
111+
<Compile Include="My Project\Settings.Designer.vb">
112+
<AutoGen>True</AutoGen>
113+
<DependentUpon>Settings.settings</DependentUpon>
114+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
115+
</Compile>
116+
<EmbeddedResource Include="My Project\Resources.resx">
117+
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
118+
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
119+
<CustomToolNamespace>My.Resources</CustomToolNamespace>
120+
</EmbeddedResource>
121+
<None Include="My Project\Settings.settings">
122+
<Generator>SettingsSingleFileGenerator</Generator>
123+
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
124+
</None>
125+
</ItemGroup>
126+
<ItemGroup>
127+
<None Include="App.config" />
128+
</ItemGroup>
129+
<ItemGroup>
130+
<Content Include="CarsXtraScheduling.sql">
131+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
132+
</Content>
133+
</ItemGroup>
134+
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
135+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Window x:Class="DXRichEditSyntaxExample.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:DXRichEditSyntaxExample"
7+
xmlns:dxre="http://schemas.devexpress.com/winfx/2008/xaml/richedit"
8+
mc:Ignorable="d"
9+
Title="MainWindow" Height="450" Width="800">
10+
<Grid>
11+
<dxre:RichEditControl x:Name="richEditControl1" ActiveViewType="Draft"/>
12+
</Grid>
13+
</Window>
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
Imports DevExpress.Office.Utils
2+
Imports DevExpress.XtraRichEdit.API.Native
3+
Imports DevExpress.XtraRichEdit.Services
4+
Imports System
5+
Imports System.Collections.Generic
6+
Imports System.Drawing
7+
Imports System.Linq
8+
Imports System.Text
9+
Imports System.Threading.Tasks
10+
Imports System.Windows
11+
Imports System.Windows.Controls
12+
Imports System.Windows.Data
13+
Imports System.Windows.Documents
14+
Imports System.Windows.Input
15+
Imports System.Windows.Media.Imaging
16+
Imports System.Windows.Navigation
17+
Imports System.Windows.Shapes
18+
19+
Namespace DXRichEditSyntaxExample
20+
''' <summary>
21+
''' Interaction logic for MainWindow.xaml
22+
''' </summary>
23+
Partial Public Class MainWindow
24+
Inherits Window
25+
26+
Public Sub New()
27+
InitializeComponent()
28+
richEditControl1.ReplaceService(Of ISyntaxHighlightService)(New CustomSyntaxHighlightService(richEditControl1.Document))
29+
richEditControl1.LoadDocument("CarsXtraScheduling.sql")
30+
richEditControl1.Document.Sections(0).Page.Width = Units.InchesToDocumentsF(80F)
31+
richEditControl1.Document.DefaultCharacterProperties.FontName = "Courier New"
32+
End Sub
33+
End Class
34+
Public Class CustomSyntaxHighlightService
35+
Implements ISyntaxHighlightService
36+
37+
Private ReadOnly document As Document
38+
Private defaultSettings As New SyntaxHighlightProperties() With {.ForeColor = Color.Black}
39+
Private keywordSettings As New SyntaxHighlightProperties() With {.ForeColor = Color.Blue}
40+
Private stringSettings As New SyntaxHighlightProperties() With {.ForeColor = Color.Green}
41+
42+
Private keywords() As String = { "INSERT", "SELECT", "CREATE", "TABLE", "USE", "IDENTITY", "ON", "OFF", "NOT", "NULL", "WITH", "SET" }
43+
44+
Public Sub New(ByVal document As Document)
45+
Me.document = document
46+
End Sub
47+
48+
Private Function ParseTokens() As List(Of SyntaxHighlightToken)
49+
Dim tokens As New List(Of SyntaxHighlightToken)()
50+
Dim ranges() As DocumentRange = Nothing
51+
' search for quotation marks
52+
ranges = document.FindAll("'", SearchOptions.None)
53+
For i As Integer = 0 To (ranges.Length \ 2) - 1
54+
tokens.Add(New SyntaxHighlightToken(ranges(i * 2).Start.ToInt(), ranges(i * 2 + 1).Start.ToInt() - ranges(i * 2).Start.ToInt() + 1, stringSettings))
55+
Next i
56+
' search for keywords
57+
For i As Integer = 0 To keywords.Length - 1
58+
ranges = document.FindAll(keywords(i), SearchOptions.CaseSensitive Or SearchOptions.WholeWord)
59+
60+
For j As Integer = 0 To ranges.Length - 1
61+
If Not IsRangeInTokens(ranges(j), tokens) Then
62+
tokens.Add(New SyntaxHighlightToken(ranges(j).Start.ToInt(), ranges(j).Length, keywordSettings))
63+
End If
64+
Next j
65+
Next i
66+
' order tokens by their start position
67+
tokens.Sort(New SyntaxHighlightTokenComparer())
68+
' fill in gaps in document coverage
69+
AddPlainTextTokens(tokens)
70+
Return tokens
71+
End Function
72+
73+
Private Sub AddPlainTextTokens(ByVal tokens As List(Of SyntaxHighlightToken))
74+
Dim count As Integer = tokens.Count
75+
If count = 0 Then
76+
tokens.Add(New SyntaxHighlightToken(0, document.Range.End.ToInt(), defaultSettings))
77+
Return
78+
End If
79+
tokens.Insert(0, New SyntaxHighlightToken(0, tokens(0).Start, defaultSettings))
80+
For i As Integer = 1 To count - 1
81+
tokens.Insert(i * 2, New SyntaxHighlightToken(tokens(i * 2 - 1).End, tokens(i * 2).Start - tokens(i * 2 - 1).End, defaultSettings))
82+
Next i
83+
tokens.Add(New SyntaxHighlightToken(tokens(count * 2 - 1).End, document.Range.End.ToInt() - tokens(count * 2 - 1).End, defaultSettings))
84+
End Sub
85+
86+
Private Function IsRangeInTokens(ByVal range As DocumentRange, ByVal tokens As List(Of SyntaxHighlightToken)) As Boolean
87+
Return tokens.Any(Function(t) IsIntersect(range, t))
88+
End Function
89+
Private Function IsIntersect(ByVal range As DocumentRange, ByVal token As SyntaxHighlightToken) As Boolean
90+
Dim start As Integer = range.Start.ToInt()
91+
If start >= token.Start AndAlso start < token.End Then
92+
Return True
93+
End If
94+
Dim [end] As Integer = range.End.ToInt() - 1
95+
If [end] >= token.Start AndAlso [end] < token.End Then
96+
Return True
97+
End If
98+
Return False
99+
End Function
100+
101+
Public Sub ForceExecute()
102+
Execute()
103+
End Sub
104+
Public Sub Execute()
105+
document.ApplySyntaxHighlight(ParseTokens())
106+
End Sub
107+
End Class
108+
109+
Public Class SyntaxHighlightTokenComparer
110+
Implements IComparer(Of SyntaxHighlightToken)
111+
112+
Public Function Compare(ByVal x As SyntaxHighlightToken, ByVal y As SyntaxHighlightToken) As Integer Implements IComparer(Of SyntaxHighlightToken).Compare
113+
Return x.Start - y.Start
114+
End Function
115+
End Class
116+
End Namespace

0 commit comments

Comments
 (0)