Skip to content

Commit 8d7a212

Browse files
committed
WakeOnLAN/PortScanner/NetworkInterface - Search implementet
1 parent df0dadf commit 8d7a212

7 files changed

Lines changed: 165 additions & 18 deletions

File tree

Source/NETworkManager/ViewModels/Applications/IPScannerViewModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ public IPScannerViewModel(IDialogCoordinator instance)
339339
return info.Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0;
340340
};
341341

342-
343342
LoadSettings();
344343

345344
// Detect if settings have changed...

Source/NETworkManager/ViewModels/Applications/NetworkInterfaceViewModel.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,23 @@ public bool ExpandProfileView
618618
OnPropertyChanged();
619619
}
620620
}
621+
622+
private string _search;
623+
public string Search
624+
{
625+
get { return _search; }
626+
set
627+
{
628+
if (value == _search)
629+
return;
630+
631+
_search = value;
632+
633+
NetworkInterfaceProfiles.Refresh();
634+
635+
OnPropertyChanged();
636+
}
637+
}
621638
#endregion
622639
#endregion
623640

@@ -635,6 +652,18 @@ public NetworkInterfaceViewModel(IDialogCoordinator instance)
635652

636653
_networkInterfaceProfiles = CollectionViewSource.GetDefaultView(NetworkInterfaceProfileManager.Profiles);
637654
_networkInterfaceProfiles.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
655+
_networkInterfaceProfiles.Filter = o =>
656+
{
657+
if (string.IsNullOrEmpty(Search))
658+
return true;
659+
660+
NetworkInterfaceProfileInfo info = o as NetworkInterfaceProfileInfo;
661+
662+
string search = Search.Trim();
663+
664+
// Search by: Name
665+
return info.Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0;
666+
};
638667

639668
LoadSettings();
640669

Source/NETworkManager/ViewModels/Applications/PortScannerViewModel.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,23 @@ public bool ExpandProfileView
319319
OnPropertyChanged();
320320
}
321321
}
322+
323+
private string _search;
324+
public string Search
325+
{
326+
get { return _search; }
327+
set
328+
{
329+
if (value == _search)
330+
return;
331+
332+
_search = value;
333+
334+
PortScannerProfiles.Refresh();
335+
336+
OnPropertyChanged();
337+
}
338+
}
322339
#endregion
323340
#endregion
324341

@@ -334,6 +351,18 @@ public PortScannerViewModel(IDialogCoordinator instance)
334351
_portScannerProfiles = CollectionViewSource.GetDefaultView(PortScannerProfileManager.Profiles);
335352
_portScannerProfiles.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
336353
_portScannerProfiles.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
354+
_portScannerProfiles.Filter = o =>
355+
{
356+
if (string.IsNullOrEmpty(Search))
357+
return true;
358+
359+
PortScannerProfileInfo info = o as PortScannerProfileInfo;
360+
361+
string search = Search.Trim();
362+
363+
// Search by: Name
364+
return info.Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0;
365+
};
337366

338367
LoadSettings();
339368

Source/NETworkManager/ViewModels/Applications/WakeOnLanViewModel.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,23 @@ public bool ExpandClientView
178178
OnPropertyChanged();
179179
}
180180
}
181+
182+
private string _search;
183+
public string Search
184+
{
185+
get { return _search; }
186+
set
187+
{
188+
if (value == _search)
189+
return;
190+
191+
_search = value;
192+
193+
WakeOnLANClients.Refresh();
194+
195+
OnPropertyChanged();
196+
}
197+
}
181198
#endregion
182199
#endregion
183200

@@ -192,6 +209,18 @@ public WakeOnLANViewModel(IDialogCoordinator instance)
192209
_wakeOnLANClients = CollectionViewSource.GetDefaultView(WakeOnLANClientManager.Clients);
193210
_wakeOnLANClients.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
194211
_wakeOnLANClients.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
212+
_wakeOnLANClients.Filter = o =>
213+
{
214+
if (string.IsNullOrEmpty(Search))
215+
return true;
216+
217+
WakeOnLANClientInfo info = o as WakeOnLANClientInfo;
218+
219+
string search = Search.Trim();
220+
221+
// Search by: Name
222+
return info.Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0;
223+
};
195224

196225
LoadSettings();
197226

Source/NETworkManager/Views/Applications/NetworkInterfaceView.xaml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:Network="clr-namespace:NETworkManager.Models.Network"
77
xmlns:IconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
8+
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
89
xmlns:Converter="clr-namespace:NETworkManager.Converters"
910
xmlns:Validator="clr-namespace:NETworkManager.Validators"
1011
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
@@ -17,6 +18,7 @@
1718
<Converter:BooleanReverseToVisibilityConverter x:Key="BooleanReverseToVisibilityConverter" />
1819
<Converter:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
1920
<Converter:IPAddressArrayToStringConverter x:Key="IPAddressArrayToStringConverter" />
21+
<Converter:NullOrEmptyToBoolConverter x:Key="NullOrEmptyToBoolConverter" />
2022
<Converter:NullToFalseConverter x:Key="NullToFalseConverter" />
2123
<Converter:PhysicalAddressToStringConverter x:Key="PhysicalAddressToStringConverter" />
2224
<Converter:ValidateNetworkInterfaceProfileConverter x:Key="ValidateNetworkInterfaceProfileConverter" />
@@ -486,11 +488,24 @@
486488
<Expander x:Name="expanderProfiles" Header="{DynamicResource String_Header_Profiles}" Style="{StaticResource RightExpander}" IsExpanded="{Binding ExpandProfileView}">
487489
<Grid Width="250">
488490
<Grid.RowDefinitions>
491+
<RowDefinition Height="Auto" />
492+
<RowDefinition Height="10" />
489493
<RowDefinition Height="*" />
490494
<RowDefinition Height="10" />
491495
<RowDefinition Height="Auto" />
492496
</Grid.RowDefinitions>
493-
<ListBox Grid.Column="0" Grid.Row="0" x:Name="listBoxProfiles" FontSize="14" ItemsSource="{Binding NetworkInterfaceProfiles}" DisplayMemberPath="Name" SelectedItem="{Binding SelectedProfile}"> <ListBox.Resources>
497+
<TextBox x:Name="txtSearch" Grid.Column="0" BorderBrush="{DynamicResource GrayBrush8}" BorderThickness="1" FontSize="14" VerticalAlignment="Center" Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_Search}" Controls:TextBoxHelper.ClearTextButton="True">
498+
<TextBox.Style>
499+
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource SearchMetroTextBox}">
500+
<Style.Triggers>
501+
<Trigger Property="Controls:TextBoxHelper.HasText" Value="True">
502+
<Setter Property="Controls:TextBoxHelper.ButtonContentTemplate" Value="{x:Null}" />
503+
</Trigger>
504+
</Style.Triggers>
505+
</Style>
506+
</TextBox.Style>
507+
</TextBox>
508+
<ListBox Grid.Column="0" Grid.Row="2" x:Name="listBoxProfiles" FontSize="14" ItemsSource="{Binding NetworkInterfaceProfiles}" DisplayMemberPath="Name" SelectedItem="{Binding SelectedProfile}"> <ListBox.Resources>
494509
<Style TargetType="{x:Type ScrollViewer}" BasedOn="{StaticResource DefaulScrollViewer}" />
495510
<ContextMenu x:Key="ListBoxItemContextMenu" Opened="ContextMenu_Opened" MinWidth="150">
496511
<MenuItem Header="{DynamicResource String_Delete}" Command="{Binding DeleteProfileCommand}">
@@ -511,19 +526,25 @@
511526
<KeyBinding Command="{Binding DeleteProfileCommand}" Key="Delete" />
512527
</ListBox.InputBindings>
513528
</ListBox>
514-
<TextBlock Grid.Column="0" Grid.Row="0" FontSize="18" Foreground="{DynamicResource GrayBrush3}" Text="{DynamicResource String_NoProfilesFoundCreateOne}" VerticalAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center" Margin="10,0" >
529+
<TextBlock Grid.Row="2" FontSize="18" Foreground="{DynamicResource GrayBrush3}" VerticalAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center" Margin="10,0" >
515530
<TextBlock.Style>
516531
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource HeaderTextBlock}">
517532
<Setter Property="Visibility" Value="Collapsed" />
518533
<Style.Triggers>
519-
<DataTrigger Binding="{Binding NetworkInterfaceProfiles.Count}" Value="0">
520-
<Setter Property="Visibility" Value="Visible" />
534+
<DataTrigger Binding="{Binding NetworkInterfaceProfiles.Count}" Value="0" >
535+
<DataTrigger.Setters>
536+
<Setter Property="Visibility" Value="Visible" />
537+
<Setter Property="Text" Value="{DynamicResource String_NoProfilesFoundCreateOne}" />
538+
</DataTrigger.Setters>
539+
</DataTrigger>
540+
<DataTrigger Binding="{Binding Search, Converter={StaticResource NullOrEmptyToBoolConverter}}" Value="False">
541+
<Setter Property="Text" Value="{DynamicResource String_NothingFound}" />
521542
</DataTrigger>
522543
</Style.Triggers>
523544
</Style>
524545
</TextBlock.Style>
525546
</TextBlock>
526-
<Button x:Name="btnAddProfile" Grid.Column="0" Grid.Row="2" Command="{Binding AddProfileCommand}">
547+
<Button x:Name="btnAddProfile" Grid.Column="0" Grid.Row="4" Command="{Binding AddProfileCommand}">
527548
<Button.Content>
528549
<Grid>
529550
<Grid.ColumnDefinitions>

Source/NETworkManager/Views/Applications/PortScannerView.xaml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
<Converter:BooleanReverseConverter x:Key="BooleanReverseConverter" />
1717
<Converter:IPAddressToStringConverter x:Key="IPAddressToStringConverter" />
1818
<Converter:NullableDateTimeToStringConverter x:Key="NullableDateTimeToStringConverter" />
19-
<Converter:NullOrEmptyToStringConverter x:Key="NullOrEmptyToStringConverter" />
19+
<Converter:NullOrEmptyToBoolConverter x:Key="NullOrEmptyToBoolConverter" />
20+
<Converter:NullOrEmptyToStringConverter x:Key="NullOrEmptyToStringConverter" />
2021
<Converter:PortStatusToStringConverter x:Key="PortStatusToStringConverter" />
2122
</UserControl.Resources>
2223
<Grid>
@@ -251,11 +252,24 @@
251252
<Expander x:Name="expanderProfiles" Header="{DynamicResource String_Header_Profiles}" Style="{StaticResource RightExpander}" IsExpanded="{Binding ExpandProfileView}">
252253
<Grid Width="250">
253254
<Grid.RowDefinitions>
255+
<RowDefinition Height="Auto" />
256+
<RowDefinition Height="10" />
254257
<RowDefinition Height="*" />
255258
<RowDefinition Height="10" />
256259
<RowDefinition Height="Auto" />
257260
</Grid.RowDefinitions>
258-
<ListBox Grid.Column="0" Grid.Row="0" x:Name="listBoxProfiles" FontSize="14" ItemsSource="{Binding PortScannerProfiles}" DisplayMemberPath="Name" SelectedItem="{Binding SelectedProfile}">
261+
<TextBox x:Name="txtSearch" Grid.Column="0" BorderBrush="{DynamicResource GrayBrush8}" BorderThickness="1" FontSize="14" VerticalAlignment="Center" Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_Search}" Controls:TextBoxHelper.ClearTextButton="True">
262+
<TextBox.Style>
263+
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource SearchMetroTextBox}">
264+
<Style.Triggers>
265+
<Trigger Property="Controls:TextBoxHelper.HasText" Value="True">
266+
<Setter Property="Controls:TextBoxHelper.ButtonContentTemplate" Value="{x:Null}" />
267+
</Trigger>
268+
</Style.Triggers>
269+
</Style>
270+
</TextBox.Style>
271+
</TextBox>
272+
<ListBox Grid.Column="0" Grid.Row="2" x:Name="listBoxProfiles" FontSize="14" ItemsSource="{Binding PortScannerProfiles}" DisplayMemberPath="Name" SelectedItem="{Binding SelectedProfile}">
259273
<ListBox.Resources>
260274
<Style TargetType="{x:Type ScrollViewer}" BasedOn="{StaticResource DefaulScrollViewer}" />
261275
<ContextMenu x:Key="ListBoxItemContextMenu" Opened="ContextMenu_Opened" MinWidth="150">
@@ -316,19 +330,25 @@
316330
</GroupStyle>
317331
</ListBox.GroupStyle>
318332
</ListBox>
319-
<TextBlock Grid.Column="0" Grid.Row="0" FontSize="18" Foreground="{DynamicResource GrayBrush3}" Text="{DynamicResource String_NoProfilesFoundCreateOne}" VerticalAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center" Margin="10,0" >
333+
<TextBlock Grid.Row="2" FontSize="18" Foreground="{DynamicResource GrayBrush3}" VerticalAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center" Margin="10,0" >
320334
<TextBlock.Style>
321335
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource HeaderTextBlock}">
322336
<Setter Property="Visibility" Value="Collapsed" />
323337
<Style.Triggers>
324-
<DataTrigger Binding="{Binding PortScannerProfiles.Count}" Value="0">
325-
<Setter Property="Visibility" Value="Visible" />
338+
<DataTrigger Binding="{Binding PortScannerProfiles.Count}" Value="0" >
339+
<DataTrigger.Setters>
340+
<Setter Property="Visibility" Value="Visible" />
341+
<Setter Property="Text" Value="{DynamicResource String_NoProfilesFoundCreateOne}" />
342+
</DataTrigger.Setters>
343+
</DataTrigger>
344+
<DataTrigger Binding="{Binding Search, Converter={StaticResource NullOrEmptyToBoolConverter}}" Value="False">
345+
<Setter Property="Text" Value="{DynamicResource String_NothingFound}" />
326346
</DataTrigger>
327347
</Style.Triggers>
328348
</Style>
329349
</TextBlock.Style>
330350
</TextBlock>
331-
<Button x:Name="btnAddProfile" Grid.Column="0" Grid.Row="2" Command="{Binding AddProfileCommand}">
351+
<Button x:Name="btnAddProfile" Grid.Column="0" Grid.Row="4" Command="{Binding AddProfileCommand}">
332352
<Button.Content>
333353
<Grid>
334354
<Grid.ColumnDefinitions>

0 commit comments

Comments
 (0)