namespace IndexFormula.Finance.Win { using IndexFormula.Finance; using MuchInfo.Chart.Data.EnumTypes; using System; using System.CodeDom.Compiler; using System.ComponentModel; using System.Drawing; using System.IO; using System.Windows; using System.Windows.Forms; [ToolboxItem(false)] public class FormulaSourceEditor : Form { private Button btnClose; private Button btnCompile; private Button btnDebug; private Button btnFormula; private Button btnInsertMethod; private CheckBox cbIsMainView; private CheckBox cbNotRealNameSpace; private ComboBox cbParamType; private IContainer components; private static FormulaSourceEditor CurrentEditor; private bool DisableChange; private string filename = ""; private TreeView FormulaTree; private FormulaSpace fs; private ColumnHeader HeaderColumn; private ColumnHeader HeaderLine; private ColumnHeader HeaderMessage; private ColumnHeader HeaderName; private ColumnHeader HeaderNumber; private ImageList ilFormula; private TreeNode LastNode; private ListBox lbIntelliSence; private Label lDefaultValue; private Label lFormulaProgramCode; private Label lFormulaProgramDesc; private Label lFormulaProgramName; private Label lFullName; private Label lMaxValue; private Label lMinValue; private Label lNamespaceDescription; private Label lNamespaceName; private Label lOverride = new Label(); private Label lParamDesc; private Label lParamName; private Label lParamType; private ListView lvErrors; private Label lVersion; private MenuItem menuItem1; private MenuItem menuItem4; private MenuItem miCompile; private MenuItem miExit; private MenuItem miNew; private MenuItem miOpen; private MenuItem miSave; private MenuItem miSaveAs; private MainMenu mmFumular; private bool modified; private OpenFileDialog odFormula; private Panel pnBottom; private Panel pnCode; private Panel pnFormula; private Panel pnNamespace; private Panel pnProgram; private Panel pnTop; private SaveFileDialog sdFormula; private Splitter spFormula; private Splitter spProgram; private TextBox tbDefaultValue; private RichTextBox tbFormulaProgramCode; private TextBox tbFormulaProgramDesc; private TextBox tbFormulaProgramName; private TextBox tbMaxValue; private TextBox tbMinValue; private TextBox tbNamespaceDesc; private TextBox tbNamespaceName; private TextBox tbParamDesc; private TextBox tbParamName; private TextBox tbProgramFullName; private TextBox tbVersion; private TabControl tcFormula; private TabPage tpFormulaProgram; private TabPage tpNamespace; private ContextMenuStrip cmTree; private ToolStripMenuItem miAddNamespace; private ToolStripMenuItem miAddFormulaProgram; private ToolStripMenuItem miAddParam; private ToolStripMenuItem miDeleteNode; private TabPage tpParameter; public FormulaSourceEditor() { this.InitializeComponent(); this.fs = new FormulaSpace("FML"); this.fs.Description = "Namespace description"; this.fs.Version = "1.0.0.0"; this.LoadToTree(this.fs); this.lOverride.Parent = this.pnFormula; this.lOverride.Width = 0x7d0; this.lOverride.Height = 0x18; this.lOverride.Top = this.tcFormula.Top; this.lOverride.Left = 0; this.lOverride.BringToFront(); this.lOverride.BackColor = Color.WhiteSmoke; this.lOverride.Font = new Font("verdana", 11f, FontStyle.Bold); this.lOverride.ForeColor = Color.DarkGray; this.AddChangeEvent(this); } private void AddChangeEvent(Control c) { if (c is TextBox) { ((TextBox)c).TextChanged += new EventHandler(this.cbIsMainView_CheckedChanged); } else if (c is CheckBox) { ((CheckBox)c).TextChanged += new EventHandler(this.cbIsMainView_CheckedChanged); } else if (c is RichTextBox) { ((RichTextBox)c).TextChanged += new EventHandler(this.cbIsMainView_CheckedChanged); } foreach (Control control in c.Controls) { this.AddChangeEvent(control); } } private void AddError(CompilerErrorCollection ces, FormulaProgram fp) { this.lvErrors.Items.Clear(); foreach (CompilerError error in ces) { ListViewItem item = null; if (fp != null) { item = this.lvErrors.Items.Add(fp.Name); item.Tag = fp; } else { FormulaProgram programByLineNum = this.fs.GetProgramByLineNum(error.Line); if (programByLineNum != null) { item = this.lvErrors.Items.Add(programByLineNum.Name); programByLineNum.AdjustErrors(error); item.Tag = programByLineNum; } else { item = this.lvErrors.Items.Add(""); } } if (item != null) { item.SubItems.Add(error.Line.ToString()); item.SubItems.Add(error.Column.ToString()); item.SubItems.Add(error.ErrorNumber.ToString()); item.SubItems.Add(error.ErrorText); } } } private void btnClose_Click(object sender, EventArgs e) { base.Close(); } private void btnCompile_Click(object sender, EventArgs e) { this.Compile(); } private void btnDebug_Click(object sender, EventArgs e) { FormulaProgram tag = (FormulaProgram)this.FormulaTree.SelectedNode.Tag; try { tag.Compile(); this.lvErrors.Items.Clear(); this.lvErrors.Items.Add("OK!"); } catch (FormulaErrorException exception) { this.AddError(exception.ces, tag); } } private void btnFormula_Click(object sender, EventArgs e) { string str = new SelectFormula().Select(null, null, true); if (str != null) { Clipboard.SetDataObject("\"" + str + "\""); this.tbFormulaProgramCode.Paste(); } } private void btnInsertMethod_Click(object sender, EventArgs e) { string data = new SelectMethod().Select(null); if (data != null) { Clipboard.SetDataObject(data); this.tbFormulaProgramCode.Paste(); } } private void cbIsMainView_CheckedChanged(object sender, EventArgs e) { if (!this.DisableChange) { this.Modified = true; } } /// /// 编译成DLL /// /// private bool Compile() { bool flag; try { long ticks = DateTime.Now.Ticks; this.SaveDataToNode(); string curFileDir = Path.GetDirectoryName(this.filename); string curFileName = Path.GetFileName(this.filename); string sourceFile = string.Format("{0}\\{1}", curFileDir, curFileName.Replace('.', '_') + ".cs"); string dllFile = string.Format("{0}\\{1}", curFileDir, curFileName.Replace('.', '_') + ".dll"); this.fs.SaveCShartSource(sourceFile); string ReferenceRoot = Environment.CurrentDirectory; this.fs.Compile(dllFile, ReferenceRoot); this.lvErrors.Items.Clear(); this.lvErrors.Items.Add("OK! - " + ((DateTime.Now.Ticks - ticks) / 0x2710L) + "ms"); flag = true; } catch (FormulaErrorException exception) { this.AddError(exception.ces, null); flag = false; } finally { this.LocateFirstProgram(); } return flag; } protected override void Dispose(bool disposing) { if (disposing && (this.components != null)) { this.components.Dispose(); } base.Dispose(disposing); } private TreeNode FindNode(TreeNode tn, FormulaProgram fp) { if (tn.Tag == fp) { return tn; } foreach (TreeNode node in tn.Nodes) { TreeNode node2 = this.FindNode(node, fp); if (node2 != null) { return node2; } } return null; } private TreeNode FindNode(TreeNode tn, string ProgramName) { if ((tn.Tag is FormulaProgram) && ((tn.Tag as FormulaProgram).Name == ProgramName)) { return tn; } foreach (TreeNode node in tn.Nodes) { TreeNode node2 = this.FindNode(node, ProgramName); if (node2 != null) { return node2; } } return null; } private void FormulaEditor_Activated(object sender, EventArgs e) { this.tbFormulaProgramCode.Focus(); } private void FormulaEditor_Closing(object sender, CancelEventArgs e) { if (this.Modified) { e.Cancel = true; } } private void FormulaEditor_Load(object sender, EventArgs e) { this.cbParamType.Items.Clear(); this.cbParamType.Items.AddRange(Enum.GetNames(typeof(FormulaParamType))); string[] commandLineArgs = Environment.GetCommandLineArgs(); if (commandLineArgs.Length == 2) { this.LoadEditor(commandLineArgs[1], null); } else if (commandLineArgs.Length == 3) { this.LoadEditor(commandLineArgs[1], commandLineArgs[2]); } } private void FormulaTree_AfterSelect(object sender, TreeViewEventArgs e) { this.DisableChange = true; try { if (e.Node.Tag is FormulaSpace) { FormulaSpace tag = (FormulaSpace)e.Node.Tag; if (e.Node.Parent == null && tag.Name == "FML") { tbNamespaceName.Enabled = false; cbNotRealNameSpace.Enabled = false; } else { tbNamespaceName.Enabled = true; cbNotRealNameSpace.Enabled = true; } this.tbNamespaceName.Text = tag.Name; this.tbNamespaceDesc.Text = tag.Description; this.tbVersion.Visible = e.Node.Parent == null; this.lVersion.Visible = this.tbVersion.Visible; this.tbVersion.Text = tag.Version; this.cbNotRealNameSpace.Checked = tag.GroupOnly; this.tcFormula.SelectedTab = this.tpNamespace; this.lOverride.Text = "Namespace properties:" + tag.Name; } else if (e.Node.Tag is FormulaProgram) { FormulaProgram program = (FormulaProgram)e.Node.Tag; this.tbFormulaProgramName.Text = program.Name; this.tbProgramFullName.Text = program.FullName; if (program.Code != null) { this.tbFormulaProgramCode.Lines = this.Trim(program.Code.Split(new char[] { '\n' })); } else { this.tbFormulaProgramCode.Text = ""; } if (program.Description != null) { this.tbFormulaProgramDesc.Lines = this.Trim(program.Description.Split(new char[] { '\n' })); } else { this.tbFormulaProgramDesc.Text = ""; } this.cbIsMainView.Checked = program.IsMainView; this.tcFormula.SelectedTab = this.tpFormulaProgram; this.lOverride.Text = "Formula script code:" + program.Name; } else if (e.Node.Tag is FormulaParam) { FormulaParam param = (FormulaParam)e.Node.Tag; this.tbParamName.Text = param.Name; this.tbParamDesc.Text = param.Description; this.tbMinValue.Text = param.MinValue; this.tbMaxValue.Text = param.MaxValue; this.tbDefaultValue.Text = param.DefaultValue; this.cbParamType.SelectedIndex = (int)param.ParamType; this.tcFormula.SelectedTab = this.tpParameter; this.lOverride.Text = "Formula script parameter:" + param.Name; } this.FormulaTree.Focus(); this.LastNode = e.Node; } finally { this.DisableChange = false; } } private void FormulaTree_BeforeSelect(object sender, TreeViewCancelEventArgs e) { this.SaveDataToNode(this.LastNode); } private void FormulaTree_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { TreeNode nodeAt = this.FormulaTree.GetNodeAt(e.X, e.Y); if (nodeAt == null) { nodeAt = this.FormulaTree.SelectedNode; } else { this.FormulaTree.SelectedNode = nodeAt; } if (nodeAt.Tag is FormulaSpace) { this.miAddFormulaProgram.Visible = true; this.miAddNamespace.Visible = true; this.miAddParam.Visible = false; } else if (nodeAt.Tag is FormulaProgram) { this.miAddFormulaProgram.Visible = false; this.miAddNamespace.Visible = false; this.miAddParam.Visible = true; } else if (nodeAt.Tag is FormulaParam) { this.miAddFormulaProgram.Visible = false; this.miAddNamespace.Visible = false; this.miAddParam.Visible = false; } this.cmTree.Show(this.FormulaTree, new Point(e.X, e.Y)); } } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormulaSourceEditor)); this.FormulaTree = new System.Windows.Forms.TreeView(); this.ilFormula = new System.Windows.Forms.ImageList(this.components); this.tcFormula = new System.Windows.Forms.TabControl(); this.tpNamespace = new System.Windows.Forms.TabPage(); this.pnNamespace = new System.Windows.Forms.Panel(); this.cmTree = new System.Windows.Forms.ContextMenuStrip(this.components); this.miAddNamespace = new System.Windows.Forms.ToolStripMenuItem(); this.miAddFormulaProgram = new System.Windows.Forms.ToolStripMenuItem(); this.miAddParam = new System.Windows.Forms.ToolStripMenuItem(); this.miDeleteNode = new System.Windows.Forms.ToolStripMenuItem(); this.tbVersion = new System.Windows.Forms.TextBox(); this.lVersion = new System.Windows.Forms.Label(); this.cbNotRealNameSpace = new System.Windows.Forms.CheckBox(); this.lNamespaceDescription = new System.Windows.Forms.Label(); this.tbNamespaceDesc = new System.Windows.Forms.TextBox(); this.lNamespaceName = new System.Windows.Forms.Label(); this.tbNamespaceName = new System.Windows.Forms.TextBox(); this.tpFormulaProgram = new System.Windows.Forms.TabPage(); this.spProgram = new System.Windows.Forms.Splitter(); this.pnProgram = new System.Windows.Forms.Panel(); this.btnFormula = new System.Windows.Forms.Button(); this.btnInsertMethod = new System.Windows.Forms.Button(); this.btnCompile = new System.Windows.Forms.Button(); this.lbIntelliSence = new System.Windows.Forms.ListBox(); this.lFullName = new System.Windows.Forms.Label(); this.tbProgramFullName = new System.Windows.Forms.TextBox(); this.btnDebug = new System.Windows.Forms.Button(); this.lFormulaProgramDesc = new System.Windows.Forms.Label(); this.tbFormulaProgramDesc = new System.Windows.Forms.TextBox(); this.cbIsMainView = new System.Windows.Forms.CheckBox(); this.tbFormulaProgramName = new System.Windows.Forms.TextBox(); this.lFormulaProgramName = new System.Windows.Forms.Label(); this.lFormulaProgramCode = new System.Windows.Forms.Label(); this.pnCode = new System.Windows.Forms.Panel(); this.tbFormulaProgramCode = new System.Windows.Forms.RichTextBox(); this.lvErrors = new System.Windows.Forms.ListView(); this.HeaderName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.HeaderLine = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.HeaderColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.HeaderNumber = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.HeaderMessage = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.tpParameter = new System.Windows.Forms.TabPage(); this.cbParamType = new System.Windows.Forms.ComboBox(); this.lParamType = new System.Windows.Forms.Label(); this.tbParamDesc = new System.Windows.Forms.TextBox(); this.lParamDesc = new System.Windows.Forms.Label(); this.tbParamName = new System.Windows.Forms.TextBox(); this.lParamName = new System.Windows.Forms.Label(); this.tbMaxValue = new System.Windows.Forms.TextBox(); this.tbMinValue = new System.Windows.Forms.TextBox(); this.tbDefaultValue = new System.Windows.Forms.TextBox(); this.lDefaultValue = new System.Windows.Forms.Label(); this.lMaxValue = new System.Windows.Forms.Label(); this.lMinValue = new System.Windows.Forms.Label(); this.mmFumular = new System.Windows.Forms.MainMenu(this.components); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.miNew = new System.Windows.Forms.MenuItem(); this.miOpen = new System.Windows.Forms.MenuItem(); this.miSave = new System.Windows.Forms.MenuItem(); this.miSaveAs = new System.Windows.Forms.MenuItem(); this.miCompile = new System.Windows.Forms.MenuItem(); this.menuItem4 = new System.Windows.Forms.MenuItem(); this.miExit = new System.Windows.Forms.MenuItem(); this.odFormula = new System.Windows.Forms.OpenFileDialog(); this.sdFormula = new System.Windows.Forms.SaveFileDialog(); this.pnFormula = new System.Windows.Forms.Panel(); this.pnTop = new System.Windows.Forms.Panel(); this.spFormula = new System.Windows.Forms.Splitter(); this.pnBottom = new System.Windows.Forms.Panel(); this.btnClose = new System.Windows.Forms.Button(); this.tcFormula.SuspendLayout(); this.tpNamespace.SuspendLayout(); this.pnNamespace.SuspendLayout(); this.cmTree.SuspendLayout(); this.tpFormulaProgram.SuspendLayout(); this.pnProgram.SuspendLayout(); this.pnCode.SuspendLayout(); this.tpParameter.SuspendLayout(); this.pnFormula.SuspendLayout(); this.pnTop.SuspendLayout(); this.pnBottom.SuspendLayout(); this.SuspendLayout(); // // FormulaTree // resources.ApplyResources(this.FormulaTree, "FormulaTree"); this.FormulaTree.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.FormulaTree.FullRowSelect = true; this.FormulaTree.HideSelection = false; this.FormulaTree.ImageList = this.ilFormula; this.FormulaTree.Name = "FormulaTree"; this.FormulaTree.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.FormulaTree_BeforeSelect); this.FormulaTree.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.FormulaTree_AfterSelect); this.FormulaTree.MouseDown += new System.Windows.Forms.MouseEventHandler(this.FormulaTree_MouseDown); // // ilFormula // this.ilFormula.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilFormula.ImageStream"))); this.ilFormula.TransparentColor = System.Drawing.Color.Transparent; this.ilFormula.Images.SetKeyName(0, ""); this.ilFormula.Images.SetKeyName(1, ""); this.ilFormula.Images.SetKeyName(2, ""); // // tcFormula // resources.ApplyResources(this.tcFormula, "tcFormula"); this.tcFormula.AllowDrop = true; this.tcFormula.Controls.Add(this.tpNamespace); this.tcFormula.Controls.Add(this.tpFormulaProgram); this.tcFormula.Controls.Add(this.tpParameter); this.tcFormula.Name = "tcFormula"; this.tcFormula.SelectedIndex = 0; this.tcFormula.TabStop = false; // // tpNamespace // resources.ApplyResources(this.tpNamespace, "tpNamespace"); this.tpNamespace.Controls.Add(this.pnNamespace); this.tpNamespace.Name = "tpNamespace"; // // pnNamespace // resources.ApplyResources(this.pnNamespace, "pnNamespace"); this.pnNamespace.ContextMenuStrip = this.cmTree; this.pnNamespace.Controls.Add(this.tbVersion); this.pnNamespace.Controls.Add(this.lVersion); this.pnNamespace.Controls.Add(this.cbNotRealNameSpace); this.pnNamespace.Controls.Add(this.lNamespaceDescription); this.pnNamespace.Controls.Add(this.tbNamespaceDesc); this.pnNamespace.Controls.Add(this.lNamespaceName); this.pnNamespace.Controls.Add(this.tbNamespaceName); this.pnNamespace.Name = "pnNamespace"; // // cmTree // resources.ApplyResources(this.cmTree, "cmTree"); this.cmTree.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.miAddNamespace, this.miAddFormulaProgram, this.miAddParam, this.miDeleteNode}); this.cmTree.Name = "cmTree"; // // miAddNamespace // resources.ApplyResources(this.miAddNamespace, "miAddNamespace"); this.miAddNamespace.Name = "miAddNamespace"; this.miAddNamespace.Click += new System.EventHandler(this.miAddNamespace_Click); // // miAddFormulaProgram // resources.ApplyResources(this.miAddFormulaProgram, "miAddFormulaProgram"); this.miAddFormulaProgram.Name = "miAddFormulaProgram"; this.miAddFormulaProgram.Click += new System.EventHandler(this.miAddFormulaProgram_Click); // // miAddParam // resources.ApplyResources(this.miAddParam, "miAddParam"); this.miAddParam.Name = "miAddParam"; this.miAddParam.Click += new System.EventHandler(this.miAddParam_Click); // // miDeleteNode // resources.ApplyResources(this.miDeleteNode, "miDeleteNode"); this.miDeleteNode.Name = "miDeleteNode"; this.miDeleteNode.Click += new System.EventHandler(this.miDeleteNode_Click); // // tbVersion // resources.ApplyResources(this.tbVersion, "tbVersion"); this.tbVersion.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tbVersion.Name = "tbVersion"; // // lVersion // resources.ApplyResources(this.lVersion, "lVersion"); this.lVersion.Name = "lVersion"; // // cbNotRealNameSpace // resources.ApplyResources(this.cbNotRealNameSpace, "cbNotRealNameSpace"); this.cbNotRealNameSpace.Name = "cbNotRealNameSpace"; // // lNamespaceDescription // resources.ApplyResources(this.lNamespaceDescription, "lNamespaceDescription"); this.lNamespaceDescription.BackColor = System.Drawing.SystemColors.Control; this.lNamespaceDescription.Name = "lNamespaceDescription"; // // tbNamespaceDesc // resources.ApplyResources(this.tbNamespaceDesc, "tbNamespaceDesc"); this.tbNamespaceDesc.BackColor = System.Drawing.SystemColors.Info; this.tbNamespaceDesc.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tbNamespaceDesc.Name = "tbNamespaceDesc"; // // lNamespaceName // resources.ApplyResources(this.lNamespaceName, "lNamespaceName"); this.lNamespaceName.BackColor = System.Drawing.SystemColors.Control; this.lNamespaceName.Name = "lNamespaceName"; // // tbNamespaceName // resources.ApplyResources(this.tbNamespaceName, "tbNamespaceName"); this.tbNamespaceName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tbNamespaceName.Name = "tbNamespaceName"; // // tpFormulaProgram // resources.ApplyResources(this.tpFormulaProgram, "tpFormulaProgram"); this.tpFormulaProgram.Controls.Add(this.spProgram); this.tpFormulaProgram.Controls.Add(this.pnProgram); this.tpFormulaProgram.Controls.Add(this.lvErrors); this.tpFormulaProgram.Name = "tpFormulaProgram"; // // spProgram // resources.ApplyResources(this.spProgram, "spProgram"); this.spProgram.Name = "spProgram"; this.spProgram.TabStop = false; // // pnProgram // resources.ApplyResources(this.pnProgram, "pnProgram"); this.pnProgram.Controls.Add(this.btnFormula); this.pnProgram.Controls.Add(this.btnInsertMethod); this.pnProgram.Controls.Add(this.btnCompile); this.pnProgram.Controls.Add(this.lbIntelliSence); this.pnProgram.Controls.Add(this.lFullName); this.pnProgram.Controls.Add(this.tbProgramFullName); this.pnProgram.Controls.Add(this.btnDebug); this.pnProgram.Controls.Add(this.lFormulaProgramDesc); this.pnProgram.Controls.Add(this.tbFormulaProgramDesc); this.pnProgram.Controls.Add(this.cbIsMainView); this.pnProgram.Controls.Add(this.tbFormulaProgramName); this.pnProgram.Controls.Add(this.lFormulaProgramName); this.pnProgram.Controls.Add(this.lFormulaProgramCode); this.pnProgram.Controls.Add(this.pnCode); this.pnProgram.Name = "pnProgram"; // // btnFormula // resources.ApplyResources(this.btnFormula, "btnFormula"); this.btnFormula.Name = "btnFormula"; this.btnFormula.Click += new System.EventHandler(this.btnFormula_Click); // // btnInsertMethod // resources.ApplyResources(this.btnInsertMethod, "btnInsertMethod"); this.btnInsertMethod.Name = "btnInsertMethod"; this.btnInsertMethod.Click += new System.EventHandler(this.btnInsertMethod_Click); // // btnCompile // resources.ApplyResources(this.btnCompile, "btnCompile"); this.btnCompile.Name = "btnCompile"; this.btnCompile.Click += new System.EventHandler(this.btnCompile_Click); // // lbIntelliSence // resources.ApplyResources(this.lbIntelliSence, "lbIntelliSence"); this.lbIntelliSence.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbIntelliSence.Name = "lbIntelliSence"; this.lbIntelliSence.TabStop = false; this.lbIntelliSence.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lbIntelliSence_KeyDown); // // lFullName // resources.ApplyResources(this.lFullName, "lFullName"); this.lFullName.Name = "lFullName"; // // tbProgramFullName // resources.ApplyResources(this.tbProgramFullName, "tbProgramFullName"); this.tbProgramFullName.BackColor = System.Drawing.Color.SeaShell; this.tbProgramFullName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tbProgramFullName.Name = "tbProgramFullName"; // // btnDebug // resources.ApplyResources(this.btnDebug, "btnDebug"); this.btnDebug.Name = "btnDebug"; this.btnDebug.Click += new System.EventHandler(this.btnDebug_Click); // // lFormulaProgramDesc // resources.ApplyResources(this.lFormulaProgramDesc, "lFormulaProgramDesc"); this.lFormulaProgramDesc.Name = "lFormulaProgramDesc"; // // tbFormulaProgramDesc // resources.ApplyResources(this.tbFormulaProgramDesc, "tbFormulaProgramDesc"); this.tbFormulaProgramDesc.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tbFormulaProgramDesc.Name = "tbFormulaProgramDesc"; this.tbFormulaProgramDesc.Leave += new System.EventHandler(this.tbFormulaProgramCode_Leave); // // cbIsMainView // resources.ApplyResources(this.cbIsMainView, "cbIsMainView"); this.cbIsMainView.Name = "cbIsMainView"; this.cbIsMainView.Leave += new System.EventHandler(this.tbFormulaProgramCode_Leave); // // tbFormulaProgramName // resources.ApplyResources(this.tbFormulaProgramName, "tbFormulaProgramName"); this.tbFormulaProgramName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tbFormulaProgramName.Name = "tbFormulaProgramName"; this.tbFormulaProgramName.Leave += new System.EventHandler(this.tbFormulaProgramCode_Leave); // // lFormulaProgramName // resources.ApplyResources(this.lFormulaProgramName, "lFormulaProgramName"); this.lFormulaProgramName.Name = "lFormulaProgramName"; // // lFormulaProgramCode // resources.ApplyResources(this.lFormulaProgramCode, "lFormulaProgramCode"); this.lFormulaProgramCode.Name = "lFormulaProgramCode"; // // pnCode // resources.ApplyResources(this.pnCode, "pnCode"); this.pnCode.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.pnCode.Controls.Add(this.tbFormulaProgramCode); this.pnCode.Name = "pnCode"; this.pnCode.TabStop = true; // // tbFormulaProgramCode // resources.ApplyResources(this.tbFormulaProgramCode, "tbFormulaProgramCode"); this.tbFormulaProgramCode.BackColor = System.Drawing.SystemColors.Info; this.tbFormulaProgramCode.BorderStyle = System.Windows.Forms.BorderStyle.None; this.tbFormulaProgramCode.Name = "tbFormulaProgramCode"; this.tbFormulaProgramCode.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbFormulaProgramCode_KeyDown); this.tbFormulaProgramCode.Leave += new System.EventHandler(this.tbFormulaProgramCode_Leave); // // lvErrors // resources.ApplyResources(this.lvErrors, "lvErrors"); this.lvErrors.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lvErrors.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.HeaderName, this.HeaderLine, this.HeaderColumn, this.HeaderNumber, this.HeaderMessage}); this.lvErrors.FullRowSelect = true; this.lvErrors.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; this.lvErrors.Name = "lvErrors"; this.lvErrors.UseCompatibleStateImageBehavior = false; this.lvErrors.View = System.Windows.Forms.View.Details; this.lvErrors.DoubleClick += new System.EventHandler(this.lvErrors_DoubleClick); // // HeaderName // resources.ApplyResources(this.HeaderName, "HeaderName"); // // HeaderLine // resources.ApplyResources(this.HeaderLine, "HeaderLine"); // // HeaderColumn // resources.ApplyResources(this.HeaderColumn, "HeaderColumn"); // // HeaderNumber // resources.ApplyResources(this.HeaderNumber, "HeaderNumber"); // // HeaderMessage // resources.ApplyResources(this.HeaderMessage, "HeaderMessage"); // // tpParameter // resources.ApplyResources(this.tpParameter, "tpParameter"); this.tpParameter.Controls.Add(this.cbParamType); this.tpParameter.Controls.Add(this.lParamType); this.tpParameter.Controls.Add(this.tbParamDesc); this.tpParameter.Controls.Add(this.lParamDesc); this.tpParameter.Controls.Add(this.tbParamName); this.tpParameter.Controls.Add(this.lParamName); this.tpParameter.Controls.Add(this.tbMaxValue); this.tpParameter.Controls.Add(this.tbMinValue); this.tpParameter.Controls.Add(this.tbDefaultValue); this.tpParameter.Controls.Add(this.lDefaultValue); this.tpParameter.Controls.Add(this.lMaxValue); this.tpParameter.Controls.Add(this.lMinValue); this.tpParameter.Name = "tpParameter"; // // cbParamType // resources.ApplyResources(this.cbParamType, "cbParamType"); this.cbParamType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cbParamType.Name = "cbParamType"; // // lParamType // resources.ApplyResources(this.lParamType, "lParamType"); this.lParamType.Name = "lParamType"; // // tbParamDesc // resources.ApplyResources(this.tbParamDesc, "tbParamDesc"); this.tbParamDesc.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tbParamDesc.Name = "tbParamDesc"; this.tbParamDesc.Leave += new System.EventHandler(this.tbFormulaProgramCode_Leave); // // lParamDesc // resources.ApplyResources(this.lParamDesc, "lParamDesc"); this.lParamDesc.Name = "lParamDesc"; // // tbParamName // resources.ApplyResources(this.tbParamName, "tbParamName"); this.tbParamName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tbParamName.Name = "tbParamName"; this.tbParamName.Leave += new System.EventHandler(this.tbFormulaProgramCode_Leave); // // lParamName // resources.ApplyResources(this.lParamName, "lParamName"); this.lParamName.Name = "lParamName"; // // tbMaxValue // resources.ApplyResources(this.tbMaxValue, "tbMaxValue"); this.tbMaxValue.BackColor = System.Drawing.SystemColors.Info; this.tbMaxValue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tbMaxValue.Name = "tbMaxValue"; this.tbMaxValue.Leave += new System.EventHandler(this.tbFormulaProgramCode_Leave); // // tbMinValue // resources.ApplyResources(this.tbMinValue, "tbMinValue"); this.tbMinValue.BackColor = System.Drawing.SystemColors.Info; this.tbMinValue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tbMinValue.Name = "tbMinValue"; this.tbMinValue.Leave += new System.EventHandler(this.tbFormulaProgramCode_Leave); // // tbDefaultValue // resources.ApplyResources(this.tbDefaultValue, "tbDefaultValue"); this.tbDefaultValue.BackColor = System.Drawing.SystemColors.Info; this.tbDefaultValue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tbDefaultValue.Name = "tbDefaultValue"; this.tbDefaultValue.Leave += new System.EventHandler(this.tbFormulaProgramCode_Leave); // // lDefaultValue // resources.ApplyResources(this.lDefaultValue, "lDefaultValue"); this.lDefaultValue.Name = "lDefaultValue"; // // lMaxValue // resources.ApplyResources(this.lMaxValue, "lMaxValue"); this.lMaxValue.Name = "lMaxValue"; // // lMinValue // resources.ApplyResources(this.lMinValue, "lMinValue"); this.lMinValue.Name = "lMinValue"; // // mmFumular // this.mmFumular.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1}); resources.ApplyResources(this.mmFumular, "mmFumular"); // // menuItem1 // resources.ApplyResources(this.menuItem1, "menuItem1"); this.menuItem1.Index = 0; this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.miNew, this.miOpen, this.miSave, this.miSaveAs, this.miCompile, this.menuItem4, this.miExit}); // // miNew // resources.ApplyResources(this.miNew, "miNew"); this.miNew.Index = 0; this.miNew.Click += new System.EventHandler(this.miNew_Click); // // miOpen // resources.ApplyResources(this.miOpen, "miOpen"); this.miOpen.Index = 1; this.miOpen.Click += new System.EventHandler(this.miOpen_Click); // // miSave // resources.ApplyResources(this.miSave, "miSave"); this.miSave.Index = 2; this.miSave.Click += new System.EventHandler(this.miSave_Click); // // miSaveAs // resources.ApplyResources(this.miSaveAs, "miSaveAs"); this.miSaveAs.Index = 3; this.miSaveAs.Click += new System.EventHandler(this.miSaveAs_Click); // // miCompile // resources.ApplyResources(this.miCompile, "miCompile"); this.miCompile.Index = 4; this.miCompile.Click += new System.EventHandler(this.miCompile_Click); // // menuItem4 // resources.ApplyResources(this.menuItem4, "menuItem4"); this.menuItem4.Index = 5; // // miExit // resources.ApplyResources(this.miExit, "miExit"); this.miExit.Index = 6; this.miExit.Click += new System.EventHandler(this.miExit_Click); // // odFormula // this.odFormula.DefaultExt = "fml"; resources.ApplyResources(this.odFormula, "odFormula"); this.odFormula.RestoreDirectory = true; // // sdFormula // this.sdFormula.DefaultExt = "fml"; resources.ApplyResources(this.sdFormula, "sdFormula"); this.sdFormula.RestoreDirectory = true; // // pnFormula // resources.ApplyResources(this.pnFormula, "pnFormula"); this.pnFormula.Controls.Add(this.tcFormula); this.pnFormula.Name = "pnFormula"; // // pnTop // resources.ApplyResources(this.pnTop, "pnTop"); this.pnTop.Controls.Add(this.pnFormula); this.pnTop.Controls.Add(this.spFormula); this.pnTop.Controls.Add(this.FormulaTree); this.pnTop.Name = "pnTop"; // // spFormula // resources.ApplyResources(this.spFormula, "spFormula"); this.spFormula.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); this.spFormula.Name = "spFormula"; this.spFormula.TabStop = false; // // pnBottom // resources.ApplyResources(this.pnBottom, "pnBottom"); this.pnBottom.Controls.Add(this.btnClose); this.pnBottom.Name = "pnBottom"; // // btnClose // resources.ApplyResources(this.btnClose, "btnClose"); this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.btnClose.Name = "btnClose"; this.btnClose.Click += new System.EventHandler(this.btnClose_Click); // // FormulaSourceEditor // resources.ApplyResources(this, "$this"); this.CancelButton = this.btnClose; this.Controls.Add(this.pnTop); this.Controls.Add(this.pnBottom); this.Menu = this.mmFumular; this.Name = "FormulaSourceEditor"; this.Activated += new System.EventHandler(this.FormulaEditor_Activated); this.Closing += new System.ComponentModel.CancelEventHandler(this.FormulaEditor_Closing); this.Load += new System.EventHandler(this.FormulaEditor_Load); this.Click += new System.EventHandler(this.btnDebug_Click); this.tcFormula.ResumeLayout(false); this.tpNamespace.ResumeLayout(false); this.pnNamespace.ResumeLayout(false); this.pnNamespace.PerformLayout(); this.cmTree.ResumeLayout(false); this.tpFormulaProgram.ResumeLayout(false); this.pnProgram.ResumeLayout(false); this.pnProgram.PerformLayout(); this.pnCode.ResumeLayout(false); this.tpParameter.ResumeLayout(false); this.tpParameter.PerformLayout(); this.pnFormula.ResumeLayout(false); this.pnTop.ResumeLayout(false); this.pnBottom.ResumeLayout(false); this.ResumeLayout(false); } private void lbIntelliSence_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) { this.lbIntelliSence.Visible = false; } else if (e.KeyCode == Keys.Enter) { Clipboard.SetDataObject(this.lbIntelliSence.SelectedItem.ToString()); this.tbFormulaProgramCode.Paste(); this.lbIntelliSence.Visible = false; } } private void LoadEditor(string Filename, string Formula) { if (File.Exists(Filename)) { this.LoadFromFile(Filename); if (Formula != null) { int num = Formula.LastIndexOf('.'); if (num >= 0) { Formula = Formula.Substring(num + 1); } TreeNode node = this.FindNode(this.FormulaTree.Nodes[0], Formula); if (node != null) { this.FormulaTree.SelectedNode = node; this.FormulaTree.SelectedNode.Expand(); } } } base.ShowDialog(); } private void LoadFromFile(string FileName) { if (File.Exists(FileName)) { this.fs = FormulaSpace.Read(FileName); this.fs.AddVersion(); this.Filename = FileName; this.sdFormula.FileName = this.Filename; this.LoadToTree(this.fs); this.Modified = false; this.FormulaTree.Nodes[0].Expand(); } } private void LoadToTree(FormulaSpace fs) { this.FormulaTree.BeginUpdate(); try { this.FormulaTree.Nodes.Clear(); TreeNode node = new TreeNode("FML", 0, 0); this.FormulaTree.Nodes.Add(node); this.LoadToTree(this.FormulaTree.Nodes[0], fs); } finally { this.FormulaTree.EndUpdate(); } this.FormulaTree.SelectedNode = this.FormulaTree.TopNode; } private void LoadToTree(TreeNode tn, FormulaParam fp) { tn.Text = fp.Name; tn.Tag = fp; } private void LoadToTree(TreeNode tn, FormulaProgram p) { tn.Text = p.Name; tn.Tag = p; foreach (FormulaParam param in p.Params) { TreeNode node = new TreeNode(); node.ImageIndex = 2; node.SelectedImageIndex = 2; tn.Nodes.Add(node); this.LoadToTree(node, param); } } private void LoadToTree(TreeNode tn, FormulaSpace fs) { tn.Text = fs.Name; tn.Tag = fs; foreach (FormulaSpace space in fs.Namespaces) { TreeNode node = new TreeNode(); node.ImageIndex = 0; node.SelectedImageIndex = 0; tn.Nodes.Add(node); this.LoadToTree(node, space); } foreach (FormulaProgram program in fs.Programs) { TreeNode node2 = new TreeNode(); node2.ImageIndex = 1; node2.SelectedImageIndex = 1; tn.Nodes.Add(node2); this.LoadToTree(node2, program); } } private void LocateFirstProgram() { TreeNode selectedNode = this.FormulaTree.SelectedNode; if (!(selectedNode.Tag is FormulaProgram)) { selectedNode = this.FormulaTree.Nodes[0]; while (!(selectedNode.Tag is FormulaProgram) && (selectedNode.Nodes.Count > 0)) { selectedNode = selectedNode.Nodes[0]; } } this.FormulaTree.SelectedNode = selectedNode; } private void lvErrors_DoubleClick(object sender, EventArgs e) { ListViewItem focusedItem = this.lvErrors.FocusedItem; if (focusedItem != null) { FormulaProgram tag = (FormulaProgram)focusedItem.Tag; if (tag != null) { TreeNode node = this.FindNode(this.FormulaTree.Nodes[0], tag); if (node != null) { this.FormulaTree.SelectedNode = node; int num = int.Parse(focusedItem.SubItems[1].Text); int num2 = int.Parse(focusedItem.SubItems[2].Text); for (int i = 0; (i < (num - 1)) && (i < this.tbFormulaProgramCode.Lines.Length); i++) { num2 += this.tbFormulaProgramCode.Lines[i].Length + 1; } if (num2 < 0) { num2 = 0; } this.tbFormulaProgramCode.SelectionStart = num2; this.tbFormulaProgramCode.Focus(); } } } } private void miAddFormulaProgram_Click(object sender, EventArgs e) { TreeNode selectedNode = this.FormulaTree.SelectedNode; FormulaSpace tag = (FormulaSpace)selectedNode.Tag; FormulaProgram program = new FormulaProgram(); tag.Programs.Add(program); TreeNode node = new TreeNode("NewCode"); program.Name = node.Text; selectedNode.Nodes.Add(node); node.ImageIndex = 1; node.SelectedImageIndex = 1; node.Tag = program; this.FormulaTree.SelectedNode = node; } private void miAddNamespace_Click(object sender, EventArgs e) { TreeNode selectedNode = this.FormulaTree.SelectedNode; FormulaSpace tag = (FormulaSpace)selectedNode.Tag; FormulaSpace space2 = new FormulaSpace(); tag.Namespaces.Add(space2); TreeNode node = new TreeNode("NewSpace"); space2.Name = node.Text; selectedNode.Nodes.Add(node); node.ImageIndex = 0; node.SelectedImageIndex = 0; node.Tag = space2; this.FormulaTree.SelectedNode = node; } private void miAddParam_Click(object sender, EventArgs e) { TreeNode selectedNode = this.FormulaTree.SelectedNode; FormulaProgram tag = (FormulaProgram)selectedNode.Tag; FormulaParam fp = new FormulaParam(); tag.Params.Add(fp); TreeNode node = new TreeNode("NewParam"); fp.Name = node.Text; selectedNode.Nodes.Add(node); node.ImageIndex = 2; node.SelectedImageIndex = 2; node.Tag = fp; this.FormulaTree.SelectedNode = node; } private void miCompile_Click(object sender, EventArgs e) { this.Compile(); } private void miDeleteNode_Click(object sender, EventArgs e) { TreeNode selectedNode = this.FormulaTree.SelectedNode; TreeNode parent = selectedNode.Parent; if (parent != null) { object tag = parent.Tag; object obj3 = selectedNode.Tag; if (tag is FormulaSpace) { if (obj3 is FormulaSpace) { ((FormulaSpace)tag).Namespaces.Remove((FormulaSpace)obj3); } else if (obj3 is FormulaProgram) { ((FormulaSpace)tag).Programs.Remove((FormulaProgram)obj3); } } else if ((tag is FormulaProgram) && (obj3 is FormulaParam)) { ((FormulaProgram)tag).Params.Remove((FormulaParam)obj3); } selectedNode.Remove(); } } private void miExit_Click(object sender, EventArgs e) { base.Close(); } private void miNew_Click(object sender, EventArgs e) { if (!this.Modified) { this.Filename = ""; this.fs = new FormulaSpace("FML"); this.LoadToTree(this.fs); } } private void miOpen_Click(object sender, EventArgs e) { if (!this.Modified && (this.odFormula.ShowDialog() == DialogResult.OK)) { try { this.LoadFromFile(this.odFormula.FileName); } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } private void miSave_Click(object sender, EventArgs e) { this.Save(); } private void miSaveAs_Click(object sender, EventArgs e) { this.SaveAs(); } public static void Open(string Filename, string Formula) { //if (CurrentEditor == null) //{ CurrentEditor = new FormulaSourceEditor(); //} //SetLanguage.CurrentUICulture(); CurrentEditor.LoadEditor(Filename, Formula); } public static void Show(string Filename) { CurrentEditor = new FormulaSourceEditor(); CurrentEditor.LoadEditor(Filename, ""); } private bool Save() { if (this.Filename == "") { return this.SaveAs(); } try { if (this.Compile()) { this.SaveDataToNode(); this.fs.Write(this.Filename); this.Modified = false; return true; } } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return false; } private bool SaveAs() { bool isNewFile = false; //标识文件是否为最新 if (!string.IsNullOrEmpty(this.Filename)) { this.sdFormula.FileName = this.Filename; } else { isNewFile = true; this.sdFormula.FileName = string.Format("{0}\\Plugins\\NewFML.fml", Environment.CurrentDirectory); } if (this.sdFormula.ShowDialog() == DialogResult.OK) { this.SaveDataToNode(); this.Filename = this.sdFormula.FileName; this.odFormula.FileName = this.Filename; try { if (this.Compile()) { this.fs.Write(this.Filename); this.Modified = false; if (isNewFile) //如果为最新文件,那么进行载入程序集 { //载入新存储的DLL string directoryName = Path.GetDirectoryName(this.Filename); string dllName = string.Format("{0}\\{1}.dll", directoryName, Path.GetFileName(this.Filename).Replace('.', '_')); PluginManager.LoadDll(dllName); } return true; } } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } return false; } private void SaveDataToNode() { this.SaveDataToNode(this.FormulaTree.SelectedNode); } private void SaveDataToNode(TreeNode tn) { if (tn != null) { if (tn.Tag is FormulaProgram) { FormulaProgram tag = tn.Tag as FormulaProgram; tag.Name = this.tbFormulaProgramName.Text; tag.FullName = this.tbProgramFullName.Text; tag.Code = this.tbFormulaProgramCode.Text; tag.Description = this.tbFormulaProgramDesc.Text; tag.IsMainView = this.cbIsMainView.Checked; tn.Text = tag.Name; } else if (tn.Tag is FormulaSpace) { FormulaSpace space = tn.Tag as FormulaSpace; space.Name = this.tbNamespaceName.Text; space.Description = this.tbNamespaceDesc.Text; space.Version = this.tbVersion.Text; space.GroupOnly = this.cbNotRealNameSpace.Checked; tn.Text = space.Name; } else if (tn.Tag is FormulaParam) { FormulaParam param = tn.Tag as FormulaParam; param.Name = this.tbParamName.Text; param.MinValue = this.tbMinValue.Text; param.MaxValue = this.tbMaxValue.Text; param.DefaultValue = this.tbDefaultValue.Text; if (this.cbParamType.Text == "") { this.cbParamType.SelectedIndex = 0; } param.ParamType = (FormulaParamType)this.cbParamType.SelectedIndex; param.Description = this.tbParamDesc.Text; tn.Text = param.Name; } } } private void tbFormulaProgramCode_KeyDown(object sender, KeyEventArgs e) { if ((e.KeyCode == Keys.J) && e.Control) { this.lbIntelliSence.Items.Clear(); this.lbIntelliSence.Items.AddRange(FormulaBase.GetAllFormulas()); int selectionStart = this.tbFormulaProgramCode.SelectionStart; int lineFromCharIndex = this.tbFormulaProgramCode.GetLineFromCharIndex(selectionStart); Point location = this.pnCode.Location; Point positionFromCharIndex = this.tbFormulaProgramCode.GetPositionFromCharIndex(selectionStart); positionFromCharIndex.Offset(location.X + 8, location.Y + 14); this.lbIntelliSence.Location = positionFromCharIndex; this.lbIntelliSence.Visible = true; this.lbIntelliSence.Focus(); } } private void tbFormulaProgramCode_Leave(object sender, EventArgs e) { this.SaveDataToNode(); } private string[] Trim(string[] ss) { for (int i = 0; i < ss.Length; i++) { ss[i] = ss[i].Trim(); } return ss; } public static bool EditorVisible { get { return ((CurrentEditor != null) && CurrentEditor.Visible); } } public string Filename { get { return this.filename; } set { this.filename = value; this.Text = this.filename; } } private bool Modified { get { if (this.modified) { string messageOwner = string.Empty; string messageText = string.Empty; switch (SetLanguage.currentLanguage) { case ChartLanguageType.SimplifiedChinese: messageOwner = "内容已修改。是否进行保存?"; messageText = "确认"; break; case ChartLanguageType.TraditionalChinese: messageOwner = "內容已修改。是否進行保存?"; messageText = "確認"; break; case ChartLanguageType.English: messageOwner = "Text modified. Save modifications ?"; messageText = "Confirmation"; break; } switch (MessageBox.Show(messageOwner, messageText, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)) { case DialogResult.Yes: return !this.Save(); case DialogResult.No: return false; } return true; } return false; } set { if (this.modified != value) { this.modified = value; if (this.modified) { if (!this.Text.EndsWith("*")) { this.Text = this.Text + "*"; } } else { this.Text = this.Filename; } } } } } }