Skip to content

Commit

Permalink
Show Package Source Mapping Status in Details Pane
Browse files Browse the repository at this point in the history
  • Loading branch information
donnie-msft committed May 12, 2023
1 parent ac6b25a commit ed4afa3
Show file tree
Hide file tree
Showing 24 changed files with 476 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@
[assembly: SuppressMessage("Usage", "VSTHRD010:Invoke single-threaded types on Main thread", Justification = "https://github.com/microsoft/vs-threading/issues/577", Scope = "member", Target = "~M:NuGet.PackageManagement.UI.InfiniteScrollList.LoadNextPageAsync(NuGet.PackageManagement.UI.IPackageItemLoader,System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.Collections.Generic.IEnumerable{NuGet.PackageManagement.UI.PackageItemViewModel}}")]
[assembly: SuppressMessage("Build", "CA1501:'PackageSourceMappingOptionsControl' has an object hierarchy '9' levels deep within the defining module. If possible, eliminate base classes within the hierarchy to decrease its hierarchy level below '6': 'UserControl, ContentControl, Control, FrameworkElement, UIElement, Visual, DependencyObject, DispatcherObject, Object'", Justification = "Default WPF class hierarchy", Scope = "type", Target = "~T:NuGet.Options.PackageSourceMappingOptionsControl")]
[assembly: SuppressMessage("Build", "CA1501:'AddMappingDialog' has an object hierarchy '9' levels deep within the defining module. If possible, eliminate base classes within the hierarchy to decrease its hierarchy level below '6': 'UserControl, ContentControl, Control, FrameworkElement, UIElement, Visual, DependencyObject, DispatcherObject, Object'", Justification = "Default WPF class hierarchy", Scope = "type", Target = "~T:NuGet.Options.AddMappingDialog")]
[assembly: SuppressMessage("Build", "CA1501:'PackageSourceMappingActionControl' has an object hierarchy '9' levels deep within the defining module. If possible, eliminate base classes within the hierarchy to decrease its hierarchy level below '6': 'UserControl, ContentControl, Control, FrameworkElement, UIElement, Visual, DependencyObject, DispatcherObject, Object'", Justification = "Default WPF class hierarchy", Scope = "type", Target = "~T:NuGet.PackageManagement.UI.PackageSourceMappingActionControl")]
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using Microsoft.ServiceHub.Framework;
using NuGet.PackageManagement.UI.ViewModels;
using NuGet.PackageManagement.VisualStudio;
using NuGet.Packaging.Core;
using NuGet.Versioning;
Expand Down Expand Up @@ -50,11 +51,14 @@ public abstract class DetailControlModel : INotifyPropertyChanged, IDisposable

protected DetailControlModel(
IServiceBroker serviceBroker,
IEnumerable<IProjectContextInfo> projects)
IEnumerable<IProjectContextInfo> projects,
INuGetUI uiController)
{
_nugetProjects = projects;
ServiceBroker = serviceBroker;

_options = new OptionsViewModel();
PackageSourceMappingViewModel = PackageSourceMappingActionViewModel.Create(uiController);

// Show dependency behavior and file conflict options if any of the projects are non-build integrated
_options.ShowClassicOptions = projects.Any(project => project.ProjectKind == NuGetProjectKind.PackagesConfig);
Expand Down Expand Up @@ -134,6 +138,7 @@ protected virtual void Dispose(bool disposing)

_searchResultPackage = searchResultPackage;
_filter = filter;
PackageSourceMappingViewModel.PackageId = searchResultPackage.Id;
OnPropertyChanged(nameof(Id));
OnPropertyChanged(nameof(PackagePath));
OnPropertyChanged(nameof(IconUrl));
Expand Down Expand Up @@ -814,6 +819,8 @@ public OptionsViewModel Options
}
}

public PackageSourceMappingActionViewModel PackageSourceMappingViewModel { get; }

public IEnumerable<IProjectContextInfo> NuGetProjects => _nugetProjects;

public string PackagePath => _searchResultPackage?.PackagePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using System.Windows.Data;
using Microsoft.ServiceHub.Framework;
using NuGet.PackageManagement.UI.ViewModels;
using NuGet.Packaging.Core;
using NuGet.Versioning;
using NuGet.VisualStudio;
Expand All @@ -25,8 +26,9 @@ public class PackageDetailControlModel : DetailControlModel
public PackageDetailControlModel(
IServiceBroker serviceBroker,
INuGetSolutionManagerService solutionManager,
IEnumerable<IProjectContextInfo> projects)
: base(serviceBroker, projects)
IEnumerable<IProjectContextInfo> projects,
INuGetUI uiController)
: base(serviceBroker, projects, uiController)
{
_solutionManager = solutionManager;
_solutionManager.ProjectUpdated += ProjectChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft;
using Microsoft.ServiceHub.Framework;
using Microsoft.VisualStudio.Shell;
using NuGet.PackageManagement.UI.ViewModels;
using NuGet.PackageManagement.VisualStudio;
using NuGet.ProjectModel;
using NuGet.Versioning;
Expand All @@ -36,8 +36,9 @@ internal class PackageSolutionDetailControlModel : DetailControlModel

private PackageSolutionDetailControlModel(
IServiceBroker serviceBroker,
IEnumerable<IProjectContextInfo> projects)
: base(serviceBroker, projects)
IEnumerable<IProjectContextInfo> projects,
INuGetUI uiController)
: base(serviceBroker, projects, uiController)
{
IsRequestedVisible = projects.Any(p => p.ProjectStyle == ProjectStyle.PackageReference);
}
Expand Down Expand Up @@ -68,9 +69,10 @@ internal class PackageSolutionDetailControlModel : DetailControlModel
IServiceBroker serviceBroker,
INuGetSolutionManagerService solutionManager,
IEnumerable<IProjectContextInfo> projects,
INuGetUI uiController,
CancellationToken cancellationToken)
{
var packageSolutionDetailControlModel = new PackageSolutionDetailControlModel(serviceBroker, projects);
var packageSolutionDetailControlModel = new PackageSolutionDetailControlModel(serviceBroker, projects, uiController);
await packageSolutionDetailControlModel.InitializeAsync(solutionManager, cancellationToken);
return packageSolutionDetailControlModel;
}
Expand All @@ -79,9 +81,10 @@ internal class PackageSolutionDetailControlModel : DetailControlModel
INuGetSolutionManagerService solutionManager,
IEnumerable<IProjectContextInfo> projects,
IServiceBroker serviceBroker,
INuGetUI uiController,
CancellationToken cancellationToken)
{
var packageSolutionDetailControlModel = new PackageSolutionDetailControlModel(serviceBroker, projects);
var packageSolutionDetailControlModel = new PackageSolutionDetailControlModel(serviceBroker, projects, uiController);
await packageSolutionDetailControlModel.InitializeAsync(solutionManager, cancellationToken);
return packageSolutionDetailControlModel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
<Compile Include="Utility\ProjectUtility.cs" />
<Compile Include="Utility\VsUtility.cs" />
<Compile Include="UserInterfaceService\ProgressDialogData.cs" />
<Compile Include="ViewModels\PackageSourceMappingActionViewModel.cs" />
<Compile Include="ViewModels\ViewModelBase.cs" />
<Compile Include="Xamls\DeprecatedFrameworkWindow.xaml.cs">
<DependentUpon>DeprecatedFrameworkWindow.xaml</DependentUpon>
</Compile>
Expand All @@ -181,6 +183,9 @@
<Compile Include="Xamls\PackageManagementFormatWindow.xaml.cs">
<DependentUpon>PackageManagementFormatWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Xamls\PackageSourceMappingActionControl.xaml.cs">
<DependentUpon>PackageSourceMappingActionControl.xaml</DependentUpon>
</Compile>
<Compile Include="Xamls\PRMigratorBar.xaml.cs">
<DependentUpon>PRMigratorBar.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -358,6 +363,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Xamls\PackageSourceMappingActionControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Xamls\PrefixReservedIndicator.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
36 changes: 36 additions & 0 deletions src/NuGet.Clients/NuGet.PackageManagement.UI/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/NuGet.Clients/NuGet.PackageManagement.UI/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -978,4 +978,16 @@ Please see https://aka.ms/troubleshoot_nuget_cache for more help.</value>
<data name="UpdateButton_VersionOverride_Tooltip" xml:space="preserve">
<value>Dependency version defined by VersionOverride, modify project file to change package version.</value>
</data>
<data name="Hyperlink_PackageSourceMappingSettings" xml:space="preserve">
<value>Configure</value>
</data>
<data name="Text_PackageMappingsFound" xml:space="preserve">
<value>Package source mapping found.</value>
</data>
<data name="Text_PackageMappingsNotFound" xml:space="preserve">
<value>Requires a package source mapping.</value>
</data>
<data name="Text_PackageMappingsDisabled" xml:space="preserve">
<value>Package source mapping is off.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.ServiceHub.Framework;
using NuGet.Configuration;
using NuGet.PackageManagement.UI.Utility;
using NuGet.PackageManagement.VisualStudio;
using NuGet.VisualStudio.Internal.Contracts;
Expand Down Expand Up @@ -38,6 +39,8 @@ public interface INuGetUIContext : IDisposable

IUserSettingsManager UserSettingsManager { get; }

PackageSourceMapping PackageSourceMapping { get; }

Task<bool> IsNuGetProjectUpgradeableAsync(IProjectContextInfo project, CancellationToken cancellationToken);

Task<IModalProgressDialogSession> StartModalProgressDialogAsync(string caption, ProgressDialogData initialData, INuGetUI uiService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public sealed class NuGetUIContext : INuGetUIContext
private readonly NuGetSolutionManagerServiceWrapper _solutionManagerService;
private readonly NuGetSourcesServiceWrapper _sourceService;
private IProjectContextInfo[] _projects;
private readonly ISettings _settings;

public event EventHandler<IReadOnlyCollection<string>> ProjectActionsExecuted;

Expand All @@ -44,7 +45,8 @@ public sealed class NuGetUIContext : INuGetUIContext
IPackageRestoreManager packageRestoreManager,
IOptionsPageActivator optionsPageActivator,
IUserSettingsManager userSettingsManager,
NuGetSourcesServiceWrapper sourceService)
NuGetSourcesServiceWrapper sourceService,
ISettings settings)
{
ServiceBroker = serviceBroker;
ReconnectingSearchService = nuGetSearchService;
Expand All @@ -57,11 +59,19 @@ public sealed class NuGetUIContext : INuGetUIContext
OptionsPageActivator = optionsPageActivator;
UserSettingsManager = userSettingsManager;
_sourceService = sourceService;
_settings = settings;
PackageSourceMapping = PackageSourceMapping.GetPackageSourceMapping(_settings);

_settings.SettingsChanged += Settings_SettingsChanged;
ServiceBroker.AvailabilityChanged += OnAvailabilityChanged;
SolutionManager.ActionsExecuted += OnActionsExecuted;
}

private void Settings_SettingsChanged(object sender, EventArgs e)
{
PackageSourceMapping = PackageSourceMapping.GetPackageSourceMapping(_settings);
}

public IServiceBroker ServiceBroker { get; }

public IReconnectingNuGetSearchService ReconnectingSearchService { get; }
Expand Down Expand Up @@ -96,10 +106,13 @@ public IEnumerable<IProjectContextInfo> Projects

public IUserSettingsManager UserSettingsManager { get; }

public PackageSourceMapping PackageSourceMapping { get; private set; }

public void Dispose()
{
ServiceBroker.AvailabilityChanged -= OnAvailabilityChanged;
SolutionManager.ActionsExecuted -= OnActionsExecuted;
_settings.SettingsChanged -= Settings_SettingsChanged;

_solutionManagerService.Dispose();
_sourceService.Dispose();
Expand Down Expand Up @@ -197,7 +210,8 @@ public async Task<IModalProgressDialogSession> StartModalProgressDialogAsync(str
packageRestoreManager,
optionsPageActivator,
userSettingsManager,
sourceServiceWrapper);
sourceServiceWrapper,
settings);
}

public void RaiseProjectActionsExecuted(IReadOnlyCollection<string> projectIds)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// 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 System;
using System.Linq;

namespace NuGet.PackageManagement.UI.ViewModels
{
public sealed class PackageSourceMappingActionViewModel : ViewModelBase
{
internal INuGetUI UIController { get; }

private PackageSourceMappingActionViewModel(INuGetUI uiController)
{
UIController = uiController ?? throw new ArgumentNullException(nameof(uiController));
}

public bool IsPackageSourceMappingEnabled => UIController.UIContext?.PackageSourceMapping?.IsEnabled == true;

private string? _packageId;

internal string? PackageId
{
get { return _packageId; }
set
{
if (_packageId == value)
{
return;
}

_packageId = value;

RaisePropertyChanged(nameof(IsPackageMapped));
RaisePropertyChanged(nameof(MappingStatus));
}
}

public bool IsPackageMapped
{
get
{
if (string.IsNullOrWhiteSpace(PackageId))
{
return false;
}

var packageSourceMapping = UIController.UIContext.PackageSourceMapping;
return packageSourceMapping?.GetConfiguredPackageSources(PackageId)?.Any() == true;
}
}

public string MappingStatus
{
get
{
if (IsPackageSourceMappingEnabled)
{
if (IsPackageMapped)
{
return Resources.Text_PackageMappingsFound;
}
else
{
return Resources.Text_PackageMappingsNotFound;
}
}
else
{
return Resources.Text_PackageMappingsDisabled;
}
}
}

public void SettingsChanged()
{
RaisePropertyChanged(nameof(IsPackageSourceMappingEnabled));
RaisePropertyChanged(nameof(IsPackageMapped));
RaisePropertyChanged(nameof(MappingStatus));
}

public static PackageSourceMappingActionViewModel Create(INuGetUI uiController)
{
return new PackageSourceMappingActionViewModel(uiController);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace NuGet.PackageManagement.UI.ViewModels
{
public abstract class ViewModelBase : INotifyPropertyChanged
{
public virtual event PropertyChangedEventHandler PropertyChanged;

public void RaisePropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

0 comments on commit ed4afa3

Please sign in to comment.