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