Skip to content

Commit caebc1d

Browse files
committed
feat: Filters: IsEmpty is now tri-state so you can make filter rules for empty and non-empty code items
1 parent 4158832 commit caebc1d

7 files changed

Lines changed: 27 additions & 12 deletions

File tree

docs/filterrules.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ Secondly select a number of modifiers to narrow down the rule.
1515
Match code items by access (public, private, etc...)
1616

1717
### Empty
18-
Match code items that do not have visible child items
18+
Match code items that:
19+
- Checked: do not have visible child items
20+
- Unchecked: do have visible child items
21+
- Indeterminate: either do or do not have visible child items
1922

2023
## Action
2124
Finally select then action to should be applied to the code item.

docs/links.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ Here is a list of links to helpful pages I needed when developing this extension
2323
- [Setting WPF border visible or not depending on ScrollViewer's VerticalScrollBarVisibility property](https://stackoverflow.com/questions/73199311/setting-wpf-border-visible-or-not-depending-on-scrollviewers-verticalscrollbarv/73199480#73199480)
2424
- [CommentRemover Sample](https://github.com/microsoft/VSExtensibility/tree/main/New_Extensibility_Model/Samples/CommentRemover)
2525
- [CompositeExtension Sample](https://github.com/microsoft/VSExtensibility/tree/main/New_Extensibility_Model/Samples/CompositeExtension)
26-
- [VSExtensibility - #554 - Feature request: Text Editor: Scroll to line](https://github.com/microsoft/VSExtensibility/issues/554)
26+
- [VSExtensibility - #554 - Feature request: Text Editor: Scroll to line](https://github.com/microsoft/VSExtensibility/issues/554)
27+
- [The CheckBox control](https://wpf-tutorial.com/basic-controls/the-checkbox-control/)

src/CodeNav.OutOfProc/Dialogs/FilterDialog/FilterDialogControl.xaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@
7474
BorderThickness="0,0,1,0"
7575
Margin="-6,-3,-6,-3">
7676
<StackPanel Margin="6,2,6,2" VerticalAlignment="Center">
77-
<CheckBox IsChecked="{Binding IsEmpty}" IsEnabled="{Binding IsEmptyEnabled}" />
77+
<CheckBox
78+
IsThreeState="True"
79+
IsChecked="{Binding IsEmpty}"
80+
IsEnabled="{Binding IsEmptyEnabled}" />
7881
</StackPanel>
7982
</Border>
8083
</DataTemplate>
@@ -146,7 +149,10 @@
146149
<LineBreak/>
147150
<Run FontWeight="Bold">Access:</Run> Match code items with access modifier
148151
<LineBreak/>
149-
<Run FontWeight="Bold">Empty:</Run> Match code items that do not have visible child items
152+
<Run FontWeight="Bold">Empty:</Run> Match code items that:
153+
<LineBreak/>Checked: do not have visible child items
154+
<LineBreak/>Unchecked: do have visible child items
155+
<LineBreak/>Indeterminate: either do or do not have visible child items
150156
</TextBlock>
151157
<TextBlock>
152158
<Run FontWeight="Bold">Actions</Run>

src/CodeNav.OutOfProc/Helpers/FilterRuleHelper.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@ namespace CodeNav.OutOfProc.Helpers;
77

88
public static class FilterRuleHelper
99
{
10-
public static FilterRuleViewModel? GetFilterRule(IEnumerable<FilterRuleViewModel> filterRules, CodeItem item)
10+
/// <summary>
11+
/// Get the last matching filter rule for a given code item
12+
/// </summary>
13+
/// <param name="filterRules">List of filter rules</param>
14+
/// <param name="codeItem">Code item</param>
15+
/// <returns>Matching filter rule</returns>
16+
public static FilterRuleViewModel? GetFilterRule(IEnumerable<FilterRuleViewModel> filterRules, CodeItem codeItem)
1117
{
1218
// Get the most specific filter rule for the item
1319
var filterRule = filterRules
14-
.Where(filterRule => filterRule.Access == item.Access ||
20+
.Where(filterRule => filterRule.Access == codeItem.Access ||
1521
filterRule.Access == CodeItemAccessEnum.All)
16-
.Where(filterRule => filterRule.Kind == item.Kind ||
22+
.Where(filterRule => filterRule.Kind == codeItem.Kind ||
1723
filterRule.Kind == CodeItemKindEnum.All)
18-
.Where(filterRule => filterRule.IsEmpty == IsEmpty(item))
24+
.Where(filterRule => filterRule.IsEmpty == null ||
25+
filterRule.IsEmpty == IsEmpty(codeItem))
1926
.LastOrDefault();
2027

2128
return filterRule;

src/CodeNav.OutOfProc/Helpers/SettingsHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public class FilterRule
112112

113113
public CodeItemAccessEnum Access { get; set; }
114114

115-
public bool IsEmpty { get; set; }
115+
public bool? IsEmpty { get; set; } = false;
116116

117117
public bool Hide { get; set; }
118118

src/CodeNav.OutOfProc/ViewModels/FilterRuleViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public CodeItemAccessEnum Access
3636
}
3737

3838
[DataMember]
39-
public bool IsEmpty { get; set; }
39+
public bool? IsEmpty { get; set; } = false;
4040

4141
private bool _hide;
4242

test/HelperTests/VisibilityHelperTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System.Windows;
2-
using CodeNav.OutOfProc.Constants;
3-
using CodeNav.OutOfProc.ViewModels;
42

53
namespace CodeNav.Test.HelperTests;
64

0 commit comments

Comments
 (0)