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

Telnet服务器

开发平台:

C#

  1. /*
  2. * Copyright (c) 2005 Poderosa Project, All Rights Reserved.
  3. * $Id: ChangeLogDialog.cs,v 1.2 2005/04/20 08:45:44 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.Windows.Forms;
  11. using Poderosa;
  12. using EnumDescAttributeT = Poderosa.Toolkit.EnumDescAttribute;
  13. using Poderosa.Communication;
  14. using Poderosa.ConnectionParam;
  15. using Poderosa.Terminal;
  16. namespace Poderosa.Forms
  17. {
  18. /// <summary>
  19. /// ChangeLogDialog 偺奣梫偺愢柧偱偡丅
  20. /// </summary>
  21. internal class ChangeLogDialog : System.Windows.Forms.Form
  22. {
  23. private TerminalConnection _connection;
  24. private ComboBox _logTypeBox;
  25. private System.Windows.Forms.Label _logTypeLabel;
  26. private ComboBox _fileNameBox;
  27. private System.Windows.Forms.Label _fileNameLabel;
  28. private Button _selectlogButton;
  29. private System.Windows.Forms.Button _cancelButton;
  30. private System.Windows.Forms.Button _okButton;
  31. /// <summary>
  32. /// 昁梫側僨僓僀僫曄悢偱偡丅
  33. /// </summary>
  34. private System.ComponentModel.Container components = null;
  35. public ChangeLogDialog(TerminalConnection current)
  36. {
  37. //
  38. // Windows 僼僅乕儉 僨僓僀僫 僒億乕僩偵昁梫偱偡丅
  39. //
  40. InitializeComponent();
  41. this._logTypeLabel.Text = GApp.Strings.GetString("Form.ChangeLog._logTypeLabel");
  42. this._fileNameLabel.Text = GApp.Strings.GetString("Form.ChangeLog._fileNameLabel");
  43. this._cancelButton.Text = GApp.Strings.GetString("Common.Cancel");
  44. this._okButton.Text = GApp.Strings.GetString("Common.OK");
  45. this.Text = GApp.Strings.GetString("Form.ChangeLog.Text");
  46. //
  47. // TODO: InitializeComponent 屇傃弌偟偺屻偵丄僐儞僗僩儔僋僞 僐乕僪傪捛壛偟偰偔偩偝偄丅
  48. //
  49. _connection = current;
  50. _logTypeBox.SelectedIndex = _logTypeBox.FindStringExact(EnumDescAttributeT.For(typeof(LogType)).GetDescription(_connection.LogType));
  51. if(_connection.LogType!=LogType.None) {
  52. _fileNameBox.Items.Add(_connection.LogPath);
  53. _fileNameBox.SelectedIndex = 0;
  54. }
  55. foreach(string p in GApp.ConnectionHistory.LogPaths)
  56. _fileNameBox.Items.Add(p);
  57. AdjustUI();
  58. }
  59. /// <summary>
  60. /// 巊梡偝傟偰偄傞儕僜乕僗偵屻張棟傪幚峴偟傑偡丅
  61. /// </summary>
  62. protected override void Dispose( bool disposing )
  63. {
  64. if( disposing )
  65. {
  66. if(components != null)
  67. {
  68. components.Dispose();
  69. }
  70. }
  71. base.Dispose( disposing );
  72. }
  73. #region Windows Form Designer generated code
  74. /// <summary>
  75. /// 僨僓僀僫 僒億乕僩偵昁梫側儊僜僢僪偱偡丅偙偺儊僜僢僪偺撪梕傪
  76. /// 僐乕僪 僄僨傿僞偱曄峏偟側偄偱偔偩偝偄丅
  77. /// 徚偊偪傖崲傞僐乕僪偺旔擄応強
  78. /// this._logTypeBox.Items.AddRange(EnumDescAttributeT.For(typeof(LogType)).DescriptionCollection());
  79. /// </summary>
  80. private void InitializeComponent()
  81. {
  82. this._logTypeBox = new ComboBox();
  83. this._logTypeLabel = new System.Windows.Forms.Label();
  84. this._fileNameBox = new ComboBox();
  85. this._fileNameLabel = new System.Windows.Forms.Label();
  86. this._selectlogButton = new Button();
  87. this._cancelButton = new System.Windows.Forms.Button();
  88. this._okButton = new System.Windows.Forms.Button();
  89. this.SuspendLayout();
  90. // 
  91. // _logTypeBox
  92. // 
  93. this._logTypeBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  94. this._logTypeBox.Location = new System.Drawing.Point(104, 8);
  95. this._logTypeBox.Name = "_logTypeBox";
  96. this._logTypeBox.Size = new System.Drawing.Size(96, 20);
  97. this._logTypeBox.TabIndex = 1;
  98. this._logTypeBox.SelectedIndexChanged += new System.EventHandler(this.OnLogTypeChanged);
  99. this._logTypeBox.Items.AddRange(EnumDescAttributeT.For(typeof(LogType)).DescriptionCollection());
  100. // 
  101. // _logTypeLabel
  102. // 
  103. this._logTypeLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  104. this._logTypeLabel.Location = new System.Drawing.Point(5, 8);
  105. this._logTypeLabel.Name = "_logTypeLabel";
  106. this._logTypeLabel.RightToLeft = System.Windows.Forms.RightToLeft.No;
  107. this._logTypeLabel.Size = new System.Drawing.Size(80, 16);
  108. this._logTypeLabel.TabIndex = 0;
  109. this._logTypeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  110. // 
  111. // _fileNameBox
  112. // 
  113. this._fileNameBox.Location = new System.Drawing.Point(104, 32);
  114. this._fileNameBox.Name = "_fileNameBox";
  115. this._fileNameBox.Size = new System.Drawing.Size(160, 20);
  116. this._fileNameBox.TabIndex = 3;
  117. // 
  118. // _fileNameLabel
  119. // 
  120. this._fileNameLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  121. this._fileNameLabel.Location = new System.Drawing.Point(5, 32);
  122. this._fileNameLabel.Name = "_fileNameLabel";
  123. this._fileNameLabel.RightToLeft = System.Windows.Forms.RightToLeft.No;
  124. this._fileNameLabel.Size = new System.Drawing.Size(88, 16);
  125. this._fileNameLabel.TabIndex = 2;
  126. this._fileNameLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  127. // 
  128. // _selectlogButton
  129. // 
  130. this._selectlogButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
  131. this._selectlogButton.ImageIndex = 0;
  132. this._selectlogButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  133. this._selectlogButton.Location = new System.Drawing.Point(269, 32);
  134. this._selectlogButton.Name = "_selectlogButton";
  135. this._selectlogButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
  136. this._selectlogButton.Size = new System.Drawing.Size(19, 19);
  137. this._selectlogButton.TabIndex = 4;
  138. this._selectlogButton.Text = "...";
  139. this._selectlogButton.Click += new System.EventHandler(this.OnSelectLogFile);
  140. // 
  141. // _cancelButton
  142. // 
  143. this._cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  144. this._cancelButton.ImageIndex = 0;
  145. this._cancelButton.FlatStyle = FlatStyle.System;
  146. this._cancelButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  147. this._cancelButton.Location = new System.Drawing.Point(216, 56);
  148. this._cancelButton.Name = "_cancelButton";
  149. this._cancelButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
  150. this._cancelButton.Size = new System.Drawing.Size(72, 25);
  151. this._cancelButton.TabIndex = 6;
  152. // 
  153. // _okButton
  154. // 
  155. this._okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
  156. this._okButton.ImageIndex = 0;
  157. this._okButton.FlatStyle = FlatStyle.System;
  158. this._okButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  159. this._okButton.Location = new System.Drawing.Point(128, 56);
  160. this._okButton.Name = "_okButton";
  161. this._okButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
  162. this._okButton.Size = new System.Drawing.Size(72, 25);
  163. this._okButton.TabIndex = 5;
  164. this._okButton.Click += new System.EventHandler(this.OnOK);
  165. // 
  166. // ChangeLogDialog
  167. // 
  168. this.AcceptButton = this._okButton;
  169. this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
  170. this.CancelButton = this._cancelButton;
  171. this.ClientSize = new System.Drawing.Size(292, 85);
  172. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  173.   this._cancelButton,
  174.   this._okButton,
  175.   this._logTypeBox,
  176.   this._logTypeLabel,
  177.   this._fileNameBox,
  178.   this._fileNameLabel,
  179.   this._selectlogButton});
  180. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  181. this.MaximizeBox = false;
  182. this.MinimizeBox = false;
  183. this.Name = "ChangeLogDialog";
  184. this.ShowInTaskbar = false;
  185. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  186. this.ResumeLayout(false);
  187. }
  188. #endregion
  189. private void AdjustUI() {
  190. bool e = ((LogType)EnumDescAttributeT.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None)!=LogType.None);
  191. _fileNameBox.Enabled = e;
  192. _selectlogButton.Enabled = e;
  193. }
  194. private void OnLogTypeChanged(object sender, EventArgs args) {
  195. AdjustUI();
  196. }
  197. private void OnSelectLogFile(object sender, EventArgs args) {
  198. string fn = GCUtil.SelectLogFileByDialog(this);
  199. if(fn!=null) _fileNameBox.Text = fn;
  200. }
  201. private void OnOK(object sender, EventArgs args) {
  202. this.DialogResult = DialogResult.None;
  203. LogType t = (LogType)EnumDescAttributeT.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None);
  204. string path = null;
  205. bool append = false;
  206. if(t!=LogType.None) {
  207. path = _fileNameBox.Text;
  208. LogFileCheckResult r = GCUtil.CheckLogFileName(path, this);
  209. if(r==LogFileCheckResult.Cancel || r==LogFileCheckResult.Error) return;
  210. append = (r==LogFileCheckResult.Append);
  211. }
  212. _connection.ResetLog(t, path, append);
  213. this.DialogResult = DialogResult.OK;
  214. }
  215. }
  216. }