55using Newtonsoft . Json ;
66using Ookii . Dialogs . Wpf ;
77using System ;
8+ using System . CodeDom ;
9+ using System . CodeDom . Compiler ;
810using System . Collections . Generic ;
911using System . Collections . ObjectModel ;
12+ using System . Diagnostics ;
1013using System . IO ;
1114using System . Linq ;
1215using System . Text ;
@@ -85,7 +88,7 @@ private string InjectInReplaceScript(string replaceScript)
8588 . RegexReplace ( @"\s*//(?<type>match|group).*//end\k<type>" , string . Empty , RegexOptions . Singleline )
8689 . RegexReplace ( "//capture(?<keep>.*)//endcapture" , "${keep}" , RegexOptions . Singleline ) ) ;
8790
88- public string CSharpTextSourceScript => Res . CSharpTextSourceContainer
91+ public string CSharpTextSourceScript => Res . TextSourceContainer
8992 . Replace ( "//code" , cSharpReplaceSpecialZoneCleaningRegex . Replace ( TextSourceEditor . Text , string . Empty ) )
9093 . Replace ( "//usings" , cSharpReplaceUsingsPartRegex . Match ( TextSourceEditor . Text ) . Groups [ "usings" ] . Value ) ;
9194
@@ -575,7 +578,7 @@ List<RegexResult> GetMatchesFor(string text, string fileName = "", int selection
575578 }
576579 else if ( Config . Instance . TextSourceOn == RegexTextSource . CSharpScript )
577580 {
578- dynamic sourceScript = CSharpTextSourceScript ;
581+ dynamic sourceScript = csEval . LoadCode ( CSharpTextSourceScript ) ;
579582
580583 MatchResultsTreeView . ItemsSource = GetMatchesFor ( sourceScript . Get ( ) . ToString ( ) , "script" ) ;
581584
@@ -902,7 +905,7 @@ void Extract(string text, string fileName = "")
902905 }
903906 else if ( Config . Instance . TextSourceOn == RegexTextSource . CSharpScript )
904907 {
905- dynamic sourceScript = CSharpTextSourceScript ;
908+ dynamic sourceScript = csEval . LoadCode ( CSharpTextSourceScript ) ;
906909 Extract ( sourceScript . Get ( ) . ToString ( ) , "script" ) ;
907910 }
908911 else
@@ -1616,6 +1619,15 @@ private void InsertInReplaceFromContextMenu_Click(object sender, RoutedEventArgs
16161619 catch { }
16171620 }
16181621
1622+ private void CmiReplaceCopyForCSharpString_Click ( object sender , RoutedEventArgs e )
1623+ {
1624+ try
1625+ {
1626+ Clipboard . SetText ( ( ReplaceEditor . SelectionLength > 0 ? ReplaceEditor . SelectedText : ReplaceEditor . Text ) . ToLiteral ( ) ) ;
1627+ }
1628+ catch { }
1629+ }
1630+
16191631 private void PutInRegexHistory_Click ( object sender , RoutedEventArgs e )
16201632 {
16211633 try
@@ -1805,6 +1817,15 @@ private void CmiRegexCopyForOnOneLine_Click(object sender, RoutedEventArgs e)
18051817 catch { }
18061818 }
18071819
1820+ private void CmiRegexCopyForCSharpString_Click ( object sender , RoutedEventArgs e )
1821+ {
1822+ try
1823+ {
1824+ Clipboard . SetText ( ( RegexEditor . SelectionLength > 0 ? RegexEditor . SelectedText : RegexEditor . Text ) . ToLiteral ( ) ) ;
1825+ }
1826+ catch { }
1827+ }
1828+
18081829 private void CmiRegexCopyForXml_Click ( object sender , RoutedEventArgs e )
18091830 {
18101831 try
@@ -2035,12 +2056,13 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
20352056 VistaFolderBrowserDialog folderBrowserDialog = new VistaFolderBrowserDialog ( )
20362057 {
20372058 ShowNewFolderButton = true ,
2059+ SelectedPath = @"C:\Projets"
20382060 } ;
20392061
20402062 Ookii . Dialogs . WinForms . InputDialog inputDialog = new Ookii . Dialogs . WinForms . InputDialog ( )
20412063 {
20422064 Content = "give a name for your project/solution :" ,
2043- Input = "MySolution "
2065+ Input = "TestRegexSol "
20442066 } ;
20452067
20462068 if ( folderBrowserDialog . ShowDialog ( this ) == true && inputDialog . ShowDialog ( ) == System . Windows . Forms . DialogResult . OK )
@@ -2058,8 +2080,15 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
20582080 string projectDirectory = Path . Combine ( solutionDirectory , projectName ) ;
20592081 string projectFile = Path . Combine ( projectDirectory , $ "{ projectName } .csproj") ;
20602082 string entryFile = Path . Combine ( projectDirectory , "Program.cs" ) ;
2083+ string replaceFile = Path . Combine ( projectDirectory , "CSharpReplaceContainer.cs" ) ;
2084+ string textSourceFile = Path . Combine ( projectDirectory , "TextSourceContainer.cs" ) ;
20612085 string projectGuid = Guid . NewGuid ( ) . ToString ( ) ;
20622086
2087+ string programCode = Res . VSProgram
2088+ . Replace ( "projectname" , projectName )
2089+ . Replace ( "$pattern$" , Config . Instance . RegexEditorText . ToLiteral ( ) )
2090+ . Replace ( "$replacement$" , Config . Instance . ReplaceEditorText . ToLiteral ( ) ) ;
2091+
20632092 Directory . CreateDirectory ( projectDirectory ) ;
20642093
20652094 // Write solution file
@@ -2084,14 +2113,30 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
20842113 MessageBoxButton . YesNo ,
20852114 MessageBoxImage . Question ) == MessageBoxResult . Yes )
20862115 {
2087- File . WriteAllText ( projectFile ,
2088- Res . VSProject ) ;
2116+ File . WriteAllText ( projectFile , Res . VSProject ) ;
2117+ }
2118+
2119+ if ( Config . Instance . CSharpReplaceMode )
2120+ {
2121+ File . WriteAllText ( replaceFile , ReplaceScriptForMatch ) ;
2122+ }
2123+
2124+ if ( Config . Instance . TextSourceOn == RegexTextSource . CSharpScript )
2125+ {
2126+ File . WriteAllText ( textSourceFile , CSharpTextSourceScript ) ;
20892127 }
20902128
20912129 // Write Entry file
2092- File . WriteAllText ( entryFile ,
2093- Res . VSProgram
2094- . Replace ( "projectname" , projectName ) ) ;
2130+ if ( ! File . Exists ( entryFile )
2131+ || MessageBox . Show ( $ "The entry file \" { entryFile } \" already exists.\r \n Do you want to override it ?",
2132+ "Entry file override" ,
2133+ MessageBoxButton . YesNo ,
2134+ MessageBoxImage . Question ) == MessageBoxResult . Yes )
2135+ {
2136+ File . WriteAllText ( entryFile , programCode ) ;
2137+ }
2138+
2139+ Process . Start ( $ "\" { solutionFile } \" ") ;
20952140 }
20962141 }
20972142 }
0 commit comments