Skip to content

Commit 68b2c2c

Browse files
committed
Made Anchors (and the 'Global' Flag) reflect in the UI
1 parent 73341f6 commit 68b2c2c

File tree

2 files changed

+54
-10
lines changed

2 files changed

+54
-10
lines changed

RetailCoder.VBE/UI/RegexAssistant/RegexAssistantViewModel.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,29 @@ private void RecalculateDescription()
8080
ResultItems = results;
8181
return;
8282
}
83-
var pattern = new Pattern(_pattern, _ignoreCaseFlag, _ignoreCaseFlag);
84-
//_description = pattern.Description;
83+
ResultItems = ToTreeViewItems(new Pattern(_pattern, _ignoreCaseFlag, _globalFlag));
84+
}
85+
86+
private List<TreeViewItem> ToTreeViewItems(Pattern pattern)
87+
{
8588
var resultItems = new List<TreeViewItem>();
89+
if (pattern.AnchoredAtStart)
90+
{
91+
resultItems.Add(TreeViewItemFromHeader(pattern.StartAnchorDescription));
92+
}
8693
resultItems.Add(AsTreeViewItem((dynamic)pattern.RootExpression));
87-
ResultItems = resultItems;
88-
//base.OnPropertyChanged("DescriptionResults");
94+
if (pattern.AnchoredAtEnd)
95+
{
96+
resultItems.Add(TreeViewItemFromHeader(pattern.EndAnchorDescription));
97+
}
98+
return resultItems;
99+
}
100+
101+
private TreeViewItem TreeViewItemFromHeader(string header)
102+
{
103+
var result = new TreeViewItem();
104+
result.Header = header;
105+
return result;
89106
}
90107

91108
public string DescriptionResults

Rubberduck.RegexAssistant/Pattern.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,44 @@ public Pattern(string expression, bool ignoreCase, bool global)
3737
private string AssembleDescription()
3838
{
3939
string result = string.Empty;
40-
if (_hasStartAnchor)
40+
result += StartAnchorDescription;
41+
result += RootExpression.Description;
42+
result += EndAnchorDescription;
43+
return result;
44+
}
45+
46+
public string StartAnchorDescription
47+
{
48+
get
4149
{
42-
result += Flags.HasFlag(MatcherFlags.Global) ? AssistantResources.PatternDescription_AnchorStart_GlobalEnabled : AssistantResources.PatternDescription_AnchorStart;
50+
if (AnchoredAtStart)
51+
{
52+
return Flags.HasFlag(MatcherFlags.Global)
53+
? AssistantResources.PatternDescription_AnchorStart_GlobalEnabled
54+
: AssistantResources.PatternDescription_AnchorStart;
55+
}
56+
return string.Empty;
4357
}
44-
result += RootExpression.Description;
45-
if (_hasEndAnchor)
58+
}
59+
60+
public string EndAnchorDescription
61+
{
62+
get
4663
{
47-
result += Flags.HasFlag(MatcherFlags.Global) ? AssistantResources.PatternDescription_AnchorEnd_GlobalEnabled : AssistantResources.PatternDescription_AnchorEnd;
64+
if (AnchoredAtEnd)
65+
{
66+
return Flags.HasFlag(MatcherFlags.Global)
67+
? AssistantResources.PatternDescription_AnchorEnd_GlobalEnabled
68+
: AssistantResources.PatternDescription_AnchorEnd;
69+
}
70+
return string.Empty;
4871
}
49-
return result;
5072
}
73+
74+
public bool IgnoreCase { get { return Flags.HasFlag(MatcherFlags.IgnoreCase); } }
75+
public bool Global { get { return Flags.HasFlag(MatcherFlags.Global); } }
76+
public bool AnchoredAtStart { get { return _hasStartAnchor; } }
77+
public bool AnchoredAtEnd { get { return _hasEndAnchor; } }
5178
}
5279

5380
[Flags]

0 commit comments

Comments
 (0)