FastTools.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using PaintDotNet.Base.SettingModel;
  11. using PaintDotNet.Base.CommTool;
  12. using System.IO;
  13. namespace PaintDotNet.Instrument.CustomInterface
  14. {
  15. internal class FastTools : UserControl
  16. {
  17. /// <summary>
  18. /// 右侧树形菜单
  19. /// </summary>
  20. private ToolStripItemCollection collectionRight;
  21. /// <summary>
  22. /// 工作空间
  23. /// </summary>
  24. private AppWorkspace appWorkspace;
  25. /// <summary>
  26. /// 快捷菜单的数据
  27. /// </summary>
  28. private ShortcutbarModel shortcutbar_Model = Startup.instance.shortcutbarModel;
  29. private string txtPath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\ModuleConfig.txt";
  30. private string[] menuIdArr;
  31. #region 控件
  32. private GroupBox groupBoxLeft;
  33. private ListView listViewLeft;
  34. private ListViewItem listViewLeftDown = null;
  35. private ImageList imageListLeft;
  36. private GroupBox groupBoxRight;
  37. private TreeView treeViewRight;
  38. private Button buttonAdd;
  39. private Button buttonRemove;
  40. private Button buttonUp;
  41. private Button buttonDown;
  42. private IContainer components;
  43. #endregion
  44. public FastTools(AppWorkspace appWorkspace)
  45. {
  46. this.appWorkspace = appWorkspace;
  47. InitializeComponent();
  48. InitializeLanguageText();
  49. InitVisibleMenuId();
  50. InitializeLeftTreeData();
  51. InitializeRightTreeData();
  52. InitializeTreeEvent();
  53. }
  54. /// <summary>
  55. /// 获取txt文件中已保存的菜单可用id
  56. /// </summary>
  57. private void InitVisibleMenuId()
  58. {
  59. if (System.IO.File.Exists(txtPath))
  60. {
  61. string str = System.IO.File.ReadAllText(txtPath);
  62. if (str.IndexOf(',') != -1)
  63. {
  64. menuIdArr = str.Split(',');
  65. }
  66. else
  67. {
  68. if (!string.IsNullOrEmpty(str))
  69. {
  70. menuIdArr = new string[] { str };
  71. }
  72. }
  73. }
  74. }
  75. /// <summary>
  76. /// 初始化treeview的事件
  77. /// </summary>
  78. private void InitializeTreeEvent()
  79. {
  80. this.treeViewRight.HideSelection = false;
  81. this.treeViewRight.DrawMode = TreeViewDrawMode.OwnerDrawText;
  82. this.treeViewRight.DrawNode += new DrawTreeNodeEventHandler(this.treeViewRight_DrawNode);
  83. this.treeViewRight.Invalidated += new InvalidateEventHandler(this.treeViewRight_Invalidated);
  84. this.treeViewRight.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeViewRight_MouseDown);
  85. }
  86. /// <summary>
  87. /// 右侧功能列表鼠标按下事件
  88. /// </summary>
  89. /// <param name="sender"></param>
  90. /// <param name="e"></param>
  91. private void treeViewRight_MouseDown(object sender, MouseEventArgs e)
  92. {
  93. if ((sender as TreeView) != null && e.Clicks == 2 && this.buttonAdd.Enabled)
  94. {//自定义软件界面,双击可添加
  95. if (this.treeViewRight.GetNodeAt(e.X, e.Y) == null)
  96. return;
  97. }
  98. else
  99. return;
  100. //自定义软件界面,双击可添加
  101. TreeNode downNode = this.treeViewRight.GetNodeAt(e.X, e.Y);
  102. //if ((sender as TreeView) != null)
  103. //{
  104. // this.treeViewRight.SelectedNode = this.treeViewRight.GetNodeAt(e.X, e.Y);
  105. // this.treeViewRight.Refresh();
  106. //}
  107. if (/*this.treeViewRight.SelectedNode != null && */downNode.Nodes.Count == 0)
  108. {
  109. ToolStripItem[] items = this.appWorkspace.ToolBar.MainMenu.Items.Find(downNode.Name, true);
  110. if (items != null && items.Length > 0)
  111. {
  112. if (((PdnMenuItem)(items[0])).Image != null)
  113. this.listViewLeft.SmallImageList.Images.Add(downNode.Name, ((PdnMenuItem)(items[0])).Image);
  114. else
  115. this.listViewLeft.SmallImageList.Images.Add(downNode.Name, new Bitmap(16, 16));
  116. }
  117. else
  118. {
  119. this.listViewLeft.SmallImageList.Images.Add(downNode.Name, new Bitmap(16, 16));
  120. }
  121. ListViewItem item = new ListViewItem();
  122. item.Text = downNode.Text;
  123. item.Tag = downNode.Tag;
  124. item.Name = downNode.Name;
  125. item.ImageIndex = this.listViewLeft.SmallImageList.Images.Count - 1;
  126. this.listViewLeft.Items.Add(item);
  127. }
  128. }
  129. /// <summary>
  130. /// treeView1的重绘事件
  131. /// </summary>
  132. /// <param name="sender"></param>
  133. /// <param name="e"></param>
  134. private void treeViewRight_Invalidated(object sender, InvalidateEventArgs e)
  135. {
  136. }
  137. /// <summary>
  138. /// 自定义绘制
  139. /// 参考https://www.cnblogs.com/JiYF/p/6693503.html
  140. /// </summary>
  141. /// <param name="sender"></param>
  142. /// <param name="e"></param>
  143. private void treeViewRight_DrawNode(object sender, DrawTreeNodeEventArgs e)
  144. {
  145. /**用默认颜色
  146. e.DrawDefault = true;
  147. return;
  148. **/
  149. //以下是自定义颜色
  150. if ((e.State & TreeNodeStates.Selected) != 0)
  151. {
  152. //演示为蓝(绿)底白字
  153. e.Graphics.FillRectangle(SystemBrushes.Highlight/*Brushes.Green*/, e.Node.Bounds);
  154. Font nodeFont = e.Node.NodeFont;
  155. if (nodeFont == null) nodeFont = ((TreeView)sender).Font;
  156. e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, Rectangle.Inflate(e.Bounds, 2, 0));
  157. }
  158. else
  159. {
  160. e.DrawDefault = true;
  161. }
  162. if ((e.State & TreeNodeStates.Focused) != 0)
  163. {
  164. using (Pen focusPen = new Pen(Color.Black))
  165. {
  166. focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  167. Rectangle focusBounds = e.Node.Bounds;
  168. focusBounds.Size = new Size(focusBounds.Width - 1,
  169. focusBounds.Height - 1);
  170. e.Graphics.DrawRectangle(focusPen, focusBounds);
  171. }
  172. }
  173. }
  174. /// <summary>
  175. /// 初始化左侧listview菜单
  176. /// </summary>
  177. private void InitializeLeftTreeData()
  178. {
  179. this.listViewLeft.View = View.Details;
  180. ColumnHeader header = new ColumnHeader();
  181. header.Text = PdnResources.GetString("Menu.tool.Generateshortcut.functionlist.text");
  182. header.Width = 240;
  183. this.listViewLeft.Columns.Add(header);
  184. this.listViewLeft.Items.Clear();
  185. if (shortcutbar_Model!=null) {
  186. if (shortcutbar_Model.Menus != null)
  187. {
  188. for (int i=0; i< shortcutbar_Model.Menus.Count; i++)
  189. {
  190. ToolStripItem[] items = this.appWorkspace.ToolBar.MainMenu.Items.Find(shortcutbar_Model.Menus[i].Description, true);
  191. ListViewItem item = new ListViewItem();
  192. if (items != null && items.Length > 0)
  193. {
  194. if (((PdnMenuItem)(items[0])).Image != null)
  195. this.listViewLeft.SmallImageList.Images.Add(shortcutbar_Model.Menus[i].Description, ((PdnMenuItem)(items[0])).Image);
  196. else
  197. this.listViewLeft.SmallImageList.Images.Add(shortcutbar_Model.Menus[i].Description, new Bitmap(16, 16));
  198. item.Text = ((PdnMenuItem)(items[0])).Text;
  199. }
  200. else
  201. {
  202. this.listViewLeft.SmallImageList.Images.Add(shortcutbar_Model.Menus[i].Description, new Bitmap(16, 16));
  203. item.Text = shortcutbar_Model.Menus[i].Name;// getShowName(Startup.instance.configModel.Language);
  204. }
  205. item.Tag = shortcutbar_Model.Menus[i].Id;
  206. item.Name = shortcutbar_Model.Menus[i].Description;
  207. item.ImageIndex = i;
  208. this.listViewLeft.Items.Add(item);
  209. }
  210. }
  211. }
  212. }
  213. /// <summary>
  214. /// 初始化右侧树形菜单数据
  215. /// </summary>
  216. private void InitializeRightTreeData()
  217. {
  218. this.collectionRight = this.appWorkspace.ToolBar.MainMenu.Items;
  219. TreeNode anime = new TreeNode(PdnResources.GetString("Menu.menu.Text"));
  220. this.RecursiveData(collectionRight, anime);
  221. anime.Expand();
  222. this.treeViewRight.Nodes.Add(anime);
  223. }
  224. /// <summary>
  225. /// 递归进行数据组织
  226. /// </summary>
  227. private void RecursiveData(ToolStripItemCollection collection, TreeNode anime)
  228. {
  229. for (int i = 0; i < collection.Count; i++)
  230. {
  231. TreeNode node = new TreeNode(/*collection[i].Text*/);
  232. if (collection[i] is PdnMenuItem)
  233. {
  234. PdnMenuItem item = (PdnMenuItem)collection[i];
  235. if (!item.CanShowInSenseShield)
  236. continue;
  237. node.Tag = item.MenuId;
  238. if (menuIdArr != null && menuIdArr.Length > 0)
  239. {
  240. if (Array.IndexOf(menuIdArr, item.MenuId.ToString()) != -1)
  241. {
  242. node.Name = collection[i].Name;
  243. node.Text = collection[i].Text;
  244. node.Tag = ((PdnMenuItem)collection[i]).MenuId;
  245. node.Checked = true;
  246. }
  247. else
  248. {
  249. node.Checked = false;
  250. }
  251. }
  252. if (node.Checked)
  253. {
  254. anime.Nodes.Add(node);
  255. }
  256. if (collection[i].Name.Equals("OpenRecent") || collection[i].Name.Equals("CameraSelection"))
  257. continue;
  258. RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, node);
  259. }
  260. }
  261. }
  262. #region 组件设计器生成的代码
  263. private void InitializeLanguageText()
  264. {
  265. this.buttonDown.Text = PdnResources.GetString("Menu.LabelAction.MoveDownAction.Text");
  266. this.buttonUp.Text = PdnResources.GetString("Menu.LabelAction.MoveUpAction.Text");
  267. this.buttonRemove.Text = PdnResources.GetString("Menu.Moveout.text")+" >";
  268. this.buttonAdd.Text = "< "+ PdnResources.GetString("Menu.Addto.text");
  269. this.groupBoxRight.Text = PdnResources.GetString("Menu.Availablefunctions.text");
  270. this.groupBoxLeft.Text = PdnResources.GetString("Menu.tool.Generateshortcut.Shortcutbarcontent.text");
  271. }
  272. /// <summary>
  273. /// 设计器支持所需的方法 - 不要修改
  274. /// 使用代码编辑器修改此方法的内容。
  275. /// </summary>
  276. private void InitializeComponent()
  277. {
  278. this.components = new System.ComponentModel.Container();
  279. this.groupBoxLeft = new System.Windows.Forms.GroupBox();
  280. this.listViewLeft = new System.Windows.Forms.ListView();
  281. this.imageListLeft = new System.Windows.Forms.ImageList(this.components);
  282. this.groupBoxRight = new System.Windows.Forms.GroupBox();
  283. this.treeViewRight = new System.Windows.Forms.TreeView();
  284. this.buttonAdd = new System.Windows.Forms.Button();
  285. this.buttonRemove = new System.Windows.Forms.Button();
  286. this.buttonUp = new System.Windows.Forms.Button();
  287. this.buttonDown = new System.Windows.Forms.Button();
  288. this.groupBoxLeft.SuspendLayout();
  289. this.groupBoxRight.SuspendLayout();
  290. this.SuspendLayout();
  291. //
  292. // groupBoxLeft
  293. //
  294. this.groupBoxLeft.Controls.Add(this.listViewLeft);
  295. this.groupBoxLeft.Location = new System.Drawing.Point(0, 0);
  296. this.groupBoxLeft.Name = "groupBoxLeft";
  297. this.groupBoxLeft.Size = new System.Drawing.Size(256, 398);
  298. this.groupBoxLeft.TabIndex = 0;
  299. this.groupBoxLeft.TabStop = false;
  300. this.groupBoxLeft.Text = "快捷栏内容";
  301. //
  302. // listViewLeft
  303. //
  304. this.listViewLeft.HideSelection = false;
  305. this.listViewLeft.Location = new System.Drawing.Point(7, 20);
  306. this.listViewLeft.MultiSelect = false;
  307. this.listViewLeft.Name = "listViewLeft";
  308. this.listViewLeft.Size = new System.Drawing.Size(243, 372);
  309. this.listViewLeft.SmallImageList = this.imageListLeft;
  310. this.listViewLeft.TabIndex = 0;
  311. this.listViewLeft.UseCompatibleStateImageBehavior = false;
  312. this.listViewLeft.MouseDown += ListViewLeft_MouseDown;
  313. this.listViewLeft.DrawItem += new System.Windows.Forms.DrawListViewItemEventHandler(this.listViewLeft_DrawItem);
  314. this.listViewLeft.Invalidated += new InvalidateEventHandler(this.treeViewLeft_InvalidateEvent);
  315. //
  316. // imageListLeft
  317. //
  318. this.imageListLeft.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
  319. this.imageListLeft.ImageSize = new System.Drawing.Size(16, 16);
  320. this.imageListLeft.TransparentColor = System.Drawing.Color.Transparent;
  321. //
  322. // groupBoxRight
  323. //
  324. this.groupBoxRight.Controls.Add(this.treeViewRight);
  325. this.groupBoxRight.Location = new System.Drawing.Point(367, 0);
  326. this.groupBoxRight.Name = "groupBoxRight";
  327. this.groupBoxRight.Size = new System.Drawing.Size(256, 398);
  328. this.groupBoxRight.TabIndex = 1;
  329. this.groupBoxRight.TabStop = false;
  330. this.groupBoxRight.Text = "可用功能";
  331. //
  332. // treeViewRight
  333. //
  334. this.treeViewRight.Location = new System.Drawing.Point(7, 20);
  335. this.treeViewRight.Name = "treeViewRight";
  336. this.treeViewRight.Size = new System.Drawing.Size(243, 372);
  337. this.treeViewRight.TabIndex = 0;
  338. //
  339. // buttonAdd
  340. //
  341. this.buttonAdd.Location = new System.Drawing.Point(277, 20);
  342. this.buttonAdd.Name = "buttonAdd";
  343. this.buttonAdd.Size = new System.Drawing.Size(75, 23);
  344. this.buttonAdd.TabIndex = 3;
  345. this.buttonAdd.Text = "< 添加";
  346. this.buttonAdd.UseVisualStyleBackColor = true;
  347. this.buttonAdd.Click += new System.EventHandler(this.buttonAddClick);
  348. //
  349. // buttonRemove
  350. //
  351. this.buttonRemove.Location = new System.Drawing.Point(277, 49);
  352. this.buttonRemove.Name = "buttonRemove";
  353. this.buttonRemove.Size = new System.Drawing.Size(75, 23);
  354. this.buttonRemove.TabIndex = 4;
  355. this.buttonRemove.Text = "移出 >";
  356. this.buttonRemove.UseVisualStyleBackColor = true;
  357. this.buttonRemove.Click += new System.EventHandler(this.buttonRemoveClick);
  358. //
  359. // buttonUp
  360. //
  361. this.buttonUp.Location = new System.Drawing.Point(277, 78);
  362. this.buttonUp.Name = "buttonUp";
  363. this.buttonUp.Size = new System.Drawing.Size(75, 23);
  364. this.buttonUp.TabIndex = 5;
  365. this.buttonUp.Text = "向上移动";
  366. this.buttonUp.UseVisualStyleBackColor = true;
  367. this.buttonUp.Click += new System.EventHandler(this.buttonUpClick);
  368. //
  369. // buttonDown
  370. //
  371. this.buttonDown.Location = new System.Drawing.Point(277, 107);
  372. this.buttonDown.Name = "buttonDown";
  373. this.buttonDown.Size = new System.Drawing.Size(75, 23);
  374. this.buttonDown.TabIndex = 6;
  375. this.buttonDown.Text = "向下移动";
  376. this.buttonDown.UseVisualStyleBackColor = true;
  377. this.buttonDown.Click += new System.EventHandler(this.buttonDownClick);
  378. //
  379. // FastTools
  380. //
  381. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  382. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  383. this.Controls.Add(this.buttonDown);
  384. this.Controls.Add(this.buttonUp);
  385. this.Controls.Add(this.buttonRemove);
  386. this.Controls.Add(this.buttonAdd);
  387. this.Controls.Add(this.groupBoxRight);
  388. this.Controls.Add(this.groupBoxLeft);
  389. this.Name = "FastTools";
  390. this.Size = new System.Drawing.Size(623, 398);
  391. this.groupBoxLeft.ResumeLayout(false);
  392. this.groupBoxRight.ResumeLayout(false);
  393. this.ResumeLayout(false);
  394. }
  395. private void ListViewLeft_MouseDown(object sender, MouseEventArgs e)
  396. {
  397. if ((sender as ListView) != null)
  398. {
  399. listViewLeftDown = this.listViewLeft.GetItemAt(e.X, e.Y);
  400. this.listViewLeft.Refresh();
  401. }
  402. //this.listViewLeft.Refresh();
  403. }
  404. #endregion
  405. /// <summary>
  406. /// 添加
  407. /// </summary>
  408. /// <param name="sender"></param>
  409. /// <param name="e"></param>
  410. private void buttonAddClick(object sender, EventArgs e)
  411. {
  412. if (this.treeViewRight.SelectedNode!=null && this.treeViewRight.SelectedNode.Nodes.Count==0)
  413. {
  414. ToolStripItem[] items = this.appWorkspace.ToolBar.MainMenu.Items.Find(this.treeViewRight.SelectedNode.Name, true);
  415. if (items != null && items.Length > 0)
  416. {
  417. if (((PdnMenuItem)(items[0])).Image != null)
  418. this.listViewLeft.SmallImageList.Images.Add(this.treeViewRight.SelectedNode.Name, ((PdnMenuItem)(items[0])).Image);
  419. else
  420. this.listViewLeft.SmallImageList.Images.Add(this.treeViewRight.SelectedNode.Name, new Bitmap(16, 16));
  421. }
  422. else
  423. {
  424. this.listViewLeft.SmallImageList.Images.Add(this.treeViewRight.SelectedNode.Name, new Bitmap(16, 16));
  425. }
  426. ListViewItem item = new ListViewItem();
  427. item.Text = this.treeViewRight.SelectedNode.Text;
  428. item.Tag = this.treeViewRight.SelectedNode.Tag;
  429. item.Name = this.treeViewRight.SelectedNode.Name;
  430. item.ImageIndex = this.listViewLeft.SmallImageList.Images.Count-1;
  431. this.listViewLeft.Items.Add(item);
  432. }
  433. }
  434. /// <summary>
  435. /// 移出
  436. /// </summary>
  437. /// <param name="sender"></param>
  438. /// <param name="e"></param>
  439. private void buttonRemoveClick(object sender, EventArgs e)
  440. {
  441. if (this.listViewLeft.SelectedItems.Count > 0)
  442. {
  443. foreach(ListViewItem item in this.listViewLeft.SelectedItems)
  444. this.listViewLeft.Items.Remove(item);
  445. }
  446. }
  447. /// <summary>
  448. /// 向上移动
  449. /// </summary>
  450. /// <param name="sender"></param>
  451. /// <param name="e"></param>
  452. private void buttonUpClick(object sender, EventArgs e)
  453. {
  454. if (this.listViewLeft.SelectedItems.Count == 1)
  455. {
  456. int index = this.listViewLeft.Items.IndexOf(this.listViewLeft.SelectedItems[0]);
  457. if (index > 0)
  458. {
  459. ListViewItem prenode = (ListViewItem)this.listViewLeft.Items[index-1].Clone();
  460. prenode.Name = this.listViewLeft.Items[index - 1].Name;
  461. this.listViewLeft.Items.Insert(index + 1, prenode);
  462. this.listViewLeft.Items.Remove(this.listViewLeft.Items[index - 1]);
  463. this.listViewLeft.Refresh();
  464. }
  465. }
  466. }
  467. /// <summary>
  468. /// 向下移动
  469. /// </summary>
  470. /// <param name="sender"></param>
  471. /// <param name="e"></param>
  472. private void buttonDownClick(object sender, EventArgs e)
  473. {
  474. if (this.listViewLeft.SelectedItems.Count == 1)
  475. {
  476. int index = this.listViewLeft.Items.IndexOf(this.listViewLeft.SelectedItems[0]);
  477. if (index < this.listViewLeft.Items.Count-1)
  478. {
  479. ListViewItem nextnode = (ListViewItem)this.listViewLeft.Items[index + 1].Clone();
  480. nextnode.Name = this.listViewLeft.Items[index + 1].Name;
  481. this.listViewLeft.Items.Insert(index, nextnode);
  482. this.listViewLeft.Items.Remove(this.listViewLeft.Items[index + 2]);
  483. this.listViewLeft.Refresh();
  484. }
  485. }
  486. }
  487. private void listViewLeft_DrawItem(object sender, DrawListViewItemEventArgs e)
  488. {
  489. e.DrawDefault = true;
  490. return;
  491. }
  492. /// <summary>
  493. /// treeViewLeft的重绘事件
  494. /// </summary>
  495. /// <param name="sender"></param>
  496. /// <param name="e"></param>
  497. private void treeViewLeft_InvalidateEvent(object sender, InvalidateEventArgs e)
  498. {
  499. //1009###17142
  500. if (listViewLeftDown == null)
  501. {
  502. //this.buttonUp.Enabled = false;
  503. //this.buttonDown.Enabled = false;
  504. if (this.listViewLeft.SelectedItems.Count == 1)
  505. {
  506. int index = this.listViewLeft.Items.IndexOf(this.listViewLeft.SelectedItems[0]);
  507. if (index > 0)
  508. this.buttonUp.Enabled = true;
  509. else
  510. this.buttonUp.Enabled = false;
  511. }
  512. else
  513. this.buttonUp.Enabled = false;
  514. if (this.listViewLeft.SelectedItems.Count == 1)
  515. {
  516. int index = this.listViewLeft.Items.IndexOf(this.listViewLeft.SelectedItems[0]);
  517. if (index < this.listViewLeft.Items.Count - 1)
  518. this.buttonDown.Enabled = true;
  519. else
  520. this.buttonDown.Enabled = false;
  521. }
  522. else
  523. this.buttonDown.Enabled = false;
  524. }
  525. else
  526. {
  527. int index = this.listViewLeft.Items.IndexOf(listViewLeftDown);
  528. if (index > 0)
  529. this.buttonUp.Enabled = true;
  530. else
  531. this.buttonUp.Enabled = false;
  532. index = this.listViewLeft.Items.IndexOf(listViewLeftDown);
  533. if (index < this.listViewLeft.Items.Count - 1)
  534. this.buttonDown.Enabled = true;
  535. else
  536. this.buttonDown.Enabled = false;
  537. listViewLeftDown = null;
  538. }
  539. }
  540. /// <summary>
  541. /// 保存数据到xml
  542. /// </summary>
  543. public void SaveToolbar()
  544. {
  545. shortcutbar_Model.Menus.Clear();
  546. for (int i = 0; i < this.listViewLeft.Items.Count; i++)
  547. {
  548. ShortcutbarModel.Item flow = new ShortcutbarModel.Item();
  549. flow.Id = (int)(this.listViewLeft.Items[i].Tag);
  550. flow.Name = this.listViewLeft.Items[i].Text;
  551. //################
  552. flow.Description = this.listViewLeft.Items[i].Name;
  553. shortcutbar_Model.Menus.Add(flow);
  554. }
  555. string userInfoXml = XmlSerializeHelper.XmlSerialize<ShortcutbarModel>(shortcutbar_Model);
  556. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Shortcutbar.xml";
  557. if (FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create))
  558. {
  559. //更新全局数据
  560. Startup.instance.shortcutbarModel = shortcutbar_Model;
  561. //this.appWorkspace.mainToolBarForm.setCilentSize();
  562. //this.appWorkspace.mainToolBarForm.ToolsControl.Refresh();
  563. this.appWorkspace.toolsPanel.RefreshTools();
  564. }
  565. else
  566. {
  567. MessageBox.Show(PdnResources.GetString("Menu.Shortcuttoolbarsavefailed.text"));
  568. }
  569. }
  570. /// <summary>
  571. /// 导出配置
  572. /// </summary>
  573. /// <returns></returns>
  574. public void ExportToolbarXml()
  575. {
  576. using (SaveFileDialog saveFileDialog = new SaveFileDialog())
  577. {
  578. saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  579. saveFileDialog.Filter = "Xml(*.xml)|*.xml";
  580. saveFileDialog.DefaultExt = "xml";
  581. saveFileDialog.FilterIndex = 1;
  582. saveFileDialog.CheckFileExists = false;
  583. saveFileDialog.AddExtension = true;
  584. saveFileDialog.FileName = "Shortcutbar";
  585. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  586. {
  587. string filePath = saveFileDialog.FileName;
  588. string toolbarXml = XmlSerializeHelper.XmlSerialize<ShortcutbarModel>(Startup.instance.shortcutbarModel);
  589. if (FileOperationHelper.WriteStringToFile(toolbarXml, filePath, FileMode.Create))
  590. MessageBox.Show(PdnResources.GetString("Menu.lbarconfigurationfilewassavedsuccessfu.text"));
  591. else
  592. MessageBox.Show(PdnResources.GetString("Menu.Theshortcuttoolbarsave.text"));
  593. }
  594. }
  595. }
  596. /// <summary>
  597. /// 导入配置
  598. /// </summary>
  599. /// <returns></returns>
  600. public void ImportToolbarXml()
  601. {
  602. using (var openFileDialog = new OpenFileDialog { Filter = "*.xml|*.xml" })
  603. {
  604. if (openFileDialog.ShowDialog() == DialogResult.OK)
  605. {
  606. using (Stream shortbarStream = System.IO.File.OpenRead(openFileDialog.FileName))
  607. {
  608. StreamReader sr = new StreamReader(shortbarStream);
  609. string xmlNotes = sr.ReadToEnd();
  610. ShortcutbarModel toolbarXml = XmlSerializeHelper.DESerializer<ShortcutbarModel>(xmlNotes);
  611. if (toolbarXml.Menus.Count > 0)
  612. {
  613. try
  614. {
  615. this.listViewLeft.Items.Clear();
  616. this.listViewLeft.SmallImageList = new ImageList();
  617. this.listViewLeft.BeginUpdate();
  618. for (int i = 0; i < toolbarXml.Menus.Count; i++)
  619. {
  620. ToolStripItem[] items = this.appWorkspace.ToolBar.MainMenu.Items.Find(toolbarXml.Menus[i].Description, true);
  621. ListViewItem listItem = new ListViewItem();
  622. if (items != null && items.Length > 0)
  623. {
  624. if (((PdnMenuItem)(items[0])).Image != null)
  625. this.listViewLeft.SmallImageList.Images.Add(((PdnMenuItem)(items[0])).Text, ((PdnMenuItem)(items[0])).Image);
  626. else
  627. this.listViewLeft.SmallImageList.Images.Add(((PdnMenuItem)(items[0])).Text, new Bitmap(16, 16));
  628. listItem.Text = ((PdnMenuItem)(items[0])).Text;
  629. }
  630. else
  631. {
  632. this.listViewLeft.SmallImageList.Images.Add(toolbarXml.Menus[i].Name/*getShowName(Startup.instance.configModel.Language)*/, new Bitmap(16, 16));
  633. listItem.Text = toolbarXml.Menus[i].Name;// getShowName(Startup.instance.configModel.Language);
  634. }
  635. listItem.Tag = toolbarXml.Menus[i].Id;
  636. listItem.Name = toolbarXml.Menus[i].Description;
  637. listItem.ImageIndex = i;
  638. this.listViewLeft.Items.Add(listItem);
  639. }
  640. this.listViewLeft.EndUpdate();
  641. MessageBox.Show(PdnResources.GetString("Menu.Shortcuttoolbasuccessfully.text"));
  642. }
  643. catch(Exception)
  644. {
  645. this.listViewLeft.Items.Clear();
  646. this.listViewLeft.SmallImageList = new ImageList();
  647. MessageBox.Show(PdnResources.GetString("Menu.Theshortcutconfigurationfileimportailed.text"));
  648. }
  649. }
  650. else
  651. {
  652. MessageBox.Show(PdnResources.GetString("Menu.onfiguratiofilesavedconfiguratio.text"));
  653. }
  654. }
  655. }
  656. }
  657. }
  658. }
  659. }