diff --git a/src/toolkit/Community.VisualStudio.Toolkit.Shared/ExtensionMethods/IVsHierarchyExtensions.cs b/src/toolkit/Community.VisualStudio.Toolkit.Shared/ExtensionMethods/IVsHierarchyExtensions.cs index 33259bf..f6cda36 100644 --- a/src/toolkit/Community.VisualStudio.Toolkit.Shared/ExtensionMethods/IVsHierarchyExtensions.cs +++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/ExtensionMethods/IVsHierarchyExtensions.cs @@ -132,5 +132,37 @@ public static bool IsSharedProject(this IVsHierarchy hierarchy) return hierarchy.GetSharedAssetsProject() != null; } + + /// + /// Returns the for the + /// + /// + /// + public static IVsHierarchy GetHierarchy(this IVsHierarchyItemIdentity item) => + item.IsNestedItem ? item.NestedHierarchy : item.Hierarchy; + + /// + /// Returns the 'ItemId' for the + /// + /// + /// + public static uint GetItemId(this IVsHierarchyItemIdentity item) => + item.IsNestedItem ? item.NestedItemID : item.ItemID; + + /// + /// Returns the for the + /// + /// + /// + public static IVsHierarchy GetHierarchy(this IVsHierarchyItem item) => + item.HierarchyIdentity.GetHierarchy(); + + /// + /// Returns the 'ItemId' for the + /// + /// + /// + public static uint GetItemId(this IVsHierarchyItem item) => + item.HierarchyIdentity.GetItemId(); } } diff --git a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs index 6431d07..7dd69a3 100644 --- a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs +++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs @@ -3,7 +3,6 @@ using System.Diagnostics; using System.Linq; using System.Threading.Tasks; -using System.Windows.Automation.Peers; using Microsoft.Internal.VisualStudio.PlatformUI; using Microsoft.VisualStudio; using Microsoft.VisualStudio.Shell; @@ -23,6 +22,7 @@ public class SolutionItem private IVsHierarchy _hierarchy = default!; // Initialized to non-null via the `Update()` method. private string? _fullPath; private uint _itemId; + private Lazy _isNonVisibleItem = default!; // Initialized to non-null via the `Update()` method. /// /// Creates a new instance of the solution item. @@ -38,9 +38,13 @@ internal void Update(IVsHierarchyItem item) { ThreadHelper.ThrowIfNotOnUIThread(); _item = item; - _hierarchy = item.HierarchyIdentity.IsNestedItem ? item.HierarchyIdentity.NestedHierarchy : item.HierarchyIdentity.Hierarchy; - _itemId = item.HierarchyIdentity.IsNestedItem ? item.HierarchyIdentity.NestedItemID : item.HierarchyIdentity.ItemID; + _hierarchy = item.GetHierarchy(); + _itemId = item.GetItemId(); _fullPath = GetFullPath(); + _isNonVisibleItem = new Lazy(() => + { + return HierarchyUtilities.TryGetHierarchyProperty(_hierarchy, _itemId, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, out bool isNonMemberItem) && isNonMemberItem; + }); } /// @@ -73,6 +77,11 @@ internal void Update(IVsHierarchyItem item) /// public IEnumerable Children => _children ??= _item.Children.Select(t => FromHierarchyItem(t)); + /// + /// Returns whether the item is normally hidden in solution explorer and only visible when Show All Files is enabled. + /// + public bool IsNonVisibleItem => _isNonVisibleItem.Value; + /// /// Gets information from the underlying data types. /// @@ -128,7 +137,7 @@ public void GetItemInfo(out IVsHierarchy hierarchy, out uint itemId, out IVsHier { throw new ArgumentNullException(nameof(hierarchy)); } - + ThreadHelper.ThrowIfNotOnUIThread(); IVsHierarchyItem item = hierarchy.ToHierarchyItem(itemId);