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

Telnet服务器

开发平台:

C#

  1. /*
  2. * Copyright (c) 2005 Poderosa Project, All Rights Reserved.
  3. * $Id: ModuleProperty.cs,v 1.2 2005/04/20 08:45:45 okajima Exp $
  4. */
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Collections;
  9. using System.ComponentModel;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. using Poderosa.MacroEnv;
  13. namespace Poderosa.Forms
  14. {
  15. /// <summary>
  16. /// ModuleProperty 偺奣梫偺愢柧偱偡丅
  17. /// </summary>
  18. internal class ModuleProperty : System.Windows.Forms.Form
  19. {
  20. private System.Windows.Forms.Label _titleLabel;
  21. private TextBox _title;
  22. private System.Windows.Forms.Label _pathLabel;
  23. private TextBox _path;
  24. private System.Windows.Forms.Button _selectFileButton;
  25. private System.Windows.Forms.Label _additionalAssemblyLabel;
  26. private TextBox _additionalAssembly;
  27. private System.Windows.Forms.Label _shortcutLabel;
  28. private HotKey _shortcut;
  29. private System.Windows.Forms.CheckBox _debugOption;
  30. private System.Windows.Forms.Button _okButton;
  31. private System.Windows.Forms.Button _cancelButton;
  32. //曇廤懳徾偺MacroModule 怴婯嶌惉帪偼null
  33. private MacroList _parent;
  34. private MacroModule _module;
  35. private Keys _prevShortCut;
  36. public MacroModule Module {
  37. get {
  38. return _module;
  39. }
  40. }
  41. public Keys ShortCut {
  42. get {
  43. return _shortcut.Key;
  44. }
  45. }
  46. /// <summary>
  47. /// 昁梫側僨僓僀僫曄悢偱偡丅
  48. /// </summary>
  49. private System.ComponentModel.Container components = null;
  50. public ModuleProperty(MacroList p, MacroModule mod, Keys shortcut) {
  51. _parent = p;
  52. _prevShortCut = shortcut;
  53. _module = mod==null? new MacroModule(0) : (MacroModule)mod.Clone();
  54. //
  55. // Windows 僼僅乕儉 僨僓僀僫 僒億乕僩偵昁梫偱偡丅
  56. //
  57. InitializeComponent();
  58. this._titleLabel.Text = GApp.Strings.GetString("Form.ModuleProperty._titleLabel");
  59. this._pathLabel.Text = GApp.Strings.GetString("Form.ModuleProperty._pathLabel");
  60. this._additionalAssemblyLabel.Text = GApp.Strings.GetString("Form.ModuleProperty._additionalAssemblyLabel");
  61. this._shortcutLabel.Text = GApp.Strings.GetString("Form.ModuleProperty._shortcutLabel");
  62. this._debugOption.Text = GApp.Strings.GetString("Form.ModuleProperty._debugOption");
  63. this._okButton.Text = GApp.Strings.GetString("Common.OK");
  64. this._cancelButton.Text = GApp.Strings.GetString("Common.Cancel");
  65. this.Text = GApp.Strings.GetString("Form.ModuleProperty.Text");
  66. if(mod!=null) {
  67. _title.Text = _module.Title;
  68. _path.Text = _module.Path;
  69. _additionalAssembly.Text = Concat(_module.AdditionalAssemblies);
  70. _debugOption.Checked = _module.DebugMode;
  71. _shortcut.Key = shortcut;
  72. }
  73. }
  74. /// <summary>
  75. /// 巊梡偝傟偰偄傞儕僜乕僗偵屻張棟傪幚峴偟傑偡丅
  76. /// </summary>
  77. protected override void Dispose( bool disposing )
  78. {
  79. if( disposing )
  80. {
  81. if(components != null)
  82. {
  83. components.Dispose();
  84. }
  85. }
  86. base.Dispose( disposing );
  87. }
  88. #region Windows Form Designer generated code
  89. /// <summary>
  90. /// 僨僓僀僫 僒億乕僩偵昁梫側儊僜僢僪偱偡丅偙偺儊僜僢僪偺撪梕傪
  91. /// 僐乕僪 僄僨傿僞偱曄峏偟側偄偱偔偩偝偄丅
  92. /// </summary>
  93. private void InitializeComponent()
  94. {
  95. this._titleLabel = new System.Windows.Forms.Label();
  96. this._title = new TextBox();
  97. this._pathLabel = new System.Windows.Forms.Label();
  98. this._path = new TextBox();
  99. this._selectFileButton = new System.Windows.Forms.Button();
  100. this._additionalAssemblyLabel = new System.Windows.Forms.Label();
  101. this._additionalAssembly = new TextBox();
  102. this._shortcutLabel = new System.Windows.Forms.Label();
  103. this._shortcut = new Poderosa.Forms.HotKey();
  104. this._debugOption = new System.Windows.Forms.CheckBox();
  105. this._okButton = new System.Windows.Forms.Button();
  106. this._cancelButton = new System.Windows.Forms.Button();
  107. this.SuspendLayout();
  108. // 
  109. // _titleLabel
  110. // 
  111. this._titleLabel.Location = new System.Drawing.Point(8, 8);
  112. this._titleLabel.Name = "_titleLabel";
  113. this._titleLabel.TabIndex = 0;
  114. this._titleLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  115. // 
  116. // _title
  117. // 
  118. this._title.Location = new System.Drawing.Point(120, 8);
  119. this._title.Name = "_title";
  120. this._title.Size = new System.Drawing.Size(200, 19);
  121. this._title.TabIndex = 1;
  122. this._title.Text = "";
  123. // 
  124. // _pathLabel
  125. // 
  126. this._pathLabel.Location = new System.Drawing.Point(8, 32);
  127. this._pathLabel.Name = "_pathLabel";
  128. this._pathLabel.TabIndex = 2;
  129. this._pathLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  130. // 
  131. // _path
  132. // 
  133. this._path.Location = new System.Drawing.Point(120, 32);
  134. this._path.Name = "_path";
  135. this._path.Size = new System.Drawing.Size(181, 19);
  136. this._path.TabIndex = 3;
  137. this._path.Text = "";
  138. // 
  139. // _selectFileButton
  140. // 
  141. this._selectFileButton.Location = new System.Drawing.Point(301, 32);
  142. this._selectFileButton.Name = "_selectFileButton";
  143. this._selectFileButton.FlatStyle = FlatStyle.System;
  144. this._selectFileButton.Size = new System.Drawing.Size(19, 19);
  145. this._selectFileButton.TabIndex = 4;
  146. this._selectFileButton.Text = "...";
  147. this._selectFileButton.Click += new System.EventHandler(this.OnSelectFile);
  148. // 
  149. // _additionalAssemblyLabel
  150. // 
  151. this._additionalAssemblyLabel.Location = new System.Drawing.Point(8, 56);
  152. this._additionalAssemblyLabel.Name = "_additionalAssemblyLabel";
  153. this._additionalAssemblyLabel.Size = new System.Drawing.Size(100, 32);
  154. this._additionalAssemblyLabel.TabIndex = 5;
  155. this._additionalAssemblyLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  156. // 
  157. // _additionalAssembly
  158. // 
  159. this._additionalAssembly.Location = new System.Drawing.Point(120, 64);
  160. this._additionalAssembly.Name = "_additionalAssembly";
  161. this._additionalAssembly.Size = new System.Drawing.Size(200, 19);
  162. this._additionalAssembly.TabIndex = 6;
  163. this._additionalAssembly.Text = "";
  164. // 
  165. // _shortcutLabel
  166. // 
  167. this._shortcutLabel.Location = new System.Drawing.Point(8, 88);
  168. this._shortcutLabel.Name = "_shortcutLabel";
  169. this._shortcutLabel.TabIndex = 7;
  170. this._shortcutLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  171. // 
  172. // _shortcut
  173. // 
  174. this._shortcut.DebugTextBox = null;
  175. this._shortcut.ImeMode = System.Windows.Forms.ImeMode.Disable;
  176. this._shortcut.Key = System.Windows.Forms.Keys.None;
  177. this._shortcut.Location = new System.Drawing.Point(120, 88);
  178. this._shortcut.Name = "_shortcut";
  179. this._shortcut.Size = new System.Drawing.Size(80, 19);
  180. this._shortcut.TabIndex = 8;
  181. this._shortcut.Text = "";
  182. // 
  183. // _debugOption
  184. // 
  185. this._debugOption.Location = new System.Drawing.Point(8, 112);
  186. this._debugOption.Name = "_debugOption";
  187. this._debugOption.FlatStyle = FlatStyle.System;
  188. this._debugOption.Size = new System.Drawing.Size(296, 24);
  189. this._debugOption.TabIndex = 9;
  190. // 
  191. // _okButton
  192. // 
  193. this._okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
  194. this._okButton.Location = new System.Drawing.Point(168, 136);
  195. this._okButton.Name = "_okButton";
  196. this._okButton.FlatStyle = FlatStyle.System;
  197. this._okButton.TabIndex = 10;
  198. this._okButton.Click += new System.EventHandler(this.OnOK);
  199. // 
  200. // _cancelButton
  201. // 
  202. this._cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  203. this._cancelButton.Location = new System.Drawing.Point(248, 136);
  204. this._cancelButton.Name = "_cancelButton";
  205. this._cancelButton.FlatStyle = FlatStyle.System;
  206. this._cancelButton.TabIndex = 11;
  207. // 
  208. // ModuleProperty
  209. // 
  210. this.AcceptButton = this._okButton;
  211. this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
  212. this.CancelButton = this._cancelButton;
  213. this.ClientSize = new System.Drawing.Size(330, 167);
  214. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  215.   this._titleLabel,
  216.   this._title,
  217.   this._pathLabel,
  218.   this._path,
  219.   this._selectFileButton,
  220.   this._additionalAssemblyLabel,
  221.   this._additionalAssembly,
  222.   this._shortcutLabel,
  223.   this._shortcut,
  224.   this._debugOption,
  225.   this._cancelButton,
  226.   this._okButton});
  227. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  228. this.MaximizeBox = false;
  229. this.MinimizeBox = false;
  230. this.Name = "ModuleProperty";
  231. this.ShowInTaskbar = false;
  232. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  233. this.ResumeLayout(false);
  234. }
  235. #endregion
  236. private void OnSelectFile(object sender, EventArgs args) {
  237. OpenFileDialog dlg = new OpenFileDialog();
  238. dlg.CheckFileExists = true;
  239. dlg.Multiselect = false;
  240. dlg.InitialDirectory = GApp.Options.DefaultFileDir;
  241. dlg.Title = GApp.Strings.GetString("Caption.ModuleProperty.SelectMacroFile");
  242. dlg.Filter = "JScript.NET Files(*.js)|*.js|.NET Executables(*.exe;*.dll)|*.exe;*.dll";
  243. if(GCUtil.ShowModalDialog(this, dlg)==DialogResult.OK) {
  244. GApp.Options.DefaultFileDir = GUtil.FileToDir(dlg.FileName);
  245. _path.Text = dlg.FileName;
  246. if(_title.Text.Length==0)
  247. _title.Text = System.IO.Path.GetFileName(dlg.FileName); //僼傽僀儖柤杮懱傪僨僼僅儖僩偺僞僀僩儖偵偡傞
  248. }
  249. }
  250. private void OnOK(object sender, EventArgs args) {
  251. this.DialogResult = DialogResult.None;
  252. if(!File.Exists(_path.Text)) {
  253. GUtil.Warning(this, String.Format(GApp.Strings.GetString("Message.ModuleProperty.FileNotExist"), _path.Text));
  254. }
  255. else if(_title.Text.Length>30)
  256. GUtil.Warning(this, GApp.Strings.GetString("Message.ModuleProperty.TooLongTitle"));
  257. else {
  258. if(_shortcut.Key!=_prevShortCut) {
  259. string n = _parent.FindCommandDescription(_shortcut.Key);
  260. if(n!=null) {
  261. GUtil.Warning(this, String.Format(GApp.Strings.GetString("Message.ModuleProperty.DuplicatedKey"), n));
  262. return;
  263. }
  264. }
  265. _module.Title = _title.Text;
  266. _module.Path = _path.Text;
  267. _module.DebugMode = _debugOption.Checked;
  268. _module.AdditionalAssemblies = ParseAdditionalAssemblies(_additionalAssembly.Text);
  269. this.DialogResult = DialogResult.OK;
  270. }
  271. }
  272. private string Concat(string[] v) {
  273. if(v==null) return "";
  274. StringBuilder b = new StringBuilder();
  275. foreach(string t in v) {
  276. if(b.Length>0) b.Append(';');
  277. b.Append(t);
  278. }
  279. return b.ToString();
  280. }
  281. private string[] ParseAdditionalAssemblies(string t) {
  282. string[] l = t.Split(new char[] { ';',',' });
  283. return l;
  284. }
  285. }
  286. }