protected void OnNewDataModel(object sender, EventArgs args) { var dlg = new NewFrm(); if (dlg.ShowDialog() != DialogResult.OK) { return; } var newName = dlg.GetName(); if (string.IsNullOrWhiteSpace(newName)) { MessageBox.Show("名称不能为空"); return; } var fileName = System.IO.Path.Combine(this.Path, newName) + Dict.Extenstions.XmlModel_Extension; if (File.Exists(fileName)) { MessageBox.Show("文件已经存在"); return; } var writer = File.CreateText(fileName); writer.Flush(); writer.Close(); var dataModel = new XmlModelNode(); dataModel.Parent = this; dataModel.FileName = System.IO.Path.GetFileNameWithoutExtension(fileName); dataModel.Name = dataModel.Text = System.IO.Path.GetFileNameWithoutExtension(fileName); dataModel.FullName = fileName; this.TreeNode.Expand(); var cmdHost = CommandHostManager.Instance().Get( CommandHostManager.HostType.XmlMode); var cmd = cmdHost.GetCommand(Dict.Commands.NewXmlModel) as NewXmlModelCommand; cmd.File = dataModel.FullName; cmdHost.RunCommand(Dict.Commands.NewXmlModel); }