This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExampleCodeEditor.cs
213 lines (182 loc) · 8.67 KB
/
ExampleCodeEditor.cs
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
using DevExpress.Utils;
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.Internal;
using System;
namespace SchedulerControl_WPF_API
{
public class ExampleCodeEditor
{
readonly IRichEditControl codeEditorCs;
readonly IRichEditControl codeEditorVb;
readonly IRichEditControl codeEditorCsClass;
readonly IRichEditControl codeEditorVbClass;
//public string codeCSClasses;
ExampleLanguage current;
int forceTextChangesCounter;
bool richEditTextChanged = false;
DateTime lastExampleCodeModifiedTime = DateTime.Now;
public ExampleCodeEditor(IRichEditControl codeEditorCs, IRichEditControl codeEditorVb, IRichEditControl codeEditorCsClass, IRichEditControl codeEditorVbClass)
{
this.codeEditorCs = codeEditorCs;
this.codeEditorVb = codeEditorVb;
this.codeEditorCsClass = codeEditorCsClass;
this.codeEditorVbClass = codeEditorVbClass;
this.codeEditorCs.InnerControl.InitializeDocument += new System.EventHandler(this.InitializeSyntaxHighlightForCs);
this.codeEditorVb.InnerControl.InitializeDocument += new System.EventHandler(this.InitializeSyntaxHighlightForVb);
this.codeEditorCsClass.InnerControl.InitializeDocument += new System.EventHandler(this.InitializeSyntaxHighlightForCsClass);
this.codeEditorVbClass.InnerControl.InitializeDocument += new System.EventHandler(this.InitializeSyntaxHighlightForVBClass);
}
public InnerRichEditControl CurrentCodeEditor
{
get
{
if (CurrentExampleLanguage == ExampleLanguage.Csharp)
return codeEditorCs.InnerControl;
else
return codeEditorVb.InnerControl;
}
}
public InnerRichEditControl CurrentCodeClassEditor
{
get
{
if (CurrentExampleLanguage == ExampleLanguage.Csharp)
return codeEditorCsClass.InnerControl;
else
return codeEditorVbClass.InnerControl; ;
}
}
public DateTime LastExampleCodeModifiedTime { get { return lastExampleCodeModifiedTime; } }
public bool RichEditTextChanged { get { return richEditTextChanged; } }
public ExampleLanguage CurrentExampleLanguage
{
get { return current; }
set
{
try
{
UnsubscribeRichEditEvents();
current = value;
}
finally
{
SubscribeRichEditEvent();
forceTextChangesCounter = 0; // no changes in that richEdit (CurrentCodeEditor)
richEditTextChanged = true;
}
}
}
void richEditControl_TextChanged(object sender, EventArgs e)
{
if (forceTextChangesCounter <= 0)
{
richEditTextChanged = true;
lastExampleCodeModifiedTime = DateTime.Now;
}
else
forceTextChangesCounter--;
}
public string ShowExample(CodeExample oldExample, CodeExample newExample)
{
InnerRichEditControl richEditControlCs = codeEditorCs.InnerControl;
InnerRichEditControl richEditControlVb = codeEditorVb.InnerControl;
InnerRichEditControl richEditControlCsClass = codeEditorCsClass.InnerControl;
InnerRichEditControl richEditControlVbClass = codeEditorVbClass.InnerControl;
if (oldExample != null)
{
//save edited example
oldExample.CodeCS = richEditControlCs.Text;
oldExample.CodeVB = richEditControlVb.Text;
oldExample.CodeCsHelper = richEditControlCsClass.Text;
oldExample.CodeVbHelper = richEditControlVbClass.Text;
}
string exampleCode = String.Empty;
if (newExample != null)
{
try
{
forceTextChangesCounter = 2;
exampleCode = (CurrentExampleLanguage == ExampleLanguage.Csharp) ? newExample.CodeCS : newExample.CodeVB;
richEditControlCs.Text = newExample.CodeCS;
richEditControlVb.Text = newExample.CodeVB;
richEditControlCsClass.Text = newExample.CodeCsHelper;
richEditControlVbClass.Text = newExample.CodeVbHelper;
richEditTextChanged = false;
}
finally
{
richEditTextChanged = true;
}
}
return exampleCode;
}
void UpdatePageBackground(bool codeEvaluated)
{
CurrentCodeEditor.Document.SetPageBackground((codeEvaluated) ? DXColor.Empty : DXColor.FromArgb(0xFF, 0xBC, 0xC8), true);
CurrentCodeClassEditor.Document.SetPageBackground((codeEvaluated) ? DXColor.Empty : DXColor.FromArgb(0xFF, 0xBC, 0xC8), true);
}
internal void BeforeCompile()
{
UnsubscribeRichEditEvents();
}
internal void AfterCompile(bool codeExecutedWithoutExceptions)
{
UpdatePageBackground(codeExecutedWithoutExceptions);
richEditTextChanged = false;
ResetLastExampleModifiedTime();
SubscribeRichEditEvent();
}
public void ResetLastExampleModifiedTime()
{
lastExampleCodeModifiedTime = DateTime.Now;
}
private void UnsubscribeRichEditEvents()
{
CurrentCodeEditor.ContentChanged -= richEditControl_TextChanged;
CurrentCodeClassEditor.ContentChanged -= richEditControl_TextChanged;
}
void SubscribeRichEditEvent()
{
CurrentCodeEditor.ContentChanged += richEditControl_TextChanged;
CurrentCodeClassEditor.ContentChanged += richEditControl_TextChanged;
}
void InitializeSyntaxHighlightForCs(object sender, EventArgs e)
{
SyntaxHightlightInitializeHelper syntaxHightlightInitializator = new SyntaxHightlightInitializeHelper();
syntaxHightlightInitializator.Initialize(codeEditorCs, CodeExampleDemoUtils.GetCodeExampleFileExtension(ExampleLanguage.Csharp));
DisableRichEditFeatures(codeEditorCs);
}
void InitializeSyntaxHighlightForVb(object sender, EventArgs e)
{
SyntaxHightlightInitializeHelper syntaxHightlightInitializator = new SyntaxHightlightInitializeHelper();
syntaxHightlightInitializator.Initialize(codeEditorVb, CodeExampleDemoUtils.GetCodeExampleFileExtension(ExampleLanguage.VB));
DisableRichEditFeatures(codeEditorVb);
}
private void InitializeSyntaxHighlightForCsClass(object sender, EventArgs e)
{
SyntaxHightlightInitializeHelper syntaxHightlightInitializator = new SyntaxHightlightInitializeHelper();
syntaxHightlightInitializator.Initialize(codeEditorCsClass, CodeExampleDemoUtils.GetCodeExampleFileExtension(ExampleLanguage.Csharp));
DisableRichEditFeatures(codeEditorCsClass);
}
private void InitializeSyntaxHighlightForVBClass(object sender, EventArgs e)
{
SyntaxHightlightInitializeHelper syntaxHightlightInitializator = new SyntaxHightlightInitializeHelper();
syntaxHightlightInitializator.Initialize(codeEditorVbClass, CodeExampleDemoUtils.GetCodeExampleFileExtension(ExampleLanguage.VB));
DisableRichEditFeatures(codeEditorVbClass);
}
void DisableRichEditFeatures(IRichEditControl codeEditor)
{
RichEditControlOptionsBase options = 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.CharacterFormatting = DocumentCapability.Disabled;
//options.DocumentCapabilities.ParagraphFormatting = DocumentCapability.Disabled;
options.DocumentCapabilities.Bookmarks = DocumentCapability.Disabled;
options.DocumentCapabilities.CharacterStyle = DocumentCapability.Disabled;
options.DocumentCapabilities.ParagraphStyle = DocumentCapability.Disabled;
}
}
}