@@ -226,7 +226,7 @@ private void Init()
226226
227227 // Construit l'arbre des éléments de languages de replace.
228228 BuildReplaceLanguageElements ( ) ;
229-
229+
230230 csEval
231231 . ReferenceAssemblyOf ( this )
232232 . ReferenceDomainAssemblies ( )
@@ -567,6 +567,14 @@ List<RegexResult> GetMatchesFor(string text, string fileName = "", int selection
567567
568568 MatchesResultLabel . Content = $ "{ i } matches [Index,Length] + { countAllCaptures - i } empties matches found in { ff } /{ ft } files";
569569 }
570+ else if ( Config . Instance . TextSourceOn == RegexTextSource . CSharpScript )
571+ {
572+ dynamic sourceScript = CSharpTextSourceScript ;
573+
574+ MatchResultsTreeView . ItemsSource = GetMatchesFor ( sourceScript . Get ( ) . ToString ( ) , "script" ) ;
575+
576+ MatchesResultLabel . Content = $ "{ i } matches [Index,Length] + { countAllCaptures - i } empties matches";
577+ }
570578 else
571579 {
572580 lastMatchesText = GetText ( ) ;
@@ -681,13 +689,23 @@ private void ReplaceAllButton_Click(object sender, RoutedEventArgs e)
681689 nbrOfElementToReplace = regex . Matches ( text ) . Count ;
682690 lastSelectionStart = GetSelectionStartIndex ? . Invoke ( ) ?? 0 ;
683691 lastSelectionLength = GetSelectionLength ? . Invoke ( ) ?? 0 ;
684-
692+
685693 SetSelectedText ( script . After ( regex . Replace ( text , match =>
686694 {
687695 index ++ ;
688696 return script . Replace ( match , index , currentFileName , index , 0 ) ;
689697 } ) , currentFileName , null ) ) ;
690698 break ;
699+ case RegexTextSource . CSharpScript :
700+ dynamic scriptSource = CSharpTextSourceScript ;
701+ text = script . Before ( scriptSource . Get ( ) . ToString ( ) , "script" ) ;
702+ nbrOfElementToReplace = regex . Matches ( text ) . Count ;
703+ SetTextInNew ( script . After ( regex . Replace ( text , match =>
704+ {
705+ index ++ ;
706+ return script . Replace ( match , index , "script" , index , 0 ) ;
707+ } ) , "script" , null ) ) ;
708+ break ;
691709 default :
692710 currentFileName = GetCurrentFileName ? . Invoke ( ) ?? string . Empty ;
693711 text = script . Before ( GetCurrentText ( ) , currentFileName ) ;
@@ -754,6 +772,12 @@ private void ReplaceAllButton_Click(object sender, RoutedEventArgs e)
754772 nbrOfElementToReplace = regex . Matches ( text ) . Count ;
755773 SetSelectedText ( regex . Replace ( text , ReplaceEditor . Text ) ) ;
756774 break ;
775+ case RegexTextSource . CSharpScript :
776+ dynamic script = CSharpTextSourceScript ;
777+ text = script . Get ( ) . ToString ( ) ;
778+ nbrOfElementToReplace = regex . Matches ( text ) . Count ;
779+ SetTextInNew ( regex . Replace ( text , ReplaceEditor . Text ) ) ;
780+ break ;
757781 default :
758782 text = GetCurrentText ( ) ;
759783 nbrOfElementToReplace = regex . Matches ( text ) . Count ;
@@ -870,6 +894,11 @@ void Extract(string text, string fileName = "")
870894 fileNames = GetFiles ( ) ;
871895 fileNames . ForEach ( fileName => Extract ( File . ReadAllText ( fileName ) , fileName ) ) ;
872896 }
897+ else if ( Config . Instance . TextSourceOn == RegexTextSource . CSharpScript )
898+ {
899+ dynamic sourceScript = CSharpTextSourceScript ;
900+ Extract ( sourceScript . Get ( ) . ToString ( ) , "script" ) ;
901+ }
873902 else
874903 {
875904 currentFileName = GetCurrentFileName ? . Invoke ( ) ?? string . Empty ;
@@ -981,14 +1010,17 @@ private void MatchResultsTreeView_SelectedItemChanged(object sender, RoutedPrope
9811010 {
9821011 RegexResult regexResult = e . NewValue as RegexResult ;
9831012
984- if ( regexResult ? . FileName . Length > 0 )
1013+ if ( ! regexResult ? . FileName . Equals ( "script" ) ?? true )
9851014 {
986- if ( ( TryOpen ? . Invoke ( regexResult . FileName , true ) ?? false ) && ! ( regexResult is RegexFileResult ) )
1015+ if ( regexResult ? . FileName . Length > 0 )
1016+ {
1017+ if ( ( TryOpen ? . Invoke ( regexResult . FileName , true ) ?? false ) && ! ( regexResult is RegexFileResult ) )
1018+ SetPosition ( regexResult . Index , regexResult . Length ) ;
1019+ }
1020+ else if ( regexResult != null && lastMatchesText . Equals ( GetText ( ) ) )
1021+ {
9871022 SetPosition ( regexResult . Index , regexResult . Length ) ;
988- }
989- else if ( regexResult != null && lastMatchesText . Equals ( GetText ( ) ) )
990- {
991- SetPosition ( regexResult . Index , regexResult . Length ) ;
1023+ }
9921024 }
9931025 }
9941026 catch
@@ -1722,7 +1754,6 @@ private void Save_as_MenuItem_Click(object sender, RoutedEventArgs e)
17221754 replacePatternElement . AppendChild ( replacePatternText ) ;
17231755 optionsElement . AppendChild ( optionsText ) ;
17241756
1725-
17261757 xmlDoc . Save ( dialog . FileName ) ;
17271758 }
17281759 catch ( Exception ex )
0 commit comments