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 lLink lnk;
        private FItem(lLink lnk)
        {
            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;
            cbNav.Enabled = System.IO.Directory.Exists(lnk.Path);
            if (cbNav.Enabled)
                cbNav.Checked = lnk.Navigate;
            else
                cbNav.Checked = false;
        }

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

        public static void Execute(lLink lnk)
        {
            FItem f = new FItem(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.GetFileJumbo(files[0]);
        }

        private void FItem_Load(object sender, EventArgs e)
        {

        }
    }
}
