@@ -42,7 +42,9 @@ public class AWSSessionManagerHostViewModel : ViewModelBase, IProfileManager
4242 private static readonly ILog Log = LogManager . GetLogger ( typeof ( AWSSessionManagerHostViewModel ) ) ;
4343
4444 private readonly IDialogCoordinator _dialogCoordinator ;
45+
4546 private readonly DispatcherTimer _searchDispatcherTimer = new ( ) ;
47+ private bool _searchDisabled ;
4648
4749 public IInterTabClient InterTabClient { get ; }
4850
@@ -216,8 +218,11 @@ public string Search
216218 _search = value ;
217219
218220 // Start searching...
219- IsSearching = true ;
220- _searchDispatcherTimer . Start ( ) ;
221+ if ( ! _searchDisabled )
222+ {
223+ IsSearching = true ;
224+ _searchDispatcherTimer . Start ( ) ;
225+ }
221226
222227 OnPropertyChanged ( ) ;
223228 }
@@ -239,7 +244,7 @@ public bool IsSearching
239244 OnPropertyChanged ( ) ;
240245 }
241246 }
242-
247+
243248 private bool _profileFilterIsOpen ;
244249
245250 public bool ProfileFilterIsOpen
@@ -400,7 +405,8 @@ public AWSSessionManagerHostViewModel(IDialogCoordinator instance)
400405 CreateTags ( ) ;
401406
402407 ProfileFilterTagsView = CollectionViewSource . GetDefaultView ( ProfileFilterTags ) ;
403- ProfileFilterTagsView . SortDescriptions . Add ( new SortDescription ( nameof ( ProfileFilterTagsInfo . Name ) , ListSortDirection . Ascending ) ) ;
408+ ProfileFilterTagsView . SortDescriptions . Add ( new SortDescription ( nameof ( ProfileFilterTagsInfo . Name ) ,
409+ ListSortDirection . Ascending ) ) ;
404410
405411 SetProfilesView ( new ProfileFilterInfo ( ) ) ;
406412
@@ -525,14 +531,16 @@ private bool ModifyProfile_CanExecute(object obj)
525531
526532 private void EditProfileAction ( )
527533 {
528- ProfileDialogManager . ShowEditProfileDialog ( Application . Current . MainWindow , this , SelectedProfile ) . ConfigureAwait ( false ) ;
534+ ProfileDialogManager . ShowEditProfileDialog ( Application . Current . MainWindow , this , SelectedProfile )
535+ . ConfigureAwait ( false ) ;
529536 }
530537
531538 public ICommand CopyAsProfileCommand => new RelayCommand ( _ => CopyAsProfileAction ( ) , ModifyProfile_CanExecute ) ;
532539
533540 private void CopyAsProfileAction ( )
534541 {
535- ProfileDialogManager . ShowCopyAsProfileDialog ( Application . Current . MainWindow , this , SelectedProfile ) . ConfigureAwait ( false ) ;
542+ ProfileDialogManager . ShowCopyAsProfileDialog ( Application . Current . MainWindow , this , SelectedProfile )
543+ . ConfigureAwait ( false ) ;
536544 }
537545
538546 public ICommand DeleteProfileCommand => new RelayCommand ( _ => DeleteProfileAction ( ) , ModifyProfile_CanExecute ) ;
@@ -548,7 +556,8 @@ private void DeleteProfileAction()
548556
549557 private void EditGroupAction ( object group )
550558 {
551- ProfileDialogManager . ShowEditGroupDialog ( Application . Current . MainWindow , this , ProfileManager . GetGroupByName ( $ "{ group } ") )
559+ ProfileDialogManager
560+ . ShowEditGroupDialog ( Application . Current . MainWindow , this , ProfileManager . GetGroupByName ( $ "{ group } ") )
552561 . ConfigureAwait ( false ) ;
553562 }
554563
@@ -583,13 +592,6 @@ public ICommand TextBoxSearchLostFocusCommand
583592 get { return new RelayCommand ( _ => _textBoxSearchIsFocused = false ) ; }
584593 }
585594
586- public ICommand ClearSearchCommand => new RelayCommand ( _ => ClearSearchAction ( ) ) ;
587-
588- private void ClearSearchAction ( )
589- {
590- Search = string . Empty ;
591- }
592-
593595 public ICommand OpenProfileFilterCommand => new RelayCommand ( _ => OpenProfileFilterAction ( ) ) ;
594596
595597 private void OpenProfileFilterAction ( )
@@ -603,14 +605,17 @@ private void ApplyProfileFilterAction()
603605 {
604606 RefreshProfiles ( ) ;
605607
606- IsProfileFilterSet = true ;
607608 ProfileFilterIsOpen = false ;
608609 }
609610
610611 public ICommand ClearProfileFilterCommand => new RelayCommand ( _ => ClearProfileFilterAction ( ) ) ;
611612
612613 private void ClearProfileFilterAction ( )
613614 {
615+ _searchDisabled = true ;
616+ Search = string . Empty ;
617+ _searchDisabled = false ;
618+
614619 foreach ( var tag in ProfileFilterTags )
615620 tag . IsSelected = false ;
616621
@@ -678,7 +683,8 @@ private void CheckExecutable()
678683 File . Exists ( SettingsManager . Current . AWSSessionManager_ApplicationFilePath ) ;
679684
680685 if ( IsExecutableConfigured )
681- Log . Info ( $ "PowerShell executable found: \" { SettingsManager . Current . AWSSessionManager_ApplicationFilePath } \" ") ;
686+ Log . Info (
687+ $ "PowerShell executable found: \" { SettingsManager . Current . AWSSessionManager_ApplicationFilePath } \" ") ;
682688 else
683689 Log . Warn ( "PowerShell executable not found!" ) ;
684690 }
@@ -823,33 +829,33 @@ private async Task SyncInstanceIDsFromAWS(string profile, string region)
823829 } ;
824830
825831 foreach ( var reservation in response . Reservations )
826- foreach ( var instance in reservation . Instances )
827- {
828- if ( SettingsManager . Current . AWSSessionManager_SyncOnlyRunningInstancesFromAWS &&
829- instance . State . Name . Value != "running" )
830- continue ;
832+ foreach ( var instance in reservation . Instances )
833+ {
834+ if ( SettingsManager . Current . AWSSessionManager_SyncOnlyRunningInstancesFromAWS &&
835+ instance . State . Name . Value != "running" )
836+ continue ;
831837
832- var tagName = instance . Tags . FirstOrDefault ( x => x . Key == "Name" ) ;
833-
834- var name = tagName == null || tagName . Value == null
835- ? instance . InstanceId
836- : $ "{ tagName . Value } ({ instance . InstanceId } )";
837-
838- groupInfo . Profiles . Add ( new ProfileInfo
839- {
840- Name = name ,
841- Host = instance . InstanceId ,
842- Group = $ "~ [{ profile } \\ { region } ]",
843- IsDynamic = true ,
844-
845- AWSSessionManager_Enabled = true ,
846- AWSSessionManager_InstanceID = instance . InstanceId ,
847- AWSSessionManager_OverrideProfile = true ,
848- AWSSessionManager_Profile = profile ,
849- AWSSessionManager_OverrideRegion = true ,
850- AWSSessionManager_Region = region
851- } ) ;
852- }
838+ var tagName = instance . Tags . FirstOrDefault ( x => x . Key == "Name" ) ;
839+
840+ var name = tagName == null || tagName . Value == null
841+ ? instance . InstanceId
842+ : $ "{ tagName . Value } ({ instance . InstanceId } )";
843+
844+ groupInfo . Profiles . Add ( new ProfileInfo
845+ {
846+ Name = name ,
847+ Host = instance . InstanceId ,
848+ Group = $ "~ [{ profile } \\ { region } ]",
849+ IsDynamic = true ,
850+
851+ AWSSessionManager_Enabled = true ,
852+ AWSSessionManager_InstanceID = instance . InstanceId ,
853+ AWSSessionManager_OverrideProfile = true ,
854+ AWSSessionManager_Profile = profile ,
855+ AWSSessionManager_OverrideRegion = true ,
856+ AWSSessionManager_Region = region
857+ } ) ;
858+ }
853859
854860 // Remove, replace or add group
855861 var profilesChangedCurrentState = ProfileManager . ProfilesChanged ;
@@ -1087,7 +1093,8 @@ public void OnProfileLoaded()
10871093
10881094 private void CreateTags ( )
10891095 {
1090- var tags = ProfileManager . Groups . SelectMany ( x => x . Profiles ) . Where ( x => x . AWSSessionManager_Enabled ) . SelectMany ( x => x . TagsCollection ) . Distinct ( ) . ToList ( ) ;
1096+ var tags = ProfileManager . Groups . SelectMany ( x => x . Profiles ) . Where ( x => x . AWSSessionManager_Enabled )
1097+ . SelectMany ( x => x . TagsCollection ) . Distinct ( ) . ToList ( ) ;
10911098
10921099 var tagSet = new HashSet < string > ( tags ) ;
10931100
@@ -1104,19 +1111,23 @@ private void CreateTags()
11041111 ProfileFilterTags . Add ( new ProfileFilterTagsInfo ( false , tag ) ) ;
11051112 }
11061113 }
1107-
1114+
11081115 private void SetProfilesView ( ProfileFilterInfo filter , ProfileInfo profile = null )
11091116 {
11101117 Profiles = new CollectionViewSource
11111118 {
11121119 Source = ProfileManager . Groups . SelectMany ( x => x . Profiles ) . Where ( x => x . AWSSessionManager_Enabled && (
1113- string . IsNullOrEmpty ( filter . Search ) || x . Name . IndexOf ( filter . Search , StringComparison . Ordinal ) > - 1 || x . AWSSessionManager_InstanceID . IndexOf ( filter . Search , StringComparison . Ordinal ) > - 1 ) && (
1120+ string . IsNullOrEmpty ( filter . Search ) ||
1121+ x . Name . IndexOf ( filter . Search , StringComparison . Ordinal ) > - 1 ||
1122+ x . AWSSessionManager_InstanceID . IndexOf ( filter . Search , StringComparison . Ordinal ) > - 1 ) && (
11141123 // If no tags are selected, show all profiles
11151124 ( ! filter . Tags . Any ( ) ) ||
11161125 // Any tag can match
1117- ( filter . TagsFilterMatch == ProfileFilterTagsMatch . Any && filter . Tags . Any ( tag => x . TagsCollection . Contains ( tag ) ) ) ||
1126+ ( filter . TagsFilterMatch == ProfileFilterTagsMatch . Any &&
1127+ filter . Tags . Any ( tag => x . TagsCollection . Contains ( tag ) ) ) ||
11181128 // All tags must match
1119- ( filter . TagsFilterMatch == ProfileFilterTagsMatch . All && filter . Tags . All ( tag => x . TagsCollection . Contains ( tag ) ) ) )
1129+ ( filter . TagsFilterMatch == ProfileFilterTagsMatch . All &&
1130+ filter . Tags . All ( tag => x . TagsCollection . Contains ( tag ) ) ) )
11201131 ) . OrderBy ( x => x . Group ) . ThenBy ( x => x . Name )
11211132 } . View ;
11221133
@@ -1137,12 +1148,16 @@ private void RefreshProfiles()
11371148 if ( ! _isViewActive )
11381149 return ;
11391150
1140- SetProfilesView ( new ProfileFilterInfo
1151+ var filter = new ProfileFilterInfo
11411152 {
11421153 Search = Search ,
11431154 Tags = [ .. ProfileFilterTags . Where ( x => x . IsSelected ) . Select ( x => x . Name ) ] ,
11441155 TagsFilterMatch = ProfileFilterTagsMatchAny ? ProfileFilterTagsMatch . Any : ProfileFilterTagsMatch . All
1145- } , SelectedProfile ) ;
1156+ } ;
1157+
1158+ SetProfilesView ( filter , SelectedProfile ) ;
1159+
1160+ IsProfileFilterSet = ! string . IsNullOrEmpty ( filter . Search ) || filter . Tags . Any ( ) ;
11461161 }
11471162
11481163 public void OnProfileManagerDialogOpen ( )
@@ -1179,15 +1194,15 @@ private void SettingsManager_PropertyChanged(object sender, PropertyChangedEvent
11791194 switch ( e . PropertyName )
11801195 {
11811196 case nameof ( SettingsInfo . AWSSessionManager_EnableSyncInstanceIDsFromAWS ) :
1182- {
1183- IsSyncEnabled = SettingsManager . Current . AWSSessionManager_EnableSyncInstanceIDsFromAWS ;
1197+ {
1198+ IsSyncEnabled = SettingsManager . Current . AWSSessionManager_EnableSyncInstanceIDsFromAWS ;
11841199
1185- if ( IsSyncEnabled )
1186- SyncAllInstanceIDsFromAWS ( ) . ConfigureAwait ( false ) ;
1187- else
1188- RemoveDynamicGroups ( ) ;
1189- break ;
1190- }
1200+ if ( IsSyncEnabled )
1201+ SyncAllInstanceIDsFromAWS ( ) . ConfigureAwait ( false ) ;
1202+ else
1203+ RemoveDynamicGroups ( ) ;
1204+ break ;
1205+ }
11911206 case nameof ( SettingsInfo . AWSSessionManager_SyncOnlyRunningInstancesFromAWS ) :
11921207 SyncAllInstanceIDsFromAWS ( ) . ConfigureAwait ( false ) ;
11931208 break ;
@@ -1222,7 +1237,7 @@ private void AWSSessionManager_AWSProfiles_CollectionChanged(object sender,
12221237 private void ProfileManager_OnProfilesUpdated ( object sender , EventArgs e )
12231238 {
12241239 CreateTags ( ) ;
1225-
1240+
12261241 RefreshProfiles ( ) ;
12271242 }
12281243
@@ -1236,4 +1251,4 @@ private void SearchDispatcherTimer_Tick(object sender, EventArgs e)
12361251 }
12371252
12381253 #endregion
1239- }
1254+ }
0 commit comments