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