using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using PaintDotNet.Base.SettingModel; using PaintDotNet.Base.CommTool; using System.IO; namespace PaintDotNet.Instrument.CustomInterface { internal class TopTools : UserControl { /// /// 右侧树形菜单 /// private ToolStripItemCollection collectionRight; /// /// 工作空间 /// private AppWorkspace appWorkspace; /// /// 工具栏 /// private ToolbarModel toolbar_Model = Startup.instance.toolbarModel; //private ToolbarLocationModel toolbarLocation_Model = Startup.instance.toolbarLocationModel; /// /// 自定义界面dialog /// private CustomInterfaceDialog customInterfaceDialog; #region 控件 private GroupBox groupBoxLeft; private GroupBox groupBoxRight; private Button button1;//分割线 private Button buttonAdd; private Button buttonRemove; private Button buttonUp; private Button buttonDown; private TreeView treeViewRight; public TreeView treeViewLeft; #endregion private string txtPath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\ModuleConfig.txt"; private string[] menuIdArr; public CustomInterfaceDialog CustomInterfaceDialog { set { this.customInterfaceDialog = value; } } public TopTools(AppWorkspace appWorkspace) { this.appWorkspace = appWorkspace; InitializeComponent(); InitializeLanguageText(); InitializeTreeEvent(); InitializeLeftTreeData(); InitVisibleMenuId(); InitializeRightTreeData(); } /// /// 获取txt文件中已保存的菜单可用id /// private void InitVisibleMenuId() { if (System.IO.File.Exists(txtPath)) { string str = System.IO.File.ReadAllText(txtPath); if (str.IndexOf(',') != -1) { menuIdArr = str.Split(','); } else { if (!string.IsNullOrEmpty(str)) { menuIdArr = new string[] { str }; } } } } /// /// 初始化treeview的事件 /// private void InitializeTreeEvent() { this.treeViewRight.HideSelection = false; this.treeViewRight.DrawMode = TreeViewDrawMode.OwnerDrawText; this.treeViewRight.DrawNode += new DrawTreeNodeEventHandler(this.treeView_DrawNode); this.treeViewRight.Invalidated += new InvalidateEventHandler(this.treeViewRight_InvalidateEvent); this.treeViewLeft.HideSelection = false; this.treeViewLeft.DrawMode = TreeViewDrawMode.OwnerDrawText; this.treeViewLeft.DrawNode += new DrawTreeNodeEventHandler(this.treeView_DrawNode); this.treeViewLeft.Invalidated += new InvalidateEventHandler(this.treeViewLeft_InvalidateEvent); } /// /// treeViewRight的重绘事件 /// /// /// private void treeViewRight_InvalidateEvent(object sender, InvalidateEventArgs e) { if (this.treeViewLeft.SelectedNode != null) { if (this.treeViewLeft.SelectedNode.Tag == null) this.buttonAdd.Enabled = true; } if (this.treeViewRight.SelectedNode != null) { if (this.treeViewRight.SelectedNode.Nodes.Count > 0) { this.buttonAdd.Enabled = false; } } } /// /// treeViewLeft的重绘事件 /// /// /// private void treeViewLeft_InvalidateEvent(object sender, InvalidateEventArgs e) { this.button1.Enabled = false; if (this.treeViewRight.SelectedNode != null) { if (this.treeViewRight.SelectedNode.Nodes.Count == 0) { this.buttonAdd.Enabled = true; } } this.customInterfaceDialog.DeleteButtonStatus(true); this.customInterfaceDialog.RenameButtonStatus(true); this.buttonRemove.Enabled = false; if (this.treeViewLeft.SelectedNode != null && this.treeViewLeft.SelectedNode.Tag != null) { this.customInterfaceDialog.DeleteButtonStatus(false); this.customInterfaceDialog.RenameButtonStatus(false); this.button1.Enabled = true; this.buttonAdd.Enabled = false; this.buttonRemove.Enabled = true; } //1009###17109 if (this.treeViewLeft.SelectedNode != null) { if (this.treeViewLeft.SelectedNode.Parent != null) { int index = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode); if (index > 0) this.buttonUp.Enabled = true; else this.buttonUp.Enabled = false; } else { int index = this.treeViewLeft.Nodes.IndexOf(this.treeViewLeft.SelectedNode); if (index > 0) this.buttonUp.Enabled = true; else this.buttonUp.Enabled = false; } } else this.buttonUp.Enabled = false; if (this.treeViewLeft.SelectedNode != null) { if (this.treeViewLeft.SelectedNode.Parent != null) { int index = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode); if (index < this.treeViewLeft.SelectedNode.Parent.Nodes.Count - 1) this.buttonDown.Enabled = true; else this.buttonDown.Enabled = false; } else { int index = this.treeViewLeft.Nodes.IndexOf(this.treeViewLeft.SelectedNode); if (index < this.treeViewLeft.Nodes.Count - 1) this.buttonDown.Enabled = true; else this.buttonDown.Enabled = false; } } else this.buttonDown.Enabled = false; } /// /// 自定义绘制 /// 参考https://www.cnblogs.com/JiYF/p/6693503.html /// /// /// private void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e) { /**用默认颜色 e.DrawDefault = true; return; **/ //以下是自定义颜色 if ((e.State & TreeNodeStates.Selected) != 0) { //演示为绿底白字 e.Graphics.FillRectangle(SystemBrushes.Highlight/*Brushes.Green*/, e.Node.Bounds); Font nodeFont = e.Node.NodeFont; if (nodeFont == null) nodeFont = ((TreeView)sender).Font; e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, Rectangle.Inflate(e.Bounds, 2, 0)); } else { e.DrawDefault = true; } if ((e.State & TreeNodeStates.Focused) != 0) { using (Pen focusPen = new Pen(Color.Black)) { focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; Rectangle focusBounds = e.Node.Bounds; focusBounds.Size = new Size(focusBounds.Width - 1, focusBounds.Height - 1); e.Graphics.DrawRectangle(focusPen, focusBounds); } } } /// /// 初始化左侧工作流程菜单 /// private void InitializeLeftTreeData() { ///// ///// 工具栏 ///// //private ToolbarModel toolbar_Model = Startup.instance.toolbarModel; if (toolbar_Model != null && toolbar_Model.Flows != null) { for (int i = 0; i < this.toolbar_Model.Flows.Count; i++) { TreeNode anime = new TreeNode(this.toolbar_Model.Flows[i].Name); anime.Name = this.toolbar_Model.Flows[i].Key; for (int j = 0; j < this.toolbar_Model.Flows[i].Menus.Count; j++) { TreeNode child = new TreeNode(); ToolStripItem[] items = this.appWorkspace.ToolBar.MainMenu.Items.Find(this.toolbar_Model.Flows[i].Menus[j].Description, true); if (items != null && items.Length > 0) child.Text = ((PdnMenuItem)(items[0])).Text; else child.Text = this.toolbar_Model.Flows[i].Menus[j].Name;// getShowName(Startup.instance.configModel.Language); child.Name = this.toolbar_Model.Flows[i].Menus[j].Description; child.Tag = this.toolbar_Model.Flows[i].Menus[j].Id; anime.Nodes.Add(child); } this.treeViewLeft.Nodes.Add(anime); } } } /// /// 初始化右侧树形菜单数据 /// private void InitializeRightTreeData() { this.collectionRight = this.appWorkspace.ToolBar.MainMenu.Items; TreeNode anime = new TreeNode(PdnResources.GetString("Menu.menu.Text")); this.RecursiveData(collectionRight, anime); anime.Expand(); this.treeViewRight.Nodes.Add(anime); } /// /// 递归进行数据组织 /// private void RecursiveData(ToolStripItemCollection collection, TreeNode anime) { //for (int i = 0; i < collection.Count; i++) //{ // //排除掉最近打开的文件,或者可以用数字id判断更准确 // if (!collection[i].Name.Equals("OpenRecent") && !collection[i].Name.Equals("CameraSelection")) // { // if (collection[i].GetType() != typeof(ToolStripSeparator) && ((PdnMenuItem)collection[i]).CanShowInSenseShield) // { // TreeNode node = new TreeNode(); // node.Name = collection[i].Name; // node.Text = collection[i].Text; // node.Tag = ((PdnMenuItem)collection[i]).MenuId; // anime.Nodes.Add(node); // RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, node); // } // } //} for (int i = 0; i < collection.Count; i++) { TreeNode node = new TreeNode(/*collection[i].Text*/); if (collection[i] is PdnMenuItem) { PdnMenuItem item = (PdnMenuItem)collection[i]; if (!item.CanShowInSenseShield) continue; node.Tag = item.MenuId; if (menuIdArr != null && menuIdArr.Length > 0) { if (Array.IndexOf(menuIdArr, item.MenuId.ToString()) != -1) { node.Name = collection[i].Name; node.Text = collection[i].Text; node.Tag = ((PdnMenuItem)collection[i]).MenuId; node.Checked = true; } else { node.Checked = false; } } if (node.Checked) { anime.Nodes.Add(node); } if (collection[i].Name.Equals("OpenRecent") || collection[i].Name.Equals("CameraSelection")) continue; RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, node); } } } #region 组件设计器生成的代码 private void InitializeLanguageText() { this.groupBoxLeft.Text = PdnResources.GetString("Menu.tool.Generateshortcut.Toolbarlist.text"); this.groupBoxRight.Text = PdnResources.GetString("Menu.Availablefunctions.text"); this.button1.Text = PdnResources.GetString("Menu.Thedivider.text"); this.buttonAdd.Text = "< "+ PdnResources.GetString("Menu.Addto.text"); this.buttonRemove.Text = PdnResources.GetString("Menu.Moveout.text")+ " >"; this.buttonUp.Text = PdnResources.GetString("Menu.LabelAction.MoveUpAction.Text"); this.buttonDown.Text = PdnResources.GetString("Menu.LabelAction.MoveDownAction.Text"); } /// /// 设计器支持所需的方法 - 不要修改 /// 使用代码编辑器修改此方法的内容。 /// private void InitializeComponent() { this.groupBoxLeft = new System.Windows.Forms.GroupBox(); this.treeViewLeft = new System.Windows.Forms.TreeView(); this.groupBoxRight = new System.Windows.Forms.GroupBox(); this.treeViewRight = new System.Windows.Forms.TreeView(); this.button1 = new System.Windows.Forms.Button(); this.buttonAdd = new System.Windows.Forms.Button(); this.buttonRemove = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.groupBoxLeft.SuspendLayout(); this.groupBoxRight.SuspendLayout(); this.SuspendLayout(); // // groupBoxLeft // this.groupBoxLeft.Controls.Add(this.treeViewLeft); this.groupBoxLeft.Location = new System.Drawing.Point(0, 0); this.groupBoxLeft.Name = "groupBoxLeft"; this.groupBoxLeft.Size = new System.Drawing.Size(256, 398); this.groupBoxLeft.TabIndex = 0; this.groupBoxLeft.TabStop = false; this.groupBoxLeft.Text = "工具栏列表"; // // treeViewLeft // this.treeViewLeft.Location = new System.Drawing.Point(7, 20); this.treeViewLeft.Name = "treeViewLeft"; this.treeViewLeft.Size = new System.Drawing.Size(243, 372); this.treeViewLeft.TabIndex = 0; this.treeViewLeft.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeViewLeft_MouseDown); // // groupBoxRight // this.groupBoxRight.Controls.Add(this.treeViewRight); this.groupBoxRight.Location = new System.Drawing.Point(367, 0); this.groupBoxRight.Name = "groupBoxRight"; this.groupBoxRight.Size = new System.Drawing.Size(256, 398); this.groupBoxRight.TabIndex = 1; this.groupBoxRight.TabStop = false; this.groupBoxRight.Text = "可用功能"; // // treeViewRight // this.treeViewRight.Location = new System.Drawing.Point(7, 20); this.treeViewRight.Name = "treeViewRight"; this.treeViewRight.Size = new System.Drawing.Size(243, 372); this.treeViewRight.TabIndex = 0; this.treeViewRight.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeViewRight_MouseDown); // // button1 // this.button1.Location = new System.Drawing.Point(277, 20); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 2; this.button1.Text = "分割线"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // buttonAdd // this.buttonAdd.Location = new System.Drawing.Point(277, 50); this.buttonAdd.Name = "buttonAdd"; this.buttonAdd.Size = new System.Drawing.Size(75, 23); this.buttonAdd.TabIndex = 3; this.buttonAdd.Text = "< 添加"; this.buttonAdd.UseVisualStyleBackColor = true; this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); // // buttonRemove // this.buttonRemove.Location = new System.Drawing.Point(277, 80); this.buttonRemove.Name = "buttonRemove"; this.buttonRemove.Size = new System.Drawing.Size(75, 23); this.buttonRemove.TabIndex = 4; this.buttonRemove.Text = "移出 >"; this.buttonRemove.UseVisualStyleBackColor = true; this.buttonRemove.Click += new System.EventHandler(this.buttonRemove_Click); // // buttonUp // this.buttonUp.Location = new System.Drawing.Point(277, 110); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(75, 23); this.buttonUp.TabIndex = 5; this.buttonUp.Text = "向上移动"; this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.Click += new System.EventHandler(this.buttonUp_Click); // // buttonDown // this.buttonDown.Location = new System.Drawing.Point(277, 140); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(75, 23); this.buttonDown.TabIndex = 6; this.buttonDown.Text = "向下移动"; this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.Click += new System.EventHandler(this.buttonDown_Click); // // TopTools // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonRemove); this.Controls.Add(this.buttonAdd); this.Controls.Add(this.button1); this.Controls.Add(this.groupBoxRight); this.Controls.Add(this.groupBoxLeft); this.Name = "TopTools"; this.Size = new System.Drawing.Size(623, 398); this.groupBoxLeft.ResumeLayout(false); this.groupBoxRight.ResumeLayout(false); this.ResumeLayout(false); } #endregion /// /// 添加分割线 /// /// /// private void button1_Click(object sender, EventArgs e) { if (this.treeViewLeft.SelectedNode != null && this.treeViewLeft.SelectedNode.Parent != null) { int index = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode); TreeNode child = new TreeNode(); child.Text = "--------";// this.treeViewLeft.SelectedNode.Text;//显示的名称 多语言 child.Name = "SeparateLine";// this.treeViewLeft.SelectedNode.Name;//唯一标识 英文 child.Tag = -1;// this.treeViewLeft.SelectedNode.Tag;//唯一标识 数字 this.treeViewLeft.SelectedNode.Parent.Nodes.Insert(index, child); SaveToolbar(6, this.treeViewLeft.SelectedNode.Parent.Name, index, child.Name, child.Text, (int)child.Tag); } } /// /// 添加 /// /// /// private void buttonAdd_Click(object sender, EventArgs e) { if (this.treeViewRight.SelectedNode != null && this.treeViewLeft.SelectedNode != null) { TreeNode child = new TreeNode(); child.Text = this.treeViewRight.SelectedNode.Text;//显示的名称 多语言 child.Name = this.treeViewRight.SelectedNode.Name;//唯一标识 英文 child.Tag = this.treeViewRight.SelectedNode.Tag;//唯一标识 数字 this.treeViewLeft.SelectedNode.Nodes.Add(child); SaveToolbar(1, this.treeViewLeft.SelectedNode.Name, 0, child.Name, child.Text, (int)child.Tag); } } /// /// 移出 /// /// /// private void buttonRemove_Click(object sender, EventArgs e) { if (this.treeViewLeft.SelectedNode != null && this.treeViewLeft.SelectedNode.Tag != null && this.treeViewLeft.SelectedNode.Parent != null && this.treeViewLeft.SelectedNode.Parent.Name != null) { string toolStripContrainerName = this.treeViewLeft.SelectedNode.Parent.Name; int toolStripItemIndex = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode); this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode); this.treeViewLeft.Refresh(); SaveToolbar(3, toolStripContrainerName, toolStripItemIndex); } } /// /// 向上移动 /// /// /// private void buttonUp_Click(object sender, EventArgs e) { if (this.treeViewLeft.SelectedNode != null) { if (this.treeViewLeft.SelectedNode.Parent != null) { string toolStripContrainerName = this.treeViewLeft.SelectedNode.Parent.Name; int toolStripItemIndex = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode); int index = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode); if (index > 0) { TreeNode prenode = (TreeNode)this.treeViewLeft.SelectedNode.PrevNode.Clone(); this.treeViewLeft.SelectedNode.Parent.Nodes.Insert(index + 1, prenode); this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode.PrevNode); } SaveToolbar(4, toolStripContrainerName, toolStripItemIndex); } else { int index = this.treeViewLeft.Nodes.IndexOf(this.treeViewLeft.SelectedNode); if (index > 0) { TreeNode prenode = (TreeNode)this.treeViewLeft.SelectedNode.PrevNode.Clone(); this.treeViewLeft.Nodes.Insert(index + 1, prenode); this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode.PrevNode); } } this.treeViewLeft.Refresh(); } } /// /// 向下移动 /// /// /// private void buttonDown_Click(object sender, EventArgs e) { if (this.treeViewLeft.SelectedNode != null) { if (this.treeViewLeft.SelectedNode.Parent != null) { string toolStripContrainerName = this.treeViewLeft.SelectedNode.Parent.Name; int toolStripItemIndex = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode); int index = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode); if (index < this.treeViewLeft.SelectedNode.Parent.Nodes.Count - 1) { TreeNode prenode = (TreeNode)this.treeViewLeft.SelectedNode.NextNode.Clone(); this.treeViewLeft.SelectedNode.Parent.Nodes.Insert(index, prenode); this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode.NextNode); } SaveToolbar(5, toolStripContrainerName, toolStripItemIndex); } else { int index = this.treeViewLeft.Nodes.IndexOf(this.treeViewLeft.SelectedNode); if (index < this.treeViewLeft.Nodes.Count - 1) { TreeNode prenode = (TreeNode)this.treeViewLeft.SelectedNode.NextNode.Clone(); this.treeViewLeft.Nodes.Insert(index, prenode); this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode.NextNode); } } this.treeViewLeft.Refresh(); } } /// /// 左侧工作流程鼠标按下事件 /// /// /// private void treeViewLeft_MouseDown(object sender, MouseEventArgs e) { if ((sender as TreeView) != null) { this.treeViewLeft.SelectedNode = this.treeViewLeft.GetNodeAt(e.X, e.Y); this.treeViewLeft.Refresh(); } } /// /// 右侧功能列表鼠标按下事件 /// /// /// private void treeViewRight_MouseDown(object sender, MouseEventArgs e) { if ((sender as TreeView) != null && e.Clicks == 2 && this.buttonAdd.Enabled) {//自定义软件界面,双击可添加 if (this.treeViewLeft.Nodes.Count == 0) return; TreeNode downNode = this.treeViewRight.GetNodeAt(e.X, e.Y); this.treeViewRight.SelectedNode = downNode; if (downNode/*this.treeViewRight.SelectedNode*/ != null && this.treeViewLeft.SelectedNode != null) { TreeNode child = new TreeNode(); child.Text = downNode.Text;//显示的名称 多语言 child.Name = downNode.Name;//唯一标识 英文 child.Tag = downNode.Tag;//唯一标识 数字 this.treeViewLeft.SelectedNode.Nodes.Add(child); } this.treeViewRight.Refresh(); SaveToolbar(1, this.treeViewLeft.SelectedNode.Name, 0, downNode.Name, downNode.Text, (int)downNode.Tag); return; } if ((sender as TreeView) != null) { this.treeViewRight.SelectedNode = this.treeViewRight.GetNodeAt(e.X, e.Y); this.treeViewRight.Refresh(); } } /// /// 供父界面调用的删除方法 /// public void TreeView2Delete() { if (this.treeViewLeft.SelectedNode != null) { string toolStripContrainerName = this.treeViewLeft.SelectedNode.Name; this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode); if (this.treeViewLeft.Nodes.Count == 0) { buttonAdd.Enabled = false; } SaveToolbar(2, toolStripContrainerName); } } /// /// 供父界面调用的获取选中的节点的文本 /// public string GetSelectedNodeText() { if (this.treeViewLeft.SelectedNode == null) return null; return this.treeViewLeft.SelectedNode.Text; } /// /// 供父界面调用的新建节点 /// public void CreateTreeView2Node(string name) { TreeNode treeNode = new TreeNode(name); treeNode.Name = GetTimeStamp(); this.treeViewLeft.Nodes.Add(treeNode); } /// /// 供父界面调用的新建节点 /// public void ReNameTreeView2Node(string name) { if (this.treeViewLeft.SelectedNode != null) { this.treeViewLeft.SelectedNode.Text = name; } } /// /// 保存配置文件 /// /// 1添加 2删除 3移出 4向上移动 5向下移动 6添加分割线 7添加新的节点 /// /// public void SaveToolbar(int saveFlag = 0, string toolStripContrainerName = null, int toolStripItemIndex = 0, string nodeName = null, string nodeText = null, int nodeTag = 0) { ToolbarModel toolbar_Model1 = new ToolbarModel(); toolbar_Model1.Flows = new List(); for (int i = 0; i < this.treeViewLeft.Nodes.Count; i++) { ToolbarModel.Flow old = this.toolbar_Model.Flows.Find(a=>a.Name.Equals(this.treeViewLeft.Nodes[i].Text)); ToolbarModel.Flow flow = new ToolbarModel.Flow(); flow.Show = old == null ? true : old.Show; flow.Menus = new List(); flow.Name = this.treeViewLeft.Nodes[i].Text; if (this.treeViewLeft.Nodes[i].Name == null || this.treeViewLeft.Nodes[i].Name == "") { flow.Key = GetTimeStamp(); } else { flow.Key = (string)this.treeViewLeft.Nodes[i].Name; } //ToolbarLocationModel.Flow flowJ = Startup.instance.toolbarLocationModel.Flows.Find(a => a.Key.Equals(flow.Key)); //ToolbarModel.Flow flowJ = Startup.instance.toolbarModel.Flows.Find(a => a.Key.Equals(flow.Key)); if (old == null) { //ToolbarLocationModel.Flow flowJ2 = new ToolbarLocationModel.Flow(); //flowJ2.Key = flow.Key; //flowJ2.X = -100; //flowJ2.Y = -100; //toolbarLocation_Model.Flows.Add(flowJ2); flow.X = -100; flow.Y = -100; } else { //toolbarLocation_Model.Flows.Add(flowJ); flow.X = old.X; flow.Y = old.Y; } if (this.treeViewLeft.Nodes[i].Nodes.Count > 0) { for (int j = 0; j < this.treeViewLeft.Nodes[i].Nodes.Count; j++) { ToolbarModel.Flow.Item item = new ToolbarModel.Flow.Item(); item.Id = (int)(this.treeViewLeft.Nodes[i].Nodes[j].Tag); item.Name = this.treeViewLeft.Nodes[i].Nodes[j].Text; item.Description = this.treeViewLeft.Nodes[i].Nodes[j].Name; flow.Menus.Add(item); } } toolbar_Model1.Flows.Add(flow); } string userInfoXml = XmlSerializeHelper.XmlSerialize(toolbar_Model1); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Toolbar.xml"; if (FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create)) { Startup.instance.toolbarModel = toolbar_Model1; } else { MessageBox.Show(PdnResources.GetString("Menu.Toolbarsavefailed.text")); } appWorkspace.ToolBar.test1(true, saveFlag, toolStripContrainerName, toolStripItemIndex, nodeName, nodeText, nodeTag);/*ResetCustomizeTools*/ appWorkspace.ToolBar.InitializeContextMenuStrip(); } /// /// 获取时间戳 /// /// public string GetTimeStamp() { TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); return Convert.ToInt64(ts.TotalMilliseconds).ToString(); } /// /// 导出配置 /// /// public void ExportToolbarXml() { using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); saveFileDialog.Filter = "Xml(*.xml)|*.xml"; saveFileDialog.DefaultExt = "xml"; saveFileDialog.FilterIndex = 1; saveFileDialog.CheckFileExists = false; saveFileDialog.AddExtension = true; saveFileDialog.FileName = "Toolbar"; if(saveFileDialog.ShowDialog() == DialogResult.OK) { string filePath = saveFileDialog.FileName; string toolbarXml = XmlSerializeHelper.XmlSerialize(Startup.instance.toolbarModel); if (FileOperationHelper.WriteStringToFile(toolbarXml, filePath, FileMode.Create)) MessageBox.Show(PdnResources.GetString("Menu.Thetoolbarsuccessfully.text")); else MessageBox.Show(PdnResources.GetString("Menu.Toolbarconfigurationfilesavefailed.text")); } } } /// /// 导入配置 /// /// public void ImportToolbarXml() { using (var openFileDialog = new OpenFileDialog { Filter = "*.xml|*.xml" }) { if(openFileDialog.ShowDialog() == DialogResult.OK) { using (Stream toolbarStream = System.IO.File.OpenRead(openFileDialog.FileName)) { StreamReader sr = new StreamReader(toolbarStream); string xmlNotes = sr.ReadToEnd(); ToolbarModel toolbarXml = XmlSerializeHelper.DESerializer(xmlNotes); if(toolbarXml.Flows.Count > 0) { this.toolbar_Model = toolbarXml; this.treeViewLeft.Nodes.Clear(); InitializeLeftTreeData(); MessageBox.Show(PdnResources.GetString("Menu.Thtoolbarwasimportedsuccessfully.text")); SaveToolbar(); } else { MessageBox.Show(PdnResources.GetString("Menu.onfiguratiofilesavedconfiguratio.text")); } } } } } } }