Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

namespace NuGet.PackageManagement.UI
{
public record PackageFilterOptions
{
public bool? ShowPrerelease { get; set; }
public bool? ShowOnlyVulnerable { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,25 @@ private void SelectMatchingUpdatePackages(ShowUpdatePackageOptions updatePackage
}
}

public void SelectPackageFilterOptions(PackageFilterOptions filterOptions)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (filterOptions == null)
{
return;
}

if (filterOptions.ShowPrerelease.HasValue)
{
_topPanel.CheckboxPrerelease.IsChecked = filterOptions.ShowPrerelease;
}

if (filterOptions.ShowOnlyVulnerable.HasValue)
{
_topPanel._checkboxVulnerabilities.IsChecked = filterOptions.ShowOnlyVulnerable;
}
}

private void CleanUp()
{
NuGetUIThreadHelper.JoinableTaskFactory.Run(async () =>
Expand Down
87 changes: 64 additions & 23 deletions src/NuGet.Clients/NuGet.Tools/NuGetPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,39 +1019,55 @@ private async Task<IVsWindowFrame> CreateDocWindowForSolutionAsync()

private void ShowManageLibraryPackageForSolutionDialog(object sender, EventArgs e)
{
NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async delegate
PackageManagerShowOptions options = null;
if (e is OleMenuCmdEventArgs eventArgs)
{
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

if (ShouldInitializeSolutionExperiences())
if (eventArgs?.InValue is string parameterString)
{
await InitializeSolutionExperiencesAsync();
options = new PackageManagerShowOptions() { SearchText = parameterString };
}

var windowFrame = await FindExistingSolutionWindowFrameAsync();
if (windowFrame == null)
else if (eventArgs?.InValue is PackageManagerShowOptions parameterOptions)
{
// Create the window frame
windowFrame = await CreateDocWindowForSolutionAsync();
options = parameterOptions;
}

if (windowFrame != null)
else
{
// process search string
string parameterString = null;
var args = e as OleMenuCmdEventArgs;
if (args != null)
{
parameterString = args.InValue as string;
}
var searchText = GetSearchText(parameterString);
Search(windowFrame, searchText);

windowFrame.Show();
options = new PackageManagerShowOptions();
}
}

NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async delegate
{
await ShowManageLibraryPackageForSolutionDialogAsync(options);
}).PostOnFailure(nameof(NuGetPackage), nameof(ShowManageLibraryPackageForSolutionDialog));
}

private async Task<IVsWindowFrame> ShowManageLibraryPackageForSolutionDialogAsync(PackageManagerShowOptions options)
{
string searchText = GetSearchText(options.SearchText);

await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

if (ShouldInitializeSolutionExperiences())
{
await InitializeSolutionExperiencesAsync();
}

var windowFrame = await FindExistingSolutionWindowFrameAsync();
// Create the window frame
windowFrame ??= await CreateDocWindowForSolutionAsync();

if (windowFrame != null)
{
SelectActiveItemFilter(windowFrame, options.ItemFilter);
SelectFilterOptions(windowFrame, options.PackageFilterOptions);
Search(windowFrame, searchText);
windowFrame.Show();
}

return windowFrame;
}

/// <summary>
/// Search for packages using the searchText.
/// </summary>
Expand Down Expand Up @@ -1090,6 +1106,31 @@ private void ShowUpdatePackages(IVsWindowFrame windowFrame, ShowUpdatePackageOpt
packageManagerControl?.ShowUpdatePackages(updatePackageOptions);
}

private static void SelectActiveItemFilter(IVsWindowFrame windowFrame, UI.ItemFilter? itemFilter)
{
ThreadHelper.ThrowIfNotOnUIThread();

if (itemFilter.HasValue)
{
var packageManagerControl = VsUtility.GetPackageManagerControl(windowFrame);
if (packageManagerControl != null)
{
packageManagerControl.ActiveFilter = itemFilter.Value;
}
}
}

private static void SelectFilterOptions(IVsWindowFrame windowFrame, PackageFilterOptions packageFilterOptions)
{
ThreadHelper.ThrowIfNotOnUIThread();

if (packageFilterOptions != null)
{
var packageManagerControl = VsUtility.GetPackageManagerControl(windowFrame);
packageManagerControl?.SelectPackageFilterOptions(packageFilterOptions);
}
}

// For PowerShell, it's okay to query from the worker thread.
private void BeforeQueryStatusForPowerConsole(object sender, EventArgs args)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Threading;
using NuGet.PackageManagement.UI;
using NuGet.VisualStudio;
using NuGet.VisualStudio.Telemetry;

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

object targetGuid = Guid.Empty;
object options = new PackageManagerShowOptions() { ItemFilter = ItemFilter.Installed, PackageFilterOptions = new PackageFilterOptions() { ShowOnlyVulnerable = true } };
var guidNuGetDialog = GuidList.guidNuGetDialogCmdSet;
vsUIShell.PostExecCommand(
ref guidNuGetDialog,
PkgCmdIDList.cmdidAddPackageDialogForSolution,
0,
ref targetGuid);
ref options);
}).PostOnFailure(nameof(PackageManagerLaunchService));
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/NuGet.Clients/NuGet.Tools/PackageManagerShowOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using NuGet.PackageManagement.UI;

namespace NuGetVSExtension
{
internal record PackageManagerShowOptions
{
public string? SearchText { get; set; }
public ItemFilter? ItemFilter { get; set; }
public PackageFilterOptions? PackageFilterOptions { get; set; }
}
}