CustomInterfaceDialog.cs 20 KB

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