TopTools.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using PaintDotNet.Base.SettingModel;
  6. using PaintDotNet.Base.CommTool;
  7. using System.IO;
  8. namespace PaintDotNet.Instrument.CustomInterface
  9. {
  10. internal class TopTools : UserControl
  11. {
  12. /// <summary>
  13. /// 右侧树形菜单
  14. /// </summary>
  15. private ToolStripItemCollection collectionRight;
  16. /// <summary>
  17. /// 工作空间
  18. /// </summary>
  19. private AppWorkspace appWorkspace;
  20. /// <summary>
  21. /// 工具栏
  22. /// </summary>
  23. private ToolbarModel toolbar_Model = Startup.instance.toolbarModel;
  24. //private ToolbarLocationModel toolbarLocation_Model = Startup.instance.toolbarLocationModel;
  25. /// <summary>
  26. /// 自定义界面dialog
  27. /// </summary>
  28. private CustomInterfaceDialog customInterfaceDialog;
  29. #region 控件
  30. private GroupBox groupBoxLeft;
  31. private GroupBox groupBoxRight;
  32. private Button button1;//分割线
  33. private Button buttonAdd;
  34. private Button buttonRemove;
  35. private Button buttonUp;
  36. private Button buttonDown;
  37. private TreeView treeViewRight;
  38. public TreeView treeViewLeft;
  39. #endregion
  40. private string txtPath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\ModuleConfig.txt";
  41. private string[] menuIdArr;
  42. public CustomInterfaceDialog CustomInterfaceDialog
  43. {
  44. set
  45. {
  46. this.customInterfaceDialog = value;
  47. }
  48. }
  49. public TopTools(AppWorkspace appWorkspace)
  50. {
  51. this.appWorkspace = appWorkspace;
  52. InitializeComponent();
  53. InitializeLanguageText();
  54. InitializeTreeEvent();
  55. InitializeLeftTreeData();
  56. InitVisibleMenuId();
  57. InitializeRightTreeData();
  58. }
  59. /// <summary>
  60. /// 获取txt文件中已保存的菜单可用id
  61. /// </summary>
  62. private void InitVisibleMenuId()
  63. {
  64. if (System.IO.File.Exists(txtPath))
  65. {
  66. string str = System.IO.File.ReadAllText(txtPath);
  67. if (str.IndexOf(',') != -1)
  68. {
  69. menuIdArr = str.Split(',');
  70. }
  71. else
  72. {
  73. if (!string.IsNullOrEmpty(str))
  74. {
  75. menuIdArr = new string[] { str };
  76. }
  77. }
  78. }
  79. }
  80. /// <summary>
  81. /// 初始化treeview的事件
  82. /// </summary>
  83. private void InitializeTreeEvent()
  84. {
  85. this.treeViewRight.HideSelection = false;
  86. this.treeViewRight.DrawMode = TreeViewDrawMode.OwnerDrawText;
  87. this.treeViewRight.DrawNode += new DrawTreeNodeEventHandler(this.treeView_DrawNode);
  88. this.treeViewRight.Invalidated += new InvalidateEventHandler(this.treeViewRight_InvalidateEvent);
  89. this.treeViewLeft.HideSelection = false;
  90. this.treeViewLeft.DrawMode = TreeViewDrawMode.OwnerDrawText;
  91. this.treeViewLeft.DrawNode += new DrawTreeNodeEventHandler(this.treeView_DrawNode);
  92. this.treeViewLeft.Invalidated += new InvalidateEventHandler(this.treeViewLeft_InvalidateEvent);
  93. }
  94. /// <summary>
  95. /// treeViewRight的重绘事件
  96. /// </summary>
  97. /// <param name="sender"></param>
  98. /// <param name="e"></param>
  99. private void treeViewRight_InvalidateEvent(object sender, InvalidateEventArgs e)
  100. {
  101. if (this.treeViewLeft.SelectedNode != null)
  102. {
  103. if (this.treeViewLeft.SelectedNode.Tag == null)
  104. this.buttonAdd.Enabled = true;
  105. }
  106. if (this.treeViewRight.SelectedNode != null)
  107. {
  108. if (this.treeViewRight.SelectedNode.Nodes.Count > 0)
  109. {
  110. this.buttonAdd.Enabled = false;
  111. }
  112. }
  113. }
  114. /// <summary>
  115. /// treeViewLeft的重绘事件
  116. /// </summary>
  117. /// <param name="sender"></param>
  118. /// <param name="e"></param>
  119. private void treeViewLeft_InvalidateEvent(object sender, InvalidateEventArgs e)
  120. {
  121. this.button1.Enabled = false;
  122. if (this.treeViewRight.SelectedNode != null)
  123. {
  124. if (this.treeViewRight.SelectedNode.Nodes.Count == 0)
  125. {
  126. this.buttonAdd.Enabled = true;
  127. }
  128. }
  129. this.customInterfaceDialog.DeleteButtonStatus(true);
  130. this.customInterfaceDialog.RenameButtonStatus(true);
  131. this.buttonRemove.Enabled = false;
  132. if (this.treeViewLeft.SelectedNode != null && this.treeViewLeft.SelectedNode.Tag != null)
  133. {
  134. this.customInterfaceDialog.DeleteButtonStatus(false);
  135. this.customInterfaceDialog.RenameButtonStatus(false);
  136. this.button1.Enabled = true;
  137. this.buttonAdd.Enabled = false;
  138. this.buttonRemove.Enabled = true;
  139. }
  140. //1009###17109
  141. if (this.treeViewLeft.SelectedNode != null)
  142. {
  143. if (this.treeViewLeft.SelectedNode.Parent != null)
  144. {
  145. int index = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
  146. if (index > 0)
  147. this.buttonUp.Enabled = true;
  148. else
  149. this.buttonUp.Enabled = false;
  150. }
  151. else
  152. {
  153. int index = this.treeViewLeft.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
  154. if (index > 0)
  155. this.buttonUp.Enabled = true;
  156. else
  157. this.buttonUp.Enabled = false;
  158. }
  159. }
  160. else
  161. this.buttonUp.Enabled = false;
  162. if (this.treeViewLeft.SelectedNode != null)
  163. {
  164. if (this.treeViewLeft.SelectedNode.Parent != null)
  165. {
  166. int index = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
  167. if (index < this.treeViewLeft.SelectedNode.Parent.Nodes.Count - 1)
  168. this.buttonDown.Enabled = true;
  169. else
  170. this.buttonDown.Enabled = false;
  171. }
  172. else
  173. {
  174. int index = this.treeViewLeft.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
  175. if (index < this.treeViewLeft.Nodes.Count - 1)
  176. this.buttonDown.Enabled = true;
  177. else
  178. this.buttonDown.Enabled = false;
  179. }
  180. }
  181. else
  182. this.buttonDown.Enabled = false;
  183. }
  184. /// <summary>
  185. /// 自定义绘制
  186. /// 参考https://www.cnblogs.com/JiYF/p/6693503.html
  187. /// </summary>
  188. /// <param name="sender"></param>
  189. /// <param name="e"></param>
  190. private void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
  191. {
  192. /**用默认颜色
  193. e.DrawDefault = true;
  194. return;
  195. **/
  196. //以下是自定义颜色
  197. if ((e.State & TreeNodeStates.Selected) != 0)
  198. {
  199. //演示为绿底白字
  200. e.Graphics.FillRectangle(SystemBrushes.Highlight/*Brushes.Green*/, e.Node.Bounds);
  201. Font nodeFont = e.Node.NodeFont;
  202. if (nodeFont == null) nodeFont = ((TreeView)sender).Font;
  203. e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, Rectangle.Inflate(e.Bounds, 2, 0));
  204. }
  205. else
  206. {
  207. e.DrawDefault = true;
  208. }
  209. if ((e.State & TreeNodeStates.Focused) != 0)
  210. {
  211. using (Pen focusPen = new Pen(Color.Black))
  212. {
  213. focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  214. Rectangle focusBounds = e.Node.Bounds;
  215. focusBounds.Size = new Size(focusBounds.Width - 1,
  216. focusBounds.Height - 1);
  217. e.Graphics.DrawRectangle(focusPen, focusBounds);
  218. }
  219. }
  220. }
  221. /// <summary>
  222. /// 初始化左侧工作流程菜单
  223. /// </summary>
  224. private void InitializeLeftTreeData()
  225. {
  226. ///// <summary>
  227. ///// 工具栏
  228. ///// </summary>
  229. //private ToolbarModel toolbar_Model = Startup.instance.toolbarModel;
  230. if (toolbar_Model != null && toolbar_Model.Flows != null)
  231. {
  232. for (int i = 0; i < this.toolbar_Model.Flows.Count; i++)
  233. {
  234. TreeNode anime = new TreeNode(this.toolbar_Model.Flows[i].Name);
  235. anime.Name = this.toolbar_Model.Flows[i].Key;
  236. for (int j = 0; j < this.toolbar_Model.Flows[i].Menus.Count; j++)
  237. {
  238. TreeNode child = new TreeNode();
  239. ToolStripItem[] items = this.appWorkspace.ToolBar.MainMenu.Items.Find(this.toolbar_Model.Flows[i].Menus[j].Description, true);
  240. if (items != null && items.Length > 0)
  241. child.Text = ((PdnMenuItem)(items[0])).Text;
  242. else
  243. child.Text = this.toolbar_Model.Flows[i].Menus[j].Name;// getShowName(Startup.instance.configModel.Language);
  244. child.Name = this.toolbar_Model.Flows[i].Menus[j].Description;
  245. child.Tag = this.toolbar_Model.Flows[i].Menus[j].Id;
  246. anime.Nodes.Add(child);
  247. }
  248. this.treeViewLeft.Nodes.Add(anime);
  249. }
  250. }
  251. }
  252. /// <summary>
  253. /// 初始化右侧树形菜单数据
  254. /// </summary>
  255. private void InitializeRightTreeData()
  256. {
  257. this.collectionRight = this.appWorkspace.ToolBar.MainMenu.Items;
  258. TreeNode anime = new TreeNode(PdnResources.GetString("Menu.menu.Text"));
  259. this.RecursiveData(collectionRight, anime);
  260. anime.Expand();
  261. this.treeViewRight.Nodes.Add(anime);
  262. }
  263. /// <summary>
  264. /// 递归进行数据组织
  265. /// </summary>
  266. private void RecursiveData(ToolStripItemCollection collection, TreeNode anime)
  267. {
  268. //for (int i = 0; i < collection.Count; i++)
  269. //{
  270. // //排除掉最近打开的文件,或者可以用数字id判断更准确
  271. // if (!collection[i].Name.Equals("OpenRecent") && !collection[i].Name.Equals("CameraSelection"))
  272. // {
  273. // if (collection[i].GetType() != typeof(ToolStripSeparator) && ((PdnMenuItem)collection[i]).CanShowInSenseShield)
  274. // {
  275. // TreeNode node = new TreeNode();
  276. // node.Name = collection[i].Name;
  277. // node.Text = collection[i].Text;
  278. // node.Tag = ((PdnMenuItem)collection[i]).MenuId;
  279. // anime.Nodes.Add(node);
  280. // RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, node);
  281. // }
  282. // }
  283. //}
  284. for (int i = 0; i < collection.Count; i++)
  285. {
  286. TreeNode node = new TreeNode(/*collection[i].Text*/);
  287. if (collection[i] is PdnMenuItem)
  288. {
  289. PdnMenuItem item = (PdnMenuItem)collection[i];
  290. if (!item.CanShowInSenseShield)
  291. continue;
  292. node.Tag = item.MenuId;
  293. if (menuIdArr != null && menuIdArr.Length > 0)
  294. {
  295. if (Array.IndexOf(menuIdArr, item.MenuId.ToString()) != -1)
  296. {
  297. node.Name = collection[i].Name;
  298. node.Text = collection[i].Text;
  299. node.Tag = ((PdnMenuItem)collection[i]).MenuId;
  300. node.Checked = true;
  301. }
  302. else
  303. {
  304. node.Checked = false;
  305. }
  306. }
  307. if (node.Checked)
  308. {
  309. anime.Nodes.Add(node);
  310. }
  311. if (collection[i].Name.Equals("OpenRecent") || collection[i].Name.Equals("CameraSelection"))
  312. continue;
  313. RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, node);
  314. }
  315. }
  316. }
  317. #region 组件设计器生成的代码
  318. private void InitializeLanguageText()
  319. {
  320. this.groupBoxLeft.Text = PdnResources.GetString("Menu.tool.Generateshortcut.Toolbarlist.text");
  321. this.groupBoxRight.Text = PdnResources.GetString("Menu.Availablefunctions.text");
  322. this.button1.Text = PdnResources.GetString("Menu.Thedivider.text");
  323. this.buttonAdd.Text = "< "+ PdnResources.GetString("Menu.Addto.text");
  324. this.buttonRemove.Text = PdnResources.GetString("Menu.Moveout.text")+ " >";
  325. this.buttonUp.Text = PdnResources.GetString("Menu.LabelAction.MoveUpAction.Text");
  326. this.buttonDown.Text = PdnResources.GetString("Menu.LabelAction.MoveDownAction.Text");
  327. }
  328. /// <summary>
  329. /// 设计器支持所需的方法 - 不要修改
  330. /// 使用代码编辑器修改此方法的内容。
  331. /// </summary>
  332. private void InitializeComponent()
  333. {
  334. this.groupBoxLeft = new System.Windows.Forms.GroupBox();
  335. this.treeViewLeft = new System.Windows.Forms.TreeView();
  336. this.groupBoxRight = new System.Windows.Forms.GroupBox();
  337. this.treeViewRight = new System.Windows.Forms.TreeView();
  338. this.button1 = new System.Windows.Forms.Button();
  339. this.buttonAdd = new System.Windows.Forms.Button();
  340. this.buttonRemove = new System.Windows.Forms.Button();
  341. this.buttonUp = new System.Windows.Forms.Button();
  342. this.buttonDown = new System.Windows.Forms.Button();
  343. this.groupBoxLeft.SuspendLayout();
  344. this.groupBoxRight.SuspendLayout();
  345. this.SuspendLayout();
  346. //
  347. // groupBoxLeft
  348. //
  349. this.groupBoxLeft.Controls.Add(this.treeViewLeft);
  350. this.groupBoxLeft.Location = new System.Drawing.Point(0, 0);
  351. this.groupBoxLeft.Name = "groupBoxLeft";
  352. this.groupBoxLeft.Size = new System.Drawing.Size(256, 398);
  353. this.groupBoxLeft.TabIndex = 0;
  354. this.groupBoxLeft.TabStop = false;
  355. this.groupBoxLeft.Text = "工具栏列表";
  356. //
  357. // treeViewLeft
  358. //
  359. this.treeViewLeft.Location = new System.Drawing.Point(7, 20);
  360. this.treeViewLeft.Name = "treeViewLeft";
  361. this.treeViewLeft.Size = new System.Drawing.Size(243, 372);
  362. this.treeViewLeft.TabIndex = 0;
  363. this.treeViewLeft.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeViewLeft_MouseDown);
  364. //
  365. // groupBoxRight
  366. //
  367. this.groupBoxRight.Controls.Add(this.treeViewRight);
  368. this.groupBoxRight.Location = new System.Drawing.Point(367, 0);
  369. this.groupBoxRight.Name = "groupBoxRight";
  370. this.groupBoxRight.Size = new System.Drawing.Size(256, 398);
  371. this.groupBoxRight.TabIndex = 1;
  372. this.groupBoxRight.TabStop = false;
  373. this.groupBoxRight.Text = "可用功能";
  374. //
  375. // treeViewRight
  376. //
  377. this.treeViewRight.Location = new System.Drawing.Point(7, 20);
  378. this.treeViewRight.Name = "treeViewRight";
  379. this.treeViewRight.Size = new System.Drawing.Size(243, 372);
  380. this.treeViewRight.TabIndex = 0;
  381. this.treeViewRight.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeViewRight_MouseDown);
  382. //
  383. // button1
  384. //
  385. this.button1.Location = new System.Drawing.Point(277, 20);
  386. this.button1.Name = "button1";
  387. this.button1.Size = new System.Drawing.Size(75, 23);
  388. this.button1.TabIndex = 2;
  389. this.button1.Text = "分割线";
  390. this.button1.UseVisualStyleBackColor = true;
  391. this.button1.Click += new System.EventHandler(this.button1_Click);
  392. //
  393. // buttonAdd
  394. //
  395. this.buttonAdd.Location = new System.Drawing.Point(277, 50);
  396. this.buttonAdd.Name = "buttonAdd";
  397. this.buttonAdd.Size = new System.Drawing.Size(75, 23);
  398. this.buttonAdd.TabIndex = 3;
  399. this.buttonAdd.Text = "< 添加";
  400. this.buttonAdd.UseVisualStyleBackColor = true;
  401. this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
  402. //
  403. // buttonRemove
  404. //
  405. this.buttonRemove.Location = new System.Drawing.Point(277, 80);
  406. this.buttonRemove.Name = "buttonRemove";
  407. this.buttonRemove.Size = new System.Drawing.Size(75, 23);
  408. this.buttonRemove.TabIndex = 4;
  409. this.buttonRemove.Text = "移出 >";
  410. this.buttonRemove.UseVisualStyleBackColor = true;
  411. this.buttonRemove.Click += new System.EventHandler(this.buttonRemove_Click);
  412. //
  413. // buttonUp
  414. //
  415. this.buttonUp.Location = new System.Drawing.Point(277, 110);
  416. this.buttonUp.Name = "buttonUp";
  417. this.buttonUp.Size = new System.Drawing.Size(75, 23);
  418. this.buttonUp.TabIndex = 5;
  419. this.buttonUp.Text = "向上移动";
  420. this.buttonUp.UseVisualStyleBackColor = true;
  421. this.buttonUp.Click += new System.EventHandler(this.buttonUp_Click);
  422. //
  423. // buttonDown
  424. //
  425. this.buttonDown.Location = new System.Drawing.Point(277, 140);
  426. this.buttonDown.Name = "buttonDown";
  427. this.buttonDown.Size = new System.Drawing.Size(75, 23);
  428. this.buttonDown.TabIndex = 6;
  429. this.buttonDown.Text = "向下移动";
  430. this.buttonDown.UseVisualStyleBackColor = true;
  431. this.buttonDown.Click += new System.EventHandler(this.buttonDown_Click);
  432. //
  433. // TopTools
  434. //
  435. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  436. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  437. this.Controls.Add(this.buttonDown);
  438. this.Controls.Add(this.buttonUp);
  439. this.Controls.Add(this.buttonRemove);
  440. this.Controls.Add(this.buttonAdd);
  441. this.Controls.Add(this.button1);
  442. this.Controls.Add(this.groupBoxRight);
  443. this.Controls.Add(this.groupBoxLeft);
  444. this.Name = "TopTools";
  445. this.Size = new System.Drawing.Size(623, 398);
  446. this.groupBoxLeft.ResumeLayout(false);
  447. this.groupBoxRight.ResumeLayout(false);
  448. this.ResumeLayout(false);
  449. }
  450. #endregion
  451. /// <summary>
  452. /// 添加分割线
  453. /// </summary>
  454. /// <param name="sender"></param>
  455. /// <param name="e"></param>
  456. private void button1_Click(object sender, EventArgs e)
  457. {
  458. if (this.treeViewLeft.SelectedNode != null && this.treeViewLeft.SelectedNode.Parent != null)
  459. {
  460. int index = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
  461. TreeNode child = new TreeNode();
  462. child.Text = "--------";// this.treeViewLeft.SelectedNode.Text;//显示的名称 多语言
  463. child.Name = "SeparateLine";// this.treeViewLeft.SelectedNode.Name;//唯一标识 英文
  464. child.Tag = -1;// this.treeViewLeft.SelectedNode.Tag;//唯一标识 数字
  465. this.treeViewLeft.SelectedNode.Parent.Nodes.Insert(index, child);
  466. SaveToolbar(6, this.treeViewLeft.SelectedNode.Parent.Name, index, child.Name, child.Text, (int)child.Tag);
  467. }
  468. }
  469. /// <summary>
  470. /// 添加
  471. /// </summary>
  472. /// <param name="sender"></param>
  473. /// <param name="e"></param>
  474. private void buttonAdd_Click(object sender, EventArgs e)
  475. {
  476. if (this.treeViewRight.SelectedNode != null && this.treeViewLeft.SelectedNode != null)
  477. {
  478. TreeNode child = new TreeNode();
  479. child.Text = this.treeViewRight.SelectedNode.Text;//显示的名称 多语言
  480. child.Name = this.treeViewRight.SelectedNode.Name;//唯一标识 英文
  481. child.Tag = this.treeViewRight.SelectedNode.Tag;//唯一标识 数字
  482. this.treeViewLeft.SelectedNode.Nodes.Add(child);
  483. SaveToolbar(1, this.treeViewLeft.SelectedNode.Name, 0, child.Name, child.Text, (int)child.Tag);
  484. }
  485. }
  486. /// <summary>
  487. /// 移出
  488. /// </summary>
  489. /// <param name="sender"></param>
  490. /// <param name="e"></param>
  491. private void buttonRemove_Click(object sender, EventArgs e)
  492. {
  493. if (this.treeViewLeft.SelectedNode != null && this.treeViewLeft.SelectedNode.Tag != null
  494. && this.treeViewLeft.SelectedNode.Parent != null && this.treeViewLeft.SelectedNode.Parent.Name != null)
  495. {
  496. string toolStripContrainerName = this.treeViewLeft.SelectedNode.Parent.Name;
  497. int toolStripItemIndex = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
  498. this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode);
  499. this.treeViewLeft.Refresh();
  500. SaveToolbar(3, toolStripContrainerName, toolStripItemIndex);
  501. }
  502. }
  503. /// <summary>
  504. /// 向上移动
  505. /// </summary>
  506. /// <param name="sender"></param>
  507. /// <param name="e"></param>
  508. private void buttonUp_Click(object sender, EventArgs e)
  509. {
  510. if (this.treeViewLeft.SelectedNode != null)
  511. {
  512. if (this.treeViewLeft.SelectedNode.Parent != null)
  513. {
  514. string toolStripContrainerName = this.treeViewLeft.SelectedNode.Parent.Name;
  515. int toolStripItemIndex = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
  516. int index = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
  517. if (index > 0)
  518. {
  519. TreeNode prenode = (TreeNode)this.treeViewLeft.SelectedNode.PrevNode.Clone();
  520. this.treeViewLeft.SelectedNode.Parent.Nodes.Insert(index + 1, prenode);
  521. this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode.PrevNode);
  522. }
  523. SaveToolbar(4, toolStripContrainerName, toolStripItemIndex);
  524. }
  525. else
  526. {
  527. int index = this.treeViewLeft.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
  528. if (index > 0)
  529. {
  530. TreeNode prenode = (TreeNode)this.treeViewLeft.SelectedNode.PrevNode.Clone();
  531. this.treeViewLeft.Nodes.Insert(index + 1, prenode);
  532. this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode.PrevNode);
  533. }
  534. }
  535. this.treeViewLeft.Refresh();
  536. }
  537. }
  538. /// <summary>
  539. /// 向下移动
  540. /// </summary>
  541. /// <param name="sender"></param>
  542. /// <param name="e"></param>
  543. private void buttonDown_Click(object sender, EventArgs e)
  544. {
  545. if (this.treeViewLeft.SelectedNode != null)
  546. {
  547. if (this.treeViewLeft.SelectedNode.Parent != null)
  548. {
  549. string toolStripContrainerName = this.treeViewLeft.SelectedNode.Parent.Name;
  550. int toolStripItemIndex = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
  551. int index = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
  552. if (index < this.treeViewLeft.SelectedNode.Parent.Nodes.Count - 1)
  553. {
  554. TreeNode prenode = (TreeNode)this.treeViewLeft.SelectedNode.NextNode.Clone();
  555. this.treeViewLeft.SelectedNode.Parent.Nodes.Insert(index, prenode);
  556. this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode.NextNode);
  557. }
  558. SaveToolbar(5, toolStripContrainerName, toolStripItemIndex);
  559. }
  560. else
  561. {
  562. int index = this.treeViewLeft.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
  563. if (index < this.treeViewLeft.Nodes.Count - 1)
  564. {
  565. TreeNode prenode = (TreeNode)this.treeViewLeft.SelectedNode.NextNode.Clone();
  566. this.treeViewLeft.Nodes.Insert(index, prenode);
  567. this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode.NextNode);
  568. }
  569. }
  570. this.treeViewLeft.Refresh();
  571. }
  572. }
  573. /// <summary>
  574. /// 左侧工作流程鼠标按下事件
  575. /// </summary>
  576. /// <param name="sender"></param>
  577. /// <param name="e"></param>
  578. private void treeViewLeft_MouseDown(object sender, MouseEventArgs e)
  579. {
  580. if ((sender as TreeView) != null)
  581. {
  582. this.treeViewLeft.SelectedNode = this.treeViewLeft.GetNodeAt(e.X, e.Y);
  583. this.treeViewLeft.Refresh();
  584. }
  585. }
  586. /// <summary>
  587. /// 右侧功能列表鼠标按下事件
  588. /// </summary>
  589. /// <param name="sender"></param>
  590. /// <param name="e"></param>
  591. private void treeViewRight_MouseDown(object sender, MouseEventArgs e)
  592. {
  593. if ((sender as TreeView) != null && e.Clicks == 2 && this.buttonAdd.Enabled)
  594. {//自定义软件界面,双击可添加
  595. if (this.treeViewLeft.Nodes.Count == 0) return;
  596. TreeNode downNode = this.treeViewRight.GetNodeAt(e.X, e.Y);
  597. this.treeViewRight.SelectedNode = downNode;
  598. if (downNode/*this.treeViewRight.SelectedNode*/ != null && this.treeViewLeft.SelectedNode != null)
  599. {
  600. TreeNode child = new TreeNode();
  601. child.Text = downNode.Text;//显示的名称 多语言
  602. child.Name = downNode.Name;//唯一标识 英文
  603. child.Tag = downNode.Tag;//唯一标识 数字
  604. this.treeViewLeft.SelectedNode.Nodes.Add(child);
  605. }
  606. this.treeViewRight.Refresh();
  607. SaveToolbar(1, this.treeViewLeft.SelectedNode.Name, 0, downNode.Name, downNode.Text, (int)downNode.Tag);
  608. return;
  609. }
  610. if ((sender as TreeView) != null)
  611. {
  612. this.treeViewRight.SelectedNode = this.treeViewRight.GetNodeAt(e.X, e.Y);
  613. this.treeViewRight.Refresh();
  614. }
  615. }
  616. /// <summary>
  617. /// 供父界面调用的删除方法
  618. /// </summary>
  619. public void TreeView2Delete()
  620. {
  621. if (this.treeViewLeft.SelectedNode != null)
  622. {
  623. string toolStripContrainerName = this.treeViewLeft.SelectedNode.Name;
  624. this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode);
  625. if (this.treeViewLeft.Nodes.Count == 0)
  626. {
  627. buttonAdd.Enabled = false;
  628. }
  629. SaveToolbar(2, toolStripContrainerName);
  630. }
  631. }
  632. /// <summary>
  633. /// 供父界面调用的获取选中的节点的文本
  634. /// </summary>
  635. public string GetSelectedNodeText()
  636. {
  637. if (this.treeViewLeft.SelectedNode == null)
  638. return null;
  639. return this.treeViewLeft.SelectedNode.Text;
  640. }
  641. /// <summary>
  642. /// 供父界面调用的新建节点
  643. /// </summary>
  644. public void CreateTreeView2Node(string name)
  645. {
  646. TreeNode treeNode = new TreeNode(name);
  647. treeNode.Name = GetTimeStamp();
  648. this.treeViewLeft.Nodes.Add(treeNode);
  649. }
  650. /// <summary>
  651. /// 供父界面调用的新建节点
  652. /// </summary>
  653. public void ReNameTreeView2Node(string name)
  654. {
  655. if (this.treeViewLeft.SelectedNode != null)
  656. {
  657. this.treeViewLeft.SelectedNode.Text = name;
  658. }
  659. }
  660. /// <summary>
  661. /// 保存配置文件
  662. /// </summary>
  663. /// <param name="saveFlag">1添加 2删除 3移出 4向上移动 5向下移动 6添加分割线 7添加新的节点</param>
  664. /// <param name="toolStripContrainerName"></param>
  665. /// <param name="toolStripItemTag"></param>
  666. public void SaveToolbar(int saveFlag = 0, string toolStripContrainerName = null, int toolStripItemIndex = 0, string nodeName = null, string nodeText = null, int nodeTag = 0)
  667. {
  668. ToolbarModel toolbar_Model1 = new ToolbarModel();
  669. toolbar_Model1.Flows = new List<ToolbarModel.Flow>();
  670. for (int i = 0; i < this.treeViewLeft.Nodes.Count; i++)
  671. {
  672. ToolbarModel.Flow old = this.toolbar_Model.Flows.Find(a=>a.Name.Equals(this.treeViewLeft.Nodes[i].Text));
  673. ToolbarModel.Flow flow = new ToolbarModel.Flow();
  674. flow.Show = old == null ? true : old.Show;
  675. flow.Menus = new List<ToolbarModel.Flow.Item>();
  676. flow.Name = this.treeViewLeft.Nodes[i].Text;
  677. if (this.treeViewLeft.Nodes[i].Name == null || this.treeViewLeft.Nodes[i].Name == "")
  678. {
  679. flow.Key = GetTimeStamp();
  680. }
  681. else
  682. {
  683. flow.Key = (string)this.treeViewLeft.Nodes[i].Name;
  684. }
  685. //ToolbarLocationModel.Flow flowJ = Startup.instance.toolbarLocationModel.Flows.Find(a => a.Key.Equals(flow.Key));
  686. //ToolbarModel.Flow flowJ = Startup.instance.toolbarModel.Flows.Find(a => a.Key.Equals(flow.Key));
  687. if (old == null)
  688. {
  689. //ToolbarLocationModel.Flow flowJ2 = new ToolbarLocationModel.Flow();
  690. //flowJ2.Key = flow.Key;
  691. //flowJ2.X = -100;
  692. //flowJ2.Y = -100;
  693. //toolbarLocation_Model.Flows.Add(flowJ2);
  694. flow.X = -100;
  695. flow.Y = -100;
  696. }
  697. else
  698. {
  699. //toolbarLocation_Model.Flows.Add(flowJ);
  700. flow.X = old.X;
  701. flow.Y = old.Y;
  702. }
  703. if (this.treeViewLeft.Nodes[i].Nodes.Count > 0)
  704. {
  705. for (int j = 0; j < this.treeViewLeft.Nodes[i].Nodes.Count; j++)
  706. {
  707. ToolbarModel.Flow.Item item = new ToolbarModel.Flow.Item();
  708. item.Id = (int)(this.treeViewLeft.Nodes[i].Nodes[j].Tag);
  709. item.Name = this.treeViewLeft.Nodes[i].Nodes[j].Text;
  710. item.Description = this.treeViewLeft.Nodes[i].Nodes[j].Name;
  711. flow.Menus.Add(item);
  712. }
  713. }
  714. toolbar_Model1.Flows.Add(flow);
  715. }
  716. string userInfoXml = XmlSerializeHelper.XmlSerialize<ToolbarModel>(toolbar_Model1);
  717. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Toolbar.xml";
  718. if (FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create))
  719. {
  720. Startup.instance.toolbarModel = toolbar_Model1;
  721. }
  722. else
  723. {
  724. MessageBox.Show(PdnResources.GetString("Menu.Toolbarsavefailed.text"));
  725. }
  726. appWorkspace.ToolBar.test1(true, saveFlag, toolStripContrainerName, toolStripItemIndex, nodeName, nodeText, nodeTag);/*ResetCustomizeTools*/
  727. appWorkspace.ToolBar.InitializeContextMenuStrip();
  728. }
  729. /// <summary>
  730. /// 获取时间戳
  731. /// </summary>
  732. /// <returns></returns>
  733. public string GetTimeStamp()
  734. {
  735. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  736. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  737. }
  738. /// <summary>
  739. /// 导出配置
  740. /// </summary>
  741. /// <returns></returns>
  742. public void ExportToolbarXml()
  743. {
  744. using (SaveFileDialog saveFileDialog = new SaveFileDialog())
  745. {
  746. saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  747. saveFileDialog.Filter = "Xml(*.xml)|*.xml";
  748. saveFileDialog.DefaultExt = "xml";
  749. saveFileDialog.FilterIndex = 1;
  750. saveFileDialog.CheckFileExists = false;
  751. saveFileDialog.AddExtension = true;
  752. saveFileDialog.FileName = "Toolbar";
  753. if(saveFileDialog.ShowDialog() == DialogResult.OK)
  754. {
  755. string filePath = saveFileDialog.FileName;
  756. string toolbarXml = XmlSerializeHelper.XmlSerialize<ToolbarModel>(Startup.instance.toolbarModel);
  757. if (FileOperationHelper.WriteStringToFile(toolbarXml, filePath, FileMode.Create))
  758. MessageBox.Show(PdnResources.GetString("Menu.Thetoolbarsuccessfully.text"));
  759. else
  760. MessageBox.Show(PdnResources.GetString("Menu.Toolbarconfigurationfilesavefailed.text"));
  761. }
  762. }
  763. }
  764. /// <summary>
  765. /// 导入配置
  766. /// </summary>
  767. /// <returns></returns>
  768. public void ImportToolbarXml()
  769. {
  770. using (var openFileDialog = new OpenFileDialog { Filter = "*.xml|*.xml" })
  771. {
  772. if(openFileDialog.ShowDialog() == DialogResult.OK)
  773. {
  774. using (Stream toolbarStream = System.IO.File.OpenRead(openFileDialog.FileName))
  775. {
  776. StreamReader sr = new StreamReader(toolbarStream);
  777. string xmlNotes = sr.ReadToEnd();
  778. ToolbarModel toolbarXml = XmlSerializeHelper.DESerializer<ToolbarModel>(xmlNotes);
  779. if(toolbarXml.Flows.Count > 0)
  780. {
  781. this.toolbar_Model = toolbarXml;
  782. this.treeViewLeft.Nodes.Clear();
  783. InitializeLeftTreeData();
  784. MessageBox.Show(PdnResources.GetString("Menu.Thtoolbarwasimportedsuccessfully.text"));
  785. SaveToolbar();
  786. }
  787. else
  788. {
  789. MessageBox.Show(PdnResources.GetString("Menu.onfiguratiofilesavedconfiguratio.text"));
  790. }
  791. }
  792. }
  793. }
  794. }
  795. }
  796. }