Ejemplo n.º 1
0
        public void DocumentSaved(EnvDTE.Document document)
        {
            QtProject qtPro = QtProject.Create(document.ProjectItem.ContainingProject);

            if (!HelperFunctions.IsQtProject(qtPro.VCProject))
            {
                return;
            }

            VCFile file = (VCFile)((IVCCollection)qtPro.VCProject.Files).Item(document.FullName);

            if (file.Extension == ".ui")
            {
                if (QtVSIPSettings.AutoUpdateUicSteps() && !QtProject.HasUicStep(file))
                {
                    qtPro.AddUic4BuildStep(file);
                }
                return;
            }

            if (!HelperFunctions.HasSourceFileExtension(file.Name) && !HelperFunctions.HasHeaderFileExtension(file.Name))
            {
                return;
            }

            if (HelperFunctions.HasQObjectDeclaration(file))
            {
                if (!qtPro.HasMocStep(file))
                {
                    qtPro.AddMocStep(file);
                }
            }
            else
            {
                qtPro.RemoveMocStep(file);
            }

            if (HelperFunctions.HasSourceFileExtension(file.Name))
            {
                string moccedFileName = "moc_" + file.Name;

                if (qtPro.IsMoccedFileIncluded(file))
                {
                    // exclude moc_foo.cpp from build
//#if (VS2012 || VS2013 || VS2015)
                    // Code copied here from 'GetFilesFromProject'
                    // For some reason error CS1771 was generated from function call
                    List <VCFile> tmpList = new System.Collections.Generic.List <VCFile>();
                    moccedFileName = HelperFunctions.NormalizeRelativeFilePath(moccedFileName);

                    FileInfo fi = new FileInfo(moccedFileName);
                    foreach (VCFile f in (IVCCollection)qtPro.VCProject.Files)
                    {
                        if (f.Name.ToLower() == fi.Name.ToLower())
                        {
                            tmpList.Add(f);
                        }
                    }
                    foreach (VCFile moccedFile in tmpList)
                    {
                        QtProject.ExcludeFromAllBuilds(moccedFile);
                    }
//#else
///                    foreach (VCFile moccedFile in qtPro.GetFilesFromProject(moccedFileName))
//                        QtProject.ExcludeFromAllBuilds(moccedFile);
//#endif
                }
                else
                {
                    // make sure that moc_foo.cpp isn't excluded from build
//#if (VS2012 || VS2013 || VS2015)
                    // Code copied here from 'GetFilesFromProject'
                    // For some reason error CS1771 was generated from function call
                    List <VCFile> moccedFiles = new System.Collections.Generic.List <VCFile>();
                    moccedFileName = HelperFunctions.NormalizeRelativeFilePath(moccedFileName);

                    FileInfo fi = new FileInfo(moccedFileName);
                    foreach (VCFile f in (IVCCollection)qtPro.VCProject.Files)
                    {
                        if (f.Name.ToLower() == fi.Name.ToLower())
                        {
                            moccedFiles.Add(f);
                        }
                    }
//#else
//                    List<VCFile> moccedFiles = qtPro.GetFilesFromProject(moccedFileName);
//#endif
                    if (moccedFiles.Count > 0)
                    {
                        bool     hasDifferentMocFilesPerConfig   = QtVSIPSettings.HasDifferentMocFilePerConfig(qtPro.Project);
                        bool     hasDifferentMocFilesPerPlatform = QtVSIPSettings.HasDifferentMocFilePerPlatform(qtPro.Project);
                        VCFilter generatedFiles = qtPro.FindFilterFromGuid(Filters.GeneratedFiles().UniqueIdentifier);
                        foreach (VCFile fileInFilter in (IVCCollection)generatedFiles.Files)
                        {
                            if (fileInFilter.Name == moccedFileName)
                            {
                                foreach (VCFileConfiguration config in (IVCCollection)fileInFilter.FileConfigurations)
                                {
                                    bool            exclude  = true;
                                    VCConfiguration vcConfig = config.ProjectConfiguration as VCConfiguration;
                                    if (hasDifferentMocFilesPerConfig && hasDifferentMocFilesPerPlatform)
                                    {
                                        VCPlatform platform     = vcConfig.Platform as VCPlatform;
                                        string     platformName = platform.Name;
                                        if (fileInFilter.RelativePath.ToLower().Contains(vcConfig.ConfigurationName.ToLower()) &&
                                            fileInFilter.RelativePath.ToLower().Contains(platform.Name.ToLower()))
                                        {
                                            exclude = false;
                                        }
                                    }
                                    else if (hasDifferentMocFilesPerConfig)
                                    {
                                        if (fileInFilter.RelativePath.ToLower().Contains(vcConfig.ConfigurationName.ToLower()))
                                        {
                                            exclude = false;
                                        }
                                    }
                                    else if (hasDifferentMocFilesPerPlatform)
                                    {
                                        VCPlatform platform     = vcConfig.Platform as VCPlatform;
                                        string     platformName = platform.Name;
                                        if (fileInFilter.RelativePath.ToLower().Contains(platformName.ToLower()))
                                        {
                                            exclude = false;
                                        }
                                    }
                                    else
                                    {
                                        exclude = false;
                                    }
                                    if (config.ExcludedFromBuild != exclude)
                                    {
                                        config.ExcludedFromBuild = exclude;
                                    }
                                }
                            }
                        }
                        foreach (VCFilter filt in (IVCCollection)generatedFiles.Filters)
                        {
                            foreach (VCFile f in (IVCCollection)filt.Files)
                            {
                                if (f.Name == moccedFileName)
                                {
                                    foreach (VCFileConfiguration config in (IVCCollection)f.FileConfigurations)
                                    {
                                        VCConfiguration vcConfig        = config.ProjectConfiguration as VCConfiguration;
                                        string          filterToLookFor = "";
                                        if (hasDifferentMocFilesPerConfig)
                                        {
                                            filterToLookFor = vcConfig.ConfigurationName;
                                        }
                                        if (hasDifferentMocFilesPerPlatform)
                                        {
                                            VCPlatform platform = vcConfig.Platform as VCPlatform;
                                            if (!string.IsNullOrEmpty(filterToLookFor))
                                            {
                                                filterToLookFor += '_';
                                            }
                                            filterToLookFor += platform.Name;
                                        }
                                        if (filt.Name == filterToLookFor)
                                        {
                                            if (config.ExcludedFromBuild)
                                            {
                                                config.ExcludedFromBuild = false;
                                            }
                                        }
                                        else
                                        {
                                            if (!config.ExcludedFromBuild)
                                            {
                                                config.ExcludedFromBuild = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void DocumentSaved(Document document)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var qtPro = QtProject.Create(document.ProjectItem.ContainingProject);

            if (!HelperFunctions.IsQtProject(qtPro.VCProject))
            {
                return;
            }

            var file = (VCFile)((IVCCollection)qtPro.VCProject.Files).Item(document.FullName);

            if (HelperFunctions.IsUicFile(file.Name))
            {
                if (QtVSIPSettings.AutoUpdateUicSteps() && !QtProject.HasUicStep(file))
                {
                    qtPro.AddUic4BuildStep(file);
                }
                return;
            }

            if (!HelperFunctions.IsSourceFile(file.Name) && !HelperFunctions.IsHeaderFile(file.Name))
            {
                return;
            }

            if (HelperFunctions.HasQObjectDeclaration(file))
            {
                if (!qtPro.HasMocStep(file))
                {
                    qtPro.AddMocStep(file);
                }
            }
            else
            {
                if (qtPro.HasMocStep(file))
                {
                    qtPro.RemoveMocStep(file);
                }
            }

            if (HelperFunctions.IsSourceFile(file.Name))
            {
                var moccedFileName = "moc_" + file.Name;

                if (qtPro.IsMoccedFileIncluded(file))
                {
                    foreach (var moccedFile in qtPro.GetFilesFromProject(moccedFileName))
                    {
                        QtProject.ExcludeFromAllBuilds(moccedFile);
                    }
                }
                else
                {
                    var moccedFiles = qtPro.GetFilesFromProject(moccedFileName);
                    if (moccedFiles.Any())
                    {
                        var hasDifferentMocFilesPerConfig   = QtVSIPSettings.HasDifferentMocFilePerConfig(qtPro.Project);
                        var hasDifferentMocFilesPerPlatform = QtVSIPSettings.HasDifferentMocFilePerPlatform(qtPro.Project);
                        var generatedFiles = qtPro.FindFilterFromGuid(Filters.GeneratedFiles().UniqueIdentifier);
                        foreach (VCFile fileInFilter in (IVCCollection)generatedFiles.Files)
                        {
                            if (fileInFilter.Name == moccedFileName)
                            {
                                foreach (VCFileConfiguration config in (IVCCollection)fileInFilter.FileConfigurations)
                                {
                                    var exclude  = true;
                                    var vcConfig = config.ProjectConfiguration as VCConfiguration;
                                    if (hasDifferentMocFilesPerConfig && hasDifferentMocFilesPerPlatform)
                                    {
                                        var platform = vcConfig.Platform as VCPlatform;
                                        if (fileInFilter.RelativePath.ToLower().Contains(vcConfig.ConfigurationName.ToLower()) &&
                                            fileInFilter.RelativePath.ToLower().Contains(platform.Name.ToLower()))
                                        {
                                            exclude = false;
                                        }
                                    }
                                    else if (hasDifferentMocFilesPerConfig)
                                    {
                                        if (fileInFilter.RelativePath.ToLower().Contains(vcConfig.ConfigurationName.ToLower()))
                                        {
                                            exclude = false;
                                        }
                                    }
                                    else if (hasDifferentMocFilesPerPlatform)
                                    {
                                        var platform     = vcConfig.Platform as VCPlatform;
                                        var platformName = platform.Name;
                                        if (fileInFilter.RelativePath.ToLower().Contains(platformName.ToLower()))
                                        {
                                            exclude = false;
                                        }
                                    }
                                    else
                                    {
                                        exclude = false;
                                    }
                                    if (config.ExcludedFromBuild != exclude)
                                    {
                                        config.ExcludedFromBuild = exclude;
                                    }
                                }
                            }
                        }
                        foreach (VCFilter filt in (IVCCollection)generatedFiles.Filters)
                        {
                            foreach (VCFile f in (IVCCollection)filt.Files)
                            {
                                if (f.Name == moccedFileName)
                                {
                                    foreach (VCFileConfiguration config in (IVCCollection)f.FileConfigurations)
                                    {
                                        var vcConfig        = config.ProjectConfiguration as VCConfiguration;
                                        var filterToLookFor = string.Empty;
                                        if (hasDifferentMocFilesPerConfig)
                                        {
                                            filterToLookFor = vcConfig.ConfigurationName;
                                        }
                                        if (hasDifferentMocFilesPerPlatform)
                                        {
                                            var platform = vcConfig.Platform as VCPlatform;
                                            if (!string.IsNullOrEmpty(filterToLookFor))
                                            {
                                                filterToLookFor += '_';
                                            }
                                            filterToLookFor += platform.Name;
                                        }
                                        if (filt.Name == filterToLookFor)
                                        {
                                            if (config.ExcludedFromBuild)
                                            {
                                                config.ExcludedFromBuild = false;
                                            }
                                        }
                                        else
                                        {
                                            if (!config.ExcludedFromBuild)
                                            {
                                                config.ExcludedFromBuild = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }