PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/stable-1.1.1/Client/Settings/AddEditSettingDialog.cs

#
C# | 300 lines | 218 code | 38 blank | 44 comment | 5 complexity | 11cbfb38c213482ae612055c706253ac MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. //-----------------------------------------------------------------------
  2. // <copyright>
  3. // Copyright (C) Ruslan Yakushev for the PHP Manager for IIS project.
  4. //
  5. // This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
  6. // See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
  7. // </copyright>
  8. //-----------------------------------------------------------------------
  9. //#define VSDesigner
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Windows.Forms;
  13. using Microsoft.Web.Management.Client.Win32;
  14. using Web.Management.PHP.Config;
  15. namespace Web.Management.PHP.Settings
  16. {
  17. internal sealed class AddEditSettingDialog :
  18. #if VSDesigner
  19. Form
  20. #else
  21. TaskForm
  22. #endif
  23. {
  24. private string _settingName;
  25. private PHPModule _module;
  26. private bool _canAccept;
  27. private Label _nameLabel;
  28. private TextBox _nameTextBox;
  29. private Label _valueLabel;
  30. private TextBox _valueTextBox;
  31. private Label _sectionLabel;
  32. private ManagementPanel _contentPanel;
  33. private TextBox _sectionTextBox;
  34. private LinkLabel _helpLinkLabel;
  35. private AutoCompleteStringCollection _autoCompleteSections;
  36. /// <summary>
  37. /// Required designer variable.
  38. /// </summary>
  39. private System.ComponentModel.IContainer components = null;
  40. // Constructor for Add Setting Dialog
  41. public AddEditSettingDialog(PHPModule module, IEnumerable<string> sections)
  42. : base(module)
  43. {
  44. _module = module;
  45. InitializeComponent();
  46. InitializeUI();
  47. // The dialog is used in the "Add setting" mode
  48. Text = Resources.AddEditSettingDialogAddSetting;
  49. _autoCompleteSections = new AutoCompleteStringCollection();
  50. foreach (string section in sections)
  51. {
  52. _autoCompleteSections.Add(section);
  53. }
  54. _sectionTextBox.AutoCompleteCustomSource = _autoCompleteSections;
  55. _sectionTextBox.Text = "PHP";
  56. UpdateUI();
  57. }
  58. // Constructor for Edit Setting Dialog
  59. public AddEditSettingDialog(PHPModule module, PHPIniSetting setting)
  60. : base(module)
  61. {
  62. _module = module;
  63. InitializeComponent();
  64. InitializeUI();
  65. // The dialog is used in the "Edit setting" mode
  66. Text = Resources.AddEditSettingDialogEditSetting;
  67. _nameTextBox.Enabled = false;
  68. _sectionTextBox.Enabled = false;
  69. _nameTextBox.Text = setting.Name;
  70. _valueTextBox.Text = setting.Value;
  71. _sectionTextBox.Text = setting.Section;
  72. UpdateUI();
  73. }
  74. protected override bool CanAccept
  75. {
  76. get
  77. {
  78. return _canAccept;
  79. }
  80. }
  81. protected override bool CanShowHelp
  82. {
  83. get
  84. {
  85. return true;
  86. }
  87. }
  88. internal string SettingName
  89. {
  90. get
  91. {
  92. return _settingName;
  93. }
  94. set
  95. {
  96. _settingName = value;
  97. }
  98. }
  99. /// <summary>
  100. /// Clean up any resources being used.
  101. /// </summary>
  102. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  103. protected override void Dispose(bool disposing)
  104. {
  105. if (disposing && (components != null))
  106. {
  107. components.Dispose();
  108. }
  109. base.Dispose(disposing);
  110. }
  111. private void InitializeComponent()
  112. {
  113. this._nameLabel = new System.Windows.Forms.Label();
  114. this._nameTextBox = new System.Windows.Forms.TextBox();
  115. this._valueLabel = new System.Windows.Forms.Label();
  116. this._valueTextBox = new System.Windows.Forms.TextBox();
  117. this._sectionLabel = new System.Windows.Forms.Label();
  118. this._sectionTextBox = new System.Windows.Forms.TextBox();
  119. this._helpLinkLabel = new System.Windows.Forms.LinkLabel();
  120. this.SuspendLayout();
  121. //
  122. // _nameLabel
  123. //
  124. this._nameLabel.AutoSize = true;
  125. this._nameLabel.Location = new System.Drawing.Point(0, 14);
  126. this._nameLabel.Name = "_nameLabel";
  127. this._nameLabel.Size = new System.Drawing.Size(38, 13);
  128. this._nameLabel.TabIndex = 0;
  129. this._nameLabel.Text = Resources.AddEditSettingDialogName;
  130. //
  131. // _nameTextBox
  132. //
  133. this._nameTextBox.Location = new System.Drawing.Point(0, 30);
  134. this._nameTextBox.Name = "_nameTextBox";
  135. this._nameTextBox.Size = new System.Drawing.Size(259, 20);
  136. this._nameTextBox.TabIndex = 1;
  137. this._nameTextBox.TextChanged += new System.EventHandler(this.OnTextBoxTextChanged);
  138. //
  139. // _valueLabel
  140. //
  141. this._valueLabel.AutoSize = true;
  142. this._valueLabel.Location = new System.Drawing.Point(0, 91);
  143. this._valueLabel.Name = "_valueLabel";
  144. this._valueLabel.Size = new System.Drawing.Size(37, 13);
  145. this._valueLabel.TabIndex = 2;
  146. this._valueLabel.Text = Resources.AddEditSettingDialogValue;
  147. //
  148. // _valueTextBox
  149. //
  150. this._valueTextBox.Location = new System.Drawing.Point(0, 107);
  151. this._valueTextBox.Name = "_valueTextBox";
  152. this._valueTextBox.Size = new System.Drawing.Size(259, 20);
  153. this._valueTextBox.TabIndex = 3;
  154. this._valueTextBox.TextChanged += new System.EventHandler(this.OnTextBoxTextChanged);
  155. //
  156. // _sectionLabel
  157. //
  158. this._sectionLabel.AutoSize = true;
  159. this._sectionLabel.Location = new System.Drawing.Point(0, 143);
  160. this._sectionLabel.Name = "_sectionLabel";
  161. this._sectionLabel.Size = new System.Drawing.Size(46, 13);
  162. this._sectionLabel.TabIndex = 4;
  163. this._sectionLabel.Text = Resources.AddEditSettingDialogSection;
  164. //
  165. // _sectionTextBox
  166. //
  167. this._sectionTextBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
  168. this._sectionTextBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
  169. this._sectionTextBox.Location = new System.Drawing.Point(0, 160);
  170. this._sectionTextBox.Name = "_sectionTextBox";
  171. this._sectionTextBox.Size = new System.Drawing.Size(259, 20);
  172. this._sectionTextBox.TabIndex = 5;
  173. //
  174. // _helpLinkLabel
  175. //
  176. this._helpLinkLabel.AutoSize = true;
  177. this._helpLinkLabel.Enabled = false;
  178. this._helpLinkLabel.Location = new System.Drawing.Point(0, 57);
  179. this._helpLinkLabel.Name = "_helpLinkLabel";
  180. this._helpLinkLabel.Size = new System.Drawing.Size(143, 13);
  181. this._helpLinkLabel.TabIndex = 6;
  182. this._helpLinkLabel.TabStop = true;
  183. this._helpLinkLabel.Text = Resources.AddEditSettingDialogLearnMore;
  184. this._helpLinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.OnHelpLinkLabelLinkClicked);
  185. //
  186. // AddEditSettingDialog
  187. //
  188. this.ClientSize = new System.Drawing.Size(284, 262);
  189. this.Controls.Add(this._helpLinkLabel);
  190. this.Controls.Add(this._sectionTextBox);
  191. this.Controls.Add(this._sectionLabel);
  192. this.Controls.Add(this._valueTextBox);
  193. this.Controls.Add(this._valueLabel);
  194. this.Controls.Add(this._nameTextBox);
  195. this.Controls.Add(this._nameLabel);
  196. this.Name = "AddEditSettingDialog";
  197. this.ResumeLayout(false);
  198. #if VSDesigner
  199. this.PerformLayout();
  200. #endif
  201. }
  202. public void InitializeUI()
  203. {
  204. this._contentPanel = new ManagementPanel();
  205. this._contentPanel.SuspendLayout();
  206. this._contentPanel.Location = new System.Drawing.Point(0, 0);
  207. this._contentPanel.Dock = DockStyle.Fill;
  208. this._contentPanel.Controls.Add(_nameLabel);
  209. this._contentPanel.Controls.Add(_nameTextBox);
  210. this._contentPanel.Controls.Add(_helpLinkLabel);
  211. this._contentPanel.Controls.Add(_valueLabel);
  212. this._contentPanel.Controls.Add(_valueTextBox);
  213. this._contentPanel.Controls.Add(_sectionLabel);
  214. this._contentPanel.Controls.Add(_sectionTextBox);
  215. this._contentPanel.ResumeLayout(false);
  216. this._contentPanel.PerformLayout();
  217. SetContent(_contentPanel);
  218. UpdateTaskForm();
  219. }
  220. protected override void OnAccept()
  221. {
  222. try
  223. {
  224. PHPIniSetting setting = new PHPIniSetting();
  225. setting.Name = _nameTextBox.Text.Trim();
  226. setting.Value = _valueTextBox.Text.Trim();
  227. setting.Section = _sectionTextBox.Text.Trim();
  228. RemoteObjectCollection<PHPIniSetting> settings = new RemoteObjectCollection<PHPIniSetting>();
  229. settings.Add(setting);
  230. _module.Proxy.AddOrUpdateSettings(settings);
  231. DialogResult = DialogResult.OK;
  232. SettingName = setting.Name;
  233. Close();
  234. }
  235. catch (Exception ex)
  236. {
  237. DisplayErrorMessage(ex, Resources.ResourceManager);
  238. }
  239. }
  240. private void OnHelpLinkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  241. {
  242. this.ShowHelp();
  243. }
  244. private void OnTextBoxTextChanged(object sender, EventArgs e)
  245. {
  246. UpdateUI();
  247. }
  248. protected override void ShowHelp()
  249. {
  250. Helper.Browse("http://www.php.net/" + _nameTextBox.Text.Trim());
  251. }
  252. private void UpdateUI()
  253. {
  254. string name = _nameTextBox.Text.Trim();
  255. string value = _valueTextBox.Text.Trim();
  256. string section = _sectionTextBox.Text.Trim();
  257. _canAccept = !String.IsNullOrEmpty(name) && !String.IsNullOrEmpty(value) && !String.IsNullOrEmpty(section);
  258. _helpLinkLabel.Enabled = !String.IsNullOrEmpty(name);
  259. UpdateTaskForm();
  260. }
  261. }
  262. }