From 14bf718d08c3dabb7679eb0b9ce73cef5e71b59c Mon Sep 17 00:00:00 2001 From: WMJ Date: Wed, 12 Dec 2018 17:48:09 +0800 Subject: [PATCH] + Showed property initialization and expression on Navi Bar menu --- Codist/Config.cs | 5 +- Codist/NaviBar/CSharpBar.cs | 60 +++++++++++++------- Codist/Options/CSharpNaviBarPage.Designer.cs | 53 ++++++++++++----- Codist/Options/CSharpNaviBarPage.cs | 21 ++++--- TestProject/TestPage.cs | 3 +- 5 files changed, 95 insertions(+), 47 deletions(-) diff --git a/Codist/Config.cs b/Codist/Config.cs index 9ea3de60..5077c0d4 100644 --- a/Codist/Config.cs +++ b/Codist/Config.cs @@ -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 } diff --git a/Codist/NaviBar/CSharpBar.cs b/Codist/NaviBar/CSharpBar.cs index 6db88250..7f24f98b 100644 --- a/Codist/NaviBar/CSharpBar.cs +++ b/Codist/NaviBar/CSharpBar.cs @@ -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 ClickHandler { get; set; } @@ -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; @@ -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; @@ -648,7 +666,7 @@ void AddMemberDeclarations(SyntaxNode node, bool isExternal) { void AddVariables(SeparatedSyntaxList 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 diff --git a/Codist/Options/CSharpNaviBarPage.Designer.cs b/Codist/Options/CSharpNaviBarPage.Designer.cs index 66f759d6..dc3ea904 100644 --- a/Codist/Options/CSharpNaviBarPage.Designer.cs +++ b/Codist/Options/CSharpNaviBarPage.Designer.cs @@ -27,6 +27,7 @@ protected override void Dispose(bool disposing) { private void InitializeComponent() { this._OptionTabs = new System.Windows.Forms.TabControl(); this.tabPage2 = new System.Windows.Forms.TabPage(); + this._ParameterListParamNameBox = new System.Windows.Forms.CheckBox(); this.titleLabel1 = new Codist.Controls.TitleLabel(); this._RangeHighlightBox = new System.Windows.Forms.CheckBox(); this._ParameterListBox = new System.Windows.Forms.CheckBox(); @@ -35,7 +36,8 @@ private void InitializeComponent() { this._FieldValueBox = new System.Windows.Forms.CheckBox(); this._ToolTipBox = new System.Windows.Forms.CheckBox(); this._SyntaxNodesBox = new System.Windows.Forms.CheckBox(); - this._ParameterListParamNameBox = new System.Windows.Forms.CheckBox(); + this._AutoPropertyValueBox = new System.Windows.Forms.CheckBox(); + this.label1 = new System.Windows.Forms.Label(); this._OptionTabs.SuspendLayout(); this.tabPage2.SuspendLayout(); this.SuspendLayout(); @@ -54,6 +56,8 @@ private void InitializeComponent() { // // tabPage2 // + this.tabPage2.Controls.Add(this.label1); + this.tabPage2.Controls.Add(this._AutoPropertyValueBox); this.tabPage2.Controls.Add(this._ParameterListParamNameBox); this.tabPage2.Controls.Add(this.titleLabel1); this.tabPage2.Controls.Add(this._RangeHighlightBox); @@ -71,6 +75,16 @@ private void InitializeComponent() { this.tabPage2.Text = "Navigation Bar"; this.tabPage2.UseVisualStyleBackColor = true; // + // _ParameterListParamNameBox + // + this._ParameterListParamNameBox.AutoSize = true; + this._ParameterListParamNameBox.Location = new System.Drawing.Point(31, 141); + this._ParameterListParamNameBox.Name = "_ParameterListParamNameBox"; + this._ParameterListParamNameBox.Size = new System.Drawing.Size(173, 19); + this._ParameterListParamNameBox.TabIndex = 4; + this._ParameterListParamNameBox.Text = "Use parameter name"; + this._ParameterListParamNameBox.UseVisualStyleBackColor = true; + // // titleLabel1 // this.titleLabel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) @@ -97,27 +111,27 @@ private void InitializeComponent() { this._ParameterListBox.Location = new System.Drawing.Point(15, 116); this._ParameterListBox.Name = "_ParameterListBox"; this._ParameterListBox.Size = new System.Drawing.Size(157, 19); - this._ParameterListBox.TabIndex = 4; + this._ParameterListBox.TabIndex = 3; this._ParameterListBox.Text = "Method parameter"; this._ParameterListBox.UseVisualStyleBackColor = true; // // _RegionBox // this._RegionBox.AutoSize = true; - this._RegionBox.Location = new System.Drawing.Point(15, 216); + this._RegionBox.Location = new System.Drawing.Point(15, 241); this._RegionBox.Name = "_RegionBox"; this._RegionBox.Size = new System.Drawing.Size(165, 19); - this._RegionBox.TabIndex = 7; + this._RegionBox.TabIndex = 8; this._RegionBox.Text = "#region directive"; this._RegionBox.UseVisualStyleBackColor = true; // // _PartialClassBox // this._PartialClassBox.AutoSize = true; - this._PartialClassBox.Location = new System.Drawing.Point(15, 191); + this._PartialClassBox.Location = new System.Drawing.Point(15, 216); this._PartialClassBox.Name = "_PartialClassBox"; this._PartialClassBox.Size = new System.Drawing.Size(197, 19); - this._PartialClassBox.TabIndex = 6; + this._PartialClassBox.TabIndex = 7; this._PartialClassBox.Text = "Partial class members"; this._PartialClassBox.UseVisualStyleBackColor = true; // @@ -151,15 +165,24 @@ private void InitializeComponent() { this._SyntaxNodesBox.Text = "Syntax detail"; this._SyntaxNodesBox.UseVisualStyleBackColor = true; // - // _ParameterListParamNameBox + // _AutoPropertyValueBox // - this._ParameterListParamNameBox.AutoSize = true; - this._ParameterListParamNameBox.Location = new System.Drawing.Point(31, 141); - this._ParameterListParamNameBox.Name = "_ParameterListParamNameBox"; - this._ParameterListParamNameBox.Size = new System.Drawing.Size(173, 19); - this._ParameterListParamNameBox.TabIndex = 8; - this._ParameterListParamNameBox.Text = "Use parameter name"; - this._ParameterListParamNameBox.UseVisualStyleBackColor = true; + this._AutoPropertyValueBox.AutoSize = true; + this._AutoPropertyValueBox.Location = new System.Drawing.Point(31, 191); + this._AutoPropertyValueBox.Name = "_AutoPropertyValueBox"; + this._AutoPropertyValueBox.Size = new System.Drawing.Size(133, 19); + this._AutoPropertyValueBox.TabIndex = 6; + this._AutoPropertyValueBox.Text = "Auto property"; + this._AutoPropertyValueBox.UseVisualStyleBackColor = true; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 279); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(391, 15); + this.label1.TabIndex = 9; + this.label1.Text = "Note: currently Navigation Bar works on C# only."; // // CSharpNaviBarPage // @@ -188,5 +211,7 @@ private void InitializeComponent() { private System.Windows.Forms.CheckBox _RangeHighlightBox; private Controls.TitleLabel titleLabel1; private System.Windows.Forms.CheckBox _ParameterListParamNameBox; + private System.Windows.Forms.CheckBox _AutoPropertyValueBox; + private System.Windows.Forms.Label label1; } } diff --git a/Codist/Options/CSharpNaviBarPage.cs b/Codist/Options/CSharpNaviBarPage.cs index 636c8e4d..538d5657 100644 --- a/Codist/Options/CSharpNaviBarPage.cs +++ b/Codist/Options/CSharpNaviBarPage.cs @@ -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)); @@ -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); }); } } diff --git a/TestProject/TestPage.cs b/TestProject/TestPage.cs index 0425edf2..003dc2ec 100644 --- a/TestProject/TestPage.cs +++ b/TestProject/TestPage.cs @@ -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--; }