-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewLicensesToAdd.xaml.cs
85 lines (72 loc) · 2.42 KB
/
ViewLicensesToAdd.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace LicenseMe;
public partial class ViewLicensesToAdd : Window
{
/// <summary>
/// The directory to modify
/// </summary>
private GitDirectory DirToModify { get; }
/// <summary>
/// Inits the License-Window and customizes the Header with the Repositoryname
/// </summary>
/// <param name="directory"></param>
public ViewLicensesToAdd(GitDirectory directory)
{
InitializeComponent();
DirToModify = directory;
Title = $"Add license to \"{DirToModify.Name}\" repository";
}
/// <summary>
/// Loads all Licenses from the GitHub API
/// </summary>
public async Task LoadLicenses()
{
await foreach (var license in GithubApiCommunicator.GetLicenses())
{
LicenseView.Items.Add(license);
}
LicenseView.SelectedItem = LicenseView.Items[0];
}
/// <summary>
/// Feeds the Elements with Information given by the License
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void LicenseViewSelection(object sender, RoutedEventArgs e)
{
var license = LicenseView.SelectedItem as BasicLicense;
KeyText.Text = license.Key;
NameText.Text = license.Name;
SpdxIdText.Text = license.SpdxId;
NodeIdText.Text = license.NodeId;
var advanced = await license.GetAdvancedLicenseInformation();
HyperlinkText.Text = advanced.HtmlUrl;
LicenseUrlLink.NavigateUri = new Uri(advanced.HtmlUrl);
LicenseDescription.Text = advanced.Description;
PermsList.ItemsSource = advanced.Permissions;
CondList.ItemsSource = advanced.Conditions;
LimsList.ItemsSource = advanced.Limitations;
}
/// <summary>
/// Starts the Process of Adding a Chosen License
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void ChosenLicenseClick(object sender, RoutedEventArgs e)
{
await DirToModify.AddLicense(LicenseView.SelectedItem as BasicLicense);
Close();
}
/// <summary>
/// Closes this window.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AbortLicensingClick(object sender, RoutedEventArgs e)
{
Close();
}
}