Skip to content

Commit

Permalink
Feature: IP Scanner button in network interface, fix bug in redirect (#…
Browse files Browse the repository at this point in the history
…2046)

* Feature: IP Scanner button for selected interface

* Fix: Show error message if application was not found on redirect

* Docs: Add #2046
  • Loading branch information
BornToBeRoot committed Mar 14, 2023
1 parent 56a7f7e commit 821a471
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 24 deletions.
Expand Up @@ -11,11 +11,11 @@ namespace NETworkManager.Converters;
public sealed class IPAddressSubnetmaskTupleArrayToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
{
if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
return "-/-";

if (!(value is Tuple<IPAddress, IPAddress>[] ipAddresses))
if (value is not Tuple<IPAddress, IPAddress>[] ipAddresses)
return "-/-";

var result = string.Empty;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Source/NETworkManager.Localization/Resources/Strings.resx
Expand Up @@ -3316,4 +3316,7 @@ Changes to this value will take effect after the application is restarted. Wheth
<data name="ScanPorts" xml:space="preserve">
<value>Scan ports</value>
</data>
<data name="CouldNotFindApplicationXXXMessage" xml:space="preserve">
<value>Could not find the application "{0}". Maybe the application was hidden in the settings?</value>
</data>
</root>
2 changes: 1 addition & 1 deletion Source/NETworkManager.Models/EventSystem/EventSystem.cs
Expand Up @@ -4,7 +4,7 @@ namespace NETworkManager.Models.EventSystem;

public class EventSystem
{
// This will notify the mail window, to change the view to another application and redirect some data (hostname, ip)
// This will notify the main window, to change the view to another application and redirect some data (hostname, ip)
public static event EventHandler OnRedirectDataToApplicationEvent;

public static void RedirectToApplication(ApplicationName application, string data)
Expand Down
17 changes: 15 additions & 2 deletions Source/NETworkManager/MainWindow.xaml.cs
Expand Up @@ -936,13 +936,26 @@ private void ClearSearchOnApplicationListMinimize()
ListViewApplication.ScrollIntoView(SelectedApplication);
}

private void EventSystem_RedirectDataToApplicationEvent(object sender, EventArgs e)
private async void EventSystem_RedirectDataToApplicationEvent(object sender, EventArgs e)
{
if (e is not EventSystemRedirectArgs data)
return;

// Change view
SelectedApplication = Applications.SourceCollection.Cast<ApplicationInfo>().FirstOrDefault(x => x.Name == data.Application);
var application = Applications.Cast<ApplicationInfo>().FirstOrDefault(x => x.Name == data.Application);

if (application == null)
{
var settings = AppearanceManager.MetroDialog;
settings.AffirmativeButtonText = Localization.Resources.Strings.OK;

await this.ShowMessageAsync(Localization.Resources.Strings.Error, string.Format(Localization.Resources.Strings.CouldNotFindApplicationXXXMessage, data.Application.ToString()));

return;
}

// Change view
SelectedApplication = application;

// Crate a new tab / perform action
switch (data.Application)
Expand Down
7 changes: 7 additions & 0 deletions Source/NETworkManager/Resources/Styles/RectangleStyles.xaml
@@ -1,6 +1,13 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks">
<Style x:Key="ButtonWithImageRectangle" TargetType="{x:Type Rectangle}">
<Setter Property="Width" Value="20" />
<Setter Property="Height" Value="20" />
<Setter Property="Margin" Value="10,5,0,5" />
<Setter Property="Fill" Value="{DynamicResource MahApps.Brushes.Gray3}" />
</Style>

<Style x:Key="HelpImageRectangle" TargetType="{x:Type Rectangle}">
<Style.Resources>
<Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource DefaultToolTip}" />
Expand Down
9 changes: 7 additions & 2 deletions Source/NETworkManager/Resources/Styles/TextBlockStyles.xaml
Expand Up @@ -52,8 +52,13 @@

<Style x:Key="StatusMessageTextBlock" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource WrapTextBlock}" />

<Style x:Key="CenterTextBlock" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource DefaultTextBlock}" >
<Setter Property="Margin" Value="0,0,10,0" />
<!-- TextBlock style for buttons with images and text -->
<Style x:Key="ButtonWithImageTextBlock" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource DefaultTextBlock}" >
<Setter Property="Margin" Value="10,5" />
<Setter Property="TextAlignment" Value="Center" />
</Style>

<Style x:Key="CenterTextBlock" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource DefaultTextBlock}" >
<Setter Property="VerticalAlignment" Value="Center" />
</Style>

Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager/Resources/Styles/TextBoxStyles.xaml
Expand Up @@ -11,7 +11,7 @@
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource DefaultErrorTemplate}" />
</Style>

<!-- Apply the default design to all text boxes -->
<!-- Apply the default design to all TextBox -->
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource DefaultTextBox}" />

<Style x:Key="ConsoleTextBox" TargetType="{x:Type TextBox}" BasedOn="{StaticResource DefaultTextBox}">
Expand Down
16 changes: 15 additions & 1 deletion Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs
Expand Up @@ -20,6 +20,7 @@
using NETworkManager.Profiles;
using System.Windows.Threading;
using NETworkManager.Models;
using NETworkManager.Models.EventSystem;

namespace NETworkManager.ViewModels;

Expand Down Expand Up @@ -681,7 +682,20 @@ public void OpenNetworkConnectionsAction()
{
OpenNetworkConnectionsAsync();
}


public ICommand IPScannerCommand => new RelayCommand(p => IPScannerAction(), AdditionalCommands_CanExecute);

private void IPScannerAction()
{
var ipTuple = SelectedNetworkInterface?.IPv4Address.FirstOrDefault();

// ToDo: Log error in the future
if (ipTuple == null)
return;

EventSystem.RedirectToApplication(ApplicationName.IPScanner, $"{ipTuple.Item1}/{Subnetmask.ConvertSubnetmaskToCidr(ipTuple.Item2)}");
}

public ICommand FlushDNSCommand => new RelayCommand(p => FlushDNSAction(), AdditionalCommands_CanExecute);

private void FlushDNSAction()
Expand Down
61 changes: 46 additions & 15 deletions Source/NETworkManager/Views/NetworkInterfaceView.xaml
Expand Up @@ -244,12 +244,41 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle Width="20" Height="20" Margin="10,5,0,5" Fill="{DynamicResource MahApps.Brushes.Gray3}">
<Rectangle Style="{StaticResource ButtonWithImageRectangle}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Modern Kind=Network}" />
</Rectangle.OpacityMask>
</Rectangle>
<TextBlock Grid.Column="1" Text="{x:Static localization:Strings.NetworkConnectionsDots}" FontSize="14" Margin="10,5" TextAlignment="Center"/>
<TextBlock Grid.Column="1" Text="{x:Static localization:Strings.NetworkConnectionsDots}" Style="{StaticResource ButtonWithImageTextBlock}" />
</Grid>
</Button.Content>
</Button>
<Button HorizontalAlignment="Left" Command="{Binding IPScannerCommand}" Margin="0,0,10,0">
<Button.Resources>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource ImageWithTextButton}">
<Setter Property="IsEnabled" Value="True" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsNetworkInterfaceLoading}" Value="True">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=SelectedNetworkInterface.IPv4ProtocolAvailable}" Value="False">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Resources>
<Button.Content>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle Style="{StaticResource ButtonWithImageRectangle}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Uniform" Visual="{iconPacks:FontAwesome Kind=NetworkWiredSolid}" />
</Rectangle.OpacityMask>
</Rectangle>
<TextBlock Grid.Column="1" Text="{x:Static localization:Strings.IPScanner}" Style="{StaticResource ButtonWithImageTextBlock}" />
</Grid>
</Button.Content>
</Button>
Expand All @@ -260,12 +289,12 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle Width="20" Height="20" Margin="10,5,0,5" Fill="{DynamicResource MahApps.Brushes.Gray3}">
<Rectangle Style="{StaticResource ButtonWithImageRectangle}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Modern Kind=ListDelete}" />
</Rectangle.OpacityMask>
</Rectangle>
<TextBlock Grid.Column="1" Text="{x:Static localization:Strings.FlushDNSCache}" FontSize="14" Margin="10,5" TextAlignment="Center"/>
<TextBlock Grid.Column="1" Text="{x:Static localization:Strings.FlushDNSCache}" Style="{StaticResource ButtonWithImageTextBlock}" />
</Grid>
</Button.Content>
</Button>
Expand All @@ -276,12 +305,12 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle Width="20" Height="20" Margin="10,4,0,4" Fill="{DynamicResource MahApps.Brushes.Gray3}">
<Rectangle Style="{StaticResource ButtonWithImageRectangle}" Margin="10,4,0,4">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Modern Kind=Refresh}" />
</Rectangle.OpacityMask>
</Rectangle>
<TextBlock Grid.Column="1" Text="{x:Static localization:Strings.ReleaseRenew}" FontSize="14" Margin="10,4" TextAlignment="Center"/>
<TextBlock Grid.Column="1" Text="{x:Static localization:Strings.ReleaseRenew}" Style="{StaticResource ButtonWithImageTextBlock}" Margin="10,4" />
</Grid>
</mah:DropDownButton.Content>
<mah:DropDownButton.Items>
Expand Down Expand Up @@ -603,6 +632,7 @@
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
Expand All @@ -612,8 +642,8 @@
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Style="{StaticResource CenterTextBlock}" Text="{x:Static localization:Strings.IPv4Address}" />
<TextBox x:Name="TextBoxConfigIPAddress" Grid.Column="1" Grid.Row="0" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleIPv4Address}">
<TextBlock Grid.Column="0" Grid.Row="0" Text="{x:Static localization:Strings.IPv4Address}" />
<TextBox x:Name="TextBoxConfigIPAddress" Grid.Column="2" Grid.Row="0" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleIPv4Address}">
<TextBox.Text>
<Binding Path="ConfigIPAddress" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
Expand All @@ -623,8 +653,8 @@
</Binding>
</TextBox.Text>
</TextBox>
<TextBlock Grid.Column="0" Grid.Row="2" Style="{StaticResource CenterTextBlock}" Text="{x:Static localization:Strings.SubnetmaskOrCIDR}" />
<ComboBox x:Name="ComboBoxConfigSubnetmaskOrCidr" Grid.Column="1" Grid.Row="2" Style="{StaticResource EditableComboBox}" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleIPv4SubnetmaskIPv4CIDR}" ItemsSource="{x:Static network:Subnetmask.List}">
<TextBlock Grid.Column="0" Grid.Row="2" Text="{x:Static localization:Strings.SubnetmaskOrCIDR}" />
<ComboBox x:Name="ComboBoxConfigSubnetmaskOrCidr" Grid.Column="2" Grid.Row="2" Style="{StaticResource EditableComboBox}" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleIPv4SubnetmaskIPv4CIDR}" ItemsSource="{x:Static network:Subnetmask.List}">
<ComboBox.Text>
<Binding Path="ConfigSubnetmaskOrCidr" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
Expand All @@ -650,7 +680,7 @@
</ComboBox.ItemTemplate>
</ComboBox>
<TextBlock Grid.Column="0" Grid.Row="4" Style="{StaticResource CenterTextBlock}" Text="{x:Static localization:Strings.DefaultGateway}" />
<TextBox x:Name="TextBoxConfigGateway" Grid.Column="1" Grid.Row="4" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleIPv4Gateway}">
<TextBox x:Name="TextBoxConfigGateway" Grid.Column="2" Grid.Row="4" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleIPv4Gateway}">
<TextBox.Text>
<Binding Path="ConfigGateway" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
Expand All @@ -677,15 +707,16 @@
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Style="{StaticResource CenterTextBlock}" Text="{x:Static localization:Strings.PrimaryDNSServer}" />
<TextBox x:Name="TextBoxConfigPrimaryDNSServer" Grid.Column="1" Grid.Row="0" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleIPv4Gateway}">
<TextBlock Grid.Column="0" Grid.Row="0" Text="{x:Static localization:Strings.PrimaryDNSServer}" />
<TextBox x:Name="TextBoxConfigPrimaryDNSServer" Grid.Column="2" Grid.Row="0" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleIPv4Gateway}">
<TextBox.Text>
<Binding Path="ConfigPrimaryDNSServer" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
Expand All @@ -694,8 +725,8 @@
</Binding>
</TextBox.Text>
</TextBox>
<TextBlock Grid.Column="0" Grid.Row="2" Style="{StaticResource CenterTextBlock}" Text="{x:Static localization:Strings.SecondaryDNSServer}" />
<TextBox x:Name="TextBoxConfigSecondaryDNSServer" Grid.Column="1" Grid.Row="2" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleIPv4DNSServer}">
<TextBlock Grid.Column="0" Grid.Row="2" Text="{x:Static localization:Strings.SecondaryDNSServer}" />
<TextBox x:Name="TextBoxConfigSecondaryDNSServer" Grid.Column="2" Grid.Row="2" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleIPv4DNSServer}">
<TextBox.Text>
<Binding Path="ConfigSecondaryDNSServer" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
Expand Down

0 comments on commit 821a471

Please sign in to comment.