@@ -25,7 +25,7 @@ public ProfilesViewModel()
2525 ListSortDirection . Ascending ) ) ;
2626
2727 SetGroupsView ( ) ;
28-
28+
2929 ProfileManager . OnProfilesUpdated += ProfileManager_OnProfilesUpdated ;
3030
3131 _searchDispatcherTimer . Interval = GlobalStaticConfiguration . SearchDispatcherTimerTimeSpan ;
@@ -35,7 +35,7 @@ public ProfilesViewModel()
3535 #endregion
3636
3737 #region Variables
38-
38+
3939 private readonly DispatcherTimer _searchDispatcherTimer = new ( ) ;
4040 private bool _searchDisabled ;
4141
@@ -56,6 +56,8 @@ private set
5656 }
5757 }
5858
59+ private bool _disableProfileRefresh ;
60+
5961 private ProfileInfo _lastSelectedProfileOnRefresh ;
6062
6163 private GroupInfo _selectedGroup = new ( ) ;
@@ -70,21 +72,22 @@ public GroupInfo SelectedGroup
7072
7173 _selectedGroup = value ;
7274
73- // NullReferenceException occurs if profile file is changed
74- if ( value != null )
75+ // Check for null, because a NullReferenceException can occur when a profile file is changed
76+ // Temporarily disable profile refresh to avoid multiple refreshes and prevent the filter from being reset.
77+ if ( value != null && ! _disableProfileRefresh )
7578 {
7679 // Set/update tags based on current group
7780 CreateTags ( ) ;
78-
81+
7982 var filter = new ProfileFilterInfo
8083 {
8184 Search = Search ,
8285 Tags = [ .. ProfileFilterTags . Where ( x => x . IsSelected ) . Select ( x => x . Name ) ] ,
8386 TagsFilterMatch = ProfileFilterTagsMatchAny ? ProfileFilterTagsMatch . Any : ProfileFilterTagsMatch . All
8487 } ;
85-
86- SetProfilesView ( filter , value , _lastSelectedProfileOnRefresh ) ;
87-
88+
89+ SetProfilesView ( filter , value , _lastSelectedProfileOnRefresh ) ;
90+
8891 IsProfileFilterSet = ! string . IsNullOrEmpty ( filter . Search ) || filter . Tags . Any ( ) ;
8992 }
9093 else
@@ -95,7 +98,7 @@ public GroupInfo SelectedGroup
9598 OnPropertyChanged ( ) ;
9699 }
97100 }
98-
101+
99102 private ICollectionView _profiles ;
100103
101104 public ICollectionView Profiles
@@ -266,7 +269,7 @@ private void DeleteGroupAction()
266269 {
267270 ProfileDialogManager . ShowDeleteGroupDialog ( Application . Current . MainWindow , this , SelectedGroup ) . ConfigureAwait ( false ) ;
268271 }
269-
272+
270273 public ICommand AddProfileCommand => new RelayCommand ( _ => AddProfileAction ( ) ) ;
271274
272275 private void AddProfileAction ( )
@@ -358,14 +361,19 @@ public void OnViewHide()
358361
359362 private void SetGroupsView ( GroupInfo group = null )
360363 {
364+ _disableProfileRefresh = true ;
365+
361366 Groups = new CollectionViewSource
362367 {
363368 Source = ProfileManager . Groups . Where ( x => ! x . IsDynamic ) . OrderBy ( x => x . Name )
364369 } . View ;
365-
366- // Set specific group or first if null
370+
371+ // Set to null, so even when the same group is selected, the profiles get refreshed
367372 SelectedGroup = null ;
368373
374+ _disableProfileRefresh = false ;
375+
376+ // Set specific group or first if null
369377 if ( group != null )
370378 SelectedGroup = Groups . SourceCollection . Cast < GroupInfo > ( ) . FirstOrDefault ( x => x . Equals ( group ) ) ??
371379 Groups . SourceCollection . Cast < GroupInfo > ( ) . MinBy ( x => x . Name ) ;
@@ -378,7 +386,7 @@ private void CreateTags()
378386 // Get all tags from profiles in the selected group
379387 var tags = ProfileManager . Groups . First ( x => x . Name == SelectedGroup . Name ) . Profiles
380388 . SelectMany ( x => x . TagsCollection ) . Distinct ( ) . ToList ( ) ;
381-
389+
382390 var tagSet = new HashSet < string > ( tags ) ;
383391
384392 for ( var i = ProfileFilterTags . Count - 1 ; i >= 0 ; i -- )
@@ -394,7 +402,7 @@ private void CreateTags()
394402 ProfileFilterTags . Add ( new ProfileFilterTagsInfo ( false , tag ) ) ;
395403 }
396404 }
397-
405+
398406 private void SetProfilesView ( ProfileFilterInfo filter , GroupInfo group , ProfileInfo profile = null )
399407 {
400408 Profiles = new CollectionViewSource
0 commit comments