Skip to content

Commit a270e87

Browse files
committed
C# as text source OK
1 parent 62cd50e commit a270e87

File tree

4 files changed

+46
-32
lines changed

4 files changed

+46
-32
lines changed

RegexDialog/Model/RegexFileResult.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,15 @@ internal class RegexFileResult : RegexResult
77
public RegexFileResult(Regex regex, Capture regexElement, int regexElementNb, string fileName) : base(regex, regexElement, regexElementNb, fileName, 0)
88
{}
99

10-
public override string Name
11-
{
12-
get
13-
{
14-
return $"File {RegexElementNb}: {Children.Count} matches found in \"{FileName}\"";
15-
}
16-
}
10+
public override string Name => $"File {RegexElementNb}: {Children.Count} matches found in \"{FileName}\"";
1711

1812
public override bool IsExpanded { get => true; }
1913

2014
public override void RefreshExpands()
2115
{
22-
Children.ForEach(delegate (RegexResult child)
23-
{
24-
child.RefreshExpands();
25-
});
16+
Children.ForEach(child => child.RefreshExpands());
2617
}
2718

28-
public override string ElementType
29-
{
30-
get
31-
{
32-
return "File";
33-
}
34-
}
19+
public override string ElementType => "File";
3520
}
3621
}

RegexDialog/Model/RegexMatchResult.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public RegexMatchResult(Regex regex, Match match, int matchNb, string fileName =
1212
Children = match.Groups
1313
.Cast<Group>()
1414
.ToList()
15-
.ConvertAll(delegate(Group group)
15+
.ConvertAll(group =>
1616
{
1717
RegexResult result = new RegexGroupResult(regex, group, i, fileName, selectionIndex)
1818
{
@@ -34,10 +34,7 @@ public override void RefreshExpands()
3434
{
3535
if (Config.Instance.MatchesShowLevel > 1)
3636
{
37-
Children.ForEach(delegate(RegexResult child)
38-
{
39-
child.RefreshExpands();
40-
});
37+
Children.ForEach(child => child.RefreshExpands());
4138

4239
IsExpanded = true;
4340
}

RegexDialog/RegExToolDialog.xaml.cs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private void Init()
226226

227227
// Construit l'arbre des éléments de languages de replace.
228228
BuildReplaceLanguageElements();
229-
229+
230230
csEval
231231
.ReferenceAssemblyOf(this)
232232
.ReferenceDomainAssemblies()
@@ -567,6 +567,14 @@ List<RegexResult> GetMatchesFor(string text, string fileName = "", int selection
567567

568568
MatchesResultLabel.Content = $"{i} matches [Index,Length] + {countAllCaptures - i} empties matches found in {ff}/{ft} files";
569569
}
570+
else if(Config.Instance.TextSourceOn == RegexTextSource.CSharpScript)
571+
{
572+
dynamic sourceScript = CSharpTextSourceScript;
573+
574+
MatchResultsTreeView.ItemsSource = GetMatchesFor(sourceScript.Get().ToString(), "script");
575+
576+
MatchesResultLabel.Content = $"{i} matches [Index,Length] + {countAllCaptures - i} empties matches";
577+
}
570578
else
571579
{
572580
lastMatchesText = GetText();
@@ -681,13 +689,23 @@ private void ReplaceAllButton_Click(object sender, RoutedEventArgs e)
681689
nbrOfElementToReplace = regex.Matches(text).Count;
682690
lastSelectionStart = GetSelectionStartIndex?.Invoke() ?? 0;
683691
lastSelectionLength = GetSelectionLength?.Invoke() ?? 0;
684-
692+
685693
SetSelectedText(script.After(regex.Replace(text, match =>
686694
{
687695
index++;
688696
return script.Replace(match, index, currentFileName, index, 0);
689697
}), currentFileName, null));
690698
break;
699+
case RegexTextSource.CSharpScript:
700+
dynamic scriptSource = CSharpTextSourceScript;
701+
text = script.Before(scriptSource.Get().ToString(), "script");
702+
nbrOfElementToReplace = regex.Matches(text).Count;
703+
SetTextInNew(script.After(regex.Replace(text, match =>
704+
{
705+
index++;
706+
return script.Replace(match, index, "script", index, 0);
707+
}), "script", null));
708+
break;
691709
default:
692710
currentFileName = GetCurrentFileName?.Invoke() ?? string.Empty;
693711
text = script.Before(GetCurrentText(), currentFileName);
@@ -754,6 +772,12 @@ private void ReplaceAllButton_Click(object sender, RoutedEventArgs e)
754772
nbrOfElementToReplace = regex.Matches(text).Count;
755773
SetSelectedText(regex.Replace(text, ReplaceEditor.Text));
756774
break;
775+
case RegexTextSource.CSharpScript:
776+
dynamic script = CSharpTextSourceScript;
777+
text = script.Get().ToString();
778+
nbrOfElementToReplace = regex.Matches(text).Count;
779+
SetTextInNew(regex.Replace(text, ReplaceEditor.Text));
780+
break;
757781
default:
758782
text = GetCurrentText();
759783
nbrOfElementToReplace = regex.Matches(text).Count;
@@ -870,6 +894,11 @@ void Extract(string text, string fileName = "")
870894
fileNames = GetFiles();
871895
fileNames.ForEach(fileName => Extract(File.ReadAllText(fileName), fileName));
872896
}
897+
else if(Config.Instance.TextSourceOn == RegexTextSource.CSharpScript)
898+
{
899+
dynamic sourceScript = CSharpTextSourceScript;
900+
Extract(sourceScript.Get().ToString(), "script");
901+
}
873902
else
874903
{
875904
currentFileName = GetCurrentFileName?.Invoke() ?? string.Empty;
@@ -981,14 +1010,17 @@ private void MatchResultsTreeView_SelectedItemChanged(object sender, RoutedPrope
9811010
{
9821011
RegexResult regexResult = e.NewValue as RegexResult;
9831012

984-
if (regexResult?.FileName.Length > 0)
1013+
if (!regexResult?.FileName.Equals("script") ?? true)
9851014
{
986-
if ((TryOpen?.Invoke(regexResult.FileName, true) ?? false) && !(regexResult is RegexFileResult))
1015+
if (regexResult?.FileName.Length > 0)
1016+
{
1017+
if ((TryOpen?.Invoke(regexResult.FileName, true) ?? false) && !(regexResult is RegexFileResult))
1018+
SetPosition(regexResult.Index, regexResult.Length);
1019+
}
1020+
else if (regexResult != null && lastMatchesText.Equals(GetText()))
1021+
{
9871022
SetPosition(regexResult.Index, regexResult.Length);
988-
}
989-
else if (regexResult != null && lastMatchesText.Equals(GetText()))
990-
{
991-
SetPosition(regexResult.Index, regexResult.Length);
1023+
}
9921024
}
9931025
}
9941026
catch
@@ -1722,7 +1754,6 @@ private void Save_as_MenuItem_Click(object sender, RoutedEventArgs e)
17221754
replacePatternElement.AppendChild(replacePatternText);
17231755
optionsElement.AppendChild(optionsText);
17241756

1725-
17261757
xmlDoc.Save(dialog.FileName);
17271758
}
17281759
catch (Exception ex)

RegexDialog/RegexDialog.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@
217217
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
218218
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
219219
</Reference>
220+
<Reference Include="System.Web" />
220221
<Reference Include="System.Windows.Forms" />
221222
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
222223
<HintPath>..\packages\Microsoft.SDK.Expression.Blend.1.0.0\lib\net45\System.Windows.Interactivity.dll</HintPath>

0 commit comments

Comments
 (0)