Esempio n. 1
0
        private void OnBeforeQueryStatus(object sender, EventArgs e)
        {
            OleMenuCommand mc = sender as OleMenuCommand;

            EnvDTE.DTE     dte;
            EnvDTE.Project project;
            object[]       activeSolutionProjects;
            string         activeProject = "";

            dte = (EnvDTE.DTE)Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService(typeof(EnvDTE.DTE));
            activeSolutionProjects = dte.ActiveSolutionProjects as object[];

            if (activeSolutionProjects != null)
            {
                foreach (object activeSolutionProject in activeSolutionProjects)
                {
                    project       = activeSolutionProject as EnvDTE.Project;
                    activeProject = project.FullName;
                }
            }

            UnityBuildProjectPackage unityBuildProjectPackage = package as UnityBuildProjectPackage;

            projectDic = unityBuildProjectPackage.GetUnityBuildDirectoryInfo();

            listDic = new List <KeyValuePair <string, int> >(projectDic);

            if (mc != null)
            {
                for (int i = 0; i < projectDic.Count; ++i)
                {
                    if (listDic[i].Key == activeProject)
                    {
                        if (listDic[i].Value == 2)
                        {
                            mc.Enabled = true;
                            return;
                        }
                        else if (mc.CommandID.ID == 257 && listDic[i].Value == 0)
                        {
                            mc.Enabled = false;
                        }
                        else if (mc.CommandID.ID == 257 && listDic[i].Value == 1)
                        {
                            mc.Enabled = true;
                        }
                        else if (mc.CommandID.ID == 258 && listDic[i].Value == 0)
                        {
                            mc.Enabled = true;
                        }
                        else if (mc.CommandID.ID == 258 && listDic[i].Value == 1)
                        {
                            mc.Enabled = false;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        int IVsHierarchyEvents.OnItemAdded(uint itemidParent, uint itemidSiblingPrev, uint itemidAdded)
        {
            string activeProject = "";

            object[] activeSolutionProjects;
            activeSolutionProjects = _dte.ActiveSolutionProjects as object[];
            if (activeSolutionProjects != null)
            {
                foreach (object activeSolutionProject in activeSolutionProjects)
                {
                    project       = activeSolutionProject as EnvDTE.Project;
                    activeProject = project.FullName;
                }
            }

            UnityBuildProjectPackage           unityBuildProjectPackage = package as UnityBuildProjectPackage;
            Dictionary <string, int>           dicInfo = unityBuildProjectPackage.GetUnityBuildDirectoryInfo();
            List <KeyValuePair <string, int> > listDic;

            listDic = new List <KeyValuePair <string, int> >(dicInfo);
            int moamoaStatus = 1;

            for (int i = 0; i < listDic.Count; ++i)
            {
                if (listDic[i].Key == activeProject)
                {
                    moamoaStatus = listDic[i].Value;
                }
            }

            object res;

            hierarchy.GetProperty(itemidAdded, (int)__VSHPROPID.VSHPROPID_ExtObject, out res);
            dynamic resFileName = res as EnvDTE.ProjectItem;

            Microsoft.VisualStudio.VCProjectEngine.VCFile file = resFileName.Object as Microsoft.VisualStudio.VCProjectEngine.VCFile;
            if (file.Extension == ".h")
            {
                return(VSConstants.S_OK);
            }

            foreach (Microsoft.VisualStudio.VCProjectEngine.VCFileConfiguration info in file.FileConfigurations)
            {
                if (moamoaStatus == 0)
                {
                    info.ExcludedFromBuild = true;
                }
                else if (moamoaStatus == 1)
                {
                    info.ExcludedFromBuild = false;
                }
            }
            project.Save();
            return(VSConstants.S_OK);
        }
        private void OnBeforeQueryStatus(object sender, EventArgs e)
        {
            OleMenuCommand mc = sender as OleMenuCommand;

            UnityBuildProjectPackage unityBuildProjectPackage = package as UnityBuildProjectPackage;

            projectDic = unityBuildProjectPackage.GetUnityBuildDirectoryInfo();
            listDic    = new List <KeyValuePair <string, int> >(projectDic);

            List <int> trueKeyValue   = new List <int>();
            List <int> falseKeyValue  = new List <int>();
            List <int> enableKeyValue = new List <int>();

            if (mc != null)
            {
                for (int i = 0; i < listDic.Count; ++i)
                {
                    trueKeyValue.Add(1);
                    falseKeyValue.Add(0);
                    enableKeyValue.Add(listDic[i].Value);
                }

                bool enableTrue  = enableKeyValue.SequenceEqual(trueKeyValue);
                bool enableFalse = enableKeyValue.SequenceEqual(falseKeyValue);

                if (enableTrue == false && enableFalse == false)
                {
                    mc.Enabled = true;
                    trueKeyValue.Clear();
                    falseKeyValue.Clear();
                    return;
                }
                else
                {
                    if (enableTrue == true & enableFalse == false)
                    {
                        if (mc.CommandID.ID == 0x0103)
                        {
                            mc.Enabled = true;
                        }
                        else if (mc.CommandID.ID == 0x0104)
                        {
                            mc.Enabled = false;
                        }
                    }
                    else if (enableTrue == false & enableFalse == true)
                    {
                        if (mc.CommandID.ID == 0x0103)
                        {
                            mc.Enabled = false;
                        }
                        else if (mc.CommandID.ID == 0x0104)
                        {
                            mc.Enabled = true;
                        }
                    }
                }
                trueKeyValue.Clear();
                falseKeyValue.Clear();
            }
        }