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

Telnet服务器

开发平台:

C#

  1. /*
  2. * Copyright (c) 2005 Poderosa Project, All Rights Reserved.
  3. * $Id: GenericOptionPanel.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 Poderosa.Toolkit;
  9. using Poderosa.Config;
  10. using Poderosa.UI;
  11. namespace Poderosa.Forms
  12. {
  13. /// <summary>
  14. /// GenericOptionPanel 偺奣梫偺愢柧偱偡丅
  15. /// </summary>
  16. internal class GenericOptionPanel : OptionDialog.CategoryPanel
  17. {
  18. private System.Windows.Forms.Label _languageLabel;
  19. private ComboBox _languageBox;
  20. private System.Windows.Forms.Label _actionOnLaunchLabel;
  21. private ComboBox _actionOnLaunchBox;
  22. private System.Windows.Forms.Label _MRUSizeLabel;
  23. private TextBox _MRUSize;
  24. private System.Windows.Forms.Label _serialCountLabel;
  25. private TextBox _serialCount;
  26. private CheckBox _showToolBar;
  27. private CheckBox _showStatusBar;
  28. private CheckBox _showTabBar;
  29. private System.Windows.Forms.GroupBox _tabBarGroup;
  30. private System.Windows.Forms.Label _tabStyleLabel;
  31. private ComboBox _tabStyleBox;
  32. private CheckBox _splitterRatioBox;
  33. private CheckBox _askCloseOnExit;
  34. private CheckBox _quitAppWithLastPane;
  35. private System.Windows.Forms.Label _optionPreservePlaceLabel;
  36. private ComboBox _optionPreservePlace;
  37. private System.Windows.Forms.Label _optionPreservePlacePath;
  38. public GenericOptionPanel()
  39. {
  40. InitializeComponent();
  41. FillText();
  42. }
  43. private void InitializeComponent() {
  44. this._actionOnLaunchLabel = new System.Windows.Forms.Label();
  45. this._actionOnLaunchBox = new ComboBox();
  46. this._MRUSizeLabel = new System.Windows.Forms.Label();
  47. this._MRUSize = new TextBox();
  48. this._serialCountLabel = new System.Windows.Forms.Label();
  49. this._serialCount = new TextBox();
  50. this._tabBarGroup = new System.Windows.Forms.GroupBox();
  51. this._tabStyleLabel = new System.Windows.Forms.Label();
  52. this._tabStyleBox = new ComboBox();
  53. this._splitterRatioBox = new System.Windows.Forms.CheckBox();
  54. this._showToolBar = new System.Windows.Forms.CheckBox();
  55. this._showTabBar = new System.Windows.Forms.CheckBox();
  56. this._showStatusBar = new System.Windows.Forms.CheckBox();
  57. this._askCloseOnExit = new System.Windows.Forms.CheckBox();
  58. this._quitAppWithLastPane = new System.Windows.Forms.CheckBox();
  59. this._optionPreservePlaceLabel = new System.Windows.Forms.Label();
  60. this._optionPreservePlace = new ComboBox();
  61. this._optionPreservePlacePath = new Label();
  62. this._languageLabel = new Label();
  63. this._languageBox = new ComboBox();
  64. this._tabBarGroup.SuspendLayout();
  65. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  66.    this._actionOnLaunchLabel,
  67.    this._actionOnLaunchBox,
  68.    this._MRUSizeLabel,
  69.    this._MRUSize,
  70.    this._serialCountLabel,
  71.    this._serialCount,
  72.    this._showToolBar,
  73.    this._showTabBar,
  74.    this._showStatusBar,
  75.    this._tabBarGroup,
  76.    this._splitterRatioBox,
  77.    this._askCloseOnExit,
  78.    this._quitAppWithLastPane,
  79.    this._optionPreservePlaceLabel,
  80.    this._optionPreservePlacePath,
  81.    this._optionPreservePlace,
  82.    this._languageLabel,
  83.    this._languageBox});
  84. // 
  85. // _languageLabel
  86. // 
  87. this._languageLabel.Location = new System.Drawing.Point(16, 8);
  88. this._languageLabel.Name = "_languageLabel";
  89. this._languageLabel.Size = new System.Drawing.Size(168, 24);
  90. this._languageLabel.TabIndex = 0;
  91. this._languageLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  92. // 
  93. // _languageBox
  94. // 
  95. this._languageBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  96. this._languageBox.Location = new System.Drawing.Point(208, 8);
  97. this._languageBox.Name = "_languageBox";
  98. this._languageBox.Size = new System.Drawing.Size(216, 20);
  99. this._languageBox.TabIndex = 1;
  100. // 
  101. // _actionOnLaunchLabel
  102. // 
  103. this._actionOnLaunchLabel.Location = new System.Drawing.Point(16, 32);
  104. this._actionOnLaunchLabel.Name = "_actionOnLaunchLabel";
  105. this._actionOnLaunchLabel.Size = new System.Drawing.Size(104, 23);
  106. this._actionOnLaunchLabel.TabIndex = 2;
  107. this._actionOnLaunchLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  108. // 
  109. // _actionOnLaunchBox
  110. // 
  111. this._actionOnLaunchBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  112. this._actionOnLaunchBox.Location = new System.Drawing.Point(208, 32);
  113. this._actionOnLaunchBox.Name = "_actionOnLaunchBox";
  114. this._actionOnLaunchBox.Size = new System.Drawing.Size(216, 20);
  115. this._actionOnLaunchBox.TabIndex = 3;
  116. // 
  117. // _MRUSizeLabel
  118. // 
  119. this._MRUSizeLabel.Location = new System.Drawing.Point(16, 56);
  120. this._MRUSizeLabel.Name = "_MRUSizeLabel";
  121. this._MRUSizeLabel.Size = new System.Drawing.Size(272, 23);
  122. this._MRUSizeLabel.TabIndex = 4;
  123. this._MRUSizeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  124. // 
  125. // _MRUSize
  126. // 
  127. this._MRUSize.Location = new System.Drawing.Point(304, 56);
  128. this._MRUSize.MaxLength = 2;
  129. this._MRUSize.Name = "_MRUSize";
  130. this._MRUSize.Size = new System.Drawing.Size(120, 19);
  131. this._MRUSize.TabIndex = 5;
  132. this._MRUSize.Text = "";
  133. // 
  134. // _serialCountLabel
  135. // 
  136. this._serialCountLabel.Location = new System.Drawing.Point(16, 80);
  137. this._serialCountLabel.Name = "_serialCountLabel";
  138. this._serialCountLabel.Size = new System.Drawing.Size(272, 23);
  139. this._serialCountLabel.TabIndex = 6;
  140. this._serialCountLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  141. // 
  142. // _serialCount
  143. // 
  144. this._serialCount.Location = new System.Drawing.Point(304, 80);
  145. this._serialCount.MaxLength = 2;
  146. this._serialCount.Name = "_serialCount";
  147. this._serialCount.Size = new System.Drawing.Size(120, 19);
  148. this._serialCount.TabIndex = 7;
  149. this._serialCount.Text = "";
  150. // 
  151. // _showTabBar
  152. // 
  153. this._showTabBar.Location = new System.Drawing.Point(24, 107);
  154. this._showTabBar.Name = "_showTabBar";
  155. this._showTabBar.FlatStyle = FlatStyle.System;
  156. this._showTabBar.Size = new System.Drawing.Size(136, 23);
  157. this._showTabBar.TabIndex = 8;
  158. this._showTabBar.CheckedChanged += new EventHandler(OnShowTabBarCheckedChanged);
  159. // 
  160. // _tabBarGroup
  161. // 
  162. this._tabBarGroup.Controls.AddRange(new System.Windows.Forms.Control[] {
  163.    this._tabStyleLabel,
  164.    this._tabStyleBox});
  165. this._tabBarGroup.Location = new System.Drawing.Point(16, 112);
  166. this._tabBarGroup.Name = "_tabBarGroup";
  167. this._tabBarGroup.FlatStyle = FlatStyle.System;
  168. this._tabBarGroup.Size = new System.Drawing.Size(408, 40);
  169. this._tabBarGroup.TabIndex = 9;
  170. this._tabBarGroup.TabStop = false;
  171. // 
  172. // _tabStyleLabel
  173. // 
  174. this._tabStyleLabel.Location = new System.Drawing.Point(16, 14);
  175. this._tabStyleLabel.Name = "_tabStyleLabel";
  176. this._tabStyleLabel.Size = new System.Drawing.Size(104, 24);
  177. this._tabStyleLabel.TabIndex = 10;
  178. this._tabStyleLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  179. // 
  180. // _tabStyleBox
  181. // 
  182. this._tabStyleBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  183. this._tabStyleBox.Location = new System.Drawing.Point(192, 15);
  184. this._tabStyleBox.Name = "_tabStyleBox";
  185. this._tabStyleBox.Size = new System.Drawing.Size(196, 20);
  186. this._tabStyleBox.TabIndex = 11;
  187. // 
  188. // _splitterRatioBox
  189. // 
  190. this._splitterRatioBox.Location = new System.Drawing.Point(24, 160);
  191. this._splitterRatioBox.Name = "_splitterRatioBox";
  192. this._splitterRatioBox.FlatStyle = FlatStyle.System;
  193. this._splitterRatioBox.Size = new System.Drawing.Size(320, 20);
  194. this._splitterRatioBox.TabIndex = 12;
  195. // 
  196. // _showToolBar
  197. // 
  198. this._showToolBar.Location = new System.Drawing.Point(24, 184);
  199. this._showToolBar.Name = "_showToolBar";
  200. this._showToolBar.FlatStyle = FlatStyle.System;
  201. this._showToolBar.Size = new System.Drawing.Size(168, 23);
  202. this._showToolBar.TabIndex = 13;
  203. // 
  204. // _showStatusBar
  205. // 
  206. this._showStatusBar.Location = new System.Drawing.Point(224, 184);
  207. this._showStatusBar.Name = "_showStatusBar";
  208. this._showStatusBar.FlatStyle = FlatStyle.System;
  209. this._showStatusBar.Size = new System.Drawing.Size(168, 23);
  210. this._showStatusBar.TabIndex = 14;
  211. // 
  212. // _askCloseOnExit
  213. // 
  214. this._askCloseOnExit.Location = new System.Drawing.Point(24, 220);
  215. this._askCloseOnExit.Name = "_askCloseOnExit";
  216. this._askCloseOnExit.FlatStyle = FlatStyle.System;
  217. this._askCloseOnExit.Size = new System.Drawing.Size(296, 23);
  218. this._askCloseOnExit.TabIndex = 15;
  219. // 
  220. // _quitAppWithLastPane
  221. // 
  222. this._quitAppWithLastPane.Location = new System.Drawing.Point(24, 244);
  223. this._quitAppWithLastPane.Name = "_quitAppWithLastPane";
  224. this._quitAppWithLastPane.FlatStyle = FlatStyle.System;
  225. this._quitAppWithLastPane.Size = new System.Drawing.Size(296, 23);
  226. this._quitAppWithLastPane.TabIndex = 16;
  227. // 
  228. // _optionPreservePlaceLabel
  229. // 
  230. this._optionPreservePlaceLabel.Location = new System.Drawing.Point(16, 268);
  231. this._optionPreservePlaceLabel.Name = "_optionPreservePlaceLabel";
  232. this._optionPreservePlaceLabel.Size = new System.Drawing.Size(208, 24);
  233. this._optionPreservePlaceLabel.TabIndex = 17;
  234. this._optionPreservePlaceLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  235. // 
  236. // _optionPreservePlaceBox
  237. // 
  238. this._optionPreservePlace.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  239. this._optionPreservePlace.Location = new System.Drawing.Point(224, 268);
  240. this._optionPreservePlace.Name = "_optionPreservePlaceBox";
  241. this._optionPreservePlace.Size = new System.Drawing.Size(200, 20);
  242. this._optionPreservePlace.TabIndex = 18;
  243. this._optionPreservePlace.SelectedIndexChanged += new System.EventHandler(this.OnOptionPreservePlaceChanged);
  244. // 
  245. // _optionPreservePlacePath
  246. // 
  247. this._optionPreservePlacePath.Location = new System.Drawing.Point(16, 292);
  248. this._optionPreservePlacePath.BorderStyle = BorderStyle.FixedSingle;
  249. this._optionPreservePlacePath.Name = "_optionPreservePlacePath";
  250. this._optionPreservePlacePath.Size = new System.Drawing.Size(408, 36);
  251. this._optionPreservePlacePath.TabIndex = 19;
  252. this._optionPreservePlacePath.TextAlign = System.Drawing.ContentAlignment.TopLeft;
  253. this.BackColor = ThemeUtil.TabPaneBackColor;
  254. this._tabBarGroup.ResumeLayout();
  255. }
  256. private void FillText() {
  257. this._actionOnLaunchLabel.Text = GApp.Strings.GetString("Form.OptionDialog._actionOnLaunchLabel");
  258. this._MRUSizeLabel.Text = GApp.Strings.GetString("Form.OptionDialog._MRUSizeLabel");
  259. this._serialCountLabel.Text = GApp.Strings.GetString("Form.OptionDialog._serialCountLabel");
  260. this._showTabBar.Text = GApp.Strings.GetString("Form.OptionDialog._showTabBar");
  261. this._tabStyleLabel.Text = GApp.Strings.GetString("Form.OptionDialog._tabStyleLabel");
  262. this._splitterRatioBox.Text = GApp.Strings.GetString("Form.OptionDialog._splitterRatioBox");
  263. this._showToolBar.Text = GApp.Strings.GetString("Form.OptionDialog._showToolBar");
  264. this._showStatusBar.Text = GApp.Strings.GetString("Form.OptionDialog._showStatusBar");
  265. this._askCloseOnExit.Text = GApp.Strings.GetString("Form.OptionDialog._askCloseOnExit");
  266. this._quitAppWithLastPane.Text = GApp.Strings.GetString("Form.OptionDialog._quitAppWithLastPane");
  267. this._optionPreservePlaceLabel.Text = GApp.Strings.GetString("Form.OptionDialog._optionPreservePlaceLabel");
  268. this._languageLabel.Text = GApp.Strings.GetString("Form.OptionDialog._languageLabel");
  269. _tabStyleBox.Items.AddRange(EnumDescAttribute.For(typeof(TabBarStyle)).DescriptionCollection());
  270. _optionPreservePlace.Items.AddRange(EnumDescAttribute.For(typeof(OptionPreservePlace)).DescriptionCollection());
  271. _languageBox.Items.AddRange(EnumDescAttribute.For(typeof(Language)).DescriptionCollection());
  272. }
  273. public override void InitUI(ContainerOptions options) {
  274. _MRUSize.Text = options.MRUSize.ToString();
  275. _serialCount.Text = options.SerialCount.ToString();
  276. _actionOnLaunchBox.Items.Add(GApp.Strings.GetString("Caption.OptionDialog.ActionOnLaunch.Nothing"));
  277. _actionOnLaunchBox.Items.Add(GApp.Strings.GetString("Caption.OptionDialog.ActionOnLaunch.NewConnection"));
  278. for(int i=0; i<GApp.MacroManager.ModuleCount; i++)
  279. _actionOnLaunchBox.Items.Add(GApp.Strings.GetString("Caption.OptionDialog.ActionOnLaunch.Macro")+GApp.MacroManager.GetModule(i).Title);
  280. _actionOnLaunchBox.SelectedIndex = ToActionOnLaunchIndex(options.ActionOnLaunch);
  281. _showToolBar.Checked = options.ShowToolBar;
  282. _showTabBar.Checked = options.ShowTabBar;
  283. _showStatusBar.Checked = options.ShowStatusBar;
  284. _splitterRatioBox.Checked = options.SplitterPreservesRatio;
  285. _tabStyleBox.SelectedIndex = (int)options.TabBarStyle;
  286. _askCloseOnExit.Checked = options.AskCloseOnExit;
  287. _quitAppWithLastPane.Checked = options.QuitAppWithLastPane;
  288. _optionPreservePlace.SelectedIndex = (int)options.OptionPreservePlace;
  289. _languageBox.SelectedIndex = (int)options.Language;
  290. }
  291. public override bool Commit(ContainerOptions options) {
  292. string itemname = null;
  293. bool successful = false;
  294. try {
  295. options.ActionOnLaunch = ToActionOnLaunchCID(_actionOnLaunchBox.SelectedIndex);
  296. itemname = GApp.Strings.GetString("Caption.OptionDialog.MRUCount");
  297. options.MRUSize = Int32.Parse(_MRUSize.Text);
  298. itemname = GApp.Strings.GetString("Caption.OptionDialog.SerialPortCount");
  299. options.SerialCount = Int32.Parse(_serialCount.Text);
  300. options.ShowTabBar = _showTabBar.Checked;
  301. options.ShowToolBar = _showToolBar.Checked;
  302. options.SplitterPreservesRatio = _splitterRatioBox.Checked;
  303. options.TabBarStyle = (TabBarStyle)_tabStyleBox.SelectedIndex;
  304. options.ShowStatusBar = _showStatusBar.Checked;
  305. options.AskCloseOnExit = _askCloseOnExit.Checked;
  306. options.QuitAppWithLastPane = _quitAppWithLastPane.Checked;
  307. if(GApp.Options.OptionPreservePlace!=(OptionPreservePlace)_optionPreservePlace.SelectedIndex && !GApp.IsRegistryWritable) {
  308. GUtil.Warning(this, GApp.Strings.GetString("Message.OptionDialog.RegistryWriteAuthWarning"));
  309. return false;
  310. }
  311. options.OptionPreservePlace = (OptionPreservePlace)_optionPreservePlace.SelectedIndex;
  312. options.Language = (Language)_languageBox.SelectedIndex;
  313. if(options.Language==Language.Japanese && GApp.Options.EnvLanguage==Language.English) {
  314. if(GUtil.AskUserYesNo(this, GApp.Strings.GetString("Message.OptionDialog.AskJapaneseFont"))==DialogResult.No)
  315. return false;
  316. }
  317. successful = true;
  318. }
  319. catch(FormatException) {
  320. GUtil.Warning(this, String.Format(GApp.Strings.GetString("Message.OptionDialog.InvalidItem"), itemname));
  321. }
  322. catch(InvalidOptionException ex) {
  323. GUtil.Warning(this, ex.Message);
  324. }
  325. return successful;
  326. }
  327. private void OnShowTabBarCheckedChanged(object sender, EventArgs args) {
  328. _tabStyleBox.Enabled = _showTabBar.Checked;
  329. _splitterRatioBox.Enabled = _showTabBar.Checked;
  330. }
  331. private void OnOptionPreservePlaceChanged(object sender, EventArgs e) {
  332. AdjustOptionFileLocation((OptionPreservePlace)_optionPreservePlace.SelectedIndex);
  333. }
  334. private void AdjustOptionFileLocation(OptionPreservePlace p) {
  335. _optionPreservePlacePath.Text = GApp.GetOptionDirectory(p);
  336. }
  337. private static int ToActionOnLaunchIndex(CID action) {
  338. if(action==CID.NOP)
  339. return 0;
  340. else if(action==CID.NewConnection)
  341. return 1;
  342. else //CID.ExecMacro
  343. return 2 + (int)(action - CID.ExecMacro);
  344. }
  345. private static CID ToActionOnLaunchCID(int n) {
  346. if(n==0)
  347. return CID.NOP;
  348. else if(n==1)
  349. return CID.NewConnection;
  350. else
  351. return CID.ExecMacro + (n-2);
  352. }
  353. }
  354. }