123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845 |
- 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
- {
- /// <summary>
- /// 右侧树形菜单
- /// </summary>
- private ToolStripItemCollection collectionRight;
- /// <summary>
- /// 工作空间
- /// </summary>
- private AppWorkspace appWorkspace;
- /// <summary>
- /// 工具栏
- /// </summary>
- private ToolbarModel toolbar_Model = Startup.instance.toolbarModel;
- //private ToolbarLocationModel toolbarLocation_Model = Startup.instance.toolbarLocationModel;
- /// <summary>
- /// 自定义界面dialog
- /// </summary>
- 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();
-
- }
- /// <summary>
- /// 获取txt文件中已保存的菜单可用id
- /// </summary>
- 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 };
- }
- }
- }
- }
- /// <summary>
- /// 初始化treeview的事件
- /// </summary>
- 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);
- }
- /// <summary>
- /// treeViewRight的重绘事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- }
- }
- }
- /// <summary>
- /// treeViewLeft的重绘事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- }
- /// <summary>
- /// 自定义绘制
- /// 参考https://www.cnblogs.com/JiYF/p/6693503.html
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- }
- /// <summary>
- /// 初始化左侧工作流程菜单
- /// </summary>
- private void InitializeLeftTreeData()
- {
- ///// <summary>
- ///// 工具栏
- ///// </summary>
- //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);
- }
- }
- }
- /// <summary>
- /// 初始化右侧树形菜单数据
- /// </summary>
- 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);
- }
- /// <summary>
- /// 递归进行数据组织
- /// </summary>
- 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");
- }
- /// <summary>
- /// 设计器支持所需的方法 - 不要修改
- /// 使用代码编辑器修改此方法的内容。
- /// </summary>
- 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
- /// <summary>
- /// 添加分割线
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 移出
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 向上移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- }
- /// <summary>
- /// 向下移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- }
- /// <summary>
- /// 左侧工作流程鼠标按下事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- }
- /// <summary>
- /// 右侧功能列表鼠标按下事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- }
- /// <summary>
- /// 供父界面调用的删除方法
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 供父界面调用的获取选中的节点的文本
- /// </summary>
- public string GetSelectedNodeText()
- {
- if (this.treeViewLeft.SelectedNode == null)
- return null;
- return this.treeViewLeft.SelectedNode.Text;
- }
- /// <summary>
- /// 供父界面调用的新建节点
- /// </summary>
- public void CreateTreeView2Node(string name)
- {
- TreeNode treeNode = new TreeNode(name);
- treeNode.Name = GetTimeStamp();
- this.treeViewLeft.Nodes.Add(treeNode);
- }
- /// <summary>
- /// 供父界面调用的新建节点
- /// </summary>
- public void ReNameTreeView2Node(string name)
- {
- if (this.treeViewLeft.SelectedNode != null)
- {
- this.treeViewLeft.SelectedNode.Text = name;
- }
- }
- /// <summary>
- /// 保存配置文件
- /// </summary>
- /// <param name="saveFlag">1添加 2删除 3移出 4向上移动 5向下移动 6添加分割线 7添加新的节点</param>
- /// <param name="toolStripContrainerName"></param>
- /// <param name="toolStripItemTag"></param>
- 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<ToolbarModel.Flow>();
- 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<ToolbarModel.Flow.Item>();
- 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<ToolbarModel>(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();
- }
- /// <summary>
- /// 获取时间戳
- /// </summary>
- /// <returns></returns>
- public string GetTimeStamp()
- {
- TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- return Convert.ToInt64(ts.TotalMilliseconds).ToString();
- }
- /// <summary>
- /// 导出配置
- /// </summary>
- /// <returns></returns>
- 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<ToolbarModel>(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"));
- }
- }
- }
- /// <summary>
- /// 导入配置
- /// </summary>
- /// <returns></returns>
- 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<ToolbarModel>(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"));
- }
- }
- }
- }
- }
- }
- }
|