Skip to content

Commit 90b1997

Browse files
committed
Search implemented
1 parent 8d9b2c4 commit 90b1997

3 files changed

Lines changed: 68 additions & 7 deletions

File tree

Source/NETworkManager/Controls/RemoteDesktopControl.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using NETworkManager.Models.RemoteDesktop;
2-
using NETworkManager.ViewModels;
32
using System.ComponentModel;
43
using System.Runtime.CompilerServices;
54
using System.Windows;

Source/NETworkManager/ViewModels/Applications/RemoteDesktopViewModel.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.ComponentModel;
1111
using System.Windows.Data;
1212
using System.Collections.Generic;
13+
using System;
1314

1415
namespace NETworkManager.ViewModels.Applications
1516
{
@@ -43,7 +44,7 @@ public ICollectionView RemoteDesktopSessions
4344
{
4445
get { return _remoteDesktopSessions; }
4546
}
46-
47+
4748
private RemoteDesktopSessionInfo _selectedSession = new RemoteDesktopSessionInfo();
4849
public RemoteDesktopSessionInfo SelectedSession
4950
{
@@ -74,6 +75,23 @@ public bool ExpandSessionView
7475
OnPropertyChanged();
7576
}
7677
}
78+
79+
private string _search;
80+
public string Search
81+
{
82+
get { return _search; }
83+
set
84+
{
85+
if (value == _search)
86+
return;
87+
88+
_search = value;
89+
90+
RemoteDesktopSessions.Refresh();
91+
92+
OnPropertyChanged();
93+
}
94+
}
7795
#endregion
7896
#endregion
7997

@@ -92,6 +110,17 @@ public RemoteDesktopViewModel(IDialogCoordinator instance)
92110
_remoteDesktopSessions = CollectionViewSource.GetDefaultView(RemoteDesktopSessionManager.Sessions);
93111
_remoteDesktopSessions.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
94112
_remoteDesktopSessions.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
113+
_remoteDesktopSessions.Filter = o =>
114+
{
115+
if (string.IsNullOrEmpty(Search))
116+
return true;
117+
118+
RemoteDesktopSessionInfo info = o as RemoteDesktopSessionInfo;
119+
120+
string search = Search.Trim();
121+
122+
return info.Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0;
123+
};
95124

96125
LoadSettings();
97126

@@ -116,6 +145,24 @@ private void ConnectSession(Models.RemoteDesktop.RemoteDesktopSessionInfo sessio
116145
TabContents.Add(new DragablzTabContent(string.IsNullOrEmpty(Header) ? sessionInfo.Hostname : Header, new RemoteDesktopControl(sessionInfo)));
117146
SelectedTabIndex = TabContents.Count - 1;
118147
}
148+
149+
private void RemoteDesktopSession_Search(object sender, FilterEventArgs e)
150+
{
151+
if (string.IsNullOrEmpty(Search))
152+
{
153+
e.Accepted = true;
154+
return;
155+
}
156+
157+
RemoteDesktopSessionInfo info = e.Item as RemoteDesktopSessionInfo;
158+
159+
string search = Search.Trim();
160+
161+
if (info.Hostname.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0)
162+
e.Accepted = true;
163+
else
164+
e.Accepted = false;
165+
}
119166
#endregion
120167

121168
#region ICommand & Actions

Source/NETworkManager/Views/Applications/RemoteDesktopView.xaml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
xmlns:Dialog="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
99
xmlns:Converter="clr-namespace:NETworkManager.Converters"
1010
xmlns:ConfigurtationManager="clr-namespace:NETworkManager.Models.Settings"
11+
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
12+
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
1113
Dialog:DialogParticipation.Register="{Binding}"
1214
mc:Ignorable="d">
1315
<UserControl.Resources>
@@ -48,7 +50,7 @@
4850
<Setter Property="ContentTemplate">
4951
<Setter.Value>
5052
<DataTemplate>
51-
<ContentPresenter Content="{Binding Content}" Visibility="{Binding Source={x:Static ConfigurtationManager:ConfigurationManager.Current}, Path=FixAirspace, Converter={StaticResource BooleanReverseToVisibilityConverter}}" />
53+
<ContentPresenter Content="{Binding Content}" Visibility="{Binding Source={x:Static ConfigurtationManager:ConfigurationManager.Current}, Path=FixAirspace, Converter={StaticResource BooleanReverseToVisibilityConverter}}" />
5254
</DataTemplate>
5355
</Setter.Value>
5456
</Setter>
@@ -59,11 +61,24 @@
5961
<Expander Header="{DynamicResource String_Header_Sessions}" Style="{StaticResource RightExpander}" IsExpanded="{Binding ExpandSessionView}">
6062
<Grid Width="250">
6163
<Grid.RowDefinitions>
64+
<RowDefinition Height="Auto" />
65+
<RowDefinition Height="10" />
6266
<RowDefinition Height="*" />
6367
<RowDefinition Height="10" />
6468
<RowDefinition Height="Auto" />
6569
</Grid.RowDefinitions>
66-
<ListBox Grid.Column="0" Grid.Row="0" FontSize="14" ItemsSource="{Binding RemoteDesktopSessions}" DisplayMemberPath="Name" SelectedItem="{Binding SelectedSession}">
70+
<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}" mah:TextBoxHelper.ButtonCommand="{Binding TextBoxSearchCommand}" Controls:TextBoxHelper.ClearTextButton="True">
71+
<TextBox.Style>
72+
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource SearchMetroTextBox}">
73+
<Style.Triggers>
74+
<Trigger Property="Controls:TextBoxHelper.HasText" Value="True">
75+
<Setter Property="Controls:TextBoxHelper.ButtonContentTemplate" Value="{x:Null}" />
76+
</Trigger>
77+
</Style.Triggers>
78+
</Style>
79+
</TextBox.Style>
80+
</TextBox>
81+
<ListBox Grid.Row="2" FontSize="14" ItemsSource="{Binding RemoteDesktopSessions}" DisplayMemberPath="Name" SelectedItem="{Binding SelectedSession}">
6782
<ListBox.Resources>
6883
<Style TargetType="{x:Type ScrollViewer}" BasedOn="{StaticResource DefaulScrollViewer}" />
6984
<ContextMenu x:Key="ListBoxItemContextMenu" Opened="ContextMenu_Opened" MinWidth="150">
@@ -75,7 +90,7 @@
7590
</Rectangle.OpacityMask>
7691
</Rectangle>
7792
</MenuItem.Icon>
78-
</MenuItem>
93+
</MenuItem>
7994
<MenuItem Header="{DynamicResource String_Edit}" Command="{Binding EditSessionCommand}">
8095
<MenuItem.Icon>
8196
<Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
@@ -136,7 +151,7 @@
136151
</Style>
137152
</ListBox.ItemContainerStyle>
138153
</ListBox>
139-
<TextBlock Grid.Column="0" Grid.Row="0" FontSize="18" Foreground="{DynamicResource GrayBrush3}" Text="{DynamicResource String_NoSessionsFoundCreateOne}" VerticalAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center" Margin="10,0" >
154+
<TextBlock Grid.Row="2" FontSize="18" Foreground="{DynamicResource GrayBrush3}" Text="{DynamicResource String_NoSessionsFoundCreateOne}" VerticalAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center" Margin="10,0" >
140155
<TextBlock.Style>
141156
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource HeaderTextBlock}">
142157
<Setter Property="Visibility" Value="Collapsed" />
@@ -148,7 +163,7 @@
148163
</Style>
149164
</TextBlock.Style>
150165
</TextBlock>
151-
<Button x:Name="btnAddProfile" Grid.Column="0" Grid.Row="2" Command="{Binding AddSessionCommand}" Style="{StaticResource ImageWithTextButton}">
166+
<Button x:Name="btnAddProfile" Grid.Row="4" Command="{Binding AddSessionCommand}" Style="{StaticResource ImageWithTextButton}">
152167
<Button.Content>
153168
<Grid>
154169
<Grid.ColumnDefinitions>

0 commit comments

Comments
 (0)