Skip to content

Commit 90be422

Browse files
authored
Improve view in Solution PM UI for Solution Explorer gold bar entry point (#6803)
1 parent 6dd19ee commit 90be422

5 files changed

Lines changed: 115 additions & 26 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
#nullable enable
5+
6+
namespace NuGet.PackageManagement.UI
7+
{
8+
public record PackageFilterOptions
9+
{
10+
public bool? ShowPrerelease { get; set; }
11+
public bool? ShowOnlyVulnerable { get; set; }
12+
}
13+
}

src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageManagerControl.xaml.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,25 @@ private void SelectMatchingUpdatePackages(ShowUpdatePackageOptions updatePackage
15701570
}
15711571
}
15721572

1573+
public void SelectPackageFilterOptions(PackageFilterOptions filterOptions)
1574+
{
1575+
ThreadHelper.ThrowIfNotOnUIThread();
1576+
if (filterOptions == null)
1577+
{
1578+
return;
1579+
}
1580+
1581+
if (filterOptions.ShowPrerelease.HasValue)
1582+
{
1583+
_topPanel.CheckboxPrerelease.IsChecked = filterOptions.ShowPrerelease;
1584+
}
1585+
1586+
if (filterOptions.ShowOnlyVulnerable.HasValue)
1587+
{
1588+
_topPanel._checkboxVulnerabilities.IsChecked = filterOptions.ShowOnlyVulnerable;
1589+
}
1590+
}
1591+
15731592
private void CleanUp()
15741593
{
15751594
NuGetUIThreadHelper.JoinableTaskFactory.Run(async () =>

src/NuGet.Clients/NuGet.Tools/NuGetPackage.cs

Lines changed: 64 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,39 +1019,55 @@ private async Task<IVsWindowFrame> CreateDocWindowForSolutionAsync()
10191019

10201020
private void ShowManageLibraryPackageForSolutionDialog(object sender, EventArgs e)
10211021
{
1022-
NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async delegate
1022+
PackageManagerShowOptions options = null;
1023+
if (e is OleMenuCmdEventArgs eventArgs)
10231024
{
1024-
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
1025-
1026-
if (ShouldInitializeSolutionExperiences())
1025+
if (eventArgs?.InValue is string parameterString)
10271026
{
1028-
await InitializeSolutionExperiencesAsync();
1027+
options = new PackageManagerShowOptions() { SearchText = parameterString };
10291028
}
1030-
1031-
var windowFrame = await FindExistingSolutionWindowFrameAsync();
1032-
if (windowFrame == null)
1029+
else if (eventArgs?.InValue is PackageManagerShowOptions parameterOptions)
10331030
{
1034-
// Create the window frame
1035-
windowFrame = await CreateDocWindowForSolutionAsync();
1031+
options = parameterOptions;
10361032
}
1037-
1038-
if (windowFrame != null)
1033+
else
10391034
{
1040-
// process search string
1041-
string parameterString = null;
1042-
var args = e as OleMenuCmdEventArgs;
1043-
if (args != null)
1044-
{
1045-
parameterString = args.InValue as string;
1046-
}
1047-
var searchText = GetSearchText(parameterString);
1048-
Search(windowFrame, searchText);
1049-
1050-
windowFrame.Show();
1035+
options = new PackageManagerShowOptions();
10511036
}
1037+
}
1038+
1039+
NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async delegate
1040+
{
1041+
await ShowManageLibraryPackageForSolutionDialogAsync(options);
10521042
}).PostOnFailure(nameof(NuGetPackage), nameof(ShowManageLibraryPackageForSolutionDialog));
10531043
}
10541044

1045+
private async Task<IVsWindowFrame> ShowManageLibraryPackageForSolutionDialogAsync(PackageManagerShowOptions options)
1046+
{
1047+
string searchText = GetSearchText(options.SearchText);
1048+
1049+
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
1050+
1051+
if (ShouldInitializeSolutionExperiences())
1052+
{
1053+
await InitializeSolutionExperiencesAsync();
1054+
}
1055+
1056+
var windowFrame = await FindExistingSolutionWindowFrameAsync();
1057+
// Create the window frame
1058+
windowFrame ??= await CreateDocWindowForSolutionAsync();
1059+
1060+
if (windowFrame != null)
1061+
{
1062+
SelectActiveItemFilter(windowFrame, options.ItemFilter);
1063+
SelectFilterOptions(windowFrame, options.PackageFilterOptions);
1064+
Search(windowFrame, searchText);
1065+
windowFrame.Show();
1066+
}
1067+
1068+
return windowFrame;
1069+
}
1070+
10551071
/// <summary>
10561072
/// Search for packages using the searchText.
10571073
/// </summary>
@@ -1090,6 +1106,31 @@ private void ShowUpdatePackages(IVsWindowFrame windowFrame, ShowUpdatePackageOpt
10901106
packageManagerControl?.ShowUpdatePackages(updatePackageOptions);
10911107
}
10921108

1109+
private static void SelectActiveItemFilter(IVsWindowFrame windowFrame, UI.ItemFilter? itemFilter)
1110+
{
1111+
ThreadHelper.ThrowIfNotOnUIThread();
1112+
1113+
if (itemFilter.HasValue)
1114+
{
1115+
var packageManagerControl = VsUtility.GetPackageManagerControl(windowFrame);
1116+
if (packageManagerControl != null)
1117+
{
1118+
packageManagerControl.ActiveFilter = itemFilter.Value;
1119+
}
1120+
}
1121+
}
1122+
1123+
private static void SelectFilterOptions(IVsWindowFrame windowFrame, PackageFilterOptions packageFilterOptions)
1124+
{
1125+
ThreadHelper.ThrowIfNotOnUIThread();
1126+
1127+
if (packageFilterOptions != null)
1128+
{
1129+
var packageManagerControl = VsUtility.GetPackageManagerControl(windowFrame);
1130+
packageManagerControl?.SelectPackageFilterOptions(packageFilterOptions);
1131+
}
1132+
}
1133+
10931134
// For PowerShell, it's okay to query from the worker thread.
10941135
private void BeforeQueryStatusForPowerConsole(object sender, EventArgs args)
10951136
{

src/NuGet.Clients/NuGet.Tools/PackageManagerLaunchService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System;
54
using System.ComponentModel.Composition;
65
using Microsoft.VisualStudio.Shell;
76
using Microsoft.VisualStudio.Shell.Interop;
87
using Microsoft.VisualStudio.Threading;
8+
using NuGet.PackageManagement.UI;
99
using NuGet.VisualStudio;
1010
using NuGet.VisualStudio.Telemetry;
1111

@@ -24,13 +24,13 @@ public void LaunchSolutionPackageManager()
2424
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
2525
IVsUIShell vsUIShell = await AsyncServiceProvider.GlobalProvider.GetServiceAsync<IVsUIShell, IVsUIShell>();
2626

27-
object targetGuid = Guid.Empty;
27+
object options = new PackageManagerShowOptions() { ItemFilter = ItemFilter.Installed, PackageFilterOptions = new PackageFilterOptions() { ShowOnlyVulnerable = true } };
2828
var guidNuGetDialog = GuidList.guidNuGetDialogCmdSet;
2929
vsUIShell.PostExecCommand(
3030
ref guidNuGetDialog,
3131
PkgCmdIDList.cmdidAddPackageDialogForSolution,
3232
0,
33-
ref targetGuid);
33+
ref options);
3434
}).PostOnFailure(nameof(PackageManagerLaunchService));
3535
}
3636
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
#nullable enable
5+
6+
using NuGet.PackageManagement.UI;
7+
8+
namespace NuGetVSExtension
9+
{
10+
internal record PackageManagerShowOptions
11+
{
12+
public string? SearchText { get; set; }
13+
public ItemFilter? ItemFilter { get; set; }
14+
public PackageFilterOptions? PackageFilterOptions { get; set; }
15+
}
16+
}

0 commit comments

Comments
 (0)