using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CobXmlSupport
{
    public class SaverListener
    {

        public Dictionary<string, GenSetting> dict { get; set; }

        public void Subscribe(GenSetting G)
        {
            G.evSave += new GenSetting.SaveHandler(SaveMethod);
        }

        public void UnSubscribe(GenSetting G)
        {
            G.evSave -= new GenSetting.SaveHandler(SaveMethod);
        }

        private void SaveMethod(GenSetting G, EventArgs e)
        {
            GenSetting tmpGS = (GenSetting)G.Clone(); 
            GenSetting tmpSett;
            if (dict.TryGetValue(tmpGS.ActualFile, out tmpSett))
            {
                dict[tmpGS.ActualFile] = tmpGS;
            }
            else dict.Add(tmpGS.ActualFile, tmpGS);
        }   
    }
}
