📄 newfile.cs
字号:
namespace Codematic
{
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
public class NewFile : Form
{
private Button btn_Cancel;
private Button btn_Ok;
private IContainer components;
private GroupBox groupBox1;
private ImageList imageList1;
private Label label1;
private Label label3;
private TextBox lblTooltip;
private ListView listView1;
private MainForm mainfrm;
private Panel panel1;
private TreeView treeView1;
public NewFile(Form mdiParentForm)
{
this.InitializeComponent();
this.mainfrm = (MainForm) mdiParentForm;
this.InitTreeView();
this.InitListView();
}
private void btn_Cancel_Click(object sender, EventArgs e)
{
base.Close();
}
private void btn_Ok_Click(object sender, EventArgs e)
{
if (this.listView1.SelectedItems.Count >= 1)
{
string text = this.listView1.SelectedItems[0].Text;
if (text != null)
{
if (!(text == "文本文件"))
{
if (text == "C# 类")
{
string path = Application.StartupPath + @"\Template\Class1.cs";
if (!File.Exists(path))
{
StreamWriter writer2 = new StreamWriter(path, false, Encoding.Default);
writer2.Write("");
writer2.Flush();
writer2.Close();
}
this.mainfrm.AddTabPage("Class1.cs", new CodeEditor(path, "cs"));
}
else if (text == "VB 类")
{
string str4 = Application.StartupPath + @"\Template\Class1.vb";
if (!File.Exists(str4))
{
StreamWriter writer3 = new StreamWriter(str4, false, Encoding.Default);
writer3.Write("");
writer3.Flush();
writer3.Close();
}
this.mainfrm.AddTabPage("Class1.vb", new CodeEditor(str4, "vb"));
}
}
else
{
string str2 = Application.StartupPath + @"\tempnewtxt.txt";
StreamWriter writer = new StreamWriter(str2, false, Encoding.Default);
writer.Write("");
writer.Flush();
writer.Close();
this.mainfrm.AddTabPage("TextFile1.txt", new CodeEditor(str2, "txt"));
}
}
base.Close();
}
}
protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = new Container();
ComponentResourceManager manager = new ComponentResourceManager(typeof(NewFile));
this.listView1 = new ListView();
this.lblTooltip = new TextBox();
this.label3 = new Label();
this.label1 = new Label();
this.panel1 = new Panel();
this.treeView1 = new TreeView();
this.groupBox1 = new GroupBox();
this.btn_Cancel = new Button();
this.btn_Ok = new Button();
this.imageList1 = new ImageList(this.components);
this.panel1.SuspendLayout();
base.SuspendLayout();
this.listView1.Dock = DockStyle.Fill;
this.listView1.Location = new Point(0, 0);
this.listView1.Name = "listView1";
this.listView1.ShowItemToolTips = true;
this.listView1.Size = new Size(0x17b, 0xb6);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.SelectedIndexChanged += new EventHandler(this.listView1_SelectedIndexChanged);
this.lblTooltip.Location = new Point(12, 0xd3);
this.lblTooltip.Name = "lblTooltip";
this.lblTooltip.ReadOnly = true;
this.lblTooltip.Size = new Size(0x224, 0x15);
this.lblTooltip.TabIndex = 8;
this.label3.AutoSize = true;
this.label3.Location = new Point(0xb3, 9);
this.label3.Name = "label3";
this.label3.Size = new Size(0x3b, 12);
this.label3.TabIndex = 7;
this.label3.Text = "模板(&T):";
this.label1.AutoSize = true;
this.label1.Location = new Point(13, 9);
this.label1.Name = "label1";
this.label1.Size = new Size(0x53, 12);
this.label1.TabIndex = 6;
this.label1.Text = "项目类型(&P):";
this.panel1.Controls.Add(this.listView1);
this.panel1.Location = new Point(0xb5, 0x1a);
this.panel1.Name = "panel1";
this.panel1.Size = new Size(0x17b, 0xb6);
this.panel1.TabIndex = 5;
this.treeView1.Location = new Point(12, 0x1a);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new Size(0xa3, 0xb6);
this.treeView1.TabIndex = 4;
this.groupBox1.Location = new Point(12, 0xee);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new Size(0x224, 4);
this.groupBox1.TabIndex = 9;
this.groupBox1.TabStop = false;
this.btn_Cancel.Location = new Point(0x1d9, 0xfc);
this.btn_Cancel.Name = "btn_Cancel";
this.btn_Cancel.Size = new Size(0x4b, 0x17);
this.btn_Cancel.TabIndex = 10;
this.btn_Cancel.Text = "取消";
this.btn_Cancel.UseVisualStyleBackColor = true;
this.btn_Cancel.Click += new EventHandler(this.btn_Cancel_Click);
this.btn_Ok.Location = new Point(0x16e, 0xfc);
this.btn_Ok.Name = "btn_Ok";
this.btn_Ok.Size = new Size(0x4b, 0x17);
this.btn_Ok.TabIndex = 10;
this.btn_Ok.Text = "确定";
this.btn_Ok.UseVisualStyleBackColor = true;
this.btn_Ok.Click += new EventHandler(this.btn_Ok_Click);
this.imageList1.ImageStream = (ImageListStreamer) manager.GetObject("imageList1.ImageStream");
this.imageList1.TransparentColor = Color.Transparent;
this.imageList1.Images.SetKeyName(0, "txt.gif");
this.imageList1.Images.SetKeyName(1, "cs32.gif");
this.imageList1.Images.SetKeyName(2, "vb.gif");
this.imageList1.Images.SetKeyName(3, "htm.gif");
base.AutoScaleDimensions = new SizeF(6f, 12f);
base.AutoScaleMode = AutoScaleMode.Font;
base.ClientSize = new Size(0x237, 0x11b);
base.Controls.Add(this.btn_Ok);
base.Controls.Add(this.btn_Cancel);
base.Controls.Add(this.groupBox1);
base.Controls.Add(this.lblTooltip);
base.Controls.Add(this.label3);
base.Controls.Add(this.label1);
base.Controls.Add(this.panel1);
base.Controls.Add(this.treeView1);
base.FormBorderStyle = FormBorderStyle.FixedDialog;
base.HelpButton = true;
base.MaximizeBox = false;
base.MinimizeBox = false;
base.Name = "NewFile";
base.ShowIcon = false;
base.StartPosition = FormStartPosition.CenterScreen;
this.Text = "新建文件";
this.panel1.ResumeLayout(false);
base.ResumeLayout(false);
base.PerformLayout();
}
private void InitListView()
{
this.listView1.Columns.Clear();
this.listView1.Items.Clear();
this.listView1.LargeImageList = this.imageList1;
this.listView1.View = View.LargeIcon;
ListViewGroup group = new ListViewGroup("Codematic 已安装的模版", HorizontalAlignment.Left);
group.Header = "Codematic 已安装的模版";
group.Name = "listViewGroup1";
this.listView1.Groups.AddRange(new ListViewGroup[] { group });
string text = "文本文件";
ListViewItem item = new ListViewItem(text, 0);
item.SubItems.Add(text);
item.ImageIndex = 0;
item.Group = group;
this.listView1.Items.AddRange(new ListViewItem[] { item });
text = "C# 类";
ListViewItem item2 = new ListViewItem(text, 0);
item2.SubItems.Add(text);
item2.ImageIndex = 1;
item2.Group = group;
this.listView1.Items.AddRange(new ListViewItem[] { item2 });
text = "VB 类";
ListViewItem item3 = new ListViewItem(text, 0);
item3.SubItems.Add(text);
item3.ImageIndex = 2;
item3.Group = group;
this.listView1.Items.AddRange(new ListViewItem[] { item3 });
}
private void InitTreeView()
{
TreeNode node = new TreeNode("常规", 0, 1);
TreeNode node2 = new TreeNode("模版", 2, 3);
this.treeView1.Nodes.Add(node);
this.treeView1.Nodes.Add(node2);
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
string str2;
if ((this.listView1.SelectedItems.Count >= 1) && ((str2 = this.listView1.SelectedItems[0].Text) != null))
{
if (!(str2 == "文本文件"))
{
if (!(str2 == "C# 类"))
{
if (str2 == "VB 类")
{
this.lblTooltip.Text = "创建空白VB 类";
}
}
else
{
this.lblTooltip.Text = "创建空白C# 类";
}
}
else
{
this.lblTooltip.Text = "创建空白文本文件";
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -