//  
//   Rebex Sample Code License
// 
//   Copyright 2025, REBEX CR s.r.o.
//   All rights reserved.
//   https://www.rebex.net/
// 
//   Permission to use, copy, modify, and/or distribute this software for any
//   purpose with or without fee is hereby granted.
// 
//   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
//   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
//   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
//   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
//   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
//   OTHER DEALINGS IN THE SOFTWARE.
// 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Rebex.Samples
{
    /// <summary>
    /// A dialog that asks for a new name.
    /// </summary>
    public partial class NewNameDialog : Form
    {
        /// <summary>
        /// Initializes a new instance of the dialog.
        /// </summary>
        /// <param name="originalName">Original name.</param>
        /// <param name="isFileName">Whether the name is a file or directory name.</param>
        public NewNameDialog(string originalName, bool isFileName)
        {			
            InitializeComponent();

            if (string.IsNullOrEmpty(originalName))
            {
                if (isFileName)
                    labelInfo.Text = "Enter a file name:";
                else
                    labelInfo.Text = "Enter a directory name:";
            }
            else
            {
                if (isFileName)
                    labelInfo.Text = string.Format("Enter a new name for the file {0}:", originalName);
                else
                    labelInfo.Text = string.Format("Enter a new name for the directory {0}:", originalName);
            }

            txtNewName.Text = originalName;
        }

        /// <summary>
        /// Gets the new name.
        /// </summary>
        public string NewName
        {
            get { return txtNewName.Text; }
        }

        /// <summary>
        /// Validates user input on closing.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NewNameDialog_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.OK && NewName.Trim() == string.Empty)
            {
                MessageBox.Show("Name cannot be empty.");
                e.Cancel = true;
            }
        }
    }
}