using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CobProgAid
{
    public partial class frmProgAidHome : Form
    {
        ResourceSet resourceSet;
        string resourceKey;
        string workItem = string.Empty;
        ShowCode ShCd;
        CodeChanger coch;

        public frmProgAidHome()
        {
            InitializeComponent();
            coch = new CodeChanger();
            Subscribe(coch);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmProgAidHome_Load(object sender, EventArgs e)
        {
            resourceSet = Properties.Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
            foreach (DictionaryEntry entry in resourceSet)
            {
                resourceKey = (string)entry.Key;
                lstProgTyp.Items.Add(resourceKey);
            }

            foreach (string file in Properties.Settings.Default.FileNames)
            {
                cmbFilename.Items.Add(file);
            }
        }

        private void clbProgType_SelectedIndexChanged(object sender, EventArgs e)
        {
            workItem = resourceSet.GetString(lstProgTyp.SelectedItem.ToString());
            //string comment = resourceSet.
            coch.Template = workItem;
            coch.TemplateName = lstProgTyp.SelectedItem.ToString();
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            ShCd = new ShowCode();
            ShCd.Parent = this;
            ShCd.Labeltext = resourceKey;
            ShCd.CodeShower.Text = coch.CodeOut;
            ShCd.ShowDialog();
        }


        private void cmbFilename_SelectedIndexChanged(object sender, EventArgs e)
        {
            coch.FileName = cmbFilename.Text;
        }
        public void Subscribe(CodeChanger m)
        {
            m.Updated += new CodeChanger.UpdHandler(UpdateText);
        }

        private void UpdateText(CodeChanger m, EventArgs e)
        {
            txtShow.Text = coch.CodeOut;
        }

        private void txtProgramName_TextChanged(object sender, EventArgs e)
        {
            coch.ProgName = txtProgramName.Text;
        }

        private void txtXmlCopy_TextChanged(object sender, EventArgs e)
        {
            coch.XMLcopy = txtXmlCopy.Text;
        }

        private void txtXmlReadCopy_TextChanged(object sender, EventArgs e)
        {
            coch.XMLReadCopy = txtXmlReadCopy.Text;
        }

        private void txtXmlFilNamn_TextChanged(object sender, EventArgs e)
        {
            coch.XMLfilename = txtXmlFilNamn.Text;
        }

    }
}
