This repository was archived by the owner on Oct 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
[NuGet] Show license metadata #9085
Open
mrward
wants to merge
12
commits into
main
Choose a base branch
from
nuget-license-metadata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c1acfb3
[NuGet] Show license metadata in Manage Packages dialog
mrward 08ddf78
[NuGet] Show license metadata in License Acceptance dialog
mrward 617951f
[NuGet] Simplify logic for license files
mrward 9f1114c
[NuGet] Fix license expression links in License Acceptance dialog
mrward 2f412e6
[NuGet] Right align license metadata and show warnings as tooltip
mrward 0c9667c
[NuGet] Improve license file dialog
mrward 57997dd
[NuGet] Switch back to native toolkit to display license dialog
mrward fe8a852
[NuGet] Ensure the file license dialog looks the same when displayed
mrward 33b2ae8
[NuGet] Fix warning logged when clicking file license link
mrward 227dc6c
[NuGet] Fix file license dialog scrollbar not always enabled
mrward 16d65e7
[NuGet] Fix license expression accessibility on license accept dialog
mrward d8adac5
[NuGet] Add accessibility label to image in license accept dialog
mrward File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
91 changes: 91 additions & 0 deletions
91
...dins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Gui/LicenseFileDialog.cs
This file contains hidden or 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,91 @@ | ||
// | ||
// LicenseFileDialog.cs | ||
// | ||
// Author: | ||
// Matt Ward <[email protected]> | ||
// | ||
// Copyright (c) 2019 Microsoft Corporation | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
using System.ComponentModel; | ||
using NuGet.PackageManagement.UI; | ||
using Xwt; | ||
using Xwt.Formats; | ||
|
||
namespace MonoDevelop.PackageManagement | ||
{ | ||
sealed class LicenseFileDialog : Dialog | ||
{ | ||
RichTextView textView; | ||
LicenseFileText licenseFileText; | ||
|
||
public LicenseFileDialog (LicenseFileText licenseFileText) | ||
{ | ||
this.licenseFileText = licenseFileText; | ||
|
||
Build (); | ||
LoadText (); | ||
|
||
licenseFileText.PropertyChanged += LicenseFileTextPropertyChanged; | ||
licenseFileText.LoadLicenseFile (); | ||
} | ||
|
||
void Build () | ||
{ | ||
Height = 450; | ||
Width = 450; | ||
Title = licenseFileText.LicenseHeader; | ||
|
||
var scrollView = new ScrollView (); | ||
scrollView.HorizontalScrollPolicy = ScrollPolicy.Never; | ||
Content = scrollView; | ||
|
||
textView = new RichTextView (); | ||
textView.ReadOnly = true; | ||
scrollView.Content = textView; | ||
|
||
var okCommand = new Command ("Ok", Core.GettextCatalog.GetString ("OK")); | ||
Buttons.Add (); | ||
DefaultCommand = okCommand; | ||
} | ||
|
||
void LicenseFileTextPropertyChanged (object sender, PropertyChangedEventArgs e) | ||
{ | ||
LoadText (); | ||
|
||
// Need to refresh the dialog after the license text has been loaded. Otherwise when using the | ||
// native toolkit the vertical scrollbar is not enabled unless you re-size the dialog. | ||
OnReallocate (); | ||
} | ||
|
||
void LoadText () | ||
{ | ||
textView.LoadText (licenseFileText.LicenseText, TextFormat.Plain); | ||
} | ||
|
||
protected override void Dispose (bool disposing) | ||
{ | ||
base.Dispose (disposing); | ||
if (disposing) { | ||
licenseFileText.PropertyChanged -= LicenseFileTextPropertyChanged; | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...oDevelop.PackageManagement/MonoDevelop.PackageManagement.Gui/LicenseFileTextExtensions.cs
This file contains hidden or 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,39 @@ | ||
// | ||
// LicenseFileTextExtensions.cs | ||
// | ||
// Author: | ||
// Matt Ward <[email protected]> | ||
// | ||
// Copyright (c) 2019 Microsoft Corporation | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
using System; | ||
using NuGet.PackageManagement.UI; | ||
|
||
namespace MonoDevelop.PackageManagement | ||
{ | ||
static class LicenseFileTextExtensions | ||
{ | ||
public static Uri CreateLicenseFileUri (this LicenseFileText licenseFileText) | ||
{ | ||
return new Uri ($"file:///{licenseFileText.Text}"); | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...noDevelop.PackageManagement/MonoDevelop.PackageManagement.Gui/LicenseLinkMarkupBuilder.cs
This file contains hidden or 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,73 @@ | ||
// | ||
// LicenseLinkMarkupBuilder.cs | ||
// | ||
// Author: | ||
// Matt Ward <[email protected]> | ||
// | ||
// Copyright (c) 2019 Microsoft Corporation | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security; | ||
using MonoDevelop.Core; | ||
using NuGet.PackageManagement.UI; | ||
|
||
namespace MonoDevelop.PackageManagement | ||
{ | ||
sealed class LicenseLinkMarkupBuilder | ||
{ | ||
List<WarningText> warnings; | ||
|
||
public string GetMarkup (IReadOnlyList<IText> textLinks) | ||
{ | ||
var markupBuilder = StringBuilderCache.Allocate (); | ||
|
||
foreach (IText textLink in textLinks) { | ||
if (textLink is LicenseText licenseText) { | ||
markupBuilder.Append (GetUriMarkup (licenseText.Link, licenseText.Text)); | ||
} else if (textLink is LicenseFileText licenseFileText) { | ||
// Should not happen. Building an expression should not contain a license file. | ||
LoggingService.LogError ("Unexpected LicenseFileText when building markup {0}", licenseFileText.Text); | ||
} else if (textLink is WarningText warning) { | ||
warnings ??= new List<WarningText> (); | ||
warnings.Add (warning); | ||
} else { | ||
markupBuilder.Append (textLink.Text); | ||
} | ||
} | ||
|
||
return StringBuilderCache.ReturnAndFree (markupBuilder); | ||
} | ||
|
||
public IEnumerable<WarningText> Warnings { | ||
get { return warnings ?? Enumerable.Empty<WarningText> (); } | ||
} | ||
|
||
static string GetUriMarkup (Uri uri, string text) | ||
{ | ||
return string.Format ( | ||
"<a href=\"{0}\">{1}</a>", | ||
uri != null ? SecurityElement.Escape (uri.ToString ()) : string.Empty, | ||
SecurityElement.Escape (text)); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is Command.Ok already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, originally that was used. However in the UX review there were complaints about showing 'Ok' instead of 'OK' as the button text. I guess I could change the Command.Ok but did not want to make that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting. So this means all "OK" in MD are "Ok"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only dialogs that use Xwt and use the Command.Ok will show 'Ok'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense to reword this globally to "OK". @hbons?