Skip to content

Commit 70a3eb9

Browse files
committed
Feature: More dialogs
1 parent 22e3bd4 commit 70a3eb9

21 files changed

+125
-118
lines changed

Source/NETworkManager/ViewModels/DropdownViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace NETworkManager.ViewModels;
99
/// <summary>
1010
/// View model for a dropdown dialog.
1111
/// </summary>
12-
public class DropdownViewModel : ViewModelBase
12+
public class DropDownViewModel : ViewModelBase
1313
{
1414
/// <summary>
1515
/// Backing field for <see cref="ValueDescription"/>.
@@ -27,13 +27,13 @@ public class DropdownViewModel : ViewModelBase
2727
private string _selectedValue;
2828

2929
/// <summary>
30-
/// Initializes a new instance of the <see cref="DropdownViewModel"/> class.
30+
/// Initializes a new instance of the <see cref="DropDownViewModel"/> class.
3131
/// </summary>
3232
/// <param name="okCommand">The action to execute when OK is clicked.</param>
3333
/// <param name="cancelHandler">The action to execute when Cancel is clicked.</param>
3434
/// <param name="values">The list of values to display in the dropdown.</param>
3535
/// <param name="valueDescription">The description of the value.</param>
36-
public DropdownViewModel(Action<DropdownViewModel> okCommand, Action<DropdownViewModel> cancelHandler,
36+
public DropDownViewModel(Action<DropDownViewModel> okCommand, Action<DropDownViewModel> cancelHandler,
3737
List<string> values, string valueDescription)
3838
{
3939
ValueDescription = valueDescription;

Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using LiveCharts.Wpf;
44
using log4net;
55
using MahApps.Metro.Controls;
6-
using MahApps.Metro.Controls.Dialogs;
76
using MahApps.Metro.SimpleChildWindow;
87
using NETworkManager.Controls;
98
using NETworkManager.Localization.Resources;
@@ -41,7 +40,6 @@ public class NetworkInterfaceViewModel : ViewModelBase, IProfileManager
4140

4241
private static readonly ILog Log = LogManager.GetLogger(typeof(NetworkInterfaceViewModel));
4342

44-
private readonly IDialogCoordinator _dialogCoordinator;
4543
private readonly DispatcherTimer _searchDispatcherTimer = new();
4644
private bool _searchDisabled;
4745
private BandwidthMeter _bandwidthMeter;
@@ -761,12 +759,10 @@ public GridLength ProfileWidth
761759
/// Initializes a new instance of the <see cref="NetworkInterfaceViewModel"/> class.
762760
/// </summary>
763761
/// <param name="instance">The dialog coordinator instance.</param>
764-
public NetworkInterfaceViewModel(IDialogCoordinator instance)
762+
public NetworkInterfaceViewModel()
765763
{
766764
_isLoading = true;
767765

768-
_dialogCoordinator = instance;
769-
770766
LoadNetworkInterfaces().ConfigureAwait(false);
771767

772768
InitialBandwidthChart();
@@ -1219,24 +1215,26 @@ private void Renew6Action()
12191215

12201216
private async Task AddIPv4AddressAction()
12211217
{
1222-
var customDialog = new CustomDialog
1223-
{
1224-
Title = Strings.AddIPv4Address
1225-
};
1218+
var childWindow = new IPAddressAndSubnetmaskChildWindow();
12261219

1227-
var ipAddressAndSubnetmaskViewModel = new IPAddressAndSubnetmaskViewModel(async instance =>
1220+
var childWindowViewModel = new IPAddressAndSubnetmaskViewModel(async instance =>
12281221
{
1229-
await _dialogCoordinator.HideMetroDialogAsync(this, customDialog);
1222+
childWindow.IsOpen = false;
1223+
ConfigurationManager.Current.IsChildWindowOpen = false;
12301224

12311225
await AddIPv4Address(instance.IPAddress, instance.Subnetmask);
1232-
}, _ => { _dialogCoordinator.HideMetroDialogAsync(this, customDialog); });
1226+
}, _ => {
1227+
childWindow.IsOpen = false;
1228+
ConfigurationManager.Current.IsChildWindowOpen = false;
1229+
});
12331230

1234-
customDialog.Content = new IPAddressAndSubnetmaskDialog
1235-
{
1236-
DataContext = ipAddressAndSubnetmaskViewModel
1237-
};
1231+
childWindow.Title = Strings.AddIPv4Address;
12381232

1239-
await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
1233+
childWindow.DataContext = childWindowViewModel;
1234+
1235+
ConfigurationManager.Current.IsChildWindowOpen = true;
1236+
1237+
await Application.Current.MainWindow.ShowChildWindowAsync(childWindow);
12401238
}
12411239

12421240
/// <summary>
@@ -1247,26 +1245,30 @@ private async Task AddIPv4AddressAction()
12471245

12481246
private async Task RemoveIPv4AddressAction()
12491247
{
1250-
var customDialog = new CustomDialog
1251-
{
1252-
Title = Strings.RemoveIPv4Address
1253-
};
1248+
var childWindow = new DropDownChildWindow();
12541249

1255-
var dropdownViewModel = new DropdownViewModel(async instance =>
1250+
var childWindowViewModel = new DropDownViewModel(async instance =>
12561251
{
1257-
await _dialogCoordinator.HideMetroDialogAsync(this, customDialog);
1252+
childWindow.IsOpen = false;
1253+
ConfigurationManager.Current.IsChildWindowOpen = false;
12581254

12591255
await RemoveIPv4Address(instance.SelectedValue.Split("/")[0]);
1260-
}, _ => { _dialogCoordinator.HideMetroDialogAsync(this, customDialog); },
1261-
SelectedNetworkInterface.IPv4Address.Select(x => $"{x.Item1}/{Subnetmask.ConvertSubnetmaskToCidr(x.Item2)}")
1262-
.ToList(), Strings.IPv4Address);
1256+
}, _ =>
1257+
{
1258+
childWindow.IsOpen = false;
1259+
ConfigurationManager.Current.IsChildWindowOpen = false;
1260+
},
1261+
[.. SelectedNetworkInterface.IPv4Address.Select(x => $"{x.Item1}/{Subnetmask.ConvertSubnetmaskToCidr(x.Item2)}")],
1262+
Strings.IPv4Address
1263+
);
12631264

1264-
customDialog.Content = new DropdownDialog
1265-
{
1266-
DataContext = dropdownViewModel
1267-
};
1265+
childWindow.Title = Strings.RemoveIPv4Address;
1266+
1267+
childWindow.DataContext = childWindowViewModel;
1268+
1269+
ConfigurationManager.Current.IsChildWindowOpen = true;
12681270

1269-
await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
1271+
await Application.Current.MainWindow.ShowChildWindowAsync(childWindow);
12701272
}
12711273

12721274
#endregion

Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Dragablz;
2-
using MahApps.Metro.Controls.Dialogs;
32
using MahApps.Metro.SimpleChildWindow;
43
using NETworkManager.Controls;
54
using NETworkManager.Localization.Resources;
@@ -28,8 +27,6 @@ public class RemoteDesktopHostViewModel : ViewModelBase, IProfileManager
2827
{
2928
#region Variables
3029

31-
private readonly IDialogCoordinator _dialogCoordinator;
32-
3330
private readonly DispatcherTimer _searchDispatcherTimer = new();
3431
private bool _searchDisabled;
3532

@@ -261,12 +258,10 @@ public GridLength ProfileWidth
261258

262259
#region Constructor, load settings
263260

264-
public RemoteDesktopHostViewModel(IDialogCoordinator instance)
261+
public RemoteDesktopHostViewModel()
265262
{
266263
_isLoading = true;
267264

268-
_dialogCoordinator = instance;
269-
270265
InterTabClient = new DragablzInterTabClient(ApplicationName.RemoteDesktop);
271266
InterTabPartition = nameof(ApplicationName.RemoteDesktop);
272267

Source/NETworkManager/Views/CredentialsChangePasswordChildWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
xmlns:simpleChildWindow="clr-namespace:MahApps.Metro.SimpleChildWindow;assembly=MahApps.Metro.SimpleChildWindow"
1111
CloseButtonCommand="{Binding Path=CancelCommand}"
1212
Style="{StaticResource DefaultChildWindow}"
13-
Loaded="ChildWindow_OnLoaded"
13+
Loaded="ChildWindow_OnLoaded"
1414
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:CredentialsChangePasswordViewModel}">
1515
<Grid Margin="10">
1616
<Grid.RowDefinitions>

Source/NETworkManager/Views/DNSLookupHostView.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Windows;
22
using System.Windows.Controls;
33
using System.Windows.Input;
4-
using MahApps.Metro.Controls.Dialogs;
54
using NETworkManager.ViewModels;
65

76
namespace NETworkManager.Views;

Source/NETworkManager/Views/DropdownDialog.xaml renamed to Source/NETworkManager/Views/DropDownChildWindow.xaml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
<UserControl x:Class="NETworkManager.Views.DropdownDialog"
1+
<simpleChildWindow:ChildWindow x:Class="NETworkManager.Views.DropDownChildWindow"
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"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:viewModels="clr-namespace:NETworkManager.ViewModels"
77
xmlns:converters="clr-namespace:NETworkManager.Converters;assembly=NETworkManager.Converters"
88
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
9-
mc:Ignorable="d" Loaded="UserControl_Loaded"
10-
d:DataContext="{d:DesignInstance viewModels:DropdownViewModel}">
11-
<UserControl.Resources>
9+
xmlns:simpleChildWindow="clr-namespace:MahApps.Metro.SimpleChildWindow;assembly=MahApps.Metro.SimpleChildWindow"
10+
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
11+
xmlns:validators="clr-namespace:NETworkManager.Validators;assembly=NETworkManager.Validators"
12+
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
13+
CloseButtonCommand="{Binding Path=CancelCommand}"
14+
Style="{StaticResource DefaultChildWindow}"
15+
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:DropDownViewModel}">
16+
<simpleChildWindow:ChildWindow.Resources>
1217
<converters:StringIsNotNullOrEmptyToBooleanConverter x:Key="StringIsNotNullOrEmptyToBooleanConverter" />
13-
</UserControl.Resources>
14-
<Grid Margin="0,20">
18+
</simpleChildWindow:ChildWindow.Resources>
19+
<Grid Margin="10">
1520
<Grid.RowDefinitions>
1621
<RowDefinition Height="*" />
1722
<RowDefinition Height="10" />
@@ -31,21 +36,23 @@
3136
<RowDefinition Height="Auto" />
3237
</Grid.RowDefinitions>
3338
<TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding ValueDescription}" />
34-
<ComboBox Grid.Column="2" Grid.Row="0" ItemsSource="{Binding Values}"
39+
<ComboBox Grid.Column="2" Grid.Row="0"
40+
x:Name="ComboBoxValues"
41+
ItemsSource="{Binding Values}"
3542
SelectedItem="{Binding SelectedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
3643
</Grid>
3744
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
3845
<Button Content="{x:Static localization:Strings.OK}" Command="{Binding OKCommand}" IsDefault="True"
39-
Margin="0,0,10,0">
46+
Margin="0,0,10,0">
4047
<Button.Style>
4148
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
4249
<Setter Property="IsEnabled" Value="False" />
4350
<Style.Triggers>
4451
<MultiDataTrigger>
4552
<MultiDataTrigger.Conditions>
4653
<Condition
47-
Binding="{Binding SelectedValue, Converter={StaticResource StringIsNotNullOrEmptyToBooleanConverter}}"
48-
Value="True" />
54+
Binding="{Binding SelectedValue, Converter={StaticResource StringIsNotNullOrEmptyToBooleanConverter}}"
55+
Value="True" />
4956
</MultiDataTrigger.Conditions>
5057
<MultiDataTrigger.Setters>
5158
<Setter Property="IsEnabled" Value="True" />
@@ -56,7 +63,7 @@
5663
</Button.Style>
5764
</Button>
5865
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True"
59-
Style="{StaticResource DefaultButton}" />
66+
Style="{StaticResource DefaultButton}" />
6067
</StackPanel>
6168
</Grid>
62-
</UserControl>
69+
</simpleChildWindow:ChildWindow>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace NETworkManager.Views;
2+
3+
public partial class DropDownChildWindow
4+
{
5+
public DropDownChildWindow()
6+
{
7+
InitializeComponent();
8+
}
9+
}

Source/NETworkManager/Views/DropdownDialog.xaml.cs

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

Source/NETworkManager/Views/ExportChildWindow.xaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
1515
CloseButtonCommand="{Binding Path=CancelCommand}"
1616
Style="{StaticResource DefaultChildWindow}"
17+
Loaded="ChildWindow_OnLoaded"
1718
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:ExportViewModel}">
1819
<simpleChildWindow:ChildWindow.Resources>
1920
<converters:BooleanToVisibilityCollapsedConverter x:Key="BooleanToVisibilityCollapsedConverter" />
@@ -72,10 +73,11 @@
7273
</WrapPanel>
7374
<TextBlock Grid.Column="0" Grid.Row="4" Text="{x:Static localization:Strings.Path}"
7475
Style="{StaticResource CenterTextBlock}" />
75-
<TextBox Grid.Column="2" Grid.Row="4" x:Name="TextBoxExportFilePath"
76-
mah:TextBoxHelper.Watermark="{x:Static localization:Strings.Location}"
77-
Style="{StaticResource BrowseFolderTextBox}"
78-
mah:TextBoxHelper.ButtonCommand="{Binding BrowseFileCommand}">
76+
<TextBox Grid.Column="2" Grid.Row="4"
77+
x:Name="TextBoxExportFilePath"
78+
mah:TextBoxHelper.Watermark="{x:Static localization:Strings.Location}"
79+
Style="{StaticResource BrowseFolderTextBox}"
80+
mah:TextBoxHelper.ButtonCommand="{Binding BrowseFileCommand}">
7981
<TextBox.Text>
8082
<Binding Path="FilePath" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
8183
<Binding.ValidationRules>
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
namespace NETworkManager.Views;
1+
using System;
2+
using System.Windows.Threading;
3+
4+
namespace NETworkManager.Views;
25

36
public partial class ExportChildWindow
47
{
58
public ExportChildWindow()
69
{
710
InitializeComponent();
811
}
9-
}
12+
13+
private void ChildWindow_OnLoaded(object sender, System.Windows.RoutedEventArgs e)
14+
{
15+
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
16+
{
17+
TextBoxExportFilePath.Focus();
18+
}));
19+
}
20+
}

0 commit comments

Comments
 (0)