Skip to content

Commit

Permalink
Merge pull request #1129 from BornToBeRoot/issue/274
Browse files Browse the repository at this point in the history
Use dropdown to remove ip address to prevent user errors
  • Loading branch information
mergify[bot] authored Jun 26, 2021
2 parents 541ec5c + 56fe2c9 commit 3556982
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Source/NETworkManager/NETworkManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
<Page Update="Views\CredentialsChangePasswordDialog.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
<Page Update="Views\DropdownDialog.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Views\NetworkConnectionView.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
Expand Down
68 changes: 68 additions & 0 deletions Source/NETworkManager/ViewModels/DropdownViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using NETworkManager.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;

namespace NETworkManager.ViewModels
{
public class DropdownViewModel : ViewModelBase
{
public ICommand OKCommand { get; }

public ICommand CancelCommand { get; }

private string _valueDescription;
public string ValueDescription
{
get => _valueDescription;
set
{
if(value == _valueDescription)
return;

_valueDescription = value;
OnPropertyChanged();
}
}

private List<string> _values;
public List<string> Values
{
get => _values;
set
{
if (value == _values)
return;

_values = value;
OnPropertyChanged();
}
}

private string _selectedValue;
public string SelectedValue
{
get => _selectedValue;
set
{
if (value == _selectedValue)
return;

_selectedValue = value;
OnPropertyChanged();
}
}

public DropdownViewModel(Action<DropdownViewModel> okCommand, Action<DropdownViewModel> cancelHandler, List<string> values, string valueDescription)
{
ValueDescription = valueDescription;
Values = values;

SelectedValue = Values.FirstOrDefault();

OKCommand = new RelayCommand(p => okCommand(this));
CancelCommand = new RelayCommand(p => cancelHandler(this));
}
}
}
10 changes: 5 additions & 5 deletions Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -806,19 +806,19 @@ private async Task RemoveIPv4AddressAction()
Title = Localization.Resources.Strings.RemoveIPv4Address
};

var ipAddressViewModel = new IPAddressViewModel(async instance =>
var dropdownViewModel = new DropdownViewModel(async instance =>
{
await _dialogCoordinator.HideMetroDialogAsync(this, customDialog);

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

customDialog.Content = new IPAddressDialog
customDialog.Content = new DropdownDialog
{
DataContext = ipAddressViewModel
DataContext = dropdownViewModel
};

await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
Expand Down
56 changes: 56 additions & 0 deletions Source/NETworkManager/Views/DropdownDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<UserControl x:Class="NETworkManager.Views.DropdownDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:viewModels="clr-namespace:NETworkManager.ViewModels"
xmlns:converters="clr-namespace:NETworkManager.Converters;assembly=NETworkManager.Converters"
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
mc:Ignorable="d" Loaded="UserControl_Loaded" d:DataContext="{d:DesignInstance viewModels:DropdownViewModel}">
<UserControl.Resources>
<converters:StringIsNotNullOrEmptyToBooleanConverter x:Key="StringIsNotNullOrEmptyToBooleanConverter" />
</UserControl.Resources>
<Grid Margin="0,20">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.Resources>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CenterTextBlock}" />
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource DefaultTextBox}" />
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding ValueDescription}" />
<ComboBox Grid.Column="2" Grid.Row="0" ItemsSource="{Binding Values}" SelectedItem="{Binding SelectedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="{x:Static localization:Strings.OK}" Command="{Binding OKCommand}" IsDefault="True" Margin="0,0,10,0">
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
<Setter Property="IsEnabled" Value="False" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding SelectedValue, Converter={StaticResource StringIsNotNullOrEmptyToBooleanConverter}}" Value="True" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="IsEnabled" Value="True" />
</MultiDataTrigger.Setters>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
</StackPanel>
</Grid>
</UserControl>
15 changes: 15 additions & 0 deletions Source/NETworkManager/Views/DropdownDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace NETworkManager.Views
{
public partial class DropdownDialog
{
public DropdownDialog()
{
InitializeComponent();
}

private void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
{

}
}
}
4 changes: 2 additions & 2 deletions docs/04_Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ permalink: /Changelog

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

0 comments on commit 3556982

Please sign in to comment.