Skip to content

Commit 6e69a48

Browse files
author
Sébastien Geiser
committed
#global ok
1 parent 16612da commit 6e69a48

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

RegexDialog/RegExToolDialog.xaml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,14 @@
336336
Content="_C#">
337337
<CheckBox.ToolTip>
338338
<StackPanel>
339-
<TextBlock>You must use at least one return keyword to return a string</TextBlock>
339+
<TextBlock>You must use at least one <Bold>return</Bold> keyword to return a string</TextBlock>
340340
<TextBlock>You can use the following variables :</TextBlock>
341-
<TextBlock>- match : Contains the current Regex Match</TextBlock>
342-
<TextBlock>- index : The index of the current match in the current file</TextBlock>
343-
<TextBlock>- fileName : (If in directory search) the fileName where the match was found</TextBlock>
344-
<TextBlock>- globalIndex : (If in directory search) the index of the match in all files</TextBlock>
345-
<TextBlock>- fileIndex : (If in directory search) the index of the file</TextBlock>
341+
<TextBlock>- <Bold>match</Bold> : Contains the current Regex Match</TextBlock>
342+
<TextBlock>- <Bold>index</Bold> : The index of the current match in the current file</TextBlock>
343+
<TextBlock>- <Bold>fileName</Bold> : (If in directory search) the fileName where the match was found</TextBlock>
344+
<TextBlock>- <Bold>globalIndex</Bold> : (If in directory search) the index of the match in all files</TextBlock>
345+
<TextBlock>- <Bold>fileIndex</Bold> : (If in directory search) the index of the file</TextBlock>
346+
<TextBlock Margin="0,5">You can declare shared variables, properties or methods putting code between <Bold>#global</Bold> and <Bold>#endglobal</Bold></TextBlock>
346347
</StackPanel>
347348
</CheckBox.ToolTip>
348349
</CheckBox>
@@ -507,7 +508,7 @@
507508
<Grid.RowDefinitions>
508509
<RowDefinition x:Name="RegexLanguageElementFirstRow" Height="*" MinHeight="50" />
509510
<RowDefinition Height="5" />
510-
<RowDefinition Height="0.1*" />
511+
<RowDefinition Height="0.1*" MinHeight="30"/>
511512
</Grid.RowDefinitions>
512513
<TreeView Name="RegexLanguagesElementsTreeView" SelectedItemChanged="RegexLanguagesElementsTreeView_SelectedItemChanged">
513514
<TreeView.Resources>
@@ -528,9 +529,9 @@
528529
</TreeView.Resources>
529530
</TreeView>
530531
<GridSplitter
531-
Grid.Row="1"
532-
VerticalAlignment="Stretch"
533-
HorizontalAlignment="Stretch"/>
532+
Grid.Row="1"
533+
VerticalAlignment="Stretch"
534+
HorizontalAlignment="Stretch"/>
534535
<TextBox Name="tbxRegexLanguageElementDescription"
535536
IsReadOnly="True"
536537
TextWrapping="Wrap"

RegexDialog/RegExToolDialog.xaml.cs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,21 @@ public partial class RegExToolDialog : Window
4545

4646
private bool mustSelectEditor = false;
4747

48-
private Regex cSharpReplacePartSplitter = new Regex("#global(?<global>.*)#endglobal", RegexOptions.Compiled);
49-
5048
private BracketColorizer currentBracketColorizer = new BracketColorizer();
5149
private BracketColorizer matchingBracketColorizer = new BracketColorizer();
5250

51+
private Regex cSharpReplacePartSplitter = new Regex(@"(?<=^|\s)\#global(?=\s)(?<global>.*)(?<=\s)\#endglobal(?=\s|$)", RegexOptions.Singleline | RegexOptions.Compiled);
52+
53+
public object ReplaceScript
54+
{
55+
get
56+
{
57+
return CSScript.Evaluator.LoadCode(Res.CSharpReplaceContainer
58+
.Replace("//code", cSharpReplacePartSplitter.Replace(ReplaceEditor.Text, string.Empty))
59+
.Replace("//global", cSharpReplacePartSplitter.Match(ReplaceEditor.Text).Groups["global"].Value));
60+
}
61+
}
62+
5363
public delegate string GetTextDelegate();
5464
public delegate string GetCurrentFileNameDelegate();
5565
public delegate void SetTextDelegate(string text);
@@ -330,7 +340,7 @@ private void ShowMatchesButton_Click(object sender, RoutedEventArgs e)
330340
}
331341

332342
/// <summary>
333-
///
343+
/// Ajoute les champs textes courant spécifié à leur historique
334344
/// </summary>
335345
/// <param name="historyNbr">1 = seulement regex, 2 = seulement replace, 0 = tout</param>
336346
private void SetToHistory(int historyNbr = 0)
@@ -550,10 +560,7 @@ private void ReplaceAllButton_Click(object sender, RoutedEventArgs e)
550560

551561
if (CSharpReplaceCheckbox.IsChecked.GetValueOrDefault())
552562
{
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));
563+
dynamic script = ReplaceScript;
557564

558565
int index = -1;
559566

@@ -759,10 +766,7 @@ private void ExtractMatchesButton_Click(object sender, RoutedEventArgs e)
759766

760767
if (CSharpReplaceCheckbox.IsChecked.GetValueOrDefault())
761768
{
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));
769+
script = ReplaceScript;
766770
}
767771

768772
void Extract(string text, string fileName = "")
@@ -1396,10 +1400,7 @@ private void ReplaceInEditor_MenuItem_Click(object sender, RoutedEventArgs e)
13961400

13971401
if (CSharpReplaceCheckbox.IsChecked.GetValueOrDefault())
13981402
{
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));
1403+
dynamic script = ReplaceScript;
14031404

14041405
int index = -1;
14051406

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

14451446
if (CSharpReplaceCheckbox.IsChecked.GetValueOrDefault())
14461447
{
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));
1448+
dynamic script = ReplaceScript;
14511449

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

0 commit comments

Comments
 (0)