Skip to content

Commit f7df8c6

Browse files
committed
Improved syntax highlighting.
1 parent 01553ef commit f7df8c6

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

Virtual_EDW/CustomTabPage.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class CustomTabPage : TabPage
8181
/// </summary>
8282
public void ApplySyntaxHighlightingForHandlebars()
8383
{
84-
TextHandling.SyntaxHighlightHandlebars(localRichTextBoxGenerationPattern, localRichTextBoxGenerationPattern.Text.TrimEnd());
84+
localRichTextBoxGenerationPattern.Rtf = TextHandling.SyntaxHighlightHandlebars(localRichTextBoxGenerationPattern.Text.TrimEnd()).Rtf;
8585
}
8686

8787
public void SetDisplayJsonFlag(bool value)
@@ -142,7 +142,7 @@ public CustomTabPage(string classification, string notes, Dictionary<string, VDW
142142
localButtonGenerate.Name = $"Generate{classification}";
143143
localButtonGenerate.Size = new Size(170, 40);
144144
localButtonGenerate.Text = $"Generate {_inputNiceName}";
145-
localButtonGenerate.Click += new EventHandler(Generate);
145+
localButtonGenerate.Click += Generate;
146146

147147
// Add 'Processing' Label
148148
var localLabelProcessing = new Label();
@@ -680,8 +680,8 @@ private void GenerateFromPattern()
680680
RaiseOnChangeMainText($"\r\n{errorCounter} error(s) have been found.\r\n");
681681
RaiseOnChangeMainText($"\r\nAssociated scripts have been saved in {FormBase.VdwConfigurationSettings.VdwOutputPath}.\r\n");
682682

683-
// Apply syntax highlighting
684-
TextHandling.SyntaxHighlightSql(localRichTextBoxGenerationOutput, localRichTextBoxGenerationOutput.Text);
683+
// Apply syntax highlighting.
684+
localRichTextBoxGenerationOutput.Rtf = TextHandling.SyntaxHighlightSql(localRichTextBoxGenerationOutput.Text).Rtf;
685685
}
686686

687687
/// <summary>

Virtual_EDW/TextHandling.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ namespace Virtual_Data_Warehouse
77
{
88
class TextHandling
99
{
10-
internal static void SyntaxHighlightHandlebars(RichTextBox inputTextBox, string inputText)
10+
internal static RichTextBox SyntaxHighlightHandlebars(string inputText)
1111
{
12-
inputTextBox.Clear();
12+
RichTextBox returnTextBox = new RichTextBox();
1313

1414
// Split the text into lines, so we can parse each line for syntax highlighting
1515
Regex splitLineRegex = new Regex("\\n");
@@ -27,8 +27,8 @@ internal static void SyntaxHighlightHandlebars(RichTextBox inputTextBox, string
2727
foreach (string token in tokens)
2828
{
2929
// Make sure the default colour is set
30-
inputTextBox.SelectionColor = Color.Black;
31-
inputTextBox.SelectionFont = new Font(inputTextBox.Font, FontStyle.Regular);
30+
returnTextBox.SelectionColor = Color.Black;
31+
returnTextBox.SelectionFont = new Font(returnTextBox.Font, FontStyle.Regular);
3232

3333
if (token == "{")
3434
{
@@ -46,32 +46,33 @@ internal static void SyntaxHighlightHandlebars(RichTextBox inputTextBox, string
4646
if (keywords[i] == token)
4747
{
4848
// Apply alternative color and font to highlight keyword.
49-
inputTextBox.SelectionColor = Color.DarkGreen;
49+
returnTextBox.SelectionColor = Color.DarkGreen;
5050
//inputTextBox.SelectionFont = new Font(inputTextBox.Font, FontStyle.Bold);
5151
break;
5252
} else if (syntaxHighlightCounter>1 && token !="{" && token!="}")
5353
{
54-
inputTextBox.SelectionColor = Color.Purple;
54+
returnTextBox.SelectionColor = Color.Purple;
5555
//inputTextBox.SelectionFont = new Font(inputTextBox.Font, FontStyle.Bold);
5656
}
5757
}
5858

59-
inputTextBox.SelectedText = token;
59+
returnTextBox.SelectedText = token;
6060

6161
if (token == "}")
6262
{
6363
syntaxHighlightCounter = 0; //Reset the counter
6464
}
6565

6666
}
67-
inputTextBox.SelectedText = "\n";
67+
returnTextBox.SelectedText = "\n";
6868
}
6969

70+
return returnTextBox;
7071
}
7172

72-
internal static void SyntaxHighlightSql(RichTextBox inputTextBox, string inputText)
73+
internal static RichTextBox SyntaxHighlightSql(string inputText)
7374
{
74-
inputTextBox.Clear();
75+
var returnTextBox = new RichTextBox();
7576

7677
// Split the text into lines, so we can parse each line for syntax highlighting
7778
Regex splitLineRegex = new Regex("\\n");
@@ -89,8 +90,8 @@ internal static void SyntaxHighlightSql(RichTextBox inputTextBox, string inputTe
8990
foreach (string token in tokens)
9091
{
9192
// Make sure the default colour is set
92-
inputTextBox.SelectionColor = Color.Black;
93-
inputTextBox.SelectionFont = new Font(inputTextBox.Font, FontStyle.Regular);
93+
returnTextBox.SelectionColor = Color.Black;
94+
returnTextBox.SelectionFont = new Font(returnTextBox.Font, FontStyle.Regular);
9495

9596
if (token == "-")
9697
{
@@ -128,7 +129,7 @@ internal static void SyntaxHighlightSql(RichTextBox inputTextBox, string inputTe
128129
if (keyWordSql[i] == token)
129130
{
130131
// Apply alternative color and font to highlight keyword.
131-
inputTextBox.SelectionColor = Color.Blue;
132+
returnTextBox.SelectionColor = Color.Blue;
132133
//inputTextBox.SelectionFont = new Font(inputTextBox.Font, FontStyle.Bold);
133134
break;
134135
}
@@ -140,7 +141,7 @@ internal static void SyntaxHighlightSql(RichTextBox inputTextBox, string inputTe
140141
if (keyWordFunction[i] == token)
141142
{
142143
// Apply alternative color and font to highlight keyword.
143-
inputTextBox.SelectionColor = Color.Purple;
144+
returnTextBox.SelectionColor = Color.Purple;
144145
//inputTextBox.SelectionFont = new Font(inputTextBox.Font, FontStyle.Bold);
145146
break;
146147
}
@@ -152,23 +153,25 @@ internal static void SyntaxHighlightSql(RichTextBox inputTextBox, string inputTe
152153
if (keyWordFunctionComment[i] == token)
153154
{
154155
// Apply alternative color and font to highlight keyword.
155-
inputTextBox.SelectionColor = Color.ForestGreen;
156+
returnTextBox.SelectionColor = Color.ForestGreen;
156157
//inputTextBox.SelectionFont = new Font(inputTextBox.Font, FontStyle.Bold);
157158
break;
158159
}
159160
}
160161

161-
inputTextBox.SelectedText = token;
162+
returnTextBox.SelectedText = token;
162163

163164
if (token == "}")
164165
{
165166
syntaxHighlightCounter = 0; //Reset the counter
166167
}
167168

168169
}
169-
inputTextBox.SelectedText = "\n";
170+
returnTextBox.SelectedText = "\n";
170171
}
171172

173+
return returnTextBox;
174+
172175
}
173176
}
174177
}

0 commit comments

Comments
 (0)