﻿using EnvDTE;

namespace DMTools.Tidier
{
    class BuildEventsHandler
    {
        public BuildEventsHandler( BuildEvents buildEvents, TidierPackage tidierPackage )
        {
            m_buildEvents = buildEvents;
            m_tidierPackage = tidierPackage;

            if( m_buildEvents != null )
            {
                m_buildEvents.OnBuildBegin += OnBuildBegin;
            }
        }

        void OnBuildBegin( vsBuildScope scope, vsBuildAction action )
        {
            m_tidierPackage.ClearTasks();
        }

        public void Disconnect()
        {
            if( m_buildEvents != null )
            {
                m_buildEvents.OnBuildBegin -= OnBuildBegin;
            }
        }

        private BuildEvents m_buildEvents;
        private TidierPackage m_tidierPackage;
    }
}
