73 lines
2.1 KiB
C#
73 lines
2.1 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
|
|
namespace YLPublishTool.Forms
|
|
{
|
|
public partial class ParseForm : Form
|
|
{
|
|
public ParseForm()
|
|
{
|
|
InitializeComponent();
|
|
openFileDialog1.InitialDirectory = AppContext.BaseDirectory;
|
|
}
|
|
|
|
public string ParseFilePath
|
|
{
|
|
get { return tbFilePath.Text; }
|
|
set { tbFilePath.Text = value; }
|
|
}
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
|
{
|
|
tbFilePath.Text = openFileDialog1.FileName;
|
|
ParseFile(tbFilePath.Text);
|
|
}
|
|
}
|
|
|
|
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
|
|
{
|
|
var tag = (ParseInfo)e.Node.Tag;
|
|
rtbResult.Text = tag.ErrorInfo ?? tag.ConvertedText;
|
|
|
|
rtbSource.SelectionColor = rtbSource.ForeColor;
|
|
rtbSource.SelectionBackColor = rtbSource.BackColor;
|
|
rtbSource.Select(tag.StartPos, tag.EndPos- tag.StartPos);
|
|
rtbSource.SelectionColor = System.Drawing.Color.White;
|
|
rtbSource.SelectionBackColor = System.Drawing.Color.Blue;
|
|
rtbSource.ScrollToCaret();
|
|
}
|
|
|
|
private void ParseForm_Load(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(ParseFilePath))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (System.IO.File.Exists(ParseFilePath))
|
|
{
|
|
ParseFile(ParseFilePath);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("文件不存在:" + ParseFilePath);
|
|
}
|
|
}
|
|
|
|
private void ParseFile(string filePath)
|
|
{
|
|
rtbSource.Text = System.IO.File.ReadAllText(filePath);
|
|
var nodes = new Parser().InnerParse(rtbSource.Text);
|
|
treeView1.Nodes.Clear();
|
|
if (nodes.Any())
|
|
{
|
|
treeView1.Nodes.AddRange(nodes.ToArray());
|
|
treeView1.ExpandAll();
|
|
treeView1.Nodes[0].EnsureVisible();
|
|
}
|
|
}
|
|
}
|
|
}
|