PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/beta-1.0.2/Client/Setup/RegisterPHPDialog.cs

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