Exemplo n.º 1
0
 public string GetPrecompiledHeaderThrough()
 {
     if (qtPro == null)
     {
         throw new QtVSException(commonError);
     }
     return(qtPro.GetPrecompiledHeaderThrough());
 }
Exemplo n.º 2
0
        public void ProjectItemsEvents_ItemAdded(ProjectItem projectItem)
        {
            Project   project = HelperFunctions.GetSelectedQtProject(VSPackage.dte);
            QtProject qtPro   = QtProject.Create(project);

            if (!HelperFunctions.IsQtProject(project))
            {
                return;
            }
            VCFilter filter = null;
            VCFile   vcFile = GetVCFileFromProject(projectItem.Name, qtPro.VCProject);

            if (vcFile == null)
            {
                return;
            }

            try
            {
                // Try to find the filter, the file is located in
                // If the file is not inside any filter, move it to
                // the according one, used by the Add-in
                filter = (VCFilter)vcFile.Parent;
            }
            catch { }

            try
            {
                FakeFilter ui  = Filters.FormFiles();
                FakeFilter qrc = Filters.ResourceFiles();
                FakeFilter ts  = Filters.TranslationFiles();
                FakeFilter h   = Filters.HeaderFiles();
                FakeFilter src = Filters.SourceFiles();

                VCFilter uiFilter  = qtPro.FindFilterFromGuid(ui.UniqueIdentifier);
                VCFilter tsFilter  = qtPro.FindFilterFromGuid(ts.UniqueIdentifier);
                VCFilter qrcFilter = qtPro.FindFilterFromGuid(qrc.UniqueIdentifier);
                VCFilter hFilter   = qtPro.FindFilterFromGuid(h.UniqueIdentifier);
                VCFilter srcFilter = qtPro.FindFilterFromGuid(src.UniqueIdentifier);

                if (HelperFunctions.HasSourceFileExtension(vcFile.Name))
                {
                    if (vcFile.Name.ToLower().StartsWith("moc_"))
                    {
                        return;
                    }
                    else if (vcFile.Name.ToLower().StartsWith("qrc_"))
                    {
                        // Do not use precompiled headers with these files
                        QtProject.SetPCHOption(vcFile, pchOption.pchNone);
                        return;
                    }
                    string pcHeaderThrough = qtPro.GetPrecompiledHeaderThrough();
                    if (pcHeaderThrough != null)
                    {
                        string pcHeaderCreator = pcHeaderThrough.Remove(pcHeaderThrough.LastIndexOf('.')) + ".cpp";
                        if (vcFile.Name.ToLower().EndsWith(pcHeaderCreator.ToLower()) &&
                            HelperFunctions.CxxFileContainsNotCommented(vcFile, "#include \"" + pcHeaderThrough + "\"", false, false))
                        {
                            //File is used to create precompiled headers
                            QtProject.SetPCHOption(vcFile, pchOption.pchCreateUsingSpecific);
                            return;
                        }
                    }
                    if (filter == null && !HelperFunctions.IsInFilter(vcFile, src))
                    {
                        if (null == srcFilter && qtPro.VCProject.CanAddFilter(src.Name))
                        {
                            srcFilter                  = (VCFilter)qtPro.VCProject.AddFilter(src.Name);
                            srcFilter.Filter           = src.Filter;
                            srcFilter.ParseFiles       = src.ParseFiles;
                            srcFilter.UniqueIdentifier = src.UniqueIdentifier;
                        }
                        qtPro.RemoveItem(projectItem);
                        qtPro.AddFileToProject(vcFile.FullPath, src);
                    }
                    if (HelperFunctions.HasQObjectDeclaration(vcFile))
                    {
//#if (VS2010 || VS2012 || VS2013 || VS2015)
                        HelperFunctions.EnsureCustomBuildToolAvailable(projectItem);
//#endif
                        qtPro.AddMocStep(vcFile);
                    }
                }
                else if (HelperFunctions.HasHeaderFileExtension(vcFile.Name))
                {
                    if (vcFile.Name.ToLower().StartsWith("ui_"))
                    {
                        return;
                    }
                    if (filter == null && !HelperFunctions.IsInFilter(vcFile, h))
                    {
                        if (null == hFilter && qtPro.VCProject.CanAddFilter(h.Name))
                        {
                            hFilter                  = (VCFilter)qtPro.VCProject.AddFilter(h.Name);
                            hFilter.Filter           = h.Filter;
                            hFilter.ParseFiles       = h.ParseFiles;
                            hFilter.UniqueIdentifier = h.UniqueIdentifier;
                        }
                        qtPro.RemoveItem(projectItem);
                        qtPro.AddFileToProject(vcFile.FullPath, h);
                    }
                    if (HelperFunctions.HasQObjectDeclaration(vcFile))
                    {
//#if (VS2010 || VS2012 || VS2013 || VS2015)
                        HelperFunctions.EnsureCustomBuildToolAvailable(projectItem);
//#endif
                        qtPro.AddMocStep(vcFile);
                    }
                }
                else if (vcFile.Name.EndsWith(".ui"))
                {
                    if (filter == null && !HelperFunctions.IsInFilter(vcFile, ui))
                    {
                        if (null == uiFilter && qtPro.VCProject.CanAddFilter(ui.Name))
                        {
                            uiFilter                  = (VCFilter)qtPro.VCProject.AddFilter(ui.Name);
                            uiFilter.Filter           = ui.Filter;
                            uiFilter.ParseFiles       = ui.ParseFiles;
                            uiFilter.UniqueIdentifier = ui.UniqueIdentifier;
                        }
                        qtPro.RemoveItem(projectItem);
                        qtPro.AddFileToProject(vcFile.FullPath, ui);
                    }
//#if (VS2010 || VS2012 || VS2013 || VS2015)
                    HelperFunctions.EnsureCustomBuildToolAvailable(projectItem);
//#endif
                    qtPro.AddUic4BuildStep(vcFile);
                }
                else if (vcFile.Name.EndsWith(".qrc"))
                {
                    if (filter == null && !HelperFunctions.IsInFilter(vcFile, qrc))
                    {
                        if (null == qrcFilter && qtPro.VCProject.CanAddFilter(qrc.Name))
                        {
                            qrcFilter                  = (VCFilter)qtPro.VCProject.AddFilter(qrc.Name);
                            qrcFilter.Filter           = qrc.Filter;
                            qrcFilter.ParseFiles       = qrc.ParseFiles;
                            qrcFilter.UniqueIdentifier = qrc.UniqueIdentifier;
                        }
                        qtPro.RemoveItem(projectItem);
                        qtPro.AddFileToProject(vcFile.FullPath, qrc);
                    }
//#if (VS2010 || VS2012 || VS2013 || VS2015)
                    HelperFunctions.EnsureCustomBuildToolAvailable(projectItem);
//#endif
                    qtPro.UpdateRccStep(vcFile, null);
                }
                else if (HelperFunctions.IsTranslationFile(vcFile))
                {
                    if (filter == null && !HelperFunctions.IsInFilter(vcFile, ts))
                    {
                        if (null == tsFilter && qtPro.VCProject.CanAddFilter(ts.Name))
                        {
                            tsFilter                  = (VCFilter)qtPro.VCProject.AddFilter(ts.Name);
                            tsFilter.Filter           = ts.Filter;
                            tsFilter.ParseFiles       = ts.ParseFiles;
                            tsFilter.UniqueIdentifier = ts.UniqueIdentifier;
                        }
                        qtPro.RemoveItem(projectItem);
                        qtPro.AddFileToProject(vcFile.FullPath, ts);
                    }
                }
            }
            catch { }

            return;
        }