@@ -59,15 +59,20 @@ public partial class RegExToolDialog : Window
59
59
private static readonly Regex cSharpReplaceGlobalPartRegex = new Regex ( @"(?<=^|\s)\#global(?=\s)(?<global>.*)(?<=\s)\#endglobal(?=\s|$)" , RegexOptions . Singleline | RegexOptions . Compiled ) ;
60
60
private static readonly Regex cSharpReplaceBeforePartRegex = new Regex ( @"(?<=^|\s)\#before(?=\s)(?<before>.*)(?<=\s)\#endbefore(?=\s|$)" , RegexOptions . Singleline | RegexOptions . Compiled ) ;
61
61
private static readonly Regex cSharpReplaceAfterPartRegex = new Regex ( @"(?<=^|\s)\#after(?=\s)(?<after>.*)(?<=\s)\#endafter(?=\s|$)" , RegexOptions . Singleline | RegexOptions . Compiled ) ;
62
+ private static readonly Regex cSharpScriptsStartOfLinesForAddingTabs = new Regex ( @"(?<start>^)(?<notend>[^\r\n])" , RegexOptions . Multiline | RegexOptions . Compiled ) ;
62
63
63
64
private string InjectInReplaceScript ( string replaceScript )
64
65
{
65
66
Match beforeMatch = cSharpReplaceBeforePartRegex . Match ( ReplaceEditor . Text ) ;
66
67
Match afterMatch = cSharpReplaceAfterPartRegex . Match ( ReplaceEditor . Text ) ;
67
68
68
69
return replaceScript
69
- . Replace ( "//code" , cSharpReplaceSpecialZoneCleaningRegex . Replace ( ReplaceEditor . Text , string . Empty ) )
70
- . Replace ( "//usings" , cSharpReplaceUsingsPartRegex . Match ( ReplaceEditor . Text ) . Groups [ "usings" ] . Value )
70
+ . Replace ( "//code" ,
71
+ cSharpScriptsStartOfLinesForAddingTabs . Replace (
72
+ cSharpReplaceSpecialZoneCleaningRegex . Replace ( ReplaceEditor . Text , string . Empty )
73
+ , match => match . Groups [ "start" ] . Value + "\t \t " + match . Groups [ "notend" ] . Value )
74
+ . TrimStart ( ) )
75
+ . Replace ( "//usings" , cSharpReplaceUsingsPartRegex . Match ( ReplaceEditor . Text ) . Groups [ "usings" ] . Value . Trim ( ) )
71
76
. Replace ( "//global" , cSharpReplaceGlobalPartRegex . Match ( ReplaceEditor . Text ) . Groups [ "global" ] . Value )
72
77
. Replace ( "//before" , beforeMatch . Success ? beforeMatch . Groups [ "before" ] . Value : "return text;" )
73
78
. Replace ( "//after" , afterMatch . Success ? afterMatch . Groups [ "after" ] . Value : "return text;" ) ;
@@ -89,7 +94,11 @@ private string InjectInReplaceScript(string replaceScript)
89
94
. RegexReplace ( "//capture(?<keep>.*)//endcapture" , "${keep}" , RegexOptions . Singleline ) ) ;
90
95
91
96
public string CSharpTextSourceScript => Res . TextSourceContainer
92
- . Replace ( "//code" , cSharpReplaceSpecialZoneCleaningRegex . Replace ( TextSourceEditor . Text , string . Empty ) )
97
+ . Replace ( "//code" ,
98
+ cSharpScriptsStartOfLinesForAddingTabs . Replace (
99
+ cSharpReplaceSpecialZoneCleaningRegex . Replace ( TextSourceEditor . Text , string . Empty )
100
+ , match => match . Groups [ "start" ] . Value + "\t \t " + match . Groups [ "notend" ] . Value )
101
+ . TrimStart ( ) )
93
102
. Replace ( "//usings" , cSharpReplaceUsingsPartRegex . Match ( TextSourceEditor . Text ) . Groups [ "usings" ] . Value ) ;
94
103
95
104
public delegate bool TryOpenDelegate ( string fileName , bool onlyIfAlreadyOpen ) ;
@@ -1654,6 +1663,7 @@ private void New_MenuItem_Click(object sender, RoutedEventArgs e)
1654
1663
1655
1664
RegexEditor . Text = string . Empty ;
1656
1665
ReplaceEditor . Text = string . Empty ;
1666
+ TextSourceEditor . Text = string . Empty ;
1657
1667
1658
1668
regExOptionViewModelsList . ForEach ( optionModel => optionModel . Selected = false ) ;
1659
1669
}
@@ -2083,11 +2093,18 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
2083
2093
string replaceFile = Path . Combine ( projectDirectory , "CSharpReplaceContainer.cs" ) ;
2084
2094
string textSourceFile = Path . Combine ( projectDirectory , "TextSourceContainer.cs" ) ;
2085
2095
string projectGuid = Guid . NewGuid ( ) . ToString ( ) ;
2096
+ string options = regExOptionViewModelsList . Count ( option => option . Selected ) == 0
2097
+ ? "RegexOptions.None"
2098
+ : string . Join ( " | " ,
2099
+ regExOptionViewModelsList
2100
+ . FindAll ( option => option . Selected )
2101
+ . Select ( option => "RegexOptions." + option . RegexOptions . ToString ( ) ) ) ;
2086
2102
2087
2103
string programCode = Res . VSProgram
2088
2104
. Replace ( "projectname" , projectName )
2089
2105
. Replace ( "$pattern$" , Config . Instance . RegexEditorText . ToLiteral ( ) )
2090
- . Replace ( "$replacement$" , Config . Instance . ReplaceEditorText . ToLiteral ( ) ) ;
2106
+ . Replace ( "$replacement$" , Config . Instance . ReplaceEditorText . ToLiteral ( ) )
2107
+ . Replace ( "_options_" , options ) ;
2091
2108
2092
2109
Directory . CreateDirectory ( projectDirectory ) ;
2093
2110
0 commit comments