5
5
using Newtonsoft . Json ;
6
6
using Ookii . Dialogs . Wpf ;
7
7
using System ;
8
+ using System . CodeDom ;
9
+ using System . CodeDom . Compiler ;
8
10
using System . Collections . Generic ;
9
11
using System . Collections . ObjectModel ;
12
+ using System . Diagnostics ;
10
13
using System . IO ;
11
14
using System . Linq ;
12
15
using System . Text ;
@@ -85,7 +88,7 @@ private string InjectInReplaceScript(string replaceScript)
85
88
. RegexReplace ( @"\s*//(?<type>match|group).*//end\k<type>" , string . Empty , RegexOptions . Singleline )
86
89
. RegexReplace ( "//capture(?<keep>.*)//endcapture" , "${keep}" , RegexOptions . Singleline ) ) ;
87
90
88
- public string CSharpTextSourceScript => Res . CSharpTextSourceContainer
91
+ public string CSharpTextSourceScript => Res . TextSourceContainer
89
92
. Replace ( "//code" , cSharpReplaceSpecialZoneCleaningRegex . Replace ( TextSourceEditor . Text , string . Empty ) )
90
93
. Replace ( "//usings" , cSharpReplaceUsingsPartRegex . Match ( TextSourceEditor . Text ) . Groups [ "usings" ] . Value ) ;
91
94
@@ -575,7 +578,7 @@ List<RegexResult> GetMatchesFor(string text, string fileName = "", int selection
575
578
}
576
579
else if ( Config . Instance . TextSourceOn == RegexTextSource . CSharpScript )
577
580
{
578
- dynamic sourceScript = CSharpTextSourceScript ;
581
+ dynamic sourceScript = csEval . LoadCode ( CSharpTextSourceScript ) ;
579
582
580
583
MatchResultsTreeView . ItemsSource = GetMatchesFor ( sourceScript . Get ( ) . ToString ( ) , "script" ) ;
581
584
@@ -902,7 +905,7 @@ void Extract(string text, string fileName = "")
902
905
}
903
906
else if ( Config . Instance . TextSourceOn == RegexTextSource . CSharpScript )
904
907
{
905
- dynamic sourceScript = CSharpTextSourceScript ;
908
+ dynamic sourceScript = csEval . LoadCode ( CSharpTextSourceScript ) ;
906
909
Extract ( sourceScript . Get ( ) . ToString ( ) , "script" ) ;
907
910
}
908
911
else
@@ -1616,6 +1619,15 @@ private void InsertInReplaceFromContextMenu_Click(object sender, RoutedEventArgs
1616
1619
catch { }
1617
1620
}
1618
1621
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
+
1619
1631
private void PutInRegexHistory_Click ( object sender , RoutedEventArgs e )
1620
1632
{
1621
1633
try
@@ -1805,6 +1817,15 @@ private void CmiRegexCopyForOnOneLine_Click(object sender, RoutedEventArgs e)
1805
1817
catch { }
1806
1818
}
1807
1819
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
+
1808
1829
private void CmiRegexCopyForXml_Click ( object sender , RoutedEventArgs e )
1809
1830
{
1810
1831
try
@@ -2035,12 +2056,13 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
2035
2056
VistaFolderBrowserDialog folderBrowserDialog = new VistaFolderBrowserDialog ( )
2036
2057
{
2037
2058
ShowNewFolderButton = true ,
2059
+ SelectedPath = @"C:\Projets"
2038
2060
} ;
2039
2061
2040
2062
Ookii . Dialogs . WinForms . InputDialog inputDialog = new Ookii . Dialogs . WinForms . InputDialog ( )
2041
2063
{
2042
2064
Content = "give a name for your project/solution :" ,
2043
- Input = "MySolution "
2065
+ Input = "TestRegexSol "
2044
2066
} ;
2045
2067
2046
2068
if ( folderBrowserDialog . ShowDialog ( this ) == true && inputDialog . ShowDialog ( ) == System . Windows . Forms . DialogResult . OK )
@@ -2058,8 +2080,15 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
2058
2080
string projectDirectory = Path . Combine ( solutionDirectory , projectName ) ;
2059
2081
string projectFile = Path . Combine ( projectDirectory , $ "{ projectName } .csproj") ;
2060
2082
string entryFile = Path . Combine ( projectDirectory , "Program.cs" ) ;
2083
+ string replaceFile = Path . Combine ( projectDirectory , "CSharpReplaceContainer.cs" ) ;
2084
+ string textSourceFile = Path . Combine ( projectDirectory , "TextSourceContainer.cs" ) ;
2061
2085
string projectGuid = Guid . NewGuid ( ) . ToString ( ) ;
2062
2086
2087
+ string programCode = Res . VSProgram
2088
+ . Replace ( "projectname" , projectName )
2089
+ . Replace ( "$pattern$" , Config . Instance . RegexEditorText . ToLiteral ( ) )
2090
+ . Replace ( "$replacement$" , Config . Instance . ReplaceEditorText . ToLiteral ( ) ) ;
2091
+
2063
2092
Directory . CreateDirectory ( projectDirectory ) ;
2064
2093
2065
2094
// Write solution file
@@ -2084,14 +2113,30 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
2084
2113
MessageBoxButton . YesNo ,
2085
2114
MessageBoxImage . Question ) == MessageBoxResult . Yes )
2086
2115
{
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 ) ;
2089
2127
}
2090
2128
2091
2129
// 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 } \" ") ;
2095
2140
}
2096
2141
}
2097
2142
}
0 commit comments