@@ -1606,33 +1606,29 @@ private void OpenRegex()
1606
1606
1607
1607
bool ? result = dialog . ShowDialog ( this ) ;
1608
1608
1609
- if ( result . HasValue && result . Value )
1609
+ if ( result . HasValue && result . Value && File . Exists ( dialog . FileName ) )
1610
1610
{
1611
- if ( File . Exists ( dialog . FileName ) )
1611
+ try
1612
1612
{
1613
- try
1614
- {
1615
- SetToHistory ( ) ;
1613
+ SetToHistory ( ) ;
1616
1614
1617
- XmlDocument xmlDoc = new XmlDocument ( ) ;
1618
- xmlDoc . Load ( dialog . FileName ) ;
1615
+ XmlDocument xmlDoc = new XmlDocument ( ) ;
1616
+ string content = File . ReadAllText ( dialog . FileName ) ;
1617
+ xmlDoc . LoadXml ( content ) ;
1619
1618
1620
- XmlElement root = xmlDoc . DocumentElement ;
1619
+ XmlElement root = xmlDoc . DocumentElement ;
1621
1620
1622
- RegexEditor . Text = root . SelectSingleNode ( "//FindPattern" ) . InnerText ;
1623
- ReplaceEditor . Text = root . SelectSingleNode ( "//ReplacePattern" ) . InnerText ;
1621
+ CSharpReplaceCheckbox . IsChecked = content . Contains ( "<!--ReplaceIsCSharp-->" ) ;
1622
+ RegexEditor . Text = root . SelectSingleNode ( "//FindPattern" ) . InnerText ;
1623
+ ReplaceEditor . Text = root . SelectSingleNode ( "//ReplacePattern" ) . InnerText ;
1624
1624
1625
- string [ ] xOptions = root . SelectSingleNode ( "//Options" ) . InnerText . Split ( ' ' ) ;
1625
+ string [ ] xOptions = root . SelectSingleNode ( "//Options" ) . InnerText . Split ( ' ' ) ;
1626
1626
1627
- regExOptionViewModelsList . ForEach ( delegate ( RegExOptionViewModel optionModel )
1628
- {
1629
- optionModel . Selected = xOptions . Contains ( optionModel . Name ) ;
1630
- } ) ;
1631
- }
1632
- catch ( Exception ex )
1633
- {
1634
- MessageBox . Show ( ex . Message , "Error" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
1635
- }
1627
+ regExOptionViewModelsList . ForEach ( ( RegExOptionViewModel optionModel ) => optionModel . Selected = xOptions . Contains ( optionModel . Name ) ) ;
1628
+ }
1629
+ catch ( Exception ex )
1630
+ {
1631
+ MessageBox . Show ( ex . Message , "Error" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
1636
1632
}
1637
1633
}
1638
1634
}
@@ -1652,13 +1648,13 @@ private void Save_as_MenuItem_Click(object sender, RoutedEventArgs e)
1652
1648
1653
1649
bool ? result = dialog . ShowDialog ( this ) ;
1654
1650
1655
- if ( result . HasValue && result . Value )
1651
+ if ( result == true )
1656
1652
{
1657
1653
try
1658
1654
{
1659
1655
XmlDocument xmlDoc = new XmlDocument ( ) ;
1660
1656
1661
- XmlDeclaration xmlDeclaration = xmlDoc . CreateXmlDeclaration ( "1.0" , null , null ) ;
1657
+ XmlDeclaration xmlDeclaration = xmlDoc . CreateXmlDeclaration ( "1.0" , null , null ) ;
1662
1658
1663
1659
XmlElement root = xmlDoc . CreateElement ( "SavedRegex" ) ;
1664
1660
xmlDoc . InsertBefore ( xmlDeclaration , xmlDoc . DocumentElement ) ;
@@ -1672,14 +1668,16 @@ private void Save_as_MenuItem_Click(object sender, RoutedEventArgs e)
1672
1668
XmlElement optionsElement = xmlDoc . CreateElement ( "Options" ) ;
1673
1669
1674
1670
root . AppendChild ( findPatternElement ) ;
1671
+ if ( CSharpReplaceCheckbox . IsChecked ?? false )
1672
+ root . AppendChild ( xmlDoc . CreateComment ( "ReplaceIsCSharp" ) ) ;
1675
1673
root . AppendChild ( replacePatternElement ) ;
1676
1674
root . AppendChild ( optionsElement ) ;
1677
1675
1678
1676
XmlText findPatternText = xmlDoc . CreateTextNode ( RegexEditor . Text ) ;
1679
1677
XmlText replacePatternText = xmlDoc . CreateTextNode ( ReplaceEditor . Text ) ;
1680
1678
1681
1679
string sOptionsText = regExOptionViewModelsList
1682
- . Aggregate < RegExOptionViewModel , string > ( "" , ( total , next ) => total + ( next . Selected ? next . Name + " " : "" ) )
1680
+ . Aggregate ( "" , ( total , next ) => total + ( next . Selected ? next . Name + " " : "" ) )
1683
1681
. Trim ( ) ;
1684
1682
1685
1683
XmlText optionsText = xmlDoc . CreateTextNode ( sOptionsText ) ;
@@ -1714,7 +1712,7 @@ private void Root_PreviewKeyDown(object sender, KeyEventArgs e)
1714
1712
{
1715
1713
if ( e . Key == Key . Escape )
1716
1714
{
1717
- this . Close ( ) ;
1715
+ Close ( ) ;
1718
1716
e . Handled = true ;
1719
1717
}
1720
1718
else if ( e . Key == Key . F5 )
0 commit comments