Example #1
0
		bool Supports (IVsHierarchyItem item, out IVsHierarchyItem actualItem)
		{
			actualItem = item;
			if (!item.HierarchyIdentity.IsRoot)
				return false;

			// We need the hierarchy fully loaded if it's not yet.
			if (!item.GetProperty<bool> (__VSPROPID4.VSPROPID_IsSolutionFullyLoaded)) {
				Guid guid;
				if (ErrorHandler.Succeeded (item.GetActualHierarchy ().GetGuidProperty ((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out guid)) &&
					// For the solution root item itself, the GUID will be empty.
					guid != Guid.Empty) {
					if (ErrorHandler.Succeeded (((IVsSolution4)solution.Value).EnsureProjectIsLoaded (ref guid, (uint)__VSBSLFLAGS.VSBSLFLAGS_None)))
						actualItem = hierarchyManager.GetHierarchyItem (item.GetActualHierarchy (), item.GetActualItemId ());
				}
			}

			if (!(actualItem.GetActualHierarchy () is IVsProject))
				return false;

			// Finally, solution folders look like projects, but they are not.
			// We need to filter them out too.
			var extenderObject = actualItem.GetExtenderObject();
			var dteProject = extenderObject as EnvDTE.Project;

			if (extenderObject != null && extenderObject.GetType ().FullName == "Microsoft.VisualStudio.Project.Automation.OAProject")
				return false;

			if (extenderObject != null && dteProject != null && (dteProject.Object is EnvDTE80.SolutionFolder))
				return false;

			return true;
		}
Example #2
0
        bool Supports(IVsHierarchyItem item, out IVsHierarchyItem actualItem)
        {
            actualItem = item;
            if (!item.HierarchyIdentity.IsRoot)
            {
                return(false);
            }

            // We need the hierarchy fully loaded if it's not yet.
            if (!item.GetProperty <bool>(__VSPROPID4.VSPROPID_IsSolutionFullyLoaded))
            {
                // EnsureProjectIsLoaded MUST be executed in the UI/Main thread
                // Otherwise (if the Supports method is being invoked from a worker thread) duplicate keys might be generated
                actualItem = asyncManager.Run(async() =>
                {
                    await asyncManager.SwitchToMainThreadAsync();

                    Guid guid;
                    if (ErrorHandler.Succeeded(item.GetActualHierarchy().GetGuidProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out guid)) &&
                        // For the solution root item itself, the GUID will be empty.
                        guid != Guid.Empty)
                    {
                        if (ErrorHandler.Succeeded(((IVsSolution4)solution.GetValue()).EnsureProjectIsLoaded(ref guid, (uint)__VSBSLFLAGS.VSBSLFLAGS_None)))
                        {
                            return(hierarchyManager.GetHierarchyItem(item.GetActualHierarchy(), item.GetActualItemId()));
                        }
                    }

                    return(item);
                });
            }

            var hierarchy = actualItem.GetActualHierarchy();

            if (!(actualItem.GetActualHierarchy() is IVsProject) && !(hierarchy is FlavoredProjectBase))
            {
                return(false);
            }

            // Finally, solution folders look like projects, but they are not.
            // We need to filter them out too.
            var extenderObject = actualItem.GetExtenderObject();
            var dteProject     = extenderObject as EnvDTE.Project;

            if (extenderObject != null && extenderObject.GetType().FullName == "Microsoft.VisualStudio.Project.Automation.OAProject")
            {
                return(false);
            }

            if (extenderObject != null && dteProject != null && (dteProject.Object is EnvDTE80.SolutionFolder))
            {
                return(false);
            }

            return(true);
        }
Example #3
0
        bool Supports(IVsHierarchyItem item, out IVsHierarchyItem actualItem)
        {
            actualItem = item;
            if (!item.HierarchyIdentity.IsRoot)
            {
                return(false);
            }

            // We need the hierarchy fully loaded if it's not yet.
            if (!item.GetProperty <bool>(__VSPROPID4.VSPROPID_IsSolutionFullyLoaded))
            {
                Guid guid;
                if (ErrorHandler.Succeeded(item.GetActualHierarchy().GetGuidProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out guid)) &&
                    // For the solution root item itself, the GUID will be empty.
                    guid != Guid.Empty)
                {
                    if (ErrorHandler.Succeeded(((IVsSolution4)solution.Value).EnsureProjectIsLoaded(ref guid, (uint)__VSBSLFLAGS.VSBSLFLAGS_None)))
                    {
                        actualItem = hierarchyManager.GetHierarchyItem(item.GetActualHierarchy(), item.GetActualItemId());
                    }
                }
            }

            if (!(actualItem.GetActualHierarchy() is IVsProject))
            {
                return(false);
            }

            // Finally, solution folders look like projects, but they are not.
            // We need to filter them out too.
            var extenderObject = actualItem.GetExtenderObject();
            var dteProject     = extenderObject as EnvDTE.Project;

            if (extenderObject != null && extenderObject.GetType().FullName == "Microsoft.VisualStudio.Project.Automation.OAProject")
            {
                return(false);
            }

            if (extenderObject != null && dteProject != null && (dteProject.Object is EnvDTE80.SolutionFolder))
            {
                return(false);
            }

            return(true);
        }
Example #4
0
        public static void Dump(this IVsHierarchyItem item, ITestOutputHelper output, params int[] additionalProperties)
        {
            using (var indented = new IndentedTestOutputHeper(output))
            {
                indented.WriteLine(PropertyValue, "Name", item.GetProperty <string>(VsHierarchyPropID.Name));
                indented.WriteLine(PropertyValue, "Text", item.Text);
                foreach (var propertyId in additionalProperties)
                {
                    if (!WritePropertyIfDefined(item, indented, propertyId, typeof(__VSPROPID)))
                    {
                        if (!WritePropertyIfDefined(item, indented, propertyId, typeof(__VSPROPID2)))
                        {
                            if (!WritePropertyIfDefined(item, indented, propertyId, typeof(__VSPROPID3)))
                            {
                                if (!WritePropertyIfDefined(item, indented, propertyId, typeof(__VSPROPID4)))
                                {
                                    if (!WritePropertyIfDefined(item, indented, propertyId, typeof(__VSPROPID5)))
                                    {
                                        if (!WritePropertyIfDefined(item, indented, propertyId, typeof(VsHierarchyPropID)))
                                        {
                                            indented.WriteLine(PropertyValue, propertyId, item.GetProperty(propertyId));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                string fullPath;
                if (ErrorHandler.Succeeded(item.GetActualHierarchy().GetCanonicalName(item.GetActualItemId(), out fullPath)) && File.Exists(fullPath))
                {
                    indented.WriteLine(PropertyValue, "FullPath", fullPath);
                }

                if (item.Children.Any())
                {
                    indented.WriteLine("Children = ");
                    using (var childIndent = new IndentedTestOutputHeper(indented, begin: "[", end: "]"))
                    {
                        foreach (var child in item.Children)
                        {
                            child.Dump(childIndent, additionalProperties);
                        }
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Gets the inner hierarchy of the flavored proejct
        /// when the actual hierarchy of the item is an instance of <see cref="FlavoredProjectBase"/>
        /// </summary>
        public static bool TryGetInnerHierarchy(this IVsHierarchyItem item, out IVsHierarchy innerHierarchy)
        {
            innerHierarchy = null;

            var hierarchy = item.GetActualHierarchy();

            if (hierarchy is FlavoredProjectBase)
            {
                innerHierarchy = hierarchy
                                 .GetType()
                                 .GetField("_innerVsHierarchy", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)?
                                 .GetValue(hierarchy) as IVsHierarchy;
            }

            return(innerHierarchy != null);
        }