From 7d555d293577b64a580fb0bdfea6cf158e26aca7 Mon Sep 17 00:00:00 2001 From: Steven Rasmussen Date: Sat, 17 Dec 2022 20:20:07 -0700 Subject: [PATCH 1/3] Adds the 'IsNonVisibleItem' property to the 'SolutionItem' class. --- .../Helpers/IVsHierarchyItem.cs | 43 +++++++++++++++++++ .../Solution/SolutionItem.cs | 23 ++++++++-- .../VSSDK.Helpers.Shared.projitems | 1 + 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 src/toolkit/Community.VisualStudio.Toolkit.Shared/Helpers/IVsHierarchyItem.cs diff --git a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Helpers/IVsHierarchyItem.cs b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Helpers/IVsHierarchyItem.cs new file mode 100644 index 0000000..1ffa78f --- /dev/null +++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Helpers/IVsHierarchyItem.cs @@ -0,0 +1,43 @@ +using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; + +namespace Community.VisualStudio.Toolkit.Shared.Helpers +{ + /// + /// Extensions for the interface. + /// + public static class VsHierarchyExtensions + { + /// + /// 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..29878f5 100644 --- a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs +++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs @@ -3,7 +3,7 @@ using System.Diagnostics; using System.Linq; using System.Threading.Tasks; -using System.Windows.Automation.Peers; +using Community.VisualStudio.Toolkit.Shared.Helpers; using Microsoft.Internal.VisualStudio.PlatformUI; using Microsoft.VisualStudio; using Microsoft.VisualStudio.Shell; @@ -23,6 +23,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 +39,18 @@ 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(() => + { + if (HierarchyUtilities.TryGetHierarchyProperty(_hierarchy, _itemId, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, out bool isNonMemberItem) + && isNonMemberItem) + { + return isNonMemberItem; + } + return false; + }); } /// @@ -73,6 +83,11 @@ internal void Update(IVsHierarchyItem item) /// public IEnumerable Children => _children ??= _item.Children.Select(t => FromHierarchyItem(t)); + /// + /// Returns whether the item is normally visible in soltuion explorer + /// + public bool IsNonVisibleItem => _isNonVisibleItem.Value; + /// /// Gets information from the underlying data types. /// @@ -128,7 +143,7 @@ public void GetItemInfo(out IVsHierarchy hierarchy, out uint itemId, out IVsHier { throw new ArgumentNullException(nameof(hierarchy)); } - + ThreadHelper.ThrowIfNotOnUIThread(); IVsHierarchyItem item = hierarchy.ToHierarchyItem(itemId); diff --git a/src/toolkit/Community.VisualStudio.Toolkit.Shared/VSSDK.Helpers.Shared.projitems b/src/toolkit/Community.VisualStudio.Toolkit.Shared/VSSDK.Helpers.Shared.projitems index 968b78f..5807193 100644 --- a/src/toolkit/Community.VisualStudio.Toolkit.Shared/VSSDK.Helpers.Shared.projitems +++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/VSSDK.Helpers.Shared.projitems @@ -10,6 +10,7 @@ + From 6bab17ce68d94016cc21d1ceb774b0f1a4c46f46 Mon Sep 17 00:00:00 2001 From: Steven Rasmussen Date: Sun, 18 Dec 2022 08:40:34 -0700 Subject: [PATCH 2/3] Addressed PR feedback. --- .../Solution/SolutionItem.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs index 29878f5..5f82eeb 100644 --- a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs +++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs @@ -44,12 +44,7 @@ internal void Update(IVsHierarchyItem item) _fullPath = GetFullPath(); _isNonVisibleItem = new Lazy(() => { - if (HierarchyUtilities.TryGetHierarchyProperty(_hierarchy, _itemId, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, out bool isNonMemberItem) - && isNonMemberItem) - { - return isNonMemberItem; - } - return false; + return HierarchyUtilities.TryGetHierarchyProperty(_hierarchy, _itemId, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, out bool isNonMemberItem) && isNonMemberItem; }); } @@ -84,7 +79,7 @@ internal void Update(IVsHierarchyItem item) public IEnumerable Children => _children ??= _item.Children.Select(t => FromHierarchyItem(t)); /// - /// Returns whether the item is normally visible in soltuion explorer + /// Returns whether the item is normally hidden in solution explorer and only visible when Show All Files is enabled. /// public bool IsNonVisibleItem => _isNonVisibleItem.Value; From 95335a686896eec6fae263ed0fde23151a314b80 Mon Sep 17 00:00:00 2001 From: Steven Rasmussen Date: Sun, 18 Dec 2022 08:44:59 -0700 Subject: [PATCH 3/3] Moved extension methods to the correct class. --- .../IVsHierarchyExtensions.cs | 32 ++++++++++++++ .../Helpers/IVsHierarchyItem.cs | 43 ------------------- .../Solution/SolutionItem.cs | 1 - .../VSSDK.Helpers.Shared.projitems | 1 - 4 files changed, 32 insertions(+), 45 deletions(-) delete mode 100644 src/toolkit/Community.VisualStudio.Toolkit.Shared/Helpers/IVsHierarchyItem.cs 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/Helpers/IVsHierarchyItem.cs b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Helpers/IVsHierarchyItem.cs deleted file mode 100644 index 1ffa78f..0000000 --- a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Helpers/IVsHierarchyItem.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Shell.Interop; - -namespace Community.VisualStudio.Toolkit.Shared.Helpers -{ - /// - /// Extensions for the interface. - /// - public static class VsHierarchyExtensions - { - /// - /// 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 5f82eeb..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 Community.VisualStudio.Toolkit.Shared.Helpers; using Microsoft.Internal.VisualStudio.PlatformUI; using Microsoft.VisualStudio; using Microsoft.VisualStudio.Shell; diff --git a/src/toolkit/Community.VisualStudio.Toolkit.Shared/VSSDK.Helpers.Shared.projitems b/src/toolkit/Community.VisualStudio.Toolkit.Shared/VSSDK.Helpers.Shared.projitems index 5807193..968b78f 100644 --- a/src/toolkit/Community.VisualStudio.Toolkit.Shared/VSSDK.Helpers.Shared.projitems +++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/VSSDK.Helpers.Shared.projitems @@ -10,7 +10,6 @@ -