-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds deprecation links in PM UI (#4144)
Search links within PM UI. Fixes NuGet/Home#10996
- Loading branch information
Fernando Aguilar
committed
Jul 30, 2021
1 parent
3ec538c
commit 8387514
Showing
21 changed files
with
451 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ents/NuGet.PackageManagement.UI/Converters/DeprecationToDeprecationLabelStateConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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.Globalization; | ||
using System.Windows.Data; | ||
using NuGet.VisualStudio.Internal.Contracts; | ||
|
||
namespace NuGet.PackageManagement.UI | ||
{ | ||
/// <summary> | ||
/// Converts from <see cref="PackageDeprecationMetadataContextInfo"/> to <see cref="PackageItemDeprecationLabelState"/> | ||
/// </summary> | ||
public class DeprecationToDeprecationLabelStateConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value is PackageDeprecationMetadataContextInfo deprecation) | ||
{ | ||
if (!string.IsNullOrEmpty(deprecation.AlternatePackage?.PackageId)) | ||
{ | ||
return PackageItemDeprecationLabelState.AlternativeAvailable; | ||
} | ||
|
||
return PackageItemDeprecationLabelState.Deprecation; | ||
} | ||
|
||
return PackageItemDeprecationLabelState.Invisible; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return null; | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/NuGet.Clients/NuGet.PackageManagement.UI/Converters/FormattedStringPartConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// 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.Globalization; | ||
using System.Windows.Data; | ||
|
||
namespace NuGet.PackageManagement.UI | ||
{ | ||
/// <summary> | ||
/// Parameter for <see cref="FormattedStringPartConverter"/> | ||
/// </summary> | ||
public enum FormattedStringPart | ||
{ | ||
Prefix, | ||
Suffix, | ||
} | ||
|
||
/// <summary> | ||
/// Extracts from a formatted string with one '{0}' placeholder to either left or right side of the placeholder | ||
/// </summary> | ||
public class FormattedStringPartConverter : IValueConverter | ||
{ | ||
/// <summary> | ||
/// Extracts either left or right side of a string with one placeholder '{0}' | ||
/// </summary> | ||
/// <param name="value">string with placeholder</param> | ||
/// <param name="targetType">Not used</param> | ||
/// <param name="parameter">A <see cref="FormattedStringPart"/> value</param> | ||
/// <param name="culture">Not used</param> | ||
/// <returns><c>null </c> if invalid value or parameter, otherwise a string with either left or right side</returns> | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
string formattedString = value as string; | ||
if (formattedString == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var mode = parameter as FormattedStringPart?; | ||
if (!mode.HasValue) | ||
{ | ||
return null; | ||
} | ||
|
||
int placeholderIndex = formattedString.IndexOf("{0}", StringComparison.Ordinal); | ||
if (placeholderIndex < 0) | ||
{ | ||
return null; | ||
} | ||
|
||
switch (mode) | ||
{ | ||
case FormattedStringPart.Prefix: | ||
return formattedString.Substring(0, placeholderIndex); | ||
case FormattedStringPart.Suffix: | ||
return formattedString.Substring(placeholderIndex + "{0}".Length); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/NuGet.Clients/NuGet.PackageManagement.UI/Models/PackageItemDeprecationLabelState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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. | ||
|
||
namespace NuGet.PackageManagement.UI | ||
{ | ||
/// <summary> | ||
/// Represents possible states of <see cref="PackageItemDeprecationLabel"/> control | ||
/// </summary> | ||
public enum PackageItemDeprecationLabelState | ||
{ | ||
/// <summary> | ||
/// Implies no Deprecation information | ||
/// </summary> | ||
Invisible, | ||
|
||
/// <summary> | ||
/// There exists Deprecation but no alternative package | ||
/// </summary> | ||
Deprecation, | ||
|
||
/// <summary> | ||
/// Deprecation with alternative package available | ||
/// </summary> | ||
AlternativeAvailable, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.