Skip to content

Commit 9257e1d

Browse files
committed
Feature: Migrate dialog
1 parent faf0c2b commit 9257e1d

File tree

4 files changed

+67
-49
lines changed

4 files changed

+67
-49
lines changed

Source/NETworkManager/ViewModels/SettingsProfilesViewModel.cs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -224,48 +224,58 @@ private async Task DeleteProfileFileAction()
224224
SelectedProfileFile = ProfileFiles.Cast<ProfileFileInfo>().FirstOrDefault();
225225
}
226226

227-
public ICommand EnableEncryptionCommand => new RelayCommand(_ => EnableEncryptionAction());
227+
public ICommand EnableEncryptionCommand => new RelayCommand(async _ => await EnableEncryptionAction().ConfigureAwait(false));
228228

229-
private async void EnableEncryptionAction()
229+
private async Task EnableEncryptionAction()
230230
{
231231
// Show encryption disclaimer
232232
if (!await DialogHelper.ShowOKCancelMessageAsync(Application.Current.MainWindow,
233233
Strings.Disclaimer,
234234
Strings.ProfileEncryptionDisclaimer))
235235
return;
236236

237-
var customDialog = new CustomDialog
238-
{
239-
Title = Strings.SetMasterPassword
240-
};
241237

242-
var credentialsSetPasswordViewModel = new CredentialsSetPasswordViewModel(async instance =>
243-
{
244-
await _dialogCoordinator.HideMetroDialogAsync(this, customDialog);
238+
var profileFile = SelectedProfileFile.Name;
245239

240+
var childWindow = new CredentialsSetPasswordChildWindow();
241+
242+
var childWindowViewModel = new CredentialsSetPasswordViewModel(async instance =>
243+
{
244+
childWindow.IsOpen = false;
245+
ConfigurationManager.Current.IsChildWindowOpen = false;
246246
try
247247
{
248248
ProfileManager.EnableEncryption(SelectedProfileFile, instance.Password);
249249
}
250250
catch (Exception ex)
251251
{
252-
var metroDialogSettings = AppearanceManager.MetroDialog;
253-
metroDialogSettings.AffirmativeButtonText = Strings.OK;
254-
255-
await _dialogCoordinator.ShowMessageAsync(this, Strings.EncryptionError,
252+
await DialogHelper.ShowOKMessageAsync(Application.Current.MainWindow,
253+
Strings.EncryptionError,
256254
$"{Strings.EncryptionErrorMessage}\n\n{ex.Message}",
257-
MessageDialogStyle.Affirmative, metroDialogSettings);
255+
ChildWindowIcon.Error).ConfigureAwait(false);
258256
}
259-
}, async _ => { await _dialogCoordinator.HideMetroDialogAsync(this, customDialog); });
260-
261-
customDialog.Content = new CredentialsSetPasswordDialog
257+
}, _ =>
262258
{
263-
DataContext = credentialsSetPasswordViewModel
264-
};
259+
childWindow.IsOpen = false;
260+
ConfigurationManager.Current.IsChildWindowOpen = false;
261+
});
262+
263+
childWindow.Title = Strings.SetMasterPassword;
264+
265+
childWindow.DataContext = childWindowViewModel;
265266

266-
await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
267+
ConfigurationManager.Current.IsChildWindowOpen = true;
268+
269+
await (Application.Current.MainWindow as MainWindow).ShowChildWindowAsync(childWindow);
270+
271+
// Re-select the profile file
272+
if (string.IsNullOrEmpty(profileFile))
273+
return;
274+
275+
SelectedProfileFile = ProfileFiles.Cast<ProfileFileInfo>()
276+
.FirstOrDefault(p => p.Name.Equals(profileFile, StringComparison.OrdinalIgnoreCase));
267277
}
268-
278+
269279
public ICommand ChangeMasterPasswordCommand => new RelayCommand(async _ => await ChangeMasterPasswordAction().ConfigureAwait(false));
270280

271281
private async Task ChangeMasterPasswordAction()

Source/NETworkManager/Views/CredentialsSetPasswordDialog.xaml renamed to Source/NETworkManager/Views/CredentialsSetPasswordChildWindow.xaml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<UserControl x:Class="NETworkManager.Views.CredentialsSetPasswordDialog"
1+
<simpleChildWindow:ChildWindow x:Class="NETworkManager.Views.CredentialsSetPasswordChildWindow"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -7,9 +7,12 @@
77
xmlns:interactivity="http://schemas.microsoft.com/xaml/behaviors"
88
xmlns:viewModels="clr-namespace:NETworkManager.ViewModels"
99
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
10-
mc:Ignorable="d" Loaded="UserControl_Loaded"
11-
d:DataContext="{d:DesignInstance viewModels:CredentialsSetPasswordViewModel}">
12-
<Grid Margin="0,20">
10+
xmlns:simpleChildWindow="clr-namespace:MahApps.Metro.SimpleChildWindow;assembly=MahApps.Metro.SimpleChildWindow"
11+
CloseButtonCommand="{Binding Path=CancelCommand}"
12+
Style="{StaticResource DefaultChildWindow}"
13+
Loaded="ChildWindow_OnLoaded"
14+
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:CredentialsSetPasswordViewModel}">
15+
<Grid Margin="10">
1316
<Grid.RowDefinitions>
1417
<RowDefinition Height="*" />
1518
<RowDefinition Height="Auto" />
@@ -33,23 +36,23 @@
3336
</Grid.RowDefinitions>
3437
<TextBlock Grid.Column="0" Grid.Row="0" Text="{x:Static localization:Strings.Password}" />
3538
<PasswordBox x:Name="PasswordBoxPassword" Grid.Column="2" Grid.Row="0"
36-
Style="{StaticResource DefaultPasswordBox}">
39+
Style="{StaticResource DefaultPasswordBox}">
3740
<interactivity:Interaction.Behaviors>
3841
<wpfHelpers:PasswordBoxBindingBehavior
39-
Password="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
42+
Password="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
4043
</interactivity:Interaction.Behaviors>
4144
</PasswordBox>
4245
<TextBlock Grid.Column="0" Grid.Row="2" Text="{x:Static localization:Strings.Repeat}" />
4346
<PasswordBox x:Name="PasswordBoxPasswordRepeat" Grid.Column="2" Grid.Row="2"
44-
Style="{StaticResource DefaultPasswordBox}">
47+
Style="{StaticResource DefaultPasswordBox}">
4548
<interactivity:Interaction.Behaviors>
4649
<wpfHelpers:PasswordBoxBindingBehavior
47-
Password="{Binding PasswordRepeat, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
50+
Password="{Binding PasswordRepeat, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
4851
</interactivity:Interaction.Behaviors>
4952
</PasswordBox>
5053
</Grid>
5154
<TextBlock Grid.Row="1" Foreground="{DynamicResource MahApps.Brushes.Accent}"
52-
Text="{x:Static localization:Strings.PasswordsDoNotMatch}" Margin="0,10,0,0">
55+
Text="{x:Static localization:Strings.PasswordsDoNotMatch}" Margin="0,10,0,0">
5356
<TextBlock.Style>
5457
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource DefaultTextBlock}">
5558
<Setter Property="Visibility" Value="Collapsed" />
@@ -69,7 +72,7 @@
6972
</TextBlock>
7073
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right">
7174
<Button Content="{x:Static localization:Strings.OK}" Command="{Binding OKCommand}" IsDefault="True"
72-
Margin="0,0,10,0">
75+
Margin="0,0,10,0">
7376
<Button.Style>
7477
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
7578
<Setter Property="IsEnabled" Value="False" />
@@ -88,7 +91,7 @@
8891
</Button.Style>
8992
</Button>
9093
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True"
91-
Style="{StaticResource DefaultButton}" />
94+
Style="{StaticResource DefaultButton}" />
9295
</StackPanel>
9396
</Grid>
94-
</UserControl>
97+
</simpleChildWindow:ChildWindow>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Windows;
3+
using System.Windows.Threading;
4+
5+
namespace NETworkManager.Views;
6+
7+
public partial class CredentialsSetPasswordChildWindow
8+
{
9+
public CredentialsSetPasswordChildWindow()
10+
{
11+
InitializeComponent();
12+
}
13+
14+
private void ChildWindow_OnLoaded(object sender, RoutedEventArgs e)
15+
{
16+
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
17+
{
18+
PasswordBoxPassword.Focus();
19+
}));
20+
}
21+
}

Source/NETworkManager/Views/CredentialsSetPasswordDialog.xaml.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)