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

Telnet服务器

开发平台:

C#

  1. /*
  2. * Copyright (c) 2005 Poderosa Project, All Rights Reserved.
  3. * $Id: TerminalOptionPanel.cs,v 1.2 2005/04/20 08:45:45 okajima Exp $
  4. */
  5. using System;
  6. using System.Windows.Forms;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using System.Drawing;
  10. using Poderosa.Toolkit;
  11. using Poderosa.Config;
  12. using Poderosa.ConnectionParam;
  13. using Poderosa.UI;
  14. namespace Poderosa.Forms
  15. {
  16. internal class TerminalOptionPanel : OptionDialog.CategoryPanel {
  17. private System.Windows.Forms.Label _badCharLabel;
  18. private ComboBox _badCharBox;
  19. private System.Windows.Forms.Label _bufferSizeLabel;
  20. private TextBox _bufferSize;
  21. private Label _disconnectNotificationLabel;
  22. private ComboBox _disconnectNotification;
  23. private CheckBox _closeOnDisconnect;
  24. private CheckBox _beepOnBellChar;
  25. private CheckBox _adjustsTabTitleToWindowTitle;
  26. private CheckBox _allowsScrollInAppMode;
  27. private CheckBox _keepAliveCheck;
  28. private TextBox  _keepAliveIntervalBox;
  29. private Label    _keepAliveLabel;
  30. private System.Windows.Forms.GroupBox _defaultLogGroup;
  31. private CheckBox _autoLogCheckBox;
  32. private System.Windows.Forms.Label _defaultLogTypeLabel;
  33. private ComboBox _defaultLogTypeBox;
  34. private System.Windows.Forms.Label _defaultLogDirectoryLabel;
  35. private TextBox _defaultLogDirectory;
  36. private System.Windows.Forms.Button _dirSelect;
  37. public TerminalOptionPanel() {
  38. InitializeComponent();
  39. FillText();
  40. }
  41. private void InitializeComponent() {
  42. this._badCharLabel = new System.Windows.Forms.Label();
  43. this._badCharBox = new ComboBox();
  44. this._bufferSizeLabel = new System.Windows.Forms.Label();
  45. this._bufferSize = new TextBox();
  46. this._disconnectNotificationLabel = new System.Windows.Forms.Label();
  47. this._disconnectNotification = new ComboBox();
  48. this._closeOnDisconnect = new System.Windows.Forms.CheckBox();
  49. this._beepOnBellChar = new System.Windows.Forms.CheckBox();
  50. this._adjustsTabTitleToWindowTitle = new CheckBox();
  51. this._allowsScrollInAppMode = new CheckBox();
  52. this._keepAliveCheck = new CheckBox();
  53. this._keepAliveIntervalBox = new TextBox();
  54. this._keepAliveLabel = new Label();
  55. this._defaultLogGroup = new System.Windows.Forms.GroupBox();
  56. this._defaultLogTypeLabel = new System.Windows.Forms.Label();
  57. this._defaultLogTypeBox = new ComboBox();
  58. this._defaultLogDirectoryLabel = new System.Windows.Forms.Label();
  59. this._defaultLogDirectory = new TextBox();
  60. this._dirSelect = new System.Windows.Forms.Button();
  61. this._autoLogCheckBox = new System.Windows.Forms.CheckBox();
  62. this._defaultLogGroup.SuspendLayout();
  63. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  64.   this._badCharLabel,
  65.   this._badCharBox,
  66.   this._bufferSizeLabel,
  67.   this._bufferSize,
  68.   this._disconnectNotificationLabel,
  69.   this._disconnectNotification,
  70.   this._closeOnDisconnect,
  71.   this._beepOnBellChar,
  72.   this._adjustsTabTitleToWindowTitle,
  73.   this._allowsScrollInAppMode,
  74.   this._autoLogCheckBox,
  75.   this._keepAliveCheck,
  76.   this._keepAliveIntervalBox,
  77.   this._keepAliveLabel,
  78.   this._defaultLogGroup});
  79. // 
  80. // _badCharLabel
  81. // 
  82. this._badCharLabel.Location = new System.Drawing.Point(24, 8);
  83. this._badCharLabel.Name = "_badCharLabel";
  84. this._badCharLabel.Size = new System.Drawing.Size(160, 23);
  85. this._badCharLabel.TabIndex = 0;
  86. this._badCharLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  87. // 
  88. // _badCharBox
  89. // 
  90. this._badCharBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  91. this._badCharBox.Location = new System.Drawing.Point(200, 8);
  92. this._badCharBox.Name = "_badCharBox";
  93. this._badCharBox.Size = new System.Drawing.Size(152, 20);
  94. this._badCharBox.TabIndex = 1;
  95. // 
  96. // _bufferSizeLabel
  97. // 
  98. this._bufferSizeLabel.Location = new System.Drawing.Point(24, 32);
  99. this._bufferSizeLabel.Name = "_bufferSizeLabel";
  100. this._bufferSizeLabel.Size = new System.Drawing.Size(96, 23);
  101. this._bufferSizeLabel.TabIndex = 2;
  102. this._bufferSizeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  103. // 
  104. // _bufferSize
  105. // 
  106. this._bufferSize.Location = new System.Drawing.Point(200, 32);
  107. this._bufferSize.Name = "_bufferSize";
  108. this._bufferSize.Size = new System.Drawing.Size(72, 19);
  109. this._bufferSize.TabIndex = 3;
  110. this._bufferSize.TextAlign = HorizontalAlignment.Left;
  111. this._bufferSize.MaxLength = 4;
  112. this._bufferSize.Text = "";
  113. // 
  114. // _disconnectNotificationLabel
  115. // 
  116. this._disconnectNotificationLabel.Location = new System.Drawing.Point(24, 56);
  117. this._disconnectNotificationLabel.Name = "_disconnectNotificationLabel";
  118. this._disconnectNotificationLabel.Size = new System.Drawing.Size(160, 23);
  119. this._disconnectNotificationLabel.TabIndex = 4;
  120. this._disconnectNotificationLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  121. // 
  122. // _disconnectNotification
  123. // 
  124. this._disconnectNotification.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  125. this._disconnectNotification.Location = new System.Drawing.Point(200, 56);
  126. this._disconnectNotification.Name = "_disconnectNotification";
  127. this._disconnectNotification.Size = new System.Drawing.Size(152, 19);
  128. this._disconnectNotification.TabIndex = 5;
  129. // 
  130. // _closeOnDisconnect
  131. // 
  132. this._closeOnDisconnect.Location = new System.Drawing.Point(24, 80);
  133. this._closeOnDisconnect.Name = "_closeOnDisconnect";
  134. this._closeOnDisconnect.FlatStyle = FlatStyle.System;
  135. this._closeOnDisconnect.Size = new System.Drawing.Size(192, 20);
  136. this._closeOnDisconnect.TabIndex = 6;
  137. // 
  138. // _beepOnBellChar
  139. // 
  140. this._beepOnBellChar.Location = new System.Drawing.Point(24, 102);
  141. this._beepOnBellChar.Name = "_beepOnBellChar";
  142. this._beepOnBellChar.FlatStyle = FlatStyle.System;
  143. this._beepOnBellChar.Size = new System.Drawing.Size(288, 20);
  144. this._beepOnBellChar.TabIndex = 7;
  145. // 
  146. // _adjustsTabTitleToWindowTitle
  147. // 
  148. this._adjustsTabTitleToWindowTitle.Location = new System.Drawing.Point(24, 126);
  149. this._adjustsTabTitleToWindowTitle.Name = "_adjustsTabTitleToWindowTitle";
  150. this._adjustsTabTitleToWindowTitle.FlatStyle = FlatStyle.System;
  151. this._adjustsTabTitleToWindowTitle.Size = new System.Drawing.Size(336, 20);
  152. this._adjustsTabTitleToWindowTitle.TabIndex = 8;
  153. // 
  154. // _allowsScrollInAppMode
  155. // 
  156. this._allowsScrollInAppMode.Location = new System.Drawing.Point(24, 150);
  157. this._allowsScrollInAppMode.Name = "_allowsScrollInAppMode";
  158. this._allowsScrollInAppMode.FlatStyle = FlatStyle.System;
  159. this._allowsScrollInAppMode.Size = new System.Drawing.Size(288, 20);
  160. this._allowsScrollInAppMode.TabIndex = 9;
  161. // 
  162. // _keepAliveCheck
  163. // 
  164. this._keepAliveCheck.Location = new System.Drawing.Point(24, 176);
  165. this._keepAliveCheck.Name = "_keepAliveCheck";
  166. this._keepAliveCheck.FlatStyle = FlatStyle.System;
  167. this._keepAliveCheck.Size = new System.Drawing.Size(244, 20);
  168. this._keepAliveCheck.TabIndex = 10;
  169. this._keepAliveCheck.CheckedChanged += new EventHandler(OnKeepAliveCheckChanged);
  170. // 
  171. // _keepAliveIntervalBox
  172. // 
  173. this._keepAliveIntervalBox.Location = new System.Drawing.Point(276, 176);
  174. this._keepAliveIntervalBox.Name = "_keepAliveIntervalBox";
  175. this._keepAliveIntervalBox.Size = new System.Drawing.Size(40, 20);
  176. this._keepAliveIntervalBox.TabIndex = 11;
  177. this._keepAliveIntervalBox.MaxLength = 2;
  178. this._keepAliveIntervalBox.TextAlign = HorizontalAlignment.Right;
  179. // 
  180. // _keepAliveLabel
  181. // 
  182. this._keepAliveLabel.Location = new System.Drawing.Point(316, 176);
  183. this._keepAliveLabel.Name = "_keepAliveLabel";
  184. this._keepAliveLabel.Size = new System.Drawing.Size(50, 20);
  185. this._keepAliveLabel.TabIndex = 12;
  186. this._keepAliveLabel.TextAlign = ContentAlignment.MiddleLeft;
  187. // 
  188. // _defaultLogGroup
  189. // 
  190. this._defaultLogGroup.Controls.AddRange(new System.Windows.Forms.Control[] {
  191.    this._defaultLogTypeLabel,
  192.    this._defaultLogTypeBox,
  193.    this._defaultLogDirectoryLabel,
  194.    this._defaultLogDirectory,
  195.    this._dirSelect});
  196. this._defaultLogGroup.Location = new System.Drawing.Point(16, 204);
  197. this._defaultLogGroup.Name = "_defaultLogGroup";
  198. this._defaultLogGroup.FlatStyle = FlatStyle.System;
  199. this._defaultLogGroup.Size = new System.Drawing.Size(392, 76);
  200. this._defaultLogGroup.TabIndex = 14;
  201. this._defaultLogGroup.TabStop = false;
  202. // 
  203. // _defaultLogTypeLabel
  204. // 
  205. this._defaultLogTypeLabel.Location = new System.Drawing.Point(8, 20);
  206. this._defaultLogTypeLabel.Name = "_defaultLogTypeLabel";
  207. this._defaultLogTypeLabel.Size = new System.Drawing.Size(96, 23);
  208. this._defaultLogTypeLabel.TabIndex = 15;
  209. this._defaultLogTypeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  210. // 
  211. // _defaultLogTypeBox
  212. // 
  213. this._defaultLogTypeBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  214. this._defaultLogTypeBox.Location = new System.Drawing.Point(128, 20);
  215. this._defaultLogTypeBox.Name = "_defaultLogTypeBox";
  216. this._defaultLogTypeBox.Size = new System.Drawing.Size(104, 20);
  217. this._defaultLogTypeBox.TabIndex = 16;
  218. // 
  219. // _defaultLogDirectoryLabel
  220. // 
  221. this._defaultLogDirectoryLabel.Location = new System.Drawing.Point(8, 48);
  222. this._defaultLogDirectoryLabel.Name = "_defaultLogDirectoryLabel";
  223. this._defaultLogDirectoryLabel.Size = new System.Drawing.Size(112, 23);
  224. this._defaultLogDirectoryLabel.TabIndex = 17;
  225. this._defaultLogDirectoryLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  226. // 
  227. // _defaultLogDirectory
  228. // 
  229. this._defaultLogDirectory.Location = new System.Drawing.Point(128, 48);
  230. this._defaultLogDirectory.Name = "_defaultLogDirectory";
  231. this._defaultLogDirectory.Size = new System.Drawing.Size(176, 19);
  232. this._defaultLogDirectory.TabIndex = 18;
  233. this._defaultLogDirectory.Text = "";
  234. // 
  235. // _dirSelect
  236. // 
  237. this._dirSelect.Location = new System.Drawing.Point(312, 48);
  238. this._dirSelect.Name = "_dirSelect";
  239. this._dirSelect.FlatStyle = FlatStyle.System;
  240. this._dirSelect.Size = new System.Drawing.Size(19, 19);
  241. this._dirSelect.TabIndex = 19;
  242. this._dirSelect.Text = "...";
  243. this._dirSelect.Click += new System.EventHandler(this.OnSelectLogDirectory);
  244. // 
  245. // _autoLogCheckBox
  246. // 
  247. this._autoLogCheckBox.Location = new System.Drawing.Point(24, 200);
  248. this._autoLogCheckBox.Name = "_autoLogCheckBox";
  249. this._autoLogCheckBox.FlatStyle = FlatStyle.System;
  250. this._autoLogCheckBox.Size = new System.Drawing.Size(200, 24);
  251. this._autoLogCheckBox.TabIndex = 13;
  252. this._autoLogCheckBox.Checked = true;
  253. this._autoLogCheckBox.CheckedChanged += new System.EventHandler(this.OnAutoLogCheckBoxClick);
  254. this.BackColor = ThemeUtil.TabPaneBackColor;
  255. this._defaultLogGroup.ResumeLayout();
  256. }
  257. private void FillText() {
  258. this._badCharLabel.Text = GApp.Strings.GetString("Form.OptionDialog._badCharLabel");
  259. this._bufferSizeLabel.Text = GApp.Strings.GetString("Form.OptionDialog._bufferSizeLabel");
  260. this._disconnectNotificationLabel.Text = GApp.Strings.GetString("Form.OptionDialog._disconnectNotificationLabel");
  261. this._closeOnDisconnect.Text = GApp.Strings.GetString("Form.OptionDialog._closeOnDisconnect");
  262. this._beepOnBellChar.Text = GApp.Strings.GetString("Form.OptionDialog._beepOnBellChar");
  263. this._adjustsTabTitleToWindowTitle.Text = GApp.Strings.GetString("Form.OptionDialog._adjustsTabTitleToWindowTitle");
  264. this._allowsScrollInAppMode.Text = GApp.Strings.GetString("Form.OptionDialog._allowsScrollInAppMode");
  265. this._keepAliveCheck.Text = GApp.Strings.GetString("Form.OptionDialog._keepAliveCheck");
  266. this._keepAliveLabel.Text = GApp.Strings.GetString("Form.OptionDialog._keepAliveLabel");
  267. this._defaultLogTypeLabel.Text = GApp.Strings.GetString("Form.OptionDialog._defaultLogTypeLabel");
  268. this._defaultLogDirectoryLabel.Text = GApp.Strings.GetString("Form.OptionDialog._defaultLogDirectoryLabel");
  269. this._autoLogCheckBox.Text = GApp.Strings.GetString("Form.OptionDialog._autoLogCheckBox");
  270. _badCharBox.Items.AddRange(EnumDescAttribute.For(typeof(WarningOption)).DescriptionCollection());
  271. _disconnectNotification.Items.AddRange(EnumDescAttribute.For(typeof(DisconnectNotification)).DescriptionCollection());
  272. _defaultLogTypeBox.Items.AddRange(new object[] {
  273.    EnumDescAttribute.For(typeof(LogType)).GetDescription(LogType.Default),
  274.    EnumDescAttribute.For(typeof(LogType)).GetDescription(LogType.Binary),
  275.    EnumDescAttribute.For(typeof(LogType)).GetDescription(LogType.Xml)});
  276. }
  277. public override void InitUI(ContainerOptions options) {
  278. _bufferSize.Text = options.TerminalBufferSize.ToString();
  279. _closeOnDisconnect.Checked = options.CloseOnDisconnect;
  280. _disconnectNotification.SelectedIndex = (int)options.DisconnectNotification;
  281. _beepOnBellChar.Checked = options.BeepOnBellChar;
  282. _badCharBox.SelectedIndex = (int)options.WarningOption;
  283. _adjustsTabTitleToWindowTitle.Checked = options.AdjustsTabTitleToWindowTitle;
  284. _allowsScrollInAppMode.Checked = options.AllowsScrollInAppMode;
  285. _keepAliveCheck.Checked = options.KeepAliveInterval!=0;
  286. _keepAliveIntervalBox.Text = _keepAliveCheck.Checked? (options.KeepAliveInterval/60000).ToString() : "5";
  287. _autoLogCheckBox.Checked = options.DefaultLogType!=LogType.None;
  288. _defaultLogTypeBox.SelectedIndex = (int)options.DefaultLogType-1;
  289. _defaultLogDirectory.Text = options.DefaultLogDirectory;
  290. }
  291. public override bool Commit(ContainerOptions options) {
  292. bool successful = false;
  293. string itemname = null;
  294. try {
  295. options.CloseOnDisconnect = _closeOnDisconnect.Checked;
  296. options.BeepOnBellChar = _beepOnBellChar.Checked;
  297. options.AdjustsTabTitleToWindowTitle = _adjustsTabTitleToWindowTitle.Checked;
  298. options.AllowsScrollInAppMode = _allowsScrollInAppMode.Checked;
  299. itemname = GApp.Strings.GetString("Caption.OptionDialog.BufferLineCount");
  300. options.TerminalBufferSize = Int32.Parse(_bufferSize.Text);
  301. itemname = GApp.Strings.GetString("Caption.OptionDialog.MRUCount");
  302. options.WarningOption = (WarningOption)_badCharBox.SelectedIndex;
  303. options.DisconnectNotification = (DisconnectNotification)_disconnectNotification.SelectedIndex;
  304. if(_keepAliveCheck.Checked) {
  305. itemname = GApp.Strings.GetString("Caption.OptionDialog.KeepAliveInterval");
  306. options.KeepAliveInterval = Int32.Parse(_keepAliveIntervalBox.Text) * 60000;
  307. if(options.KeepAliveInterval<=0) throw new FormatException();
  308. }
  309. else
  310. options.KeepAliveInterval = 0;
  311. if(_autoLogCheckBox.Checked) {
  312. if(_defaultLogDirectory.Text.Length==0) {
  313. GUtil.Warning(this, GApp.Strings.GetString("Message.OptionDialog.EmptyLogDirectory"));
  314. return false;
  315. }
  316. options.DefaultLogType = (LogType)EnumDescAttribute.For(typeof(LogType)).FromDescription(_defaultLogTypeBox.Text, LogType.None);
  317. if(!System.IO.Directory.Exists(_defaultLogDirectory.Text)) {
  318. if(GUtil.AskUserYesNo(this, String.Format(GApp.Strings.GetString("Message.OptionDialog.AskCreateDirectory"), _defaultLogDirectory.Text))==DialogResult.Yes) 
  319. System.IO.Directory.CreateDirectory(_defaultLogDirectory.Text);
  320. else
  321. return false;
  322. }
  323. options.DefaultLogDirectory = _defaultLogDirectory.Text;
  324. }
  325. else
  326. options.DefaultLogType = LogType.None;
  327. successful = true;
  328. }
  329. catch(FormatException) {
  330. GUtil.Warning(this, String.Format(GApp.Strings.GetString("Message.OptionDialog.InvalidItem"), itemname));
  331. }
  332. catch(InvalidOptionException ex) {
  333. GUtil.Warning(this, ex.Message);
  334. }
  335. return successful;
  336. }
  337. private void OnSelectLogDirectory(object sender, EventArgs e) {
  338. /*
  339.  * 傛偔傒傞偲僼僅儖僟慖戰UI偼.NET1.1偱捛壛偝傟偨傛偆偩丅CP偼偍嬑傔偛嬯楯丅
  340. CP.Windows.Forms.ShellFolderBrowser br = new CP.Windows.Forms.ShellFolderBrowser();
  341. br.Title = GApp.Strings.GetString("Caption.OptionDialog.DefaultLogDirectory");
  342. if(br.ShowDialog(this)) {
  343. _defaultLogDirectory.Text = br.FolderPath;
  344. }
  345. */
  346. FolderBrowserDialog dlg = new FolderBrowserDialog();
  347. dlg.ShowNewFolderButton = true;
  348. dlg.Description = GApp.Strings.GetString("Caption.OptionDialog.DefaultLogDirectory");
  349. if(_defaultLogDirectory.Text.Length>0 && Directory.Exists(_defaultLogDirectory.Text))
  350. dlg.SelectedPath = _defaultLogDirectory.Text;
  351. if(GCUtil.ShowModalDialog(FindForm(), dlg)==DialogResult.OK)
  352. _defaultLogDirectory.Text = dlg.SelectedPath;
  353. }
  354. private void OnAutoLogCheckBoxClick(object sender, EventArgs args) {
  355. bool e = _autoLogCheckBox.Checked;
  356. _defaultLogTypeBox.Enabled = e;
  357. if(_defaultLogTypeBox.SelectedIndex==-1) _defaultLogTypeBox.SelectedIndex = 0;
  358. _defaultLogDirectory.Enabled = e;
  359. _dirSelect.Enabled = e;
  360. }
  361. private void OnKeepAliveCheckChanged(object sender, EventArgs args) {
  362. _keepAliveIntervalBox.Enabled = _keepAliveCheck.Checked;
  363. }
  364. }
  365. }