CommandOptionPanel.cs
上传用户:szltgg
上传日期:2019-05-16
资源大小:604k
文件大小:12k
源码类别:

Telnet服务器

开发平台:

C#

  1. /*
  2. * Copyright (c) 2005 Poderosa Project, All Rights Reserved.
  3. * $Id: CommandOptionPanel.cs,v 1.2 2005/04/20 08:45:44 okajima Exp $
  4. */
  5. using System;
  6. using System.Windows.Forms;
  7. using System.Diagnostics;
  8. using System.Collections;
  9. using Poderosa.Toolkit;
  10. using Poderosa.Config;
  11. using Poderosa.UI;
  12. namespace Poderosa.Forms
  13. {
  14. internal class CommandOptionPanel : OptionDialog.CategoryPanel
  15. {
  16. private Commands _commands;
  17. private System.Windows.Forms.ListView _keyConfigList;
  18. private System.Windows.Forms.ColumnHeader _commandCategoryHeader;
  19. private System.Windows.Forms.ColumnHeader _commandNameHeader;
  20. private System.Windows.Forms.ColumnHeader _commandConfigHeader;
  21. private System.Windows.Forms.Button _resetKeyConfigButton;
  22. private System.Windows.Forms.Button _clearKeyConfigButton;
  23. private System.Windows.Forms.GroupBox _commandConfigGroup;
  24. private System.Windows.Forms.Label _commandNameLabel;
  25. private System.Windows.Forms.Label _commandName;
  26. private System.Windows.Forms.Label _currentConfigLabel;
  27. private System.Windows.Forms.Label _currentCommand;
  28. private System.Windows.Forms.Label _newAllocationLabel;
  29. private HotKey _hotKey;
  30. private System.Windows.Forms.Button _allocateKeyButton;
  31. public CommandOptionPanel()
  32. {
  33. InitializeComponent();
  34. FillText();
  35. }
  36. private void InitializeComponent() {
  37. this._keyConfigList = new System.Windows.Forms.ListView();
  38. this._commandCategoryHeader = new System.Windows.Forms.ColumnHeader();
  39. this._commandNameHeader = new System.Windows.Forms.ColumnHeader();
  40. this._commandConfigHeader = new System.Windows.Forms.ColumnHeader();
  41. this._resetKeyConfigButton = new System.Windows.Forms.Button();
  42. this._clearKeyConfigButton = new System.Windows.Forms.Button();
  43. this._commandConfigGroup = new System.Windows.Forms.GroupBox();
  44. this._commandNameLabel = new System.Windows.Forms.Label();
  45. this._commandName = new System.Windows.Forms.Label();
  46. this._currentConfigLabel = new System.Windows.Forms.Label();
  47. this._currentCommand = new System.Windows.Forms.Label();
  48. this._hotKey = new Poderosa.Forms.HotKey();
  49. this._newAllocationLabel = new System.Windows.Forms.Label();
  50. this._allocateKeyButton = new System.Windows.Forms.Button();
  51. this._commandConfigGroup.SuspendLayout();
  52. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  53.    this._keyConfigList,
  54.    this._resetKeyConfigButton,
  55.    this._clearKeyConfigButton,
  56.    this._commandConfigGroup});
  57. // 
  58. // _keyConfigList
  59. // 
  60. this._keyConfigList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
  61.  this._commandCategoryHeader,
  62.  this._commandNameHeader,
  63.  this._commandConfigHeader});
  64. this._keyConfigList.FullRowSelect = true;
  65. this._keyConfigList.GridLines = true;
  66. this._keyConfigList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
  67. this._keyConfigList.MultiSelect = false;
  68. this._keyConfigList.Name = "_keyConfigList";
  69. this._keyConfigList.Size = new System.Drawing.Size(432, 172);
  70. this._keyConfigList.TabIndex = 0;
  71. this._keyConfigList.View = System.Windows.Forms.View.Details;
  72. this._keyConfigList.SelectedIndexChanged += new System.EventHandler(this.OnKeyMapItemActivated);
  73. // 
  74. // _commandCategoryHeader
  75. // 
  76. this._commandCategoryHeader.Width = 80;
  77. // 
  78. // _commandNameHeader
  79. // 
  80. this._commandNameHeader.Width = 188;
  81. // 
  82. // _commandConfigHeader
  83. // 
  84. this._commandConfigHeader.Width = 136;
  85. // 
  86. // _resetKeyConfigButton
  87. // 
  88. this._resetKeyConfigButton.Location = new System.Drawing.Point(216, 172);
  89. this._resetKeyConfigButton.Name = "_resetKeyConfigButton";
  90. this._resetKeyConfigButton.FlatStyle = FlatStyle.System;
  91. this._resetKeyConfigButton.Size = new System.Drawing.Size(104, 23);
  92. this._resetKeyConfigButton.TabIndex = 1;
  93. this._resetKeyConfigButton.Click += new System.EventHandler(this.OnResetKeyConfig);
  94. // 
  95. // _clearKeyConfigButton
  96. // 
  97. this._clearKeyConfigButton.Location = new System.Drawing.Point(336, 172);
  98. this._clearKeyConfigButton.Name = "_clearKeyConfigButton";
  99. this._clearKeyConfigButton.FlatStyle = FlatStyle.System;
  100. this._clearKeyConfigButton.Size = new System.Drawing.Size(88, 23);
  101. this._clearKeyConfigButton.TabIndex = 2;
  102. this._clearKeyConfigButton.Click += new System.EventHandler(this.OnClearKeyConfig);
  103. // 
  104. // _commandConfigGroup
  105. // 
  106. this._commandConfigGroup.Controls.AddRange(new System.Windows.Forms.Control[] {
  107.   this._commandNameLabel,
  108.   this._commandName,
  109.   this._currentConfigLabel,
  110.   this._currentCommand,
  111.   this._hotKey,
  112.   this._newAllocationLabel,
  113.   this._allocateKeyButton});
  114. this._commandConfigGroup.Location = new System.Drawing.Point(8, 196);
  115. this._commandConfigGroup.Name = "_commandConfigGroup";
  116. this._commandConfigGroup.FlatStyle = FlatStyle.System;
  117. this._commandConfigGroup.Size = new System.Drawing.Size(416, 96);
  118. this._commandConfigGroup.TabIndex = 3;
  119. this._commandConfigGroup.TabStop = false;
  120. // 
  121. // _commandNameLabel
  122. // 
  123. this._commandNameLabel.Location = new System.Drawing.Point(8, 16);
  124. this._commandNameLabel.Name = "_commandNameLabel";
  125. this._commandNameLabel.Size = new System.Drawing.Size(88, 23);
  126. this._commandNameLabel.TabIndex = 4;
  127. this._commandNameLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  128. // 
  129. // _commandName
  130. // 
  131. this._commandName.Location = new System.Drawing.Point(112, 16);
  132. this._commandName.Name = "_commandName";
  133. this._commandName.Size = new System.Drawing.Size(248, 23);
  134. this._commandName.TabIndex = 5;
  135. this._commandName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  136. // 
  137. // _currentConfigLabel
  138. // 
  139. this._currentConfigLabel.Location = new System.Drawing.Point(8, 40);
  140. this._currentConfigLabel.Name = "_currentConfigLabel";
  141. this._currentConfigLabel.Size = new System.Drawing.Size(88, 23);
  142. this._currentConfigLabel.TabIndex = 6;
  143. this._currentConfigLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  144. // 
  145. // _currentCommand
  146. // 
  147. this._currentCommand.Location = new System.Drawing.Point(112, 40);
  148. this._currentCommand.Name = "_currentCommand";
  149. this._currentCommand.Size = new System.Drawing.Size(248, 23);
  150. this._currentCommand.TabIndex = 7;
  151. this._currentCommand.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  152. // 
  153. // _hotKey
  154. // 
  155. this._hotKey.DebugTextBox = null;
  156. this._hotKey.ImeMode = System.Windows.Forms.ImeMode.Disable;
  157. this._hotKey.Key = System.Windows.Forms.Keys.None;
  158. this._hotKey.Location = new System.Drawing.Point(112, 64);
  159. this._hotKey.Name = "_hotKey";
  160. this._hotKey.Size = new System.Drawing.Size(168, 19);
  161. this._hotKey.TabIndex = 8;
  162. this._hotKey.Text = "";
  163. // 
  164. // _newAllocationLabel
  165. // 
  166. this._newAllocationLabel.Location = new System.Drawing.Point(8, 64);
  167. this._newAllocationLabel.Name = "_newAllocationLabel";
  168. this._newAllocationLabel.Size = new System.Drawing.Size(88, 23);
  169. this._newAllocationLabel.TabIndex = 9;
  170. this._newAllocationLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  171. // 
  172. // _allocateKeyButton
  173. // 
  174. this._allocateKeyButton.Enabled = false;
  175. this._allocateKeyButton.Location = new System.Drawing.Point(288, 64);
  176. this._allocateKeyButton.Name = "_allocateKeyButton";
  177. this._allocateKeyButton.FlatStyle = FlatStyle.System;
  178. this._allocateKeyButton.Size = new System.Drawing.Size(75, 24);
  179. this._allocateKeyButton.TabIndex = 10;
  180. this._allocateKeyButton.Click += new System.EventHandler(this.OnAllocateKey);
  181. this.BackColor = ThemeUtil.TabPaneBackColor;
  182. this._commandConfigGroup.ResumeLayout();
  183. }
  184. private void FillText() {
  185. this._commandCategoryHeader.Text = GApp.Strings.GetString("Form.OptionDialog._commandCategoryHeader");
  186. this._commandNameHeader.Text = GApp.Strings.GetString("Form.OptionDialog._commandNameHeader");
  187. this._commandConfigHeader.Text = GApp.Strings.GetString("Form.OptionDialog._commandConfigHeader");
  188. this._resetKeyConfigButton.Text = GApp.Strings.GetString("Form.OptionDialog._resetKeyConfigButton");
  189. this._clearKeyConfigButton.Text = GApp.Strings.GetString("Form.OptionDialog._clearKeyConfigButton");
  190. this._commandConfigGroup.Text = GApp.Strings.GetString("Form.OptionDialog._commandConfigGroup");
  191. this._commandNameLabel.Text = GApp.Strings.GetString("Form.OptionDialog._commandNameLabel");
  192. this._currentConfigLabel.Text = GApp.Strings.GetString("Form.OptionDialog._currentConfigLabel");
  193. this._newAllocationLabel.Text = GApp.Strings.GetString("Form.OptionDialog._newAllocationLabel");
  194. this._allocateKeyButton.Text = GApp.Strings.GetString("Form.OptionDialog._allocateKeyButton");
  195. }
  196. public override void InitUI(ContainerOptions options) {
  197. _commands = (Commands)options.Commands.Clone();
  198. InitKeyConfigUI();
  199. }
  200. public override bool Commit(ContainerOptions options) {
  201. options.Commands = _commands;
  202. return true;
  203. }
  204. private void InitKeyConfigUI() {
  205. _keyConfigList.Items.Clear();
  206. IEnumerator ie = _commands.EnumEntries();
  207. while(ie.MoveNext()) {
  208. Commands.Entry e = (Commands.Entry)ie.Current;
  209. if(e.Category==Commands.Category.Fixed) continue;
  210. ListViewItem li = new ListViewItem(EnumDescAttribute.For(typeof(Commands.Category)).GetDescription(e.Category));
  211. li = _keyConfigList.Items.Add(li);
  212. li.SubItems.Add(e.Description);
  213. li.SubItems.Add(e.KeyDisplayString);
  214. li.Tag = e.CID;
  215. }
  216. }
  217. private void OnKeyMapItemActivated(object sender, EventArgs args) {
  218. if(_keyConfigList.SelectedItems.Count==0) return;
  219. CID id = (CID)_keyConfigList.SelectedItems[0].Tag;
  220. Commands.Entry e = _commands.FindEntry(id);
  221. Debug.Assert(e!=null);
  222. _hotKey.Key = e.Modifiers|e.Key;
  223. _commandName.Text = String.Format("{0} - {1}", EnumDescAttribute.For(typeof(Commands.Category)).GetDescription(e.Category), e.Description);
  224. _currentCommand.Text = e.KeyDisplayString;
  225. _allocateKeyButton.Enabled = true;
  226. }
  227. private void OnAllocateKey(object sender, EventArgs args) {
  228. if(_keyConfigList.SelectedItems.Count==0) return;
  229. CID id = (CID)_keyConfigList.SelectedItems[0].Tag;
  230. Keys key = _hotKey.Key;
  231. int code = GUtil.KeyToControlCode(key);
  232. if(code!=-1) {
  233. if(GUtil.AskUserYesNo(this, String.Format(GApp.Strings.GetString("Message.OptionDialog.AskOverwriteToASCIIInput"), _hotKey.Text, code))==DialogResult.No)
  234. return;
  235. }
  236. Commands.Entry existing = _commands.FindEntry(key);
  237. if(existing!=null && existing.CID!=id) {
  238. if(GUtil.AskUserYesNo(this, String.Format(GApp.Strings.GetString("Message.OptionDialog.AskOverwriteCommand"), existing.Description))==DialogResult.No)
  239. return;
  240. existing.Key = Keys.None;
  241. existing.Modifiers = Keys.None;
  242. FindListViewItem(existing.CID).SubItems[2].Text = "";
  243. }
  244. //愝掕傪彂偒姺偊
  245. Commands.Entry e = _commands.FindEntry(id);
  246. Debug.Assert(e!=null);
  247. _commands.ModifyKey(e.CID, key & Keys.Modifiers, key & Keys.KeyCode);
  248. _keyConfigList.SelectedItems[0].SubItems[2].Text = e.KeyDisplayString;
  249. }
  250. private void OnResetKeyConfig(object sender, EventArgs args) {
  251. _commands.Init();
  252. InitKeyConfigUI();
  253. }
  254. private void OnClearKeyConfig(object sender, EventArgs args) {
  255. _commands.ClearKeyBinds();
  256. InitKeyConfigUI();
  257. }
  258. private ListViewItem FindListViewItem(CID id) {
  259. foreach(ListViewItem li in _keyConfigList.Items) {
  260. if(li.Tag.Equals(id)) return li;
  261. }
  262. return null;
  263. }
  264. }
  265. }