Skip to content

Commit 3556982

Browse files
authored
Merge pull request #1129 from BornToBeRoot/issue/274
Use dropdown to remove ip address to prevent user errors
2 parents 541ec5c + 56fe2c9 commit 3556982

File tree

6 files changed

+150
-7
lines changed

6 files changed

+150
-7
lines changed

Source/NETworkManager/NETworkManager.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@
9090
<Page Update="Views\CredentialsChangePasswordDialog.xaml">
9191
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
9292
</Page>
93+
<Page Update="Views\DropdownDialog.xaml">
94+
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
95+
<SubType>Designer</SubType>
96+
</Page>
9397
<Page Update="Views\NetworkConnectionView.xaml">
9498
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
9599
</Page>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using NETworkManager.Utilities;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Windows.Input;
6+
7+
namespace NETworkManager.ViewModels
8+
{
9+
public class DropdownViewModel : ViewModelBase
10+
{
11+
public ICommand OKCommand { get; }
12+
13+
public ICommand CancelCommand { get; }
14+
15+
private string _valueDescription;
16+
public string ValueDescription
17+
{
18+
get => _valueDescription;
19+
set
20+
{
21+
if(value == _valueDescription)
22+
return;
23+
24+
_valueDescription = value;
25+
OnPropertyChanged();
26+
}
27+
}
28+
29+
private List<string> _values;
30+
public List<string> Values
31+
{
32+
get => _values;
33+
set
34+
{
35+
if (value == _values)
36+
return;
37+
38+
_values = value;
39+
OnPropertyChanged();
40+
}
41+
}
42+
43+
private string _selectedValue;
44+
public string SelectedValue
45+
{
46+
get => _selectedValue;
47+
set
48+
{
49+
if (value == _selectedValue)
50+
return;
51+
52+
_selectedValue = value;
53+
OnPropertyChanged();
54+
}
55+
}
56+
57+
public DropdownViewModel(Action<DropdownViewModel> okCommand, Action<DropdownViewModel> cancelHandler, List<string> values, string valueDescription)
58+
{
59+
ValueDescription = valueDescription;
60+
Values = values;
61+
62+
SelectedValue = Values.FirstOrDefault();
63+
64+
OKCommand = new RelayCommand(p => okCommand(this));
65+
CancelCommand = new RelayCommand(p => cancelHandler(this));
66+
}
67+
}
68+
}

Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -806,19 +806,19 @@ private async Task RemoveIPv4AddressAction()
806806
Title = Localization.Resources.Strings.RemoveIPv4Address
807807
};
808808

809-
var ipAddressViewModel = new IPAddressViewModel(async instance =>
809+
var dropdownViewModel = new DropdownViewModel(async instance =>
810810
{
811811
await _dialogCoordinator.HideMetroDialogAsync(this, customDialog);
812812

813-
RemoveIPv4Address(instance.IPAddress);
813+
RemoveIPv4Address(instance.SelectedValue.Split("/")[0]);
814814
}, instance =>
815815
{
816816
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
817-
});
817+
}, SelectedNetworkInterface.IPv4Address.Select(x => $"{x.Item1}/{Subnetmask.ConvertSubnetmaskToCidr(x.Item2)}").ToList(), Localization.Resources.Strings.IPv4Address);
818818

819-
customDialog.Content = new IPAddressDialog
819+
customDialog.Content = new DropdownDialog
820820
{
821-
DataContext = ipAddressViewModel
821+
DataContext = dropdownViewModel
822822
};
823823

824824
await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<UserControl x:Class="NETworkManager.Views.DropdownDialog"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:viewModels="clr-namespace:NETworkManager.ViewModels"
7+
xmlns:converters="clr-namespace:NETworkManager.Converters;assembly=NETworkManager.Converters"
8+
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
9+
mc:Ignorable="d" Loaded="UserControl_Loaded" d:DataContext="{d:DesignInstance viewModels:DropdownViewModel}">
10+
<UserControl.Resources>
11+
<converters:StringIsNotNullOrEmptyToBooleanConverter x:Key="StringIsNotNullOrEmptyToBooleanConverter" />
12+
</UserControl.Resources>
13+
<Grid Margin="0,20">
14+
<Grid.RowDefinitions>
15+
<RowDefinition Height="*" />
16+
<RowDefinition Height="10" />
17+
<RowDefinition Height="Auto" />
18+
</Grid.RowDefinitions>
19+
<Grid Grid.Row="0">
20+
<Grid.Resources>
21+
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CenterTextBlock}" />
22+
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource DefaultTextBox}" />
23+
</Grid.Resources>
24+
<Grid.ColumnDefinitions>
25+
<ColumnDefinition Width="1*" />
26+
<ColumnDefinition Width="10" />
27+
<ColumnDefinition Width="1*" />
28+
</Grid.ColumnDefinitions>
29+
<Grid.RowDefinitions>
30+
<RowDefinition Height="Auto" />
31+
</Grid.RowDefinitions>
32+
<TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding ValueDescription}" />
33+
<ComboBox Grid.Column="2" Grid.Row="0" ItemsSource="{Binding Values}" SelectedItem="{Binding SelectedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
34+
</Grid>
35+
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
36+
<Button Content="{x:Static localization:Strings.OK}" Command="{Binding OKCommand}" IsDefault="True" Margin="0,0,10,0">
37+
<Button.Style>
38+
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
39+
<Setter Property="IsEnabled" Value="False" />
40+
<Style.Triggers>
41+
<MultiDataTrigger>
42+
<MultiDataTrigger.Conditions>
43+
<Condition Binding="{Binding SelectedValue, Converter={StaticResource StringIsNotNullOrEmptyToBooleanConverter}}" Value="True" />
44+
</MultiDataTrigger.Conditions>
45+
<MultiDataTrigger.Setters>
46+
<Setter Property="IsEnabled" Value="True" />
47+
</MultiDataTrigger.Setters>
48+
</MultiDataTrigger>
49+
</Style.Triggers>
50+
</Style>
51+
</Button.Style>
52+
</Button>
53+
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
54+
</StackPanel>
55+
</Grid>
56+
</UserControl>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace NETworkManager.Views
2+
{
3+
public partial class DropdownDialog
4+
{
5+
public DropdownDialog()
6+
{
7+
InitializeComponent();
8+
}
9+
10+
private void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
11+
{
12+
13+
}
14+
}
15+
}

docs/04_Changelog.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ permalink: /Changelog
88

99
<!--
1010
## What's new?
11-
- Dashbaord - Regex for IPv4 fixed [#841](https://github.com/BornToBeRoot/NETworkManager/issues/841){:target="_blank"}
1211
- Network Interface - Remove IPv4 address added [#212](https://github.com/BornToBeRoot/NETworkManager/issues/212){:target="_blank"}
13-
- IP Scanner - Custom commands fixed [2e53b292f1dca7808fed509aa9ac39e009a3030f](https://github.com/BornToBeRoot/NETworkManager/commit/2e53b292f1dca7808fed509aa9ac39e009a3030f){:target="_blank"}
1412
- NETworkManager is now available on WinGet `winget install BornToBeRoot.NETworkManager`
1513
1614
# Bugfixes
15+
- Dashbaord - Regex for IPv4 fixed [#841](https://github.com/BornToBeRoot/NETworkManager/issues/841){:target="_blank"}
16+
- IP Scanner - Custom commands fixed [2e53b292f1dca7808fed509aa9ac39e009a3030f](https://github.com/BornToBeRoot/NETworkManager/commit/2e53b292f1dca7808fed509aa9ac39e009a3030f){:target="_blank"}
1717
- Remote Desktop - Add disconnect reason 4 [#845](https://github.com/BornToBeRoot/NETworkManager/issues/845){:target="_blank"}
1818
- Close/Minimize/Maximize buttons not visible in light theme
1919

0 commit comments

Comments
 (0)