Skip to content

Commit ad00611

Browse files
author
Sébastien Geiser
committed
Doc for Regex options
1 parent 6b05d04 commit ad00611

16 files changed

+104
-66
lines changed

CSharpRegexTools4Npp/Main.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Drawing;
55
using System.Linq;
6+
using System.Reflection;
67
using System.Runtime.InteropServices;
78
using System.Windows;
89
using System.Windows.Input;
@@ -89,7 +90,7 @@ public static void ShowTheDialog()
8990
{
9091
AppDomain.CurrentDomain.SetupInformation.PrivateBinPath = @"plugins\CSharpRegexTools4Npp";
9192

92-
IntPtr hWnd = FindWindow(null, "C# Regex Tools");
93+
IntPtr hWnd = FindWindow(null, "C# Regex Tools - " + Assembly.GetCallingAssembly().GetName().Version.ToString());
9394

9495
if (hWnd.ToInt64() > 0)
9596
{
@@ -156,7 +157,7 @@ public static void ShowTheDialog()
156157
result = false;
157158
}
158159

159-
hWnd = FindWindow(null, "C# Regex Tool");
160+
hWnd = FindWindow(null, "C# Regex Tool - " + Assembly.GetCallingAssembly().GetName().Version.ToString());
160161
if (hWnd.ToInt64() > 0)
161162
{
162163
SetForegroundWindow(hWnd);

RegexDialog/Model/RegExOptionModel.cs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
24
using System.Text.RegularExpressions;
35

46
namespace RegexDialog
57
{
68
internal class RegExOptionViewModel : NotifyPropertyChangedBaseClass
79
{
10+
private static readonly Dictionary<string, string> optionNameToDescriptionDictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(Res.RegexOptionsDescriptions);
11+
812
/// <summary>
913
/// Sélectionné
1014
/// </summary>
@@ -18,34 +22,19 @@ public bool Selected
1822
{
1923
Config.Instance.RegexOptionsSelection[Name] = value;
2024
Config.Instance.Save();
21-
NotifyPropertyChanged();
2225
}
2326
}
2427

25-
private RegexOptions regexOptions;
26-
2728
/// <summary>
2829
/// L'option d'expression régulière représentée
2930
/// </summary>
30-
public RegexOptions RegexOptions
31-
{
32-
get { return regexOptions; }
33-
set
34-
{
35-
regexOptions = value;
36-
NotifyPropertyChanged();
37-
}
38-
}
31+
public RegexOptions RegexOptions { get; set; }
3932

4033
/// <summary>
4134
/// Nom à affiché
4235
/// </summary>
43-
public string Name
44-
{
45-
get
46-
{
47-
return Enum.GetName(typeof(RegexOptions), regexOptions);
48-
}
49-
}
36+
public string Name => Enum.GetName(typeof(RegexOptions), RegexOptions);
37+
38+
public string Description => optionNameToDescriptionDictionary[Name];
5039
}
5140
}

RegexDialog/Model/RegexResult.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public RegexResult(Regex regex, Capture regexElement, int regexElementNb, string
1919
public virtual void RefreshExpands()
2020
{ }
2121

22-
public virtual bool IsExpanded { get; set; } = false;
22+
public virtual bool IsExpanded { get; set; }
2323

24-
public bool IsSelected { get; set; } = false;
24+
public bool IsSelected { get; set; }
2525

2626
public virtual string ElementType
2727
{
@@ -33,15 +33,15 @@ public virtual string ElementType
3333

3434
public string FileName { get; set; } = string.Empty;
3535

36-
public Capture RegexElement { get; } = null;
36+
public Capture RegexElement { get; }
3737

38-
public int RegexElementNb { get; } = 0;
38+
public int RegexElementNb { get; }
3939

40-
public RegexResult Parent { get; set; } = null;
40+
public RegexResult Parent { get; set; }
4141

4242
public List<RegexResult> Children { get; set; } = new List<RegexResult>();
4343

44-
public Regex Regex { get; private set; }
44+
public Regex Regex { get; }
4545

4646
public virtual string Name
4747
{
@@ -91,7 +91,7 @@ public virtual string OneLineValue
9191
}
9292
}
9393

94-
public virtual int SelectionIndex { get; set; } = 0;
94+
public virtual int SelectionIndex { get; set; }
9595

9696
public virtual int Index
9797
{

RegexDialog/RegExToolDialog.xaml

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@
7777
</DataTrigger>
7878
</Style.Triggers>
7979
</Style>
80-
80+
8181
</Window.Resources>
8282
<DockPanel Background="WhiteSmoke" >
8383
<Menu DockPanel.Dock="Top" BorderBrush="Silver" BorderThickness="0,0,0,1">
8484
<MenuItem Header="_File" >
8585
<MenuItem Header="_New" Click="New_MenuItem_Click" >
8686
<MenuItem.Icon>
8787
<Image Source="{StaticResource NewPicture}" />
88-
</MenuItem.Icon>
88+
</MenuItem.Icon>
8989
</MenuItem>
9090
<Separator/>
9191
<MenuItem Header="_Open" Click="Open_MenuItem_Click">
9292
<MenuItem.Icon>
93-
<Image Source="{StaticResource OpenPicture}" />
93+
<Image Source="{StaticResource OpenPicture}" />
9494
</MenuItem.Icon>
9595
</MenuItem>
9696
<MenuItem Header="Save _As..." Click="Save_as_MenuItem_Click" >
@@ -582,19 +582,23 @@
582582
</Grid.RowDefinitions>
583583
<DockPanel>
584584
<Grid DockPanel.Dock="Top">
585+
<Grid.ColumnDefinitions>
586+
<ColumnDefinition Width="185*"/>
587+
<ColumnDefinition Width="279*"/>
588+
</Grid.ColumnDefinitions>
585589
<Grid.RowDefinitions>
586590
<RowDefinition Height="Auto" />
587591
</Grid.RowDefinitions>
588592
<Label Content="_Find..."
589593
VerticalAlignment="Center"
590-
Margin="2,0"
594+
Margin="2,1"
591595
Padding="0"
592596
Target="{Binding ElementName=FindLanguageElementTextBox}"
593-
Foreground="Gray" />
597+
Foreground="Gray" Grid.ColumnSpan="2" />
594598
<TextBox x:Name="FindLanguageElementTextBox"
595599
TextChanged="FindLanguageElementTextBox_TextChanged"
596600
PreviewKeyDown="FindLanguageElementTextBox_PreviewKeyDown"
597-
local:TextBoxHelper.ClearOnKey="Esc">
601+
local:TextBoxHelper.ClearOnKey="Esc" Grid.ColumnSpan="2">
598602
<TextBox.Background>
599603
<MultiBinding Converter="{converters:ExpressionEvalMultiBindingConverter Expression='bindings[0] || bindings[1].Length > 0 ? Brushes.White : Brushes.Transparent'}">
600604
<Binding ElementName="FindLanguageElementTextBox" Path="IsFocused" />
@@ -608,7 +612,7 @@
608612
Background="Transparent"
609613
HorizontalAlignment="Right"
610614
VerticalAlignment="Center"
611-
Visibility="{Binding Text, ElementName=FindLanguageElementTextBox, Converter={converters:ExpressionEvalConverter Expression='binding.Length > 0 ? Visibility.Visible : Visibility.Collapsed'}}">
615+
Visibility="{Binding Text, ElementName=FindLanguageElementTextBox, Converter={converters:ExpressionEvalConverter Expression='binding.Length > 0 ? Visibility.Visible : Visibility.Collapsed'}}" Grid.Column="1" Margin="0,9">
612616
<Path x:Name="ButtonPath"
613617
Margin="3"
614618
Stroke="Black"
@@ -724,14 +728,24 @@
724728
</Grid>
725729
</TabItem>
726730
<TabItem x:Name="RegOptionsTabItem" Header="Regex Op_tions" >
727-
<ItemsControl Name="icRegexOptions">
728-
<ItemsControl.ItemTemplate>
729-
<DataTemplate>
730-
<CheckBox IsChecked="{Binding Selected}"
731-
Content="{Binding Name}" />
732-
</DataTemplate>
733-
</ItemsControl.ItemTemplate>
734-
</ItemsControl>
731+
<StackPanel>
732+
<ItemsControl Name="icRegexOptions">
733+
<ItemsControl.ItemTemplate>
734+
<DataTemplate>
735+
<CheckBox IsChecked="{Binding Selected}"
736+
Content="{Binding Name}"
737+
ToolTip="{Binding Description}"/>
738+
</DataTemplate>
739+
</ItemsControl.ItemTemplate>
740+
</ItemsControl>
741+
<TextBlock>
742+
<Hyperlink NavigateUri="https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regexoptions"
743+
RequestNavigate="Hyperlink_RequestNavigate">
744+
More informations on Regex options
745+
</Hyperlink>
746+
</TextBlock>
747+
748+
</StackPanel>
735749
</TabItem>
736750
<TabItem x:Name="TextSourceTabItem" Header="Ot_her Options">
737751
<DockPanel>

RegexDialog/RegExToolDialog.xaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ private void BuildRegexOptionsCheckBoxs()
316316
.ToList()
317317
.ForEach(regexOption =>
318318
{
319-
if (regexOption != RegexOptions.None && regexOption != RegexOptions.Compiled)
319+
if (regexOption != RegexOptions.None)
320320
{
321321
RegExOptionViewModel reovm = new RegExOptionViewModel
322322
{
@@ -2385,5 +2385,11 @@ private void ShowInCSharpButton_Click(object sender, RoutedEventArgs e)
23852385

23862386
SetCurrentTabInCSharpHighlighting();
23872387
}
2388+
2389+
private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
2390+
{
2391+
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
2392+
e.Handled = true;
2393+
}
23882394
}
23892395
}

RegexDialog/RegexDialog.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@
287287
<DesignTime>True</DesignTime>
288288
<DependentUpon>Res.resx</DependentUpon>
289289
</Compile>
290+
<None Include="Resources\RegexOptionsDescriptions.json" />
290291
<None Include="Resources\VSProgram.cs" />
291292
<Resource Include="Resources\StandardReplaceCode.cs" />
292293
<Resource Include="Resources\CSharpReplaceCallingCode.cs" />

RegexDialog/Res.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RegexDialog/Res.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@
127127
<data name="RegexLanguageElements" type="System.Resources.ResXFileRef, System.Windows.Forms">
128128
<value>resources\regexlanguageelements.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
129129
</data>
130+
<data name="RegexOptionsDescriptions" type="System.Resources.ResXFileRef, System.Windows.Forms">
131+
<value>resources\regexoptionsdescriptions.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
132+
</data>
130133
<data name="Regex_syntax_color" type="System.Resources.ResXFileRef, System.Windows.Forms">
131134
<value>resources\regex_syntax_color.xshd;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;iso-8859-1</value>
132135
</data>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"Compiled": "Specifies that the regular expression is compiled to an assembly.\r\nThis yields faster execution but increases startup time.\r\nThis value should not be assigned to the Options property when calling the CompileToAssembly(RegexCompilationInfo[], AssemblyName) method.",
3+
"CultureInvariant": "Specifies that cultural differences in language is ignored.",
4+
"ECMAScript": "Enables ECMAScript-compliant behavior for the expression.\r\nThis value can be used only in conjunction with the IgnoreCase, Multiline, and Compiled values.\r\nThe use of this value with any other values results in an exception.",
5+
"ExplicitCapture": "Specifies that the only valid captures are explicitly named or numbered groups of the form (?<name>...).\r\nThis allows unnamed parentheses to act as noncapturing groups without the syntactic clumsiness of the expression (?:...).",
6+
"IgnoreCase": "Specifies case-insensitive matching.",
7+
"IgnorePatternWhitespace": "Eliminates unescaped white space from the pattern and enables comments marked with #.\r\nHowever, this value does not affect or eliminate white space in character classes, numeric quantifiers,\r\nor tokens that mark the beginning of individual regular expression language elements.",
8+
"Multiline": "Multiline mode.\r\nChanges the meaning of ^ and $ so they match at the beginning and end, respectively, of any line, and not just the beginning and end of the entire string. ",
9+
"None": "Specifies that no options are set.",
10+
"RightToLeft": "Specifies that the search will be from right to left instead of from left to right.",
11+
"Singleline": "Specifies single-line mode.\r\nChanges the meaning of the dot (.) so it matches every character (instead of every character except \\n)."
12+
}

RegexDialog/UIHelpers/Converters/ChainingConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public class ChainingConverter : BaseConverter, IValueConverter
2525
/// </summary>
2626
public IValueConverter Converter2 { get; set; }
2727

28-
public object Converter1Parameter { get; set; } = null;
29-
public object Converter2Parameter { get; set; } = null;
28+
public object Converter1Parameter { get; set; }
29+
public object Converter2Parameter { get; set; }
3030

3131
/// <summary>
3232
/// For a list of converters to chain (Use as content Property, Converter1 and Converter2 must be null)

RegexDialog/UIHelpers/Converters/CustomBoolToVisibilityConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace RegexDialog.Converters
1212
/// </summary>
1313
public class CustomBoolToVisibilityConverter : BaseConverter, IValueConverter
1414
{
15-
public Visibility? InDesigner { get; set; } = null;
15+
public Visibility? InDesigner { get; set; }
1616

1717
/// <summary>
1818
/// The Value of the visibility when the source value is DependencyProperty.UnsetValue
@@ -30,7 +30,7 @@ public class CustomBoolToVisibilityConverter : BaseConverter, IValueConverter
3030
/// The Value of the visibility when the source value is true
3131
/// Default is Visibility.Visible
3232
/// </summary>
33-
public Visibility TrueValue { get; set; } = Visibility.Visible;
33+
public Visibility TrueValue { get; set; }
3434

3535
/// <summary>
3636
/// The Value of the visibility when the source value is true

RegexDialog/UIHelpers/Converters/EnumBooleanConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace RegexDialog.Converters
77
{
88
public class EnumBooleanConverter : BaseConverter, IValueConverter
99
{
10-
public bool InverseBool { get; set; } = false;
10+
public bool InverseBool { get; set; }
1111

1212
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1313
{

RegexDialog/UIHelpers/Converters/ExpressionEvalConverter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ public class ExpressionEvalConverter : BaseConverter, IValueConverter
2525
/// <summary>
2626
/// If <c>true</c> evaluate a string binding as an expression, if false just inject the binding in the Expression, By default : <c>false</c>
2727
/// </summary>
28-
public bool EvaluateBindingAsAnExpression { get; set; } = false;
28+
public bool EvaluateBindingAsAnExpression { get; set; }
2929

3030
/// <summary>
3131
/// If <c>true</c> evaluate a string binding as an expression, if <c>false</c> just inject the binding in the ExpressionForConvertBack, By default : <c>false</c>
3232
/// </summary>
33-
public bool EvaluateBindingAsAnExpressionForConvertBack { get; set; } = false;
33+
public bool EvaluateBindingAsAnExpressionForConvertBack { get; set; }
3434

3535
/// <summary>
3636
/// If <c>true</c> Evaluate function is callables in an expression. If <c>false</c> Evaluate is not callable.
3737
/// By default : false for security
3838
/// </summary>
39-
public bool IsEvaluateFunctionActivated { get; set; } = false;
39+
public bool IsEvaluateFunctionActivated { get; set; }
4040

4141
/// <summary>
4242
/// If <c>true</c> throw up all evaluate exceptions, if <c>false</c> just return the exception message as a string, By default <c>false</c>
4343
/// </summary>
44-
public bool ThrowExceptions { get; set; } = false;
44+
public bool ThrowExceptions { get; set; }
4545

4646
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
4747
{

RegexDialog/Utils/Config.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ private void Init()
7777

7878
public bool CSharpReplaceMode { get; set; }
7979

80-
public int OptionTabControlSelectedTabItemIndex { get; set; } = 0;
80+
public int OptionTabControlSelectedTabItemIndex { get; set; }
8181

8282
public double? DialogLeft { get; set; } = 0;
8383
public double? DialogTop { get; set; } = 0;
8484
public double? DialogWidth { get; set; } = 800;
8585
public double? DialogHeight { get; set; } = 400;
86-
public bool DialogMaximized { get; set; } = false;
86+
public bool DialogMaximized { get; set; }
8787

8888
public GridLength GridFirstColumnWidth { get; set; } = new GridLength(1, GridUnitType.Star);
8989
public GridLength GridSecondColumnWidth { get; set; } = new GridLength(1, GridUnitType.Star);

0 commit comments

Comments
 (0)