Skip to content

Commit 16612da

Browse files
author
Sébastien Geiser
committed
Add C# Globals between #global and #endglobal
1 parent 112132d commit 16612da

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

RegexDialog/RegExToolDialog.xaml.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public partial class RegExToolDialog : Window
4545

4646
private bool mustSelectEditor = false;
4747

48+
private Regex cSharpReplacePartSplitter = new Regex("#global(?<global>.*)#endglobal", RegexOptions.Compiled);
49+
4850
private BracketColorizer currentBracketColorizer = new BracketColorizer();
4951
private BracketColorizer matchingBracketColorizer = new BracketColorizer();
5052

@@ -548,7 +550,10 @@ private void ReplaceAllButton_Click(object sender, RoutedEventArgs e)
548550

549551
if (CSharpReplaceCheckbox.IsChecked.GetValueOrDefault())
550552
{
551-
dynamic script = CSScript.Evaluator.LoadCode(Res.CSharpReplaceContainer.Replace("//code", ReplaceEditor.Text));
553+
dynamic script = CSScript.Evaluator.LoadCode(
554+
Res.CSharpReplaceContainer
555+
.Replace("//code", cSharpReplacePartSplitter.Replace(ReplaceEditor.Text, string.Empty))
556+
.Replace("//global", cSharpReplacePartSplitter.Match(ReplaceEditor.Text).Groups["global"].Value));
552557

553558
int index = -1;
554559

@@ -753,9 +758,14 @@ private void ExtractMatchesButton_Click(object sender, RoutedEventArgs e)
753758
dynamic script = null;
754759

755760
if (CSharpReplaceCheckbox.IsChecked.GetValueOrDefault())
756-
script = CSScript.Evaluator.LoadCode(Res.CSharpReplaceContainer.Replace("//code", ReplaceEditor.Text));
761+
{
762+
script = CSScript.Evaluator.LoadCode(
763+
Res.CSharpReplaceContainer
764+
.Replace("//code", cSharpReplacePartSplitter.Replace(ReplaceEditor.Text, string.Empty))
765+
.Replace("//global", cSharpReplacePartSplitter.Match(ReplaceEditor.Text).Groups["global"].Value));
766+
}
757767

758-
void Extract(string text, string fileName = "")
768+
void Extract(string text, string fileName = "")
759769
{
760770
List<Match> matches = regex.Matches(text)
761771
.Cast<Match>()
@@ -1386,7 +1396,10 @@ private void ReplaceInEditor_MenuItem_Click(object sender, RoutedEventArgs e)
13861396

13871397
if (CSharpReplaceCheckbox.IsChecked.GetValueOrDefault())
13881398
{
1389-
dynamic script = CSScript.Evaluator.LoadCode(Res.CSharpReplaceContainer.Replace("//code", ReplaceEditor.Text));
1399+
dynamic script = CSScript.Evaluator.LoadCode(
1400+
Res.CSharpReplaceContainer
1401+
.Replace("//code", cSharpReplacePartSplitter.Replace(ReplaceEditor.Text, string.Empty))
1402+
.Replace("//global", cSharpReplacePartSplitter.Match(ReplaceEditor.Text).Groups["global"].Value));
13901403

13911404
int index = -1;
13921405

@@ -1431,7 +1444,10 @@ private void ReplaceInEditor_MenuItem_Click(object sender, RoutedEventArgs e)
14311444

14321445
if (CSharpReplaceCheckbox.IsChecked.GetValueOrDefault())
14331446
{
1434-
dynamic script = CSScript.Evaluator.LoadCode(Res.CSharpReplaceContainer.Replace("//code", ReplaceEditor.Text));
1447+
dynamic script = CSScript.Evaluator.LoadCode(
1448+
Res.CSharpReplaceContainer
1449+
.Replace("//code", cSharpReplacePartSplitter.Replace(ReplaceEditor.Text, string.Empty))
1450+
.Replace("//global", cSharpReplacePartSplitter.Match(ReplaceEditor.Text).Groups["global"].Value));
14351451

14361452
if (regexResult is RegexMatchResult regexMatchResult)
14371453
newText = beforeMatch + script.Replace((Match)regexMatchResult.RegexElement, regexMatchResult.RegexElementNb, regexResult.FileName, regexMatchResult.RegexElementNb, 0) + afterMatch;

RegexDialog/Resources/CSharpReplaceContainer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
public class Script
99
{
10+
//global
11+
1012
public string Replace(Match match, int index, string fileName, int globalIndex, int fileIndex)
1113
{
1214
//code

0 commit comments

Comments
 (0)