private void HandleAddItems(int cProjects, int cItems, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDocuments)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (AfterAddProjectItems != null)
            {
                List <SolutionItem> addedItems = new();
                for (int projectIndex = 0; projectIndex < cProjects; projectIndex++)
                {
                    int          firstIndex  = rgFirstIndices[projectIndex];
                    IVsProject   vsProject   = rgpProjects[projectIndex];
                    IVsHierarchy vsHierarchy = (IVsHierarchy)vsProject;

                    int nextProjectIndex = cItems;
                    if (rgFirstIndices.Length > projectIndex + 1)
                    {
                        nextProjectIndex = rgFirstIndices[projectIndex + 1];
                    }

                    for (int itemIndex = firstIndex; itemIndex < nextProjectIndex; itemIndex++)
                    {
                        string itemName = rgpszMkDocuments[itemIndex];
                        vsProject.IsDocumentInProject(itemName, out _, new VSDOCUMENTPRIORITY[1], out uint itemid);
                        SolutionItem?projectFile = SolutionItem.FromHierarchy(vsHierarchy, itemid);
                        if (projectFile != null)
                        {
                            addedItems.Add(projectFile);
                        }
                    }
                }

                AfterAddProjectItems?.Invoke(addedItems);
            }
        }
        private void HandleRenamedItems(int cProjects, int cItems, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (AfterRenameProjectItems != null)
            {
                List <ProjectItemRenameDetails> renameParams = new();
                for (int projectIndex = 0; projectIndex < cProjects; projectIndex++)
                {
                    int          firstIndex  = rgFirstIndices[projectIndex];
                    IVsProject   vsProject   = rgpProjects[projectIndex];
                    IVsHierarchy vsHierarchy = (IVsHierarchy)vsProject;

                    int nextProjectIndex = cItems;
                    if (rgFirstIndices.Length > projectIndex + 1)
                    {
                        nextProjectIndex = rgFirstIndices[projectIndex + 1];
                    }

                    for (int itemIndex = firstIndex; itemIndex < nextProjectIndex; itemIndex++)
                    {
                        string newName = rgszMkNewNames[itemIndex];
                        string oldName = rgszMkOldNames[itemIndex];
                        vsProject.IsDocumentInProject(newName, out _, new VSDOCUMENTPRIORITY[1], out uint itemid);
                        SolutionItem?projectFile = SolutionItem.FromHierarchy(vsHierarchy, itemid);
                        renameParams.Add(new ProjectItemRenameDetails(projectFile, oldName));
                    }
                }

                AfterRenameProjectItems?.Invoke(new AfterRenameProjectItemEventArgs(renameParams.ToArray()));
            }
        }
        private void HandleRemoveItems(int cProjects, int cItems, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDocuments)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (AfterRemoveProjectItems != null)
            {
                List <ProjectItemRemoveDetails> removedItems = new();
                for (int projectIndex = 0; projectIndex < cProjects; projectIndex++)
                {
                    int          firstIndex  = rgFirstIndices[projectIndex];
                    IVsProject   vsProject   = rgpProjects[projectIndex];
                    IVsHierarchy vsHierarchy = (IVsHierarchy)vsProject;
                    Project?     project     = SolutionItem.FromHierarchy(vsHierarchy, VSConstants.VSITEMID_ROOT) as Project;

                    int nextProjectIndex = cItems;
                    if (rgFirstIndices.Length > projectIndex + 1)
                    {
                        nextProjectIndex = rgFirstIndices[projectIndex + 1];
                    }

                    for (int itemIndex = firstIndex; itemIndex < nextProjectIndex; itemIndex++)
                    {
                        string itemName = rgpszMkDocuments[itemIndex];
                        removedItems.Add(new ProjectItemRemoveDetails(project, itemName));
                    }
                }

                AfterRemoveProjectItems?.Invoke(new AfterRemoveProjectItemEventArgs(removedItems.ToArray()));
            }
        }
        int IVsUpdateSolutionEvents2.UpdateProjectCfg_Begin(IVsHierarchy pHierProj, IVsCfg pCfgProj, IVsCfg pCfgSln, uint dwAction, ref int pfCancel)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            // This method is called when a specific project begins building.

            // if clean project or solution,   dwAction == 0x100000
            // if build project or solution,   dwAction == 0x010000
            // if rebuild project or solution, dwAction == 0x410000
            if (ProjectCleanStarted != null || ProjectBuildStarted != null)
            {
                Project?project = SolutionItem.FromHierarchy(pHierProj, VSConstants.VSITEMID_ROOT) as Project;

                // Clean
                if (dwAction == 0x100000)
                {
                    ProjectCleanStarted?.Invoke(project);
                }
                // Build and rebuild
                else
                {
                    ProjectBuildStarted?.Invoke(project);
                }
            }

            return(VSConstants.S_OK);
        }
 int IVsSolutionEvents.OnBeforeCloseProject(IVsHierarchy pHierarchy, int fRemoved)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     if (OnBeforeCloseProject != null)
     {
         Project?project = SolutionItem.FromHierarchy(pHierarchy, 1) as Project;
         OnBeforeCloseProject?.Invoke(project);
     }
     return(VSConstants.S_OK);
 }
 int IVsSolutionEvents.OnAfterLoadProject(IVsHierarchy pStubHierarchy, IVsHierarchy pRealHierarchy)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     if (OnAfterLoadProject != null)
     {
         Project?project = SolutionItem.FromHierarchy(pRealHierarchy, 1) as Project;
         OnAfterLoadProject?.Invoke(project);
     }
     return(VSConstants.S_OK);
 }
Ejemplo n.º 7
0
 int IVsSolutionEvents.OnAfterLoadProject(IVsHierarchy pStubHierarchy, IVsHierarchy pRealHierarchy)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     if (OnAfterLoadProject != null)
     {
         SolutionItem?item = SolutionItem.FromHierarchy(pStubHierarchy, VSConstants.VSITEMID_ROOT);
         if (item is Project project)
         {
             OnAfterLoadProject?.Invoke(project);
         }
     }
     return(VSConstants.S_OK);
 }
Ejemplo n.º 8
0
        int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (SelectionChanged != null)
            {
                SolutionItem?from = SolutionItem.FromHierarchy(pHierOld, itemidOld);
                SolutionItem?to   = SolutionItem.FromHierarchy(pHierNew, itemidNew);

                SelectionChanged.Invoke(this, new SelectionChangedEventArgs(from, to));
            }
            return(VSConstants.S_OK);
        }
Ejemplo n.º 9
0
        int IVsUpdateSolutionEvents.OnActiveProjectCfgChange(IVsHierarchy pIVsHierarchy)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (ProjectConfigurationChanged != null && pIVsHierarchy != null)
            {
                Project?project = SolutionItem.FromHierarchy(pIVsHierarchy, VSConstants.VSITEMID_ROOT) as Project;
                ProjectConfigurationChanged?.Invoke(project);
            }

            if (SolutionConfigurationChanged != null && pIVsHierarchy == null)
            {
                SolutionConfigurationChanged?.Invoke();
            }

            return(VSConstants.S_OK);
        }
Ejemplo n.º 10
0
        int IVsSolutionEvents.OnAfterOpenProject(IVsHierarchy pHierarchy, int fAdded)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (OnAfterOpenProject != null)
            {
                SolutionItem?item = SolutionItem.FromHierarchy(pHierarchy, VSConstants.VSITEMID_ROOT) as Project;
                if (item is Project project)
                {
                    OnAfterOpenProject?.Invoke(project);
                }
#if VS14
                else if (item is SolutionFolder folder && folder.FullPath != null)
                {
                    OnAfterOpenFolder?.Invoke(folder.FullPath);
                }
#endif
            }
            return(VSConstants.S_OK);
        }
        int IVsUpdateSolutionEvents2.UpdateProjectCfg_Done(IVsHierarchy pHierProj, IVsCfg pCfgProj, IVsCfg pCfgSln, uint dwAction, int fSuccess, int fCancel)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            // This method is called when a specific project finishes building.
            if (ProjectBuildDone != null || ProjectCleanDone != null)
            {
                Project?project = SolutionItem.FromHierarchy(pHierProj, VSConstants.VSITEMID_ROOT) as Project;

                // Clean
                if (dwAction == 0x100000)
                {
                    ProjectCleanDone?.Invoke(new ProjectBuildDoneEventArgs(project, fSuccess == 1));
                }
                // Build and rebuild
                else
                {
                    ProjectBuildDone?.Invoke(new ProjectBuildDoneEventArgs(project, fSuccess == 1));
                }
            }

            return(VSConstants.S_OK);
        }
Ejemplo n.º 12
0
        /// <inheritdoc/>
        public IEnumerator <Reference> GetEnumerator()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // Not all projects can have references (for example Shared Projects),
            // so when enumerating over the references in the project, we won't throw
            // an error if the manager or provider context cannot be retrieved.
            if (TryGetManager(out IVsReferenceManagerUser manager))
            {
                IVsSharedProjectReferenceProviderContext?sharedProjectContext = null;

                foreach (IVsReferenceProviderContext context in manager.GetProviderContexts().OfType <IVsReferenceProviderContext>())
                {
                    // Remember the shared project context, because it may not actually provide the
                    // references to shared projects, meaning we may have to create them ourselves.
                    if (context is IVsSharedProjectReferenceProviderContext shared)
                    {
                        sharedProjectContext = shared;
                    }

                    foreach (IVsReference reference in context.References.OfType <IVsReference>())
                    {
                        if (reference is IVsAssemblyReference assemblyReference)
                        {
                            yield return(new AssemblyReference(assemblyReference));
                        }
                        else if (reference is IVsProjectReference projectReference)
                        {
                            yield return(new ProjectReference(projectReference));
                        }
                        else
                        {
                            yield return(new Reference(reference));
                        }
                    }
                }

                // Shared projects don't seem to be listed in the provider contexts, so if there is a context
                // for shared projects but it's empty, then we'll define the shared project references ourselves.
                if (sharedProjectContext is not null && sharedProjectContext.References.Length == 0)
                {
                    IVsSolution?solution = null;

                    _project.GetItemInfo(out IVsHierarchy hierarchy, out _, out _);

                    foreach (IVsHierarchy sharedHierarchy in hierarchy.EnumOwningProjectsOfSharedAssets())
                    {
                        // A shared project seems to list itself as an owning project, so ignore
                        // this hierarchy if it's the same one that we got from our project.
                        if (sharedHierarchy == hierarchy)
                        {
                            continue;
                        }

                        IVsSharedAssetsProject?sharedProject = sharedHierarchy.GetSharedAssetsProject();
                        if (sharedProject is not null)
                        {
                            Project?project = SolutionItem.FromHierarchy(sharedHierarchy, VSConstants.VSITEMID_ROOT) as Project;
                            if (project is not null)
                            {
                                if (solution is null)
                                {
                                    solution = VS.GetRequiredService <SVsSolution, IVsSolution>();
                                }

                                IVsSharedProjectReference reference = (IVsSharedProjectReference)sharedProjectContext.CreateReference();
                                PopulateSharedProjectReference(reference, solution, project, sharedProject);
                                yield return(new ProjectReference(reference));
                            }
                        }
                    }
                }
            }
        }