PageRenderTime 36ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/stable-1.1.0/Client/Extensions/AddExtensionDialog.cs

#
C# | 234 lines | 172 code | 29 blank | 33 comment | 7 complexity | dd1f7c3e4e8437e5b86df9e4e737389e 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.Windows.Forms;
  12. using Microsoft.Web.Management.Client.Win32;
  13. namespace Web.Management.PHP.Extensions
  14. {
  15. internal sealed class AddExtensionDialog :
  16. #if VSDesigner
  17. Form
  18. #else
  19. TaskForm
  20. #endif
  21. {
  22. private PHPModule _module;
  23. private bool _isLocalConnection;
  24. private bool _canAccept;
  25. private ManagementPanel _contentPanel;
  26. private TextBox _extensionPathTextBox;
  27. private Button _browseButton;
  28. private Label _exampleLabel;
  29. private Label _pathToExtenionLabel;
  30. private string _addedExtensionName;
  31. /// <summary>
  32. /// Required designer variable.
  33. /// </summary>
  34. private System.ComponentModel.IContainer components = null;
  35. public string AddedExtensionName
  36. {
  37. get
  38. {
  39. return _addedExtensionName;
  40. }
  41. }
  42. public AddExtensionDialog(PHPModule module, bool isLocalConnection) : base(module)
  43. {
  44. _module = module;
  45. _isLocalConnection = isLocalConnection;
  46. InitializeComponent();
  47. InitializeUI();
  48. }
  49. protected override bool CanAccept
  50. {
  51. get
  52. {
  53. return _canAccept;
  54. }
  55. }
  56. protected override bool CanShowHelp
  57. {
  58. get
  59. {
  60. return true;
  61. }
  62. }
  63. /// <summary>
  64. /// Clean up any resources being used.
  65. /// </summary>
  66. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  67. protected override void Dispose(bool disposing)
  68. {
  69. if (disposing && (components != null))
  70. {
  71. components.Dispose();
  72. }
  73. base.Dispose(disposing);
  74. }
  75. private void InitializeComponent()
  76. {
  77. this._pathToExtenionLabel = new System.Windows.Forms.Label();
  78. this._extensionPathTextBox = new System.Windows.Forms.TextBox();
  79. this._browseButton = new System.Windows.Forms.Button();
  80. this._exampleLabel = new System.Windows.Forms.Label();
  81. this.SuspendLayout();
  82. //
  83. // _pathToExtenionLabel
  84. //
  85. this._pathToExtenionLabel.AutoSize = true;
  86. this._pathToExtenionLabel.Location = new System.Drawing.Point(0, 13);
  87. this._pathToExtenionLabel.Name = "_pathToExtenionLabel";
  88. this._pathToExtenionLabel.Size = new System.Drawing.Size(193, 13);
  89. this._pathToExtenionLabel.TabIndex = 0;
  90. this._pathToExtenionLabel.Text = Resources.AddExtensionDialogProvidePath;
  91. //
  92. // _extensionPathTextBox
  93. //
  94. this._extensionPathTextBox.Location = new System.Drawing.Point(3, 30);
  95. this._extensionPathTextBox.Name = "_extensionPathTextBox";
  96. this._extensionPathTextBox.Size = new System.Drawing.Size(371, 20);
  97. this._extensionPathTextBox.TabIndex = 1;
  98. this._extensionPathTextBox.TextChanged += new System.EventHandler(this.OnExtensionPathTextBoxTextChanged);
  99. //
  100. // _browseButton
  101. //
  102. this._browseButton.Location = new System.Drawing.Point(380, 28);
  103. this._browseButton.Name = "_browseButton";
  104. this._browseButton.Size = new System.Drawing.Size(27, 23);
  105. this._browseButton.TabIndex = 2;
  106. this._browseButton.Text = "...";
  107. this._browseButton.UseVisualStyleBackColor = true;
  108. this._browseButton.Click += new System.EventHandler(this.OnBrowseButtonClick);
  109. //
  110. // _exampleLabel
  111. //
  112. this._exampleLabel.AutoSize = true;
  113. this._exampleLabel.Location = new System.Drawing.Point(0, 53);
  114. this._exampleLabel.Name = "_exampleLabel";
  115. this._exampleLabel.Size = new System.Drawing.Size(159, 13);
  116. this._exampleLabel.TabIndex = 3;
  117. this._exampleLabel.Text = Resources.AddExtensionDialogExample;
  118. //
  119. // AddExtensionDialog
  120. //
  121. this.ClientSize = new System.Drawing.Size(434, 142);
  122. this.Controls.Add(this._exampleLabel);
  123. this.Controls.Add(this._browseButton);
  124. this.Controls.Add(this._extensionPathTextBox);
  125. this.Controls.Add(this._pathToExtenionLabel);
  126. this.Name = "AddExtensionDialog";
  127. this.ResumeLayout(false);
  128. this.ResumeLayout(false);
  129. #if VSDesigner
  130. this.PerformLayout();
  131. #endif
  132. }
  133. private void InitializeUI()
  134. {
  135. _contentPanel = new ManagementPanel();
  136. _contentPanel.SuspendLayout();
  137. // Only show the auto suggest if it is a local connection.
  138. // Otherwise do not show auto suggest and also hide the browse button.
  139. if (_isLocalConnection)
  140. {
  141. this._extensionPathTextBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
  142. this._extensionPathTextBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.FileSystem;
  143. }
  144. else
  145. {
  146. this._browseButton.Visible = false;
  147. }
  148. this._contentPanel.Location = new System.Drawing.Point(0, 0);
  149. this._contentPanel.Dock = DockStyle.Fill;
  150. this._contentPanel.Controls.Add(_pathToExtenionLabel);
  151. this._contentPanel.Controls.Add(_extensionPathTextBox);
  152. this._contentPanel.Controls.Add(_browseButton);
  153. this._contentPanel.Controls.Add(_exampleLabel);
  154. this._contentPanel.ResumeLayout(false);
  155. this._contentPanel.PerformLayout();
  156. this.Text = Resources.AddExtensionDialogAddExtension;
  157. SetContent(_contentPanel);
  158. UpdateTaskForm();
  159. }
  160. protected override void OnAccept()
  161. {
  162. try
  163. {
  164. string path = _extensionPathTextBox.Text.Trim();
  165. _addedExtensionName = _module.Proxy.AddExtension(path);
  166. DialogResult = DialogResult.OK;
  167. Close();
  168. }
  169. catch (Exception ex)
  170. {
  171. DisplayErrorMessage(ex, Resources.ResourceManager);
  172. }
  173. }
  174. private void OnBrowseButtonClick(object sender, EventArgs e)
  175. {
  176. using (OpenFileDialog dlg = new OpenFileDialog())
  177. {
  178. dlg.Title = Resources.AddExtensionDialogOpenFileTitle;
  179. dlg.Filter = Resources.AddExtensionDialogOpenFileFilter;
  180. if (!String.IsNullOrEmpty(_extensionPathTextBox.Text))
  181. {
  182. dlg.InitialDirectory = System.IO.Path.GetDirectoryName(_extensionPathTextBox.Text.Trim());
  183. }
  184. else
  185. {
  186. dlg.InitialDirectory = Environment.ExpandEnvironmentVariables("%SystemDrive%");
  187. }
  188. if (dlg.ShowDialog() == DialogResult.OK)
  189. {
  190. _extensionPathTextBox.Text = dlg.FileName;
  191. }
  192. }
  193. }
  194. private void OnExtensionPathTextBoxTextChanged(object sender, EventArgs e)
  195. {
  196. string path = _extensionPathTextBox .Text.Trim();
  197. _canAccept = !String.IsNullOrEmpty(path);
  198. UpdateTaskForm();
  199. }
  200. protected override void ShowHelp()
  201. {
  202. Helper.Browse(Globals.AddExtensionOnlineHelp);
  203. }
  204. }
  205. }