CustomInterfaceDialog.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. using PaintDotNet.Base.CommTool;
  2. using PaintDotNet.Instrument.CustomInterface;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace PaintDotNet.Instrument
  11. {
  12. /// <summary>
  13. /// 自定义界面
  14. /// </summary>
  15. internal class CustomInterfaceDialog : PdnBaseForm
  16. {
  17. /// <summary>
  18. /// 工作空间
  19. /// </summary>
  20. private AppWorkspace appWorkspace;
  21. /// <summary>
  22. /// 当前选中 1工具栏 2快捷键 3快捷栏
  23. /// </summary>
  24. private int currentInedx = 0;
  25. /// <summary>
  26. /// 工具栏自定义组件
  27. /// </summary>
  28. private TopTools topTools;
  29. /// <summary>
  30. /// 快捷键自定义组件
  31. /// </summary>
  32. private ShortKeys shortKeys;
  33. /// <summary>
  34. /// 快捷栏自定义组件
  35. /// </summary>
  36. private FastTools fastTools;
  37. /// <summary>
  38. /// 新增、重命名的弹窗
  39. /// </summary>
  40. private CreateNameDialog createNameDialog;
  41. /// <summary>
  42. /// 是否新建弹窗
  43. /// </summary>
  44. private bool istoCreate = true;
  45. #region 控件
  46. private CustomControl.SelectButton buttonTopTools;
  47. private CustomControl.SelectButton buttonShortKeys;
  48. private CustomControl.SelectButton buttonFastTools;
  49. private GroupBox groupBoxTypes;
  50. private Button buttonSave;
  51. private Button buttonExport;
  52. private Button buttonImport;
  53. private Button buttonCreateName;
  54. private Button buttonDeleteName;
  55. private Button buttonEditName;
  56. private GroupBox groupBoxButtons;
  57. //private Label label1;
  58. //private Label label2;
  59. #endregion
  60. public CustomInterfaceDialog(AppWorkspace AppWorkspace)
  61. {
  62. this.appWorkspace = AppWorkspace;
  63. InitializeComponent();
  64. InitializeLanguageText();
  65. this.StartPosition = FormStartPosition.CenterScreen;
  66. this.topTools = new TopTools(this.appWorkspace);
  67. this.topTools.CustomInterfaceDialog = this;
  68. this.shortKeys = new ShortKeys(this.appWorkspace);
  69. this.fastTools = new FastTools(this.appWorkspace);
  70. this.buttonTopToolsClick(null, null);
  71. }
  72. private void InitializeLanguageText()
  73. {
  74. this.Text = PdnResources.GetString("Menu.Tools.CustomInterface.Text");
  75. this.groupBoxTypes.Text = PdnResources.GetString("Menu.Type.text");
  76. this.buttonFastTools.BtnText = PdnResources.GetString("Menu.tool.Generateshortcut.Shortcutbar.text");
  77. this.buttonShortKeys.BtnText = PdnResources.GetString("Menu.hotkey.text");
  78. this.buttonTopTools.BtnText = PdnResources.GetString("Menu.tool.Generateshortcut.toolbar.text");
  79. this.groupBoxButtons.Text = PdnResources.GetString("Menu.operation.text");
  80. this.buttonDeleteName.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
  81. this.buttonEditName.Text = PdnResources.GetString("Menu.Rename.text");
  82. this.buttonCreateName.Text = PdnResources.GetString("Menu.New.text");
  83. this.buttonExport.Text = PdnResources.GetString("Menu.tool.Generateshortcut.Exportconfiguration.text");
  84. this.buttonImport.Text = PdnResources.GetString("Menu.tool.Generateshortcut.Importconfiguration.text");
  85. this.buttonSave.Text = PdnResources.GetString("Menu.File.Save.Text");
  86. }
  87. private void InitializeComponent()
  88. {
  89. this.groupBoxTypes = new System.Windows.Forms.GroupBox();
  90. this.buttonFastTools = new PaintDotNet.CustomControl.SelectButton();
  91. this.buttonShortKeys = new PaintDotNet.CustomControl.SelectButton();
  92. this.buttonTopTools = new PaintDotNet.CustomControl.SelectButton();
  93. this.groupBoxButtons = new System.Windows.Forms.GroupBox();
  94. this.buttonDeleteName = new System.Windows.Forms.Button();
  95. this.buttonEditName = new System.Windows.Forms.Button();
  96. this.buttonCreateName = new System.Windows.Forms.Button();
  97. this.buttonExport = new System.Windows.Forms.Button();
  98. this.buttonImport = new System.Windows.Forms.Button();
  99. this.buttonSave = new System.Windows.Forms.Button();
  100. this.groupBoxTypes.SuspendLayout();
  101. this.groupBoxButtons.SuspendLayout();
  102. this.SuspendLayout();
  103. //
  104. // groupBoxTypes
  105. //
  106. this.groupBoxTypes.Controls.Add(this.buttonFastTools);
  107. this.groupBoxTypes.Controls.Add(this.buttonShortKeys);
  108. this.groupBoxTypes.Controls.Add(this.buttonTopTools);
  109. this.groupBoxTypes.Location = new System.Drawing.Point(13, 13);
  110. this.groupBoxTypes.Name = "groupBoxTypes";
  111. this.groupBoxTypes.Size = new System.Drawing.Size(87, 463);
  112. this.groupBoxTypes.TabIndex = 1;
  113. this.groupBoxTypes.TabStop = false;
  114. this.groupBoxTypes.Text = "类型";
  115. //
  116. // buttonFastTools
  117. //
  118. this.buttonFastTools.BackColor = System.Drawing.SystemColors.ControlDark;
  119. this.buttonFastTools.BtnSelect = false;
  120. this.buttonFastTools.BtnText = "按钮";
  121. this.buttonFastTools.Location = new System.Drawing.Point(6, 83);
  122. this.buttonFastTools.Name = "buttonFastTools";
  123. this.buttonFastTools.Size = new System.Drawing.Size(75, 23);
  124. this.buttonFastTools.TabIndex = 2;
  125. this.buttonFastTools.Click += new System.EventHandler(this.buttonFastToolsClick);
  126. //
  127. // buttonShortKeys
  128. //
  129. this.buttonShortKeys.BackColor = System.Drawing.SystemColors.ControlDark;
  130. this.buttonShortKeys.BtnSelect = false;
  131. this.buttonShortKeys.BtnText = "按钮";
  132. this.buttonShortKeys.Location = new System.Drawing.Point(6, 53);
  133. this.buttonShortKeys.Name = "buttonShortKeys";
  134. this.buttonShortKeys.Size = new System.Drawing.Size(75, 23);
  135. this.buttonShortKeys.TabIndex = 1;
  136. this.buttonShortKeys.Click += new System.EventHandler(this.buttonShortKeysClick);
  137. //
  138. // buttonTopTools
  139. //
  140. this.buttonTopTools.BackColor = System.Drawing.SystemColors.ControlDark;
  141. this.buttonTopTools.BtnSelect = false;
  142. this.buttonTopTools.BtnText = "按钮";
  143. this.buttonTopTools.Location = new System.Drawing.Point(6, 23);
  144. this.buttonTopTools.Name = "buttonTopTools";
  145. this.buttonTopTools.Size = new System.Drawing.Size(75, 23);
  146. this.buttonTopTools.TabIndex = 0;
  147. this.buttonTopTools.Click += new System.EventHandler(this.buttonTopToolsClick);
  148. //
  149. // groupBoxButtons
  150. //
  151. this.groupBoxButtons.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  152. | System.Windows.Forms.AnchorStyles.Right)));
  153. this.groupBoxButtons.Controls.Add(this.buttonDeleteName);
  154. this.groupBoxButtons.Controls.Add(this.buttonEditName);
  155. this.groupBoxButtons.Controls.Add(this.buttonCreateName);
  156. this.groupBoxButtons.Controls.Add(this.buttonExport);
  157. this.groupBoxButtons.Controls.Add(this.buttonImport);
  158. this.groupBoxButtons.Controls.Add(this.buttonSave);
  159. this.groupBoxButtons.Location = new System.Drawing.Point(107, 13);
  160. this.groupBoxButtons.Name = "groupBoxButtons";
  161. this.groupBoxButtons.Size = new System.Drawing.Size(623, 58);
  162. this.groupBoxButtons.TabIndex = 2;
  163. this.groupBoxButtons.TabStop = false;
  164. this.groupBoxButtons.Text = "操作";
  165. //
  166. // buttonDeleteName
  167. //
  168. this.buttonDeleteName.Location = new System.Drawing.Point(461, 23);
  169. this.buttonDeleteName.Name = "buttonDeleteName";
  170. this.buttonDeleteName.Size = new System.Drawing.Size(75, 23);
  171. this.buttonDeleteName.TabIndex = 5;
  172. this.buttonDeleteName.Text = "删除";
  173. this.buttonDeleteName.UseVisualStyleBackColor = true;
  174. this.buttonDeleteName.Click += new System.EventHandler(this.buttonDeleteNameClick);
  175. //
  176. // buttonEditName
  177. //
  178. this.buttonEditName.Location = new System.Drawing.Point(379, 23);
  179. this.buttonEditName.Name = "buttonEditName";
  180. this.buttonEditName.Size = new System.Drawing.Size(75, 23);
  181. this.buttonEditName.TabIndex = 4;
  182. this.buttonEditName.Text = "重命名";
  183. this.buttonEditName.UseVisualStyleBackColor = true;
  184. this.buttonEditName.Click += new System.EventHandler(this.buttonEditNameClick);
  185. //
  186. // buttonCreateName
  187. //
  188. this.buttonCreateName.Location = new System.Drawing.Point(297, 23);
  189. this.buttonCreateName.Name = "buttonCreateName";
  190. this.buttonCreateName.Size = new System.Drawing.Size(75, 23);
  191. this.buttonCreateName.TabIndex = 3;
  192. this.buttonCreateName.Text = "新建";
  193. this.buttonCreateName.UseVisualStyleBackColor = true;
  194. this.buttonCreateName.Click += new System.EventHandler(this.buttonCreateNameClick);
  195. //
  196. // buttonExport
  197. //
  198. this.buttonExport.Location = new System.Drawing.Point(135, 23);
  199. this.buttonExport.Name = "buttonExport";
  200. this.buttonExport.Size = new System.Drawing.Size(75, 23);
  201. this.buttonExport.TabIndex = 2;
  202. this.buttonExport.Text = "导出配置";
  203. this.buttonExport.UseVisualStyleBackColor = true;
  204. this.buttonExport.Click += new System.EventHandler(this.buttonExportClick);
  205. //
  206. // buttonImport
  207. //
  208. this.buttonImport.Location = new System.Drawing.Point(216, 23);
  209. this.buttonImport.Name = "buttonImport";
  210. this.buttonImport.Size = new System.Drawing.Size(75, 23);
  211. this.buttonImport.TabIndex = 1;
  212. this.buttonImport.Text = "导入配置";
  213. this.buttonImport.UseVisualStyleBackColor = true;
  214. this.buttonImport.Click += new System.EventHandler(this.buttonImportClick);
  215. //
  216. // buttonSave
  217. //
  218. this.buttonSave.Location = new System.Drawing.Point(542, 23);
  219. this.buttonSave.Name = "buttonSave";
  220. this.buttonSave.Size = new System.Drawing.Size(75, 23);
  221. this.buttonSave.TabIndex = 0;
  222. this.buttonSave.Text = "保存";
  223. this.buttonSave.UseVisualStyleBackColor = true;
  224. this.buttonSave.Click += new System.EventHandler(this.buttonSaveClick);
  225. //
  226. // CustomInterfaceDialog
  227. //
  228. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  229. this.ClientSize = new System.Drawing.Size(742, 488);
  230. this.Controls.Add(this.groupBoxButtons);
  231. this.Controls.Add(this.groupBoxTypes);
  232. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  233. this.MaximizeBox = false;
  234. this.MinimizeBox = false;
  235. this.Name = "CustomInterfaceDialog";
  236. this.Text = "自定义界面";
  237. this.Controls.SetChildIndex(this.groupBoxTypes, 0);
  238. this.Controls.SetChildIndex(this.groupBoxButtons, 0);
  239. this.groupBoxTypes.ResumeLayout(false);
  240. this.groupBoxButtons.ResumeLayout(false);
  241. this.ResumeLayout(false);
  242. }
  243. /// <summary>
  244. /// 工具栏
  245. /// </summary>
  246. /// <param name="sender"></param>
  247. /// <param name="e"></param>
  248. private void buttonTopToolsClick(object sender, EventArgs e)
  249. {
  250. if (currentInedx != 1)
  251. {
  252. //设置按钮的选中/非选择的状态
  253. buttonTopTools.BtnSelect = true;
  254. buttonShortKeys.BtnSelect = false;
  255. buttonFastTools.BtnSelect = false;
  256. this.Controls.Remove(this.shortKeys);
  257. this.Controls.Remove(this.fastTools);
  258. this.topTools.Location = new System.Drawing.Point(107, 78);
  259. this.Controls.Add(this.topTools);
  260. currentInedx = 1;
  261. this.buttonSave.Text = PdnResources.GetString("Menu.File.Save.Text");
  262. }
  263. ChangeButtonByIndex();
  264. }
  265. /// <summary>
  266. /// 快捷键
  267. /// </summary>
  268. /// <param name="sender"></param>
  269. /// <param name="e"></param>
  270. private void buttonShortKeysClick(object sender, EventArgs e)
  271. {
  272. if (currentInedx != 2)
  273. {
  274. //设置按钮的选中/非选择的状态
  275. buttonShortKeys.BtnSelect = true;
  276. buttonFastTools.BtnSelect = false;
  277. buttonTopTools.BtnSelect = false;
  278. this.Controls.Remove(this.topTools);
  279. this.Controls.Remove(this.fastTools);
  280. this.shortKeys.Location = new System.Drawing.Point(107, 78);
  281. this.Controls.Add(this.shortKeys);
  282. currentInedx = 2;
  283. this.buttonSave.Text = PdnResources.GetString("Menu.File.Close.Text");//#17140
  284. }
  285. ChangeButtonByIndex();
  286. }
  287. /// <summary>
  288. /// 快捷栏
  289. /// </summary>
  290. /// <param name="sender"></param>
  291. /// <param name="e"></param>
  292. private void buttonFastToolsClick(object sender, EventArgs e)
  293. {
  294. if (currentInedx != 3)
  295. {
  296. //设置按钮的选中/非选择的状态
  297. buttonFastTools.BtnSelect = true;
  298. buttonTopTools.BtnSelect = false;
  299. buttonShortKeys.BtnSelect = false;
  300. this.Controls.Remove(this.topTools);
  301. this.Controls.Remove(this.shortKeys);
  302. this.fastTools.Location = new System.Drawing.Point(107, 78);
  303. this.Controls.Add(this.fastTools);
  304. currentInedx = 3;
  305. this.buttonSave.Text = PdnResources.GetString("Menu.File.Save.Text");
  306. }
  307. ChangeButtonByIndex();
  308. }
  309. private void ChangeButtonByIndex()
  310. {
  311. //6 135, 23
  312. //5 216, 23
  313. //7 297, 23 隐藏显示
  314. //8 379, 23 隐藏显示
  315. //9 461, 23 隐藏显示
  316. //4 542, 23
  317. switch (currentInedx)
  318. {
  319. case 1:
  320. this.buttonCreateName.Visible = true;
  321. this.buttonEditName.Visible = true;
  322. this.buttonDeleteName.Visible = true;
  323. this.buttonSave.Visible = false;//自定义菜单实时保存 导入配置重启生效 (这里可以去掉保存按钮了,因为实时保存,以及导入配置还差实时保存更新,或者提示“软件重启后生效”)
  324. this.buttonExport.Location = new System.Drawing.Point(135 + 81, 23);
  325. this.buttonImport.Location = new System.Drawing.Point(216 + 81, 23);
  326. this.buttonCreateName.Location = new System.Drawing.Point(297 + 81, 23);
  327. this.buttonEditName.Location = new System.Drawing.Point(379 + 81, 23);
  328. this.buttonDeleteName.Location = new System.Drawing.Point(461 + 81, 23);
  329. //this.buttonSave.Location = new System.Drawing.Point(542, 23);
  330. break;
  331. case 2:
  332. this.buttonCreateName.Visible = false;
  333. this.buttonEditName.Visible = false;
  334. this.buttonDeleteName.Visible = false;
  335. this.buttonSave.Visible = true;
  336. this.buttonExport.Location = new System.Drawing.Point(379, 23);
  337. this.buttonImport.Location = new System.Drawing.Point(461, 23);
  338. this.buttonSave.Location = new System.Drawing.Point(542, 23);
  339. break;
  340. case 3:
  341. this.buttonCreateName.Visible = false;
  342. this.buttonEditName.Visible = false;
  343. this.buttonDeleteName.Visible = false;
  344. this.buttonSave.Visible = true;
  345. this.buttonExport.Location = new System.Drawing.Point(379, 23);
  346. this.buttonImport.Location = new System.Drawing.Point(461, 23);
  347. this.buttonSave.Location = new System.Drawing.Point(542, 23);
  348. break;
  349. }
  350. }
  351. /// <summary>
  352. /// 保存
  353. /// </summary>
  354. /// <param name="sender"></param>
  355. /// <param name="e"></param>
  356. private void buttonSaveClick(object sender, EventArgs e)
  357. {
  358. switch (currentInedx)
  359. {
  360. case 1: //1工具栏
  361. this.topTools.SaveToolbar();
  362. break;
  363. case 2: //2快捷键
  364. this.Close();
  365. //SaveShortcutKeys()???
  366. break;
  367. case 3: //3快捷栏
  368. this.fastTools.SaveToolbar();
  369. break;
  370. }
  371. //this.Close();
  372. }
  373. /// <summary>
  374. /// 删除
  375. /// </summary>
  376. /// <param name="sender"></param>
  377. /// <param name="e"></param>
  378. private void buttonDeleteNameClick(object sender, EventArgs e)
  379. {
  380. if(currentInedx==1) //1工具栏
  381. {
  382. if (MessageBox.Show(PdnResources.GetString("Menu.Areyousuretodelete.Text")+"?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.OK)
  383. {
  384. this.topTools.TreeView2Delete();
  385. }
  386. }
  387. }
  388. /// <summary>
  389. /// 重命名
  390. /// </summary>
  391. /// <param name="sender"></param>
  392. /// <param name="e"></param>
  393. private void buttonEditNameClick(object sender, EventArgs e)
  394. {
  395. if(this.topTools.treeViewLeft.SelectedNode!=null)
  396. {
  397. istoCreate = false;
  398. createNameDialog = new CreateNameDialog(this);
  399. createNameDialog.SetThisText(PdnResources.GetString("Menu.tool.Generateshortcut.Edittoolbar.text"));
  400. createNameDialog.SetTextBoxValue(this.topTools.GetSelectedNodeText());
  401. createNameDialog.StartPosition = FormStartPosition.CenterParent;
  402. createNameDialog.ShowDialog();
  403. }
  404. else
  405. {
  406. MessageBox.Show(PdnResources.GetString("Menu.leaseselectthetoolbarnode.Text"));
  407. }
  408. }
  409. /// <summary>
  410. /// 新建
  411. /// </summary>
  412. /// <param name="sender"></param>
  413. /// <param name="e"></param>
  414. private void buttonCreateNameClick(object sender, EventArgs e)
  415. {
  416. istoCreate = true;
  417. createNameDialog = new CreateNameDialog(this);
  418. createNameDialog.SetThisText(PdnResources.GetString("Menu.tool.Generateshortcut.Newtoolbar.text"));
  419. createNameDialog.StartPosition = FormStartPosition.CenterParent;
  420. createNameDialog.ShowDialog();
  421. }
  422. /// <summary>
  423. /// 导入配置
  424. /// </summary>
  425. /// <param name="sender"></param>
  426. /// <param name="e"></param>
  427. private void buttonImportClick(object sender, EventArgs e)
  428. {
  429. switch (currentInedx)
  430. {
  431. case 1: //1工具栏
  432. this.topTools.ImportToolbarXml();
  433. break;
  434. case 2: //2快捷键
  435. this.shortKeys.ImportToolbarXml();
  436. break;
  437. case 3: //3快捷栏
  438. this.fastTools.ImportToolbarXml();
  439. break;
  440. }
  441. }
  442. /// <summary>
  443. /// 导出配置
  444. /// </summary>
  445. /// <param name="sender"></param>
  446. /// <param name="e"></param>
  447. private void buttonExportClick(object sender, EventArgs e)
  448. {
  449. switch (currentInedx)
  450. {
  451. case 1: //1工具栏
  452. this.topTools.ExportToolbarXml();
  453. break;
  454. case 2: //2快捷键
  455. this.shortKeys.ExportToolbarXml();
  456. break;
  457. case 3: //3快捷栏
  458. this.fastTools.ExportToolbarXml();
  459. break;
  460. }
  461. }
  462. /// <summary>
  463. /// 获取新建窗口里面输入的名称
  464. /// </summary>
  465. /// <param name="name"></param>
  466. public override void GetCreateName(string name)
  467. {
  468. if (!name.Equals(""))
  469. {
  470. if (istoCreate) //新增
  471. {
  472. this.topTools.CreateTreeView2Node(name);
  473. }
  474. else //重命名
  475. {
  476. this.topTools.ReNameTreeView2Node(name);
  477. }
  478. createNameDialog.Close();
  479. }
  480. else
  481. {
  482. MessageBox.Show(PdnResources.GetString("Menu.leaseenterworkflowname.Text"));
  483. }
  484. }
  485. /// <summary>
  486. /// 重命名按钮的可用状态
  487. /// </summary>
  488. /// <param name="canuse"></param>
  489. public void RenameButtonStatus(bool canuse)
  490. {
  491. this.buttonEditName.Enabled = canuse;
  492. }
  493. /// <summary>
  494. /// 删除按钮的可用状态
  495. /// </summary>
  496. /// <param name="canuse"></param>
  497. public void DeleteButtonStatus(bool canuse)
  498. {
  499. this.buttonDeleteName.Enabled = canuse;
  500. }
  501. }
  502. }