// <file>
//     <copyright see="prj:///doc/copyright.txt"/>
//     <license see="prj:///doc/license.txt"/>
//     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
//     <version value="$version"/>
// </file>

using System;
using System.IO;
using System.Windows.Forms;
using System.Drawing;

namespace ICSharpCode.Core.Services
{
	/// <summary>
	///     Add summary description for SaveErrorChooseDialog
	/// </summary>
	public class SaveErrorChooseDialog : Form 
	{
		Button  retryButton;
		Button  ignoreButton;
		Label   descriptionLabel;
		TextBox descriptionTextBox;
		Button  exceptionButton;
		Button  chooseLocationButton;
		
		string    displayMessage;
		Exception exceptionGot;
		
		public SaveErrorChooseDialog(string fileName, string message, string dialogName, Exception exceptionGot, bool chooseLocationEnabled) 
		{
			this.Text = dialogName;
			//  Must be called for initialization
			this.InitializeComponents(chooseLocationEnabled);
			
			StringParserService stringParserService = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService));
			displayMessage = stringParserService.Parse(message, new string[,] {
				{"FileName", fileName},
				{"Path",     Path.GetDirectoryName(fileName)},
				{"FileNameWithoutPath", Path.GetFileName(fileName)},
				{"Exception", exceptionGot.GetType().FullName},
			});
			
			descriptionTextBox.Lines = this.displayMessage.Split('\n');
			
			this.exceptionGot = exceptionGot;
		}
		
		void ShowException(object sender, EventArgs e)
		{
			MessageBox.Show(this, exceptionGot.ToString(), "Exception got");
		}
		
		/// <summary>
		///     This method was autogenerated - do not change the contents manually
		/// </summary>
		private void InitializeComponents(bool chooseLocationEnabled) 
		{
			ResourceService resourceService = (ResourceService)ServiceManager.Services.GetService(typeof(ResourceService));
			
			//
			//  Set up generated class SaveErrorChooseDialog
			// 
			this.SuspendLayout();
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Size = new Size(520, 262);
			this.Name = "SaveErrorChooseDialog";
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.ShowInTaskbar = false;
			this.StartPosition = FormStartPosition.CenterScreen;

			// 
			//  Set up member retryButton
			// 
			retryButton = new Button();
			retryButton.DialogResult = System.Windows.Forms.DialogResult.Retry;
			retryButton.Name = "retryButton";
			retryButton.TabIndex = 5;
			retryButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			retryButton.Text = resourceService.GetString("Global.RetryButtonText");
			retryButton.Size = new Size(120, 23);
			retryButton.Location = new Point(4, 206);
			this.Controls.Add(retryButton);
			
			// 
			//  Set up member ignoreButton
			// 
			ignoreButton = new Button();
			ignoreButton.Name = "ignoreButton";
			ignoreButton.DialogResult = System.Windows.Forms.DialogResult.Ignore;
			ignoreButton.TabIndex = 4;
			ignoreButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			ignoreButton.Text = resourceService.GetString("Global.IgnoreButtonText");
			ignoreButton.Size = new Size(120, 23);
			ignoreButton.Location = new Point(132, 206);
			this.Controls.Add(ignoreButton);
			
			// 
			//  Set up member descriptionLabel
			// 
			descriptionLabel = new Label();
			descriptionLabel.Name = "descriptionLabel";
			descriptionLabel.Location = new Point(8, 0);
			descriptionLabel.Size = new Size(510, 24);
			descriptionLabel.TabIndex = 3;
			descriptionLabel.Anchor = (System.Windows.Forms.AnchorStyles.Top 
						| (System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right));
			descriptionLabel.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
			descriptionLabel.Text = "Description";
			this.Controls.Add(descriptionLabel);
			
			// 
			//  Set up member descriptionTextBox
			// 
			descriptionTextBox = new TextBox();
			descriptionTextBox.Multiline = true;
			descriptionTextBox.Size = new Size(502, 174);
			descriptionTextBox.Location = new Point(8, 24);
			descriptionTextBox.TabIndex = 2;
			descriptionTextBox.Anchor = (System.Windows.Forms.AnchorStyles.Top 
						| (System.Windows.Forms.AnchorStyles.Bottom 
						| (System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
			descriptionTextBox.ReadOnly = true;
			descriptionTextBox.Name = "descriptionTextBox";
			this.Controls.Add(descriptionTextBox);
			
			// 
			//  Set up member exceptionButton
			// 
			exceptionButton = new Button();
			exceptionButton.TabIndex = 1;
			exceptionButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			exceptionButton.Name = "exceptionButton";
			exceptionButton.Text = "Show Exception";
			exceptionButton.Size = new Size(120, 23);
			exceptionButton.Location = new Point(388, 206);
			exceptionButton.Click += new EventHandler(ShowException);
			this.Controls.Add(exceptionButton);
			
			if (chooseLocationEnabled) {
				// 
				//  Set up member chooseLocationButton
				// 
				chooseLocationButton = new Button();
				chooseLocationButton.Name = "chooseLocationButton";
				chooseLocationButton.DialogResult = System.Windows.Forms.DialogResult.OK;
				chooseLocationButton.TabIndex = 0;
				chooseLocationButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
				chooseLocationButton.Text = resourceService.GetString("Global.ChooseLocationButtonText");
				chooseLocationButton.Size = new Size(120, 23);
				chooseLocationButton.Location = new Point(260, 206);
			}
			
			this.Controls.Add(chooseLocationButton);
			this.ResumeLayout(false);
		}
	}
}
