@@ -59,15 +59,20 @@ public partial class RegExToolDialog : Window
5959 private static readonly Regex cSharpReplaceGlobalPartRegex = new Regex ( @"(?<=^|\s)\#global(?=\s)(?<global>.*)(?<=\s)\#endglobal(?=\s|$)" , RegexOptions . Singleline | RegexOptions . Compiled ) ;
6060 private static readonly Regex cSharpReplaceBeforePartRegex = new Regex ( @"(?<=^|\s)\#before(?=\s)(?<before>.*)(?<=\s)\#endbefore(?=\s|$)" , RegexOptions . Singleline | RegexOptions . Compiled ) ;
6161 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 ) ;
6263
6364 private string InjectInReplaceScript ( string replaceScript )
6465 {
6566 Match beforeMatch = cSharpReplaceBeforePartRegex . Match ( ReplaceEditor . Text ) ;
6667 Match afterMatch = cSharpReplaceAfterPartRegex . Match ( ReplaceEditor . Text ) ;
6768
6869 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 ( ) )
7176 . Replace ( "//global" , cSharpReplaceGlobalPartRegex . Match ( ReplaceEditor . Text ) . Groups [ "global" ] . Value )
7277 . Replace ( "//before" , beforeMatch . Success ? beforeMatch . Groups [ "before" ] . Value : "return text;" )
7378 . Replace ( "//after" , afterMatch . Success ? afterMatch . Groups [ "after" ] . Value : "return text;" ) ;
@@ -89,7 +94,11 @@ private string InjectInReplaceScript(string replaceScript)
8994 . RegexReplace ( "//capture(?<keep>.*)//endcapture" , "${keep}" , RegexOptions . Singleline ) ) ;
9095
9196 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 ( ) )
93102 . Replace ( "//usings" , cSharpReplaceUsingsPartRegex . Match ( TextSourceEditor . Text ) . Groups [ "usings" ] . Value ) ;
94103
95104 public delegate bool TryOpenDelegate ( string fileName , bool onlyIfAlreadyOpen ) ;
@@ -1654,6 +1663,7 @@ private void New_MenuItem_Click(object sender, RoutedEventArgs e)
16541663
16551664 RegexEditor . Text = string . Empty ;
16561665 ReplaceEditor . Text = string . Empty ;
1666+ TextSourceEditor . Text = string . Empty ;
16571667
16581668 regExOptionViewModelsList . ForEach ( optionModel => optionModel . Selected = false ) ;
16591669 }
@@ -2083,11 +2093,18 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
20832093 string replaceFile = Path . Combine ( projectDirectory , "CSharpReplaceContainer.cs" ) ;
20842094 string textSourceFile = Path . Combine ( projectDirectory , "TextSourceContainer.cs" ) ;
20852095 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 ( ) ) ) ;
20862102
20872103 string programCode = Res . VSProgram
20882104 . Replace ( "projectname" , projectName )
20892105 . Replace ( "$pattern$" , Config . Instance . RegexEditorText . ToLiteral ( ) )
2090- . Replace ( "$replacement$" , Config . Instance . ReplaceEditorText . ToLiteral ( ) ) ;
2106+ . Replace ( "$replacement$" , Config . Instance . ReplaceEditorText . ToLiteral ( ) )
2107+ . Replace ( "_options_" , options ) ;
20912108
20922109 Directory . CreateDirectory ( projectDirectory ) ;
20932110
0 commit comments