// Оригинальная версия написана Cristian Forsberg
// и находится по адресу 
//http://www.businessanyplace.net/?p=spfileman


// Переделано и переведено на русский для Windows Mobile 6
// Visual Studio 2008
// Александр Климов

//------------------------------------------------------------------------------
/// <copyright from='2004' to='2005' company='Christian Forsberg'>
///		Copyright (c) Christian Forsberg, chris@businessanyplace.net.
///
///   This program is distributed in the hope that it will be useful,
///   but WITHOUT ANY WARRANTY; without even the implied warranty of
///   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
/// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;

namespace FileManager
{
	/// <summary>
	/// This is the rename form.
	/// </summary>
  public class NameForm : System.Windows.Forms.Form
  {
    private Form parentForm;
    private string itemName;
    private SetNameDelegate setNameCallback;

    #region Windows Form Designer declarations

    private System.Windows.Forms.Label nameLabel;
    private System.Windows.Forms.MainMenu mainMenu;
    private System.Windows.Forms.MenuItem doneMenuItem;
    private System.Windows.Forms.MenuItem cancelMenuItem;
    private System.Windows.Forms.TextBox nameTextBox;
    #endregion

    public NameForm(Form parentForm, string title, string itemName, SetNameDelegate setNameCallback)
    {
      this.parentForm = parentForm;
      this.Text = title;
      this.itemName = itemName;
      this.setNameCallback = setNameCallback;

      InitializeComponent();
    }

    #region Dispose
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      base.Dispose( disposing );
    }
    #endregion

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.mainMenu = new System.Windows.Forms.MainMenu();
        this.doneMenuItem = new System.Windows.Forms.MenuItem();
        this.cancelMenuItem = new System.Windows.Forms.MenuItem();
        this.nameLabel = new System.Windows.Forms.Label();
        this.nameTextBox = new System.Windows.Forms.TextBox();
        // 
        // mainMenu
        // 
        this.mainMenu.MenuItems.Add(this.doneMenuItem);
        this.mainMenu.MenuItems.Add(this.cancelMenuItem);
        // 
        // doneMenuItem
        // 
        this.doneMenuItem.Text = "Done";
        this.doneMenuItem.Click += new System.EventHandler(this.doneMenuItem_Click);
        // 
        // cancelMenuItem
        // 
        this.cancelMenuItem.Text = "Отмена";
        this.cancelMenuItem.Click += new System.EventHandler(this.cancelMenuItem_Click);
        // 
        // nameLabel
        // 
        this.nameLabel.Location = new System.Drawing.Point(3, 2);
        this.nameLabel.Size = new System.Drawing.Size(152, 22);
        this.nameLabel.Text = "Name:";
        // 
        // nameTextBox
        // 
        this.nameTextBox.Location = new System.Drawing.Point(4, 24);
        this.nameTextBox.Size = new System.Drawing.Size(163, 28);
        // 
        // NameForm
        // 
        this.ClientSize = new System.Drawing.Size(176, 180);
        this.Controls.Add(this.nameLabel);
        this.Controls.Add(this.nameTextBox);
        this.Menu = this.mainMenu;
        this.Text = "Name";
        this.Closing += new System.ComponentModel.CancelEventHandler(this.NameForm_Closing);
        this.Load += new System.EventHandler(this.NameForm_Load);

    }
    #endregion

    private void NameForm_Load(object sender, System.EventArgs e)
    {
      // Correct for designer flaw (not according to UI standard)
      nameTextBox.Height = 22;

      if(!itemName.Equals(string.Empty))
        nameTextBox.Text = itemName;

      this.parentForm.Hide();
      Cursor.Current = Cursors.Default;
    }

    #region Menu options
    private void doneMenuItem_Click(object sender, System.EventArgs e)
    {
      setNameCallback(nameTextBox.Text);
      this.DialogResult = DialogResult.OK;
      this.Close();
    }

    private void cancelMenuItem_Click(object sender, System.EventArgs e)
    {
      this.DialogResult = DialogResult.Cancel;
      this.Close();
    }
    #endregion

    private void NameForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
      parentForm.Show();
    }
  }
}
