-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountView.xaml.cs
More file actions
278 lines (224 loc) · 8.17 KB
/
AccountView.xaml.cs
File metadata and controls
278 lines (224 loc) · 8.17 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Upsilon.Apps.Passkey.GUI.WPF.Helper;
using Upsilon.Apps.Passkey.GUI.WPF.ViewModels;
using Upsilon.Apps.Passkey.GUI.WPF.ViewModels.Controls;
namespace Upsilon.Apps.Passkey.GUI.WPF.Views.Controls
{
/// <summary>
/// Interaction logic for AccountView.xaml
/// </summary>
public partial class AccountView : UserControl
{
private AccountViewModel? _viewModel;
internal string? GetAccountId() => _viewModel?.Account.ItemId;
public AccountView()
{
InitializeComponent();
}
public string? GetIdentifier()
{
return _identifiers_LB.SelectedItem is not IdentifierViewModel identifierViewModel ? null : identifierViewModel.Identifier;
}
public string? GetPassword() => _viewModel?.Password;
public void SetPassword(string password)
{
if (_viewModel is null) return;
_viewModel.Password = password;
_password_VPB.Password = _viewModel.Password;
_password_VPB.BackgroundColor = _viewModel.PasswordBackground;
_passwords_LB.ItemsSource = _viewModel.Passwords;
}
public void SetDataContext(AccountViewModel? dataContext)
{
if (dataContext is null)
{
DataContext = null;
_viewModel = null;
_identifiers_LB.ItemsSource = null;
return;
}
DataContext = _viewModel = dataContext;
_viewModel.Identifiers.Clear();
if (_viewModel.Account.Identifiers.Length == 0)
{
_viewModel.AddIdentifier(string.Empty);
}
else
{
_viewModel.Identifiers = [.. _viewModel.Account.Identifiers.Select(x => new IdentifierViewModel(_viewModel.Account, x))];
foreach (IdentifierViewModel identifier in _viewModel.Identifiers)
{
_viewModel.AddIdentifier(identifier);
}
}
_identifiers_LB.ItemsSource = _viewModel.Identifiers;
_identifiers_LB.SelectedIndex = 0;
_password_VPB.Password = _viewModel.Password;
_password_VPB.BackgroundColor = _viewModel.PasswordBackground;
_passwords_LB.ItemsSource = _viewModel.Passwords;
}
private void _identifier_DeleteClicked(object? sender, EventArgs e)
{
if (this.GetIsBusy()
|| _viewModel is null)
{
return;
}
int index = _identifiers_LB.SelectedIndex;
if (_viewModel.RemoveIdentifier((IdentifierViewModel)_identifiers_LB.SelectedItem))
{
_identifiers_LB.SelectedIndex = index < _viewModel.Identifiers.Count ? index : _viewModel.Identifiers.Count - 1;
}
}
private void _identifier_UpClicked(object? sender, EventArgs e)
{
if (this.GetIsBusy()
|| _viewModel is null)
{
return;
}
int newIndex = _identifiers_LB.SelectedIndex - 1;
if (_viewModel.MoveIdentifier(_identifiers_LB.SelectedIndex, newIndex))
{
_identifiers_LB.SelectedIndex = newIndex;
}
}
private void _identifier_DownClicked(object? sender, EventArgs e)
{
if (this.GetIsBusy()
|| _viewModel is null)
{
return;
}
int newIndex = _identifiers_LB.SelectedIndex + 1;
if (_viewModel.MoveIdentifier(_identifiers_LB.SelectedIndex, newIndex))
{
_identifiers_LB.SelectedIndex = newIndex;
}
}
private void _addButton_Click(object sender, RoutedEventArgs e)
{
if (this.GetIsBusy()) return;
_viewModel?.AddIdentifier(string.Empty);
_identifiers_LB.SelectedIndex = _identifiers_LB.Items.Count - 1;
}
private void _value_TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
NumericTextBoxHelper.PreviewTextInput(sender, e);
}
private void _value_TextBox_Pasting(object sender, DataObjectPastingEventArgs e)
{
NumericTextBoxHelper.Pasting(sender, e);
}
private void _value_TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
NumericTextBoxHelper.TextChanged(sender, e);
}
private void _password_VPB_Validated(object sender, EventArgs e)
{
if (this.GetIsBusy()
|| _viewModel is null)
{
return;
}
_viewModel.Password = _password_VPB.Password;
_password_VPB.BackgroundColor = _viewModel.PasswordBackground;
_passwords_LB.ItemsSource = _viewModel.Passwords;
}
private void _passwords_VPB_Loaded(object sender, RoutedEventArgs e)
{
if (sender is not VisiblePasswordBox passwordBox) return;
try
{
passwordBox.Password = ((PasswordViewModel)((ContentPresenter)passwordBox.TemplatedParent).Content).Password;
}
catch { }
}
private void _copyIdentifier_Clicked(object sender, RoutedEventArgs e)
{
if (this.GetIsBusy()) return;
QrCodeView.CopyToClipboard(((IdentifierViewModel)_identifiers_LB.SelectedItem).Identifier);
}
private void _showQrCodeIdentifier_Clicked(object sender, RoutedEventArgs e)
{
if (this.GetIsBusy()) return;
QrCodeView.ShowQrCode(Window.GetWindow(this),
((IdentifierViewModel)_identifiers_LB.SelectedItem).Identifier,
MainViewModel.User.ShowPasswordDelay);
}
private void _copyPassword_Clicked(object sender, RoutedEventArgs e)
{
if (this.GetIsBusy()
|| _viewModel is null)
{
return;
}
QrCodeView.CopyToClipboard(_viewModel.Password);
}
private void _showQrCodePassword_Clicked(object sender, RoutedEventArgs e)
{
if (this.GetIsBusy()
|| _viewModel is null)
{
return;
}
QrCodeView.ShowQrCode(Window.GetWindow(this),
_viewModel.Password,
MainViewModel.User.ShowPasswordDelay);
}
private void _copyPasswords_Clicked(object sender, RoutedEventArgs e)
{
if (this.GetIsBusy()
|| sender is not Button button)
{
return;
}
QrCodeView.CopyToClipboard(((PasswordViewModel)((ContentPresenter)button.TemplatedParent).Content).Password);
}
private void _showQrCodePasswords_Clicked(object sender, RoutedEventArgs e)
{
if (this.GetIsBusy()
|| sender is not Button button)
{
return;
}
QrCodeView.ShowQrCode(Window.GetWindow(this),
((PasswordViewModel)((ContentPresenter)button.TemplatedParent).Content).Password,
MainViewModel.User.ShowPasswordDelay);
}
private void _viewActivities_Button_Click(object sender, RoutedEventArgs e)
{
if (this.GetIsBusy()
|| _viewModel is null)
{
return;
}
if (this.GetIsBusy()) return;
if (MainViewModel.UserActivitiesView is not null
&& MainViewModel.UserActivitiesView.IsLoaded)
{
MainViewModel.UserActivitiesView.ViewModel.RefreshFilters(_viewModel.Account.ItemId);
_ = MainViewModel.UserActivitiesView.Activate();
return;
}
MainViewModel.UserActivitiesView = new(needsReviewFilter: false);
MainViewModel.UserActivitiesView.ViewModel.ClearFilters();
MainViewModel.UserActivitiesView.ViewModel.RefreshFilters(_viewModel.Account.ItemId);
MainViewModel.UserActivitiesView.Show();
}
private void _identifier_TextBox_KeyUp(object sender, KeyEventArgs e)
{
if (this.GetIsBusy()) return;
if (sender is not TextBox identifier_TB) return;
if (e.Key is Key.Enter
or Key.Insert)
{
string? identifier = InsertIdentifierView.InsertIdentifierDialog(_viewModel?.IdentifierAutoCompleteList ?? [], identifier_TB.Text);
if (string.IsNullOrEmpty(identifier)) return;
identifier_TB.Text = identifier;
}
}
}
}