Skip to content

Commit 112132d

Browse files
author
Sébastien Geiser
committed
Save The CSharp Checkbox state
1 parent 78bbac2 commit 112132d

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

RegexDialog/RegExToolDialog.xaml.cs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,33 +1606,29 @@ private void OpenRegex()
16061606

16071607
bool? result = dialog.ShowDialog(this);
16081608

1609-
if (result.HasValue && result.Value)
1609+
if (result.HasValue && result.Value && File.Exists(dialog.FileName))
16101610
{
1611-
if (File.Exists(dialog.FileName))
1611+
try
16121612
{
1613-
try
1614-
{
1615-
SetToHistory();
1613+
SetToHistory();
16161614

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);
16191618

1620-
XmlElement root = xmlDoc.DocumentElement;
1619+
XmlElement root = xmlDoc.DocumentElement;
16211620

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;
16241624

1625-
string[] xOptions = root.SelectSingleNode("//Options").InnerText.Split(' ');
1625+
string[] xOptions = root.SelectSingleNode("//Options").InnerText.Split(' ');
16261626

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);
16361632
}
16371633
}
16381634
}
@@ -1652,13 +1648,13 @@ private void Save_as_MenuItem_Click(object sender, RoutedEventArgs e)
16521648

16531649
bool? result = dialog.ShowDialog(this);
16541650

1655-
if (result.HasValue && result.Value)
1651+
if (result == true)
16561652
{
16571653
try
16581654
{
16591655
XmlDocument xmlDoc = new XmlDocument();
16601656

1661-
XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", null, null);
1657+
XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", null, null);
16621658

16631659
XmlElement root = xmlDoc.CreateElement("SavedRegex");
16641660
xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
@@ -1672,14 +1668,16 @@ private void Save_as_MenuItem_Click(object sender, RoutedEventArgs e)
16721668
XmlElement optionsElement = xmlDoc.CreateElement("Options");
16731669

16741670
root.AppendChild(findPatternElement);
1671+
if (CSharpReplaceCheckbox.IsChecked ?? false)
1672+
root.AppendChild(xmlDoc.CreateComment("ReplaceIsCSharp"));
16751673
root.AppendChild(replacePatternElement);
16761674
root.AppendChild(optionsElement);
16771675

16781676
XmlText findPatternText = xmlDoc.CreateTextNode(RegexEditor.Text);
16791677
XmlText replacePatternText = xmlDoc.CreateTextNode(ReplaceEditor.Text);
16801678

16811679
string sOptionsText = regExOptionViewModelsList
1682-
.Aggregate<RegExOptionViewModel, string>("", (total, next) => total + (next.Selected ? next.Name + " " : ""))
1680+
.Aggregate("", (total, next) => total + (next.Selected ? next.Name + " " : ""))
16831681
.Trim();
16841682

16851683
XmlText optionsText = xmlDoc.CreateTextNode(sOptionsText);
@@ -1714,7 +1712,7 @@ private void Root_PreviewKeyDown(object sender, KeyEventArgs e)
17141712
{
17151713
if (e.Key == Key.Escape)
17161714
{
1717-
this.Close();
1715+
Close();
17181716
e.Handled = true;
17191717
}
17201718
else if (e.Key == Key.F5)

0 commit comments

Comments
 (0)