Ejemplo n.º 1
0
        private static ICollection <VsHierarchyItem> GetExpandedProjectHierarchyItems(Project project)
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            VsHierarchyItem      projectHierarchyItem   = GetHierarchyItemForProject(project);
            IVsUIHierarchyWindow solutionExplorerWindow = GetSolutionExplorerHierarchyWindow();

            if (solutionExplorerWindow == null)
            {
                // If the solution explorer is collapsed since opening VS, this value is null. In such a case, simply exit early.
                return(new VsHierarchyItem[0]);
            }

            var expandedItems = new List <VsHierarchyItem>();

            // processCallback return values:
            //     0   continue,
            //     1   don't recurse into,
            //    -1   stop
            projectHierarchyItem.WalkDepthFirst(
                fVisible: true,
                processCallback:
                (VsHierarchyItem vsItem, object callerObject, out object newCallerObject) =>
            {
                newCallerObject = null;
                if (IsVsHierarchyItemExpanded(vsItem, solutionExplorerWindow))
                {
                    expandedItems.Add(vsItem);
                }
                return(0);
            },
                callerObject: null);

            return(expandedItems);
        }
Ejemplo n.º 2
0
        private static void CollapseProjectHierarchyItems(Project project, ISet <VsHierarchyItem> ignoredHierarcyItems)
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            VsHierarchyItem      projectHierarchyItem   = GetHierarchyItemForProject(project);
            IVsUIHierarchyWindow solutionExplorerWindow = GetSolutionExplorerHierarchyWindow();

            if (solutionExplorerWindow == null)
            {
                // If the solution explorer is collapsed since opening VS, this value is null. In such a case, simply exit early.
                return;
            }

            // processCallback return values:
            //     0   continue,
            //     1   don't recurse into,
            //    -1   stop
            projectHierarchyItem.WalkDepthFirst(
                fVisible: true,
                processCallback:
                (VsHierarchyItem currentHierarchyItem, object callerObject, out object newCallerObject) =>
            {
                newCallerObject = null;
                if (!ignoredHierarcyItems.Contains(currentHierarchyItem))
                {
                    CollapseVsHierarchyItem(currentHierarchyItem, solutionExplorerWindow);
                }
                return(0);
            },
                callerObject: null);
        }
Ejemplo n.º 3
0
        public async Task <IVsProjectAdapter> CreateAdapterForDeferredProjectAsync(IVsHierarchy project)
        {
            Assumes.Present(project);

            await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync();

            var vsHierarchyItem = VsHierarchyItem.FromVsHierarchy(project);
            var fullProjectPath = VsHierarchyUtility.GetProjectPath(project);

            var uniqueName = string.Empty;

            _vsSolution.Value.GetUniqueNameOfProject(project, out uniqueName);

            var projectNames = new ProjectNames(
                fullName: fullProjectPath,
                uniqueName: uniqueName,
                shortName: Path.GetFileNameWithoutExtension(fullProjectPath),
                customUniqueName: GetCustomUniqueName(uniqueName));

            var workspaceBuildProperties = new WorkspaceProjectBuildProperties(
                fullProjectPath, _workspaceService.Value, _threadingService);

            var projectTypeGuid = await _workspaceService.Value.GetProjectTypeGuidAsync(fullProjectPath);

            return(new VsProjectAdapter(
                       vsHierarchyItem,
                       projectNames,
                       fullProjectPath,
                       projectTypeGuid,
                       EnsureProjectIsLoaded,
                       workspaceBuildProperties,
                       _threadingService,
                       _workspaceService.Value));
        }
Ejemplo n.º 4
0
        public async Task <IVsProjectAdapter> CreateAdapterForFullyLoadedProjectAsync(EnvDTE.Project dteProject)
        {
            Assumes.Present(dteProject);

            await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync();

            var vsHierarchyItem = VsHierarchyItem.FromDteProject(dteProject);
            Func <IVsHierarchy, EnvDTE.Project> loadDteProject = _ => dteProject;

            var buildStorageProperty = vsHierarchyItem.VsHierarchy as IVsBuildPropertyStorage;
            var vsBuildProperties    = new VsProjectBuildProperties(
                dteProject, buildStorageProperty, _threadingService);

            var projectNames = await ProjectNames.FromDTEProjectAsync(dteProject);

            var fullProjectPath = EnvDTEProjectInfoUtility.GetFullProjectPath(dteProject);

            return(new VsProjectAdapter(
                       vsHierarchyItem,
                       projectNames,
                       fullProjectPath,
                       dteProject.Kind,
                       loadDteProject,
                       vsBuildProperties,
                       _threadingService));
        }
Ejemplo n.º 5
0
        public async Task <IVsProjectAdapter> CreateAdapterForFullyLoadedProjectAsync(EnvDTE.Project dteProject)
        {
            Assumes.Present(dteProject);

            _threadingService.ThrowIfNotOnUIThread();

            var vsHierarchyItem = VsHierarchyItem.FromDteProject(dteProject);
            Func <IVsHierarchy, EnvDTE.Project> loadDteProject = _ => dteProject;

            IProjectBuildProperties vsBuildProperties;

            if (vsHierarchyItem.VsHierarchy is IVsBuildPropertyStorage)
            {
                vsBuildProperties = new VsManagedLanguagesProjectBuildProperties(
                    vsHierarchyItem.VsHierarchy as IVsBuildPropertyStorage, _threadingService);
            }
            else
            {
                vsBuildProperties = new VsCoreProjectBuildProperties(dteProject, _threadingService);
            }

            var projectNames = await ProjectNames.FromDTEProjectAsync(dteProject);

            var fullProjectPath = EnvDTEProjectInfoUtility.GetFullProjectPath(dteProject);

            return(new VsProjectAdapter(
                       vsHierarchyItem,
                       projectNames,
                       fullProjectPath,
                       dteProject.Kind,
                       loadDteProject,
                       vsBuildProperties,
                       _threadingService));
        }
Ejemplo n.º 6
0
        public async Task <IVsProjectAdapter> CreateAdapterForFullyLoadedProjectAsync(EnvDTE.Project dteProject)
        {
            Assumes.Present(dteProject);

            // Get services while we might be on background thread
            var vsSolution = await _vsSolution.GetValueAsync();

            // switch to main thread and use services we know must be done on main thread.
            await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync();

            var vsHierarchyItem = await VsHierarchyItem.FromDteProjectAsync(dteProject);

            Func <IVsHierarchy, EnvDTE.Project> loadDteProject = _ => dteProject;

            var buildStorageProperty = vsHierarchyItem.VsHierarchy as IVsBuildPropertyStorage;
            var vsBuildProperties    = new VsProjectBuildProperties(
                dteProject, buildStorageProperty, _threadingService);

            var projectNames = await ProjectNames.FromDTEProjectAsync(dteProject, vsSolution);

            var fullProjectPath = dteProject.GetFullProjectPath();

            return(new VsProjectAdapter(
                       vsHierarchyItem,
                       projectNames,
                       fullProjectPath,
                       dteProject.Kind,
                       loadDteProject,
                       vsBuildProperties,
                       _threadingService));
        }
Ejemplo n.º 7
0
        public async Task <IVsProjectAdapter> CreateAdapterForFullyLoadedProjectAsync(IVsHierarchy hierarchy)
        {
            Assumes.Present(hierarchy);

            // Get services while we might be on background thread
            var vsSolution = await _vsSolution.GetValueAsync();

            // switch to main thread and use services we know must be done on main thread.
            await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync();

            var vsHierarchyItem = VsHierarchyItem.FromVsHierarchy(hierarchy);
            Func <IVsHierarchy, EnvDTE.Project> loadDteProject = hierarchy => VsHierarchyUtility.GetProjectFromHierarchy(hierarchy);

            var buildStorageProperty = vsHierarchyItem.VsHierarchy as IVsBuildPropertyStorage;
            var vsBuildProperties    = new VsProjectBuildProperties(
                new Lazy <EnvDTE.Project>(() => loadDteProject(hierarchy)), buildStorageProperty, _threadingService);

            var fullProjectPath = VsHierarchyUtility.GetProjectPath(hierarchy);
            var projectNames    = await ProjectNames.FromIVsSolution2(fullProjectPath, (IVsSolution2)vsSolution, hierarchy, CancellationToken.None);

            return(new VsProjectAdapter(
                       vsHierarchyItem,
                       projectNames,
                       fullProjectPath,
                       loadDteProject,
                       vsBuildProperties,
                       _threadingService));
        }
Ejemplo n.º 8
0
        private static void CollapseVsHierarchyItem(VsHierarchyItem vsHierarchyItem, IVsUIHierarchyWindow vsHierarchyWindow)
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            if (vsHierarchyItem == null ||
                vsHierarchyWindow == null)
            {
                return;
            }

            vsHierarchyWindow.ExpandItem(vsHierarchyItem.UIHierarchy(), vsHierarchyItem.VsItemID, EXPANDFLAGS.EXPF_CollapseFolder);
        }
Ejemplo n.º 9
0
        private static bool IsVsHierarchyItemExpanded(VsHierarchyItem hierarchyItem, IVsUIHierarchyWindow uiWindow)
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            if (!hierarchyItem.IsExpandable())
            {
                return(false);
            }

            const uint expandedStateMask = (uint)__VSHIERARCHYITEMSTATE.HIS_Expanded;
            uint       itemState;

            uiWindow.GetItemState(hierarchyItem.UIHierarchy(), hierarchyItem.VsItemID, expandedStateMask, out itemState);
            return((__VSHIERARCHYITEMSTATE)itemState == __VSHIERARCHYITEMSTATE.HIS_Expanded);
        }
Ejemplo n.º 10
0
        public VsProjectAdapter(
            VsHierarchyItem vsHierarchyItem,
            ProjectNames projectNames,
            string fullProjectPath,
            Func <IVsHierarchy, EnvDTE.Project> loadDteProject,
            IProjectBuildProperties buildProperties,
            IVsProjectThreadingService threadingService)
        {
            Assumes.Present(vsHierarchyItem);

            _vsHierarchyItem  = vsHierarchyItem;
            _dteProject       = new Lazy <EnvDTE.Project>(() => loadDteProject(_vsHierarchyItem.VsHierarchy));
            _threadingService = threadingService;
            FullProjectPath   = fullProjectPath;
            ProjectNames      = projectNames;
            BuildProperties   = buildProperties;
        }
Ejemplo n.º 11
0
        public VsProjectAdapter(
            VsHierarchyItem vsHierarchyItem,
            ProjectNames projectNames,
            string fullProjectPath,
            string projectTypeGuid,
            Func <IVsHierarchy, EnvDTE.Project> loadDteProject,
            IProjectBuildProperties buildProperties,
            IVsProjectThreadingService threadingService,
            IDeferredProjectWorkspaceService workspaceService = null)
        {
            Assumes.Present(vsHierarchyItem);

            _vsHierarchyItem  = vsHierarchyItem;
            _dteProject       = new Lazy <EnvDTE.Project>(() => loadDteProject(_vsHierarchyItem.VsHierarchy));
            _workspaceService = workspaceService;
            _threadingService = threadingService;
            _projectTypeGuid  = projectTypeGuid;

            FullProjectPath = fullProjectPath;
            ProjectNames    = projectNames;
            BuildProperties = buildProperties;
        }