This repository has been archived by the owner on May 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
OptionsPage.xaml.cs
102 lines (87 loc) · 2.73 KB
/
OptionsPage.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using Extension.Caching;
using Extension.Logging;
using GraphQLClient;
using Microsoft.VisualStudio.Shell;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace Extension.Settings
{
/// <summary>
/// Interaction logic for OptionsPage.xaml
/// </summary>
public partial class OptionsPage : UserControl
{
internal CodigaOptionPage extensionOptionsPage;
public OptionsPage()
{
InitializeComponent();
}
public void Initialize()
{
try
{
var settings = EditorSettingsProvider.GetCurrentCodigaSettings();
cbUseCodingAssistant.IsChecked = settings.UseCodingAssistant;
cbUseInlineCompletion.IsChecked = settings.UseInlineCompletion;
txtToken.Text = settings.ApiToken;
CodigaOptions.Instance.Save();
}
catch (System.Exception e)
{
ExtensionLogger.LogException(e);
}
}
private void UseCodingAssistant_Checked(object sender, System.Windows.RoutedEventArgs e)
{
CodigaOptions.Instance.UseCodingAssistant = (bool)cbUseCodingAssistant.IsChecked;
CodigaOptions.Instance.Save();
}
private void UseCodingAssistant_Unchecked(object sender, System.Windows.RoutedEventArgs e)
{
CodigaOptions.Instance.UseCodingAssistant = (bool)cbUseCodingAssistant.IsChecked;
CodigaOptions.Instance.Save();
}
private void UseInlineCompletion_Checked(object sender, System.Windows.RoutedEventArgs e)
{
CodigaOptions.Instance.UseInlineCompletion = (bool)cbUseInlineCompletion.IsChecked;
CodigaOptions.Instance.Save();
}
private void UseInlineCompletion_Unchecked(object sender, System.Windows.RoutedEventArgs e)
{
CodigaOptions.Instance.UseInlineCompletion = (bool)cbUseInlineCompletion.IsChecked;
CodigaOptions.Instance.Save();
}
private void VerifyToken_Clicked(object sender, System.Windows.RoutedEventArgs e)
{
var provider = new DefaultCodigaClientProvider();
if (!provider.TryGetClient(out var client))
return;
client.SetApiToken(txtToken.Text);
btnVerify.IsEnabled = false;
lblUserName.Text = "";
imgError.Visibility = Visibility.Collapsed;
imgCheck.Visibility = Visibility.Collapsed;
var result = ThreadHelper.JoinableTaskFactory.Run(async () =>
{
return await client.GetUserAsync();
});
string response;
if (result.Errors != null && result.Errors.Any())
{
response = CodigaClient.GetReadableErrorMessage(result.Errors.First().Message);
imgError.Visibility = Visibility.Visible;
}
else
{
CodigaOptions.Instance.ApiToken = txtToken.Text;
CodigaOptions.Instance.Save();
btnVerify.IsEnabled = true;
imgCheck.Visibility = Visibility.Visible;
response = $"Logged in as {result.Data.User.UserName}";
}
lblUserName.Text = response;
btnVerify.IsEnabled = true;
}
}
}