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

namespace Regensburger.RShare
{
    internal sealed partial class RenameDownloadDialog : Form
    {
        private Download m_Download;

        public RenameDownloadDialog(Download download)
        {
            InitializeComponent();
            m_Download = download;
            renameTextBox.Text = m_Download.FileName;
        }

        private void renameButton_Click(object sender, EventArgs e)
        {
            try
            {
                m_Download.SetFileName(renameTextBox.Text);
                Close();
            }
            catch (Exception ex)
            {
                toolStripStatusLabel.Image = Properties.Resources.error_16x16;
                toolStripStatusLabel.Text = ex.Message;
            }
        }

        private void RenameDownloadDialog_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
                Close();
        }

        private void renameTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                renameButton.PerformClick();
        }

        private void renameTextBox_TextChanged(object sender, EventArgs e)
        {
            if (renameTextBox.Text != string.Empty)
                renameButton.Enabled = true;
            else
                renameButton.Enabled = false;
        }
    }
}
