@@ -212,36 +212,66 @@ public bool IsSearching
212212 }
213213 }
214214
215- private bool _filterIsOpen ;
215+ private bool _profileFilterIsOpen ;
216216
217- public bool FilterIsOpen
217+ public bool ProfileFilterIsOpen
218218 {
219- get => _filterIsOpen ;
219+ get => _profileFilterIsOpen ;
220220 set
221221 {
222- if ( value == _filterIsOpen )
222+ if ( value == _profileFilterIsOpen )
223223 return ;
224224
225- _filterIsOpen = value ;
225+ _profileFilterIsOpen = value ;
226226 OnPropertyChanged ( ) ;
227227 }
228228 }
229229
230- public ICollectionView Tags { get ; set ; }
230+ public ICollectionView ProfileTagsFilterView { get ; set ; }
231231
232- public ObservableCollection < FilterTag > FilterTags { get ; set ; } = [ ] ;
232+ public ObservableCollection < ProfileTagsFilterInfo > ProfileTagsFilter { get ; set ; } = [ ] ;
233233
234- private bool _isFilterSet ;
234+ private bool _profileTagsMatchAny = GlobalStaticConfiguration . Profile_TagsMatchAny ;
235235
236- public bool IsFilterSet
236+ public bool ProfileTagsMatchAny
237237 {
238- get => _isFilterSet ;
238+ get => _profileTagsMatchAny ;
239239 set
240240 {
241- if ( value == _isFilterSet )
241+ if ( value == _profileTagsMatchAny )
242242 return ;
243243
244- _isFilterSet = value ;
244+ _profileTagsMatchAny = value ;
245+ OnPropertyChanged ( ) ;
246+ }
247+ }
248+
249+ private bool _profileTagsMatchAll ;
250+
251+ public bool ProfileTagsMatchAll
252+ {
253+ get => _profileTagsMatchAll ;
254+ set
255+ {
256+ if ( value == _profileTagsMatchAll )
257+ return ;
258+
259+ _profileTagsMatchAll = value ;
260+ OnPropertyChanged ( ) ;
261+ }
262+ }
263+
264+ private bool _isProfileFilterSet ;
265+
266+ public bool IsProfileFilterSet
267+ {
268+ get => _isProfileFilterSet ;
269+ set
270+ {
271+ if ( value == _isProfileFilterSet )
272+ return ;
273+
274+ _isProfileFilterSet = value ;
245275 OnPropertyChanged ( ) ;
246276 }
247277 }
@@ -316,8 +346,8 @@ public PingMonitorHostViewModel(IDialogCoordinator instance)
316346 // Profiles
317347 CreateTags ( ) ;
318348
319- Tags = CollectionViewSource . GetDefaultView ( FilterTags ) ;
320- Tags . SortDescriptions . Add ( new SortDescription ( nameof ( FilterTag . Name ) , ListSortDirection . Ascending ) ) ;
349+ ProfileTagsFilterView = CollectionViewSource . GetDefaultView ( ProfileTagsFilter ) ;
350+ ProfileTagsFilterView . SortDescriptions . Add ( new SortDescription ( nameof ( ProfileTagsFilterInfo . Name ) , ListSortDirection . Ascending ) ) ;
321351
322352 SetProfilesView ( new ProfileFilterInfo ( ) ) ;
323353
@@ -442,34 +472,34 @@ private void ClearSearchAction()
442472 Search = string . Empty ;
443473 }
444474
445- public ICommand OpenFilterCommand => new RelayCommand ( _ => OpenFilterAction ( ) ) ;
475+ public ICommand OpenProfileFilterCommand => new RelayCommand ( _ => OpenProfileFilterAction ( ) ) ;
446476
447- private void OpenFilterAction ( )
477+ private void OpenProfileFilterAction ( )
448478 {
449- FilterIsOpen = true ;
479+ ProfileFilterIsOpen = true ;
450480 }
451481
452- public ICommand ApplyFilterCommand => new RelayCommand ( _ => ApplyFilterAction ( ) ) ;
482+ public ICommand ApplyProfileFilterCommand => new RelayCommand ( _ => ApplyProfileFilterAction ( ) ) ;
453483
454- private void ApplyFilterAction ( )
484+ private void ApplyProfileFilterAction ( )
455485 {
456486 RefreshProfiles ( ) ;
457487
458- IsFilterSet = true ;
459- FilterIsOpen = false ;
488+ IsProfileFilterSet = true ;
489+ ProfileFilterIsOpen = false ;
460490 }
461491
462- public ICommand ClearFilterCommand => new RelayCommand ( _ => ClearFilterAction ( ) ) ;
492+ public ICommand ClearProfileFilterCommand => new RelayCommand ( _ => ClearProfileFilterAction ( ) ) ;
463493
464- private void ClearFilterAction ( )
494+ private void ClearProfileFilterAction ( )
465495 {
466- foreach ( var tag in FilterTags )
496+ foreach ( var tag in ProfileTagsFilter )
467497 tag . IsSelected = false ;
468498
469499 RefreshProfiles ( ) ;
470500
471- IsFilterSet = false ;
472- FilterIsOpen = false ;
501+ IsProfileFilterSet = false ;
502+ ProfileFilterIsOpen = false ;
473503 }
474504
475505 #endregion
@@ -656,18 +686,18 @@ private void CreateTags()
656686
657687 var tagSet = new HashSet < string > ( tags ) ;
658688
659- for ( var i = FilterTags . Count - 1 ; i >= 0 ; i -- )
689+ for ( var i = ProfileTagsFilter . Count - 1 ; i >= 0 ; i -- )
660690 {
661- if ( ! tagSet . Contains ( FilterTags [ i ] . Name ) )
662- FilterTags . RemoveAt ( i ) ;
691+ if ( ! tagSet . Contains ( ProfileTagsFilter [ i ] . Name ) )
692+ ProfileTagsFilter . RemoveAt ( i ) ;
663693 }
664694
665- var existingTagNames = new HashSet < string > ( FilterTags . Select ( ft => ft . Name ) ) ;
695+ var existingTagNames = new HashSet < string > ( ProfileTagsFilter . Select ( ft => ft . Name ) ) ;
666696
667697 foreach ( var tag in tags )
668698 {
669699 if ( ! existingTagNames . Contains ( tag ) )
670- FilterTags . Add ( new FilterTag ( false , tag ) ) ;
700+ ProfileTagsFilter . Add ( new ProfileTagsFilterInfo ( false , tag ) ) ;
671701 }
672702 }
673703
@@ -677,12 +707,15 @@ private void SetProfilesView(ProfileFilterInfo filter, ProfileInfo profile = nul
677707 {
678708 Source = ProfileManager . Groups . SelectMany ( x => x . Profiles ) . Where ( x => x . PingMonitor_Enabled && (
679709 string . IsNullOrEmpty ( filter . Search ) || x . Name . IndexOf ( filter . Search ) > - 1 || x . PingMonitor_Host . IndexOf ( filter . Search ) > - 1 ) && (
680- ! filter . Tags . Any ( ) || filter . Tags . All ( tag => x . TagsCollection . Contains ( tag ) ) )
710+ // If no tags are selected, show all profiles
711+ ( ! filter . Tags . Any ( ) ) ||
712+ // Any tag can match
713+ ( filter . TagsFilterMatch == ProfileTagsFilterMatch . Any && filter . Tags . Any ( tag => x . TagsCollection . Contains ( tag ) ) ) ||
714+ // All tags must match
715+ ( filter . TagsFilterMatch == ProfileTagsFilterMatch . All && filter . Tags . All ( tag => x . TagsCollection . Contains ( tag ) ) ) )
681716 ) . OrderBy ( x => x . Group ) . ThenBy ( x => x . Name )
682717 } . View ;
683718
684- // Add "Any" based in selection
685-
686719 Profiles . GroupDescriptions . Add ( new PropertyGroupDescription ( nameof ( ProfileInfo . Group ) ) ) ;
687720
688721 // Set specific profile or first if null
@@ -703,7 +736,8 @@ private void RefreshProfiles()
703736 SetProfilesView ( new ProfileFilterInfo
704737 {
705738 Search = Search ,
706- Tags = [ .. FilterTags . Where ( x => x . IsSelected ) . Select ( x => x . Name ) ]
739+ Tags = [ .. ProfileTagsFilter . Where ( x => x . IsSelected ) . Select ( x => x . Name ) ] ,
740+ TagsFilterMatch = ProfileTagsMatchAny ? ProfileTagsFilterMatch . Any : ProfileTagsFilterMatch . All
707741 } , SelectedProfile ) ;
708742 }
709743 #endregion
0 commit comments