Skip to content

Commit

Permalink
+ Showed property initialization and expression on Navi Bar menu
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Dec 12, 2018
1 parent 1ae4366 commit 14bf718
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 47 deletions.
5 changes: 3 additions & 2 deletions Codist/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,9 @@ public enum NaviBarOptions
ParameterList = 1 << 10,
ParameterListShowParamName = 1 << 11,
FieldValue = 1 << 12,
PartialClassMember = 1 << 13,
Region = 1 << 14,
AutoPropertyAnnotation = 1 << 13,
PartialClassMember = 1 << 14,
Region = 1 << 15,
Default = SyntaxDetail | SymbolToolTip | RangeHighlight | ParameterList | FieldValue | PartialClassMember | Region
}

Expand Down
60 changes: 39 additions & 21 deletions Codist/NaviBar/CSharpBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,23 +339,6 @@ internal set {
Opacity = value ? 0.7 : 1;
}
}
public bool ShowNodeDetail {
get => _ShowNodeDetail;
internal set {
_ShowNodeDetail = value;
if (value && Config.Instance.NaviBarOptions.MatchFlags(NaviBarOptions.FieldValue)) {
if (Node.IsKind(SyntaxKind.VariableDeclarator)) {
InputGestureText = (Node as VariableDeclaratorSyntax).Initializer?.Value?.ToString();
}
else if (Node.IsKind(SyntaxKind.EnumMemberDeclaration)) {
InputGestureText = (Node as EnumMemberDeclarationSyntax).EqualsValue?.Value?.ToString();
}
}
else {
InputGestureText = null;
}
}
}
internal SyntaxNode Node { get; }

private Action<NaviItem> ClickHandler { get; set; }
Expand Down Expand Up @@ -447,6 +430,42 @@ NaviItem SetHeader(SyntaxNode node, bool includeContainer, bool highlight, bool
return this;
}

NaviItem ShowNodeValue() {
if (Config.Instance.NaviBarOptions.MatchFlags(NaviBarOptions.FieldValue)) {
switch (Node.Kind()) {
case SyntaxKind.VariableDeclarator:
InputGestureText = (Node as VariableDeclaratorSyntax).Initializer?.Value?.ToString();
break;
case SyntaxKind.EnumMemberDeclaration:
InputGestureText = (Node as EnumMemberDeclarationSyntax).EqualsValue?.Value?.ToString();
break;
case SyntaxKind.PropertyDeclaration:
var p = Node as PropertyDeclarationSyntax;
if (p.Initializer != null) {
InputGestureText = p.Initializer.Value.ToString();
}
else if (p.ExpressionBody != null) {
InputGestureText = p.ExpressionBody.ToString();
}
else if (Config.Instance.NaviBarOptions.MatchFlags(NaviBarOptions.AutoPropertyAnnotation)) {
var a = p.AccessorList.Accessors;
if (a.Count == 2) {
if (a[0].Body == null && a[0].ExpressionBody == null && a[1].Body == null && a[1].ExpressionBody == null) {
InputGestureText = "{;;}";
}
}
else if (a.Count == 1) {
if (a[0].Body == null && a[0].ExpressionBody == null) {
InputGestureText = "{;}";
}
}
}
break;
}
}
return this;
}

NaviItem MarkEnclosingItem(int position) {
if (NodeIsExternal) {
return this;
Expand Down Expand Up @@ -630,9 +649,8 @@ void AddMemberDeclarations(SyntaxNode node, bool isExternal) {
else {
Items.Add(new NaviItem(_Bar, child, false, true) {
NodeIsExternal = isExternal,
ClickHandler = i => i.SelectOrGoToSource(),
ShowNodeDetail = child.IsKind(SyntaxKind.EnumMemberDeclaration)
}.MarkEnclosingItem(pos));
ClickHandler = i => i.SelectOrGoToSource()
}.ShowNodeValue().MarkEnclosingItem(pos));
}
// a member is added between #region and #endregion
regionJustStart = FALSE;
Expand All @@ -648,7 +666,7 @@ void AddMemberDeclarations(SyntaxNode node, bool isExternal) {

void AddVariables(SeparatedSyntaxList<VariableDeclaratorSyntax> fields, bool isExternal) {
foreach (var item in fields) {
Items.Add(new NaviItem(_Bar, item) { NodeIsExternal = isExternal, ShowNodeDetail = true });
Items.Add(new NaviItem(_Bar, item) { NodeIsExternal = isExternal }.ShowNodeValue());
}
}
#endregion
Expand Down
53 changes: 39 additions & 14 deletions Codist/Options/CSharpNaviBarPage.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions Codist/Options/CSharpNaviBarPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ void CSharpNaviBarPage_Load(object sender, EventArgs e) {
}
LoadConfig(Config.Instance);

_FieldValueBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.FieldValue, _FieldValueBox.Checked));
_FieldValueBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.FieldValue, _AutoPropertyValueBox.Enabled = _FieldValueBox.Checked));
_AutoPropertyValueBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.AutoPropertyAnnotation, _AutoPropertyValueBox.Checked));
_ParameterListBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.ParameterList, _ParameterListParamNameBox.Enabled = _ParameterListBox.Checked));
_ParameterListParamNameBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.ParameterListShowParamName, _ParameterListParamNameBox.Checked));
_PartialClassBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.PartialClassMember, _PartialClassBox.Checked));
Expand All @@ -39,14 +40,16 @@ void CSharpNaviBarPage_Load(object sender, EventArgs e) {

void LoadConfig(Config config) {
_UI.DoWithLock(() => {
_FieldValueBox.Checked = config.NaviBarOptions.MatchFlags(NaviBarOptions.FieldValue);
_ParameterListBox.Checked = _ParameterListParamNameBox.Enabled = config.NaviBarOptions.MatchFlags(NaviBarOptions.ParameterList);
_ParameterListParamNameBox.Checked = config.NaviBarOptions.MatchFlags(NaviBarOptions.ParameterListShowParamName);
_PartialClassBox.Checked = config.NaviBarOptions.MatchFlags(NaviBarOptions.PartialClassMember);
_RangeHighlightBox.Checked = config.NaviBarOptions.MatchFlags(NaviBarOptions.RangeHighlight);
_RegionBox.Checked = config.NaviBarOptions.MatchFlags(NaviBarOptions.Region);
_SyntaxNodesBox.Checked = config.NaviBarOptions.MatchFlags(NaviBarOptions.SyntaxDetail);
_ToolTipBox.Checked = config.NaviBarOptions.MatchFlags(NaviBarOptions.SymbolToolTip);
var o = config.NaviBarOptions;
_FieldValueBox.Checked = _AutoPropertyValueBox.Enabled = o.MatchFlags(NaviBarOptions.FieldValue);
_AutoPropertyValueBox.Checked = o.MatchFlags(NaviBarOptions.AutoPropertyAnnotation);
_ParameterListBox.Checked = _ParameterListParamNameBox.Enabled = o.MatchFlags(NaviBarOptions.ParameterList);
_ParameterListParamNameBox.Checked = o.MatchFlags(NaviBarOptions.ParameterListShowParamName);
_PartialClassBox.Checked = o.MatchFlags(NaviBarOptions.PartialClassMember);
_RangeHighlightBox.Checked = o.MatchFlags(NaviBarOptions.RangeHighlight);
_RegionBox.Checked = o.MatchFlags(NaviBarOptions.Region);
_SyntaxNodesBox.Checked = o.MatchFlags(NaviBarOptions.SyntaxDetail);
_ToolTipBox.Checked = o.MatchFlags(NaviBarOptions.SymbolToolTip);
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion TestProject/TestPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ private void TestPage_MyEvent(object sender, EventArgs e) {
};
}

protected override int Property { get; set; }
protected override int Property { get; set; } = 1;
public int PropertyAddOne => Property + 1;

public new void Method() { Property--; }

Expand Down

0 comments on commit 14bf718

Please sign in to comment.