-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpreadsheetApiModuleUtils.vb
148 lines (125 loc) · 6.27 KB
/
SpreadsheetApiModuleUtils.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
Imports DevExpress.Utils
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.Internal
Imports System
Namespace SpreadsheetWPFPivotTableExamples
Public Class ExampleCodeEditor
Private ReadOnly codeEditorCs As IRichEditControl
Private ReadOnly codeEditorVb As IRichEditControl
Private current As ExampleLanguage
Private forceTextChangesCounter As Integer
Private richEditTextChanged_Renamed As Boolean = False
Private lastExampleCodeModifiedTime_Renamed As Date = Date.Now
Public Sub New(ByVal codeEditorCs As IRichEditControl, ByVal codeEditorVb As IRichEditControl)
Me.codeEditorCs = codeEditorCs
Me.codeEditorVb = codeEditorVb
AddHandler codeEditorCs.InnerControl.InitializeDocument, AddressOf InitializeSyntaxHighlightForCs
AddHandler codeEditorVb.InnerControl.InitializeDocument, AddressOf InitializeSyntaxHighlightForVb
End Sub
Public ReadOnly Property CurrentCodeEditor() As InnerRichEditControl
Get
If CurrentExampleLanguage = ExampleLanguage.Csharp Then
Return codeEditorCs.InnerControl
Else
Return codeEditorVb.InnerControl
End If
End Get
End Property
Public ReadOnly Property LastExampleCodeModifiedTime() As Date
Get
Return lastExampleCodeModifiedTime_Renamed
End Get
End Property
Public ReadOnly Property RichEditTextChanged() As Boolean
Get
Return richEditTextChanged_Renamed
End Get
End Property
Public Property CurrentExampleLanguage() As ExampleLanguage
Get
Return current
End Get
Set(ByVal value As ExampleLanguage)
Try
UnsubscribeRichEditEvents()
current = value
Finally
SubscribeRichEditEvent()
forceTextChangesCounter = 0
richEditTextChanged_Renamed = True
End Try
End Set
End Property
Private Sub richEditControl_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
If forceTextChangesCounter <= 0 Then
richEditTextChanged_Renamed = True
lastExampleCodeModifiedTime_Renamed = Date.Now
Else
forceTextChangesCounter -= 1
End If
End Sub
Public Function ShowExample(ByVal oldExample As CodeExample, ByVal newExample As CodeExample) As String
Dim richEditControlCs As InnerRichEditControl = codeEditorCs.InnerControl
Dim richEditControlVb As InnerRichEditControl = codeEditorVb.InnerControl
If oldExample IsNot Nothing Then
oldExample.CodeCS = richEditControlCs.Text
oldExample.CodeVB = richEditControlVb.Text
End If
Dim exampleCode As String = String.Empty
If newExample IsNot Nothing Then
Try
forceTextChangesCounter = 2
exampleCode = If(CurrentExampleLanguage = ExampleLanguage.Csharp, newExample.CodeCS, newExample.CodeVB)
richEditControlCs.Text = newExample.CodeCS
richEditControlVb.Text = newExample.CodeVB
richEditTextChanged_Renamed = False
Finally
richEditTextChanged_Renamed = True
End Try
End If
Return exampleCode
End Function
Private Sub UpdatePageBackground(ByVal codeEvaluated As Boolean)
CurrentCodeEditor.Document.SetPageBackground(If(codeEvaluated, DXColor.Empty, DXColor.FromArgb(&HFF, &HBC, &HC8)), True)
End Sub
Friend Sub BeforeCompile()
UnsubscribeRichEditEvents()
End Sub
Friend Sub AfterCompile(ByVal codeExcecutedWithoutExceptions As Boolean)
UpdatePageBackground(codeExcecutedWithoutExceptions)
richEditTextChanged_Renamed = False
ResetLastExampleModifiedTime()
SubscribeRichEditEvent()
End Sub
Public Sub ResetLastExampleModifiedTime()
lastExampleCodeModifiedTime_Renamed = Date.Now
End Sub
Private Sub UnsubscribeRichEditEvents()
RemoveHandler CurrentCodeEditor.ContentChanged, AddressOf richEditControl_TextChanged
End Sub
Private Sub SubscribeRichEditEvent()
AddHandler CurrentCodeEditor.ContentChanged, AddressOf richEditControl_TextChanged
End Sub
Private Sub InitializeSyntaxHighlightForCs(ByVal sender As Object, ByVal e As EventArgs)
Dim syntaxHightlightInitializator As New SyntaxHightlightInitializeHelper()
syntaxHightlightInitializator.Initialize(codeEditorCs, CodeExampleDemoUtils.GetCodeExampleFileExtension(ExampleLanguage.Csharp))
DisableRichEditFeatures(codeEditorCs)
End Sub
Private Sub InitializeSyntaxHighlightForVb(ByVal sender As Object, ByVal e As EventArgs)
Dim syntaxHightlightInitializator As New SyntaxHightlightInitializeHelper()
syntaxHightlightInitializator.Initialize(codeEditorVb, CodeExampleDemoUtils.GetCodeExampleFileExtension(ExampleLanguage.VB))
DisableRichEditFeatures(codeEditorVb)
End Sub
Private Sub DisableRichEditFeatures(ByVal codeEditor As IRichEditControl)
Dim options As RichEditControlOptionsBase = codeEditor.InnerDocumentServer.Options
options.DocumentCapabilities.Hyperlinks = DocumentCapability.Disabled
options.DocumentCapabilities.Numbering.Bulleted = DocumentCapability.Disabled
options.DocumentCapabilities.Numbering.Simple = DocumentCapability.Disabled
options.DocumentCapabilities.Numbering.MultiLevel = DocumentCapability.Disabled
options.DocumentCapabilities.Tables = DocumentCapability.Disabled
options.DocumentCapabilities.Bookmarks = DocumentCapability.Disabled
options.DocumentCapabilities.CharacterStyle = DocumentCapability.Disabled
options.DocumentCapabilities.ParagraphStyle = DocumentCapability.Disabled
End Sub
End Class
End Namespace