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

namespace Launcheroid
{
    public partial class FItem : Form
    {
        private Launcher launcher;
        private lLink lnk;

        private FItem(Launcher launcher, lLink lnk)
        {
            this.launcher = launcher;
            this.lnk = lnk;
            InitializeComponent();
            ItemLoad();
        }

        private void ItemLoad()
        {
            Text = lnk.Name;
            tbName.Text = lnk.Name;
            tbPath.Text = lnk.Path;
            tbArgs.Text = lnk.Args;
            tbDir.Text = lnk.Dir;
            pbIco.Image = lnk.Icon;
        }

        private void ItemSave()
        {
            lnk.Name = tbName.Text;
            lnk.Path = tbPath.Text;
            lnk.Args = tbArgs.Text;
            lnk.Dir = tbDir.Text;
            lnk.Icon = (Bitmap)pbIco.Image;
            launcher.Save();
        }

        public static void Execute(Launcher launcher, lLink lnk)
        {
            FItem f = new FItem(launcher, lnk);
            f.ShowDialog();
            f.Dispose();
        }

        private void btOk_Click(object sender, EventArgs e)
        {
            ItemSave();
            Close();
        }

        private void FItem_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
        }

        private void FItem_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (files.Length != 1)
                return;
            pbIco.Image = IconTool.GetFileIcon(files[0]);
        }
    }
}
