internal void RegexRunnerFinished(RegexRunner sender)
{
Busy = false;
Runner = null;
if (sender.Error != null)
{
Status.Text = "Error encountered during processing";
MessageBox.Show(this, sender.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(sender.Replace)) // find
{
foreach (Match m in sender.Matches)
{
TreeNode n = Captures.Nodes.Add("{" + ReplaceNewLines(m.Value) + "}");
foreach (Group g in m.Groups)
{ // TODO: Is there any way to get the name of the group when explicit capture is on?
if (g.Captures.Count > 1)
{
TreeNode nn = n.Nodes.Add("...");
foreach (Capture c in g.Captures)
nn.Nodes.Add("{" + ReplaceNewLines(c.Value) + "}");
}
else if (g.Captures.Count == 1)
n.Nodes.Add(ReplaceNewLines("{" + g.Captures[0].Value) + "}");
}
}
if (sender.Matches.Count == 0)
Status.Text = "No matches";
else if (sender.Matches.Count == 1)
Status.Text = "1 match found";
else
Status.Text = sender.Matches.Count + " matches found";
Status.Text += " in " + sender.GetExecutionTime() + " ms";
Captures.ExpandAll();
}
else // replace
{
ResultText.Text = sender.Result;
if (sender.Matches.Count != 1)
Status.Text = sender.Matches.Count + " replacements performed";
else
Status.Text = "1 replacement performed";
Status.Text += " in " + sender.GetExecutionTime() + " ms";
Captures.Visible = false;
ResultText.Visible = true;
txtInput.Text = txtInput.Text.Replace("\n", "\r\n");
ResultText.Text = ResultText.Text.Replace("\r\n", "\n");
ResultText.Text = ResultText.Text.Replace("\n", "\r\n");
}
}