📄 csharpviewer.cs
字号:
using System;
using System.IO;
using System.Text;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using DDW.CSharp;
using DDW.CSharp.Dom;
using DDW.CSharp.Walk;
using DDW.CSharp.Gen;
namespace DDW.CSharpUI
{
public class CSharpViewer : System.Windows.Forms.Form
{
public System.Windows.Forms.TreeView Tree;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.RichTextBox richTextBoxAntlrTree;
private System.Windows.Forms.TabPage tabPageSource;
private System.Windows.Forms.TabPage tabPageAntlrTree;
private System.Windows.Forms.TabPage tabPageCSharpDom;
private System.Windows.Forms.TabPage tabPageRegen;
private System.Windows.Forms.RichTextBox richTextBoxSource;
private System.Windows.Forms.TabControl tabControlCode;
private System.Windows.Forms.RichTextBox richTextBoxCSharpDom;
private System.Windows.Forms.RichTextBox richTextBoxRegen;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.TabPage tabStats;
private System.Windows.Forms.RichTextBox richTextBoxStats;
private System.ComponentModel.IContainer components;
public CSharpViewer()
{
InitializeComponent();
Bitmap iconStrip = new Bitmap(GetType(), "CodeIcons.bmp");
//Images.GetBitmap("CodeIcons.bmp");
Tree.ImageList = new ImageList();
Tree.ImageList.ImageSize = new Size(18, 20);
Tree.ImageList.Images.AddStrip(iconStrip);
Tree.ImageIndex = 0;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
public string SourceText
{
get
{
return richTextBoxSource.Text;
}
set
{
richTextBoxSource.Text = value;
}
}
public string AntlrText
{
get
{
return richTextBoxAntlrTree.Text;
}
set
{
richTextBoxAntlrTree.Text = value;
}
}
public string CSDomText
{
get
{
return richTextBoxCSharpDom.Text;
}
set
{
richTextBoxCSharpDom.Text = value;
}
}
public string RegenText
{
get
{
return richTextBoxRegen.Text;
}
set
{
richTextBoxRegen.Text = value;
}
}
public string StatsText
{
get
{
return richTextBoxStats.Text;
}
set
{
richTextBoxStats.Text = value;
}
}
public void AddGraph(IGraph ig, string filename)
{
this.Tree.Nodes.Clear();
this.Tree.Nodes.Add(new IGraphNode(ig));
StringBuilder source = new StringBuilder();
StreamReader sr = File.OpenText(filename);
source.Append(sr.ReadToEnd());
sr.Close();
this.SourceText = source.ToString();
this.AntlrText = CSharp.AntlrText;
PropertyWalkerTest wt = new PropertyWalkerTest();
PropertyWalker.Walk(ig, wt);
this.CSDomText = wt.ToString();
StringBuilder sb = new StringBuilder();
StringWriter stw = new StringWriter(sb);
CSharpGen csg = new CSharpGen(stw);
csg.Parse(ig);
this.RegenText = stw.ToString();
csg.Close();
stw.Close();
}
public void AddFile(string filename)
{
IGraph ig = CSharp.GetGraph(filename);
AddGraph(ig, filename);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CSharpViewer));
this.Tree = new System.Windows.Forms.TreeView();
this.richTextBoxAntlrTree = new System.Windows.Forms.RichTextBox();
this.panel1 = new System.Windows.Forms.Panel();
this.panel3 = new System.Windows.Forms.Panel();
this.tabControlCode = new System.Windows.Forms.TabControl();
this.tabPageSource = new System.Windows.Forms.TabPage();
this.richTextBoxSource = new System.Windows.Forms.RichTextBox();
this.tabPageAntlrTree = new System.Windows.Forms.TabPage();
this.tabPageCSharpDom = new System.Windows.Forms.TabPage();
this.richTextBoxCSharpDom = new System.Windows.Forms.RichTextBox();
this.tabPageRegen = new System.Windows.Forms.TabPage();
this.richTextBoxRegen = new System.Windows.Forms.RichTextBox();
this.tabStats = new System.Windows.Forms.TabPage();
this.richTextBoxStats = new System.Windows.Forms.RichTextBox();
this.splitter1 = new System.Windows.Forms.Splitter();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.panel1.SuspendLayout();
this.panel3.SuspendLayout();
this.tabControlCode.SuspendLayout();
this.tabPageSource.SuspendLayout();
this.tabPageAntlrTree.SuspendLayout();
this.tabPageCSharpDom.SuspendLayout();
this.tabPageRegen.SuspendLayout();
this.tabStats.SuspendLayout();
this.SuspendLayout();
//
// Tree
//
this.Tree.Dock = System.Windows.Forms.DockStyle.Left;
this.Tree.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Tree.ImageIndex = -1;
this.Tree.Indent = 18;
this.Tree.ItemHeight = 20;
this.Tree.Name = "Tree";
this.Tree.SelectedImageIndex = -1;
this.Tree.Size = new System.Drawing.Size(392, 729);
this.Tree.TabIndex = 0;
this.Tree.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.Tree_AfterSelect);
//
// richTextBoxAntlrTree
//
this.richTextBoxAntlrTree.Dock = System.Windows.Forms.DockStyle.Fill;
this.richTextBoxAntlrTree.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.richTextBoxAntlrTree.Name = "richTextBoxAntlrTree";
this.richTextBoxAntlrTree.Size = new System.Drawing.Size(792, 703);
this.richTextBoxAntlrTree.TabIndex = 2;
this.richTextBoxAntlrTree.Text = "Antlr Tree";
this.richTextBoxAntlrTree.WordWrap = false;
//
// panel1
//
this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel3,
this.splitter1,
this.Tree});
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(1200, 729);
this.panel1.TabIndex = 3;
//
// panel3
//
this.panel3.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabControlCode});
this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel3.Location = new System.Drawing.Point(400, 0);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(800, 729);
this.panel3.TabIndex = 4;
//
// tabControlCode
//
this.tabControlCode.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabPageSource,
this.tabPageAntlrTree,
this.tabPageCSharpDom,
this.tabPageRegen,
this.tabStats});
this.tabControlCode.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControlCode.Name = "tabControlCode";
this.tabControlCode.SelectedIndex = 0;
this.tabControlCode.Size = new System.Drawing.Size(800, 729);
this.tabControlCode.TabIndex = 3;
//
// tabPageSource
//
this.tabPageSource.Controls.AddRange(new System.Windows.Forms.Control[] {
this.richTextBoxSource});
this.tabPageSource.Location = new System.Drawing.Point(4, 22);
this.tabPageSource.Name = "tabPageSource";
this.tabPageSource.Size = new System.Drawing.Size(792, 703);
this.tabPageSource.TabIndex = 0;
this.tabPageSource.Text = "Source";
//
// richTextBoxSource
//
this.richTextBoxSource.Dock = System.Windows.Forms.DockStyle.Fill;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -