From 293b968c9043011d26a777135812dbcf3b371e35 Mon Sep 17 00:00:00 2001 From: WMJ Date: Sat, 29 Dec 2018 09:28:18 +0800 Subject: [PATCH] + Option to show #region name on Navigation Bar + Added command for regional directives on Smart Bar --- Codist/Config.cs | 2 + Codist/Helpers/CodeAnalysisHelper.cs | 14 ++ Codist/Helpers/SemanticContext.cs | 41 +++- Codist/Helpers/ServicesHelper.cs | 4 + Codist/NaviBar/CSharpBar.cs | 41 ++-- Codist/Options/CSharpNaviBarPage.Designer.cs | 221 +++++++++++-------- Codist/Options/CSharpNaviBarPage.cs | 8 +- Codist/SmartBars/CSharpSmartBar.cs | 24 ++ README.md | 1 + 9 files changed, 241 insertions(+), 115 deletions(-) diff --git a/Codist/Config.cs b/Codist/Config.cs index 6f8ab861..fc04def0 100644 --- a/Codist/Config.cs +++ b/Codist/Config.cs @@ -534,6 +534,8 @@ public enum NaviBarOptions SyntaxDetail = 1, SymbolToolTip = 1 << 1, RangeHighlight = 1 << 2, + RegionOnBar = 1 << 3, + StripRegionNonLetter = 1 << 4, ParameterList = 1 << 10, ParameterListShowParamName = 1 << 11, FieldValue = 1 << 12, diff --git a/Codist/Helpers/CodeAnalysisHelper.cs b/Codist/Helpers/CodeAnalysisHelper.cs index 6ff6567b..c384cd06 100644 --- a/Codist/Helpers/CodeAnalysisHelper.cs +++ b/Codist/Helpers/CodeAnalysisHelper.cs @@ -238,6 +238,20 @@ public static bool IsSyntaxBlock(this SyntaxNode node) { } return false; } + + public static bool IsRegionalDirective(this SyntaxNode node) { + switch (node.Kind()) { + case SyntaxKind.IfDirectiveTrivia: + case SyntaxKind.ElifDirectiveTrivia: + case SyntaxKind.ElseDirectiveTrivia: + case SyntaxKind.EndIfDirectiveTrivia: + case SyntaxKind.RegionDirectiveTrivia: + case SyntaxKind.EndRegionDirectiveTrivia: + return true; + } + return false; + } + #endregion #region Node icon diff --git a/Codist/Helpers/SemanticContext.cs b/Codist/Helpers/SemanticContext.cs index 3706c6ee..bd7c52f6 100644 --- a/Codist/Helpers/SemanticContext.cs +++ b/Codist/Helpers/SemanticContext.cs @@ -7,7 +7,9 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; +using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; +using Microsoft.VisualStudio.Text.Outlining; namespace Codist { @@ -15,9 +17,11 @@ sealed class SemanticContext { VersionStamp _Version; SyntaxNode _Node, _NodeIncludeTrivia; + readonly IOutliningManager _OutliningManager; public SemanticContext(IWpfTextView textView) { View = textView; + _OutliningManager = ServicesHelper.Instance.OutliningManager.GetOutliningManager(textView); } public IWpfTextView View { get; } @@ -285,7 +289,42 @@ public async Task UpdateAsync(int position, CancellationToken cancellation return true; } - private void ResetNodeInfo() { + public List GetContainingNodes(SnapshotPoint start, bool includeSyntaxDetails, bool includeRegions) { + var node = Node; + var nodes = new List(5); + while (node != null) { + if (node.FullSpan.Contains(View.Selection, true) + && node.IsKind(SyntaxKind.VariableDeclaration) == false + && (includeSyntaxDetails && node.IsSyntaxBlock() || node.IsDeclaration() || node.IsKind(SyntaxKind.Attribute))) { + nodes.Add(node); + } + node = node.Parent; + } + nodes.Reverse(); + if (includeRegions == false) { + return nodes; + } + foreach (var region in GetRegions(start)) { + node = Compilation.FindTrivia(region.Extent.GetStartPoint(View.TextSnapshot)).GetStructure(); + if (node == null || node is DirectiveTriviaSyntax == false) { + continue; + } + for (int i = 0; i < nodes.Count; i++) { + if (node.SpanStart < nodes[i].SpanStart) { + nodes.Insert(i, node); + break; + } + } + } + return nodes; + } + + public IEnumerable GetRegions(int position) { + return _OutliningManager.GetAllRegions(new SnapshotSpan(View.TextSnapshot, position, 0)) + .Where(c => c.CollapsedForm as string != "..."); + } + + void ResetNodeInfo() { _Node = _NodeIncludeTrivia = null; Token = default; } diff --git a/Codist/Helpers/ServicesHelper.cs b/Codist/Helpers/ServicesHelper.cs index 7b41bbc0..07e62748 100644 --- a/Codist/Helpers/ServicesHelper.cs +++ b/Codist/Helpers/ServicesHelper.cs @@ -38,10 +38,14 @@ private ServicesHelper() { [Import] public IGlyphService Glyph { get; private set; } + [Import] + public Microsoft.VisualStudio.Text.Outlining.IOutliningManagerService OutliningManager { get; private set; } + [Import] public ITextStructureNavigatorSelectorService TextStructureNavigator { get; private set; } [Import] public IViewTagAggregatorFactoryService ViewTagAggregatorFactory { get; private set; } + } } diff --git a/Codist/NaviBar/CSharpBar.cs b/Codist/NaviBar/CSharpBar.cs index f77c924d..94cb00ad 100644 --- a/Codist/NaviBar/CSharpBar.cs +++ b/Codist/NaviBar/CSharpBar.cs @@ -6,16 +6,16 @@ using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; +using AppHelpers; using Codist.Controls; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.VisualStudio.Imaging; +using Microsoft.VisualStudio.PlatformUI; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Text.Editor; using Task = System.Threading.Tasks.Task; -using AppHelpers; -using Microsoft.VisualStudio.PlatformUI; namespace Codist.NaviBar { @@ -188,22 +188,11 @@ void ViewClosed(object sender, EventArgs e) { } async Task> UpdateModelAsync(CancellationToken token) { - if (await _SemanticContext.UpdateAsync(_View.Selection.Start.Position, token) == false) { + var start = _View.Selection.Start.Position; + if (await _SemanticContext.UpdateAsync(start, token) == false) { return new List(); } - var node = _SemanticContext.Node; - var nodes = new List(5); - var detail = Config.Instance.NaviBarOptions.MatchFlags(NaviBarOptions.SyntaxDetail); - while (node != null) { - if (node.FullSpan.Contains(_View.Selection, true) - && node.IsKind(SyntaxKind.VariableDeclaration) == false - && (detail && node.IsSyntaxBlock() || node.IsDeclaration() || node.IsKind(SyntaxKind.Attribute))) { - nodes.Add(node); - } - node = node.Parent; - } - nodes.Reverse(); - return nodes; + return _SemanticContext.GetContainingNodes(start, Config.Instance.NaviBarOptions.MatchFlags(NaviBarOptions.SyntaxDetail), Config.Instance.NaviBarOptions.MatchFlags(NaviBarOptions.RegionOnBar)); } static string GetParameterListSignature(ParameterListSyntax parameters, bool useParamName) { @@ -468,6 +457,9 @@ NaviItem SetHeader(SyntaxNode node, bool includeContainer, bool highlight, bool if (title == null) { return this; } + if (node.IsStructuredTrivia && Config.Instance.NaviBarOptions.MatchFlags(NaviBarOptions.StripRegionNonLetter)) { + title = TrimNonLetterOrDigitCharacters(title); + } if (includeContainer == false && node.IsTypeDeclaration()) { var p = node.Parent; while (p.IsTypeDeclaration()) { @@ -505,6 +497,23 @@ NaviItem SetHeader(SyntaxNode node, bool includeContainer, bool highlight, bool return this; } + static string TrimNonLetterOrDigitCharacters(string title) { + int s = 0, e = title.Length; + for (int i = 0; i < title.Length; i++) { + if (Char.IsLetterOrDigit(title[i])) { + s = i; + break; + } + } + for (int i = title.Length - 1; i >= s; i--) { + if (Char.IsLetterOrDigit(title[i])) { + e = i + 1; + break; + } + } + return s > 0 || e < title.Length ? title.Substring(s, e - s) : title; + } + NaviItem ShowNodeValue() { if (Config.Instance.NaviBarOptions.MatchFlags(NaviBarOptions.FieldValue)) { switch (Node.Kind()) { diff --git a/Codist/Options/CSharpNaviBarPage.Designer.cs b/Codist/Options/CSharpNaviBarPage.Designer.cs index dc3ea904..4c60fa63 100644 --- a/Codist/Options/CSharpNaviBarPage.Designer.cs +++ b/Codist/Options/CSharpNaviBarPage.Designer.cs @@ -27,19 +27,22 @@ 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.label1 = new System.Windows.Forms.Label(); this._RangeHighlightBox = new System.Windows.Forms.CheckBox(); - this._ParameterListBox = new System.Windows.Forms.CheckBox(); - this._RegionBox = new System.Windows.Forms.CheckBox(); - this._PartialClassBox = new System.Windows.Forms.CheckBox(); - this._FieldValueBox = new System.Windows.Forms.CheckBox(); this._ToolTipBox = new System.Windows.Forms.CheckBox(); this._SyntaxNodesBox = new System.Windows.Forms.CheckBox(); + this._RegionBox = new System.Windows.Forms.CheckBox(); + this._StripNonLetterCharactersBox = new System.Windows.Forms.CheckBox(); + this.tabPage1 = new System.Windows.Forms.TabPage(); this._AutoPropertyValueBox = new System.Windows.Forms.CheckBox(); - this.label1 = new System.Windows.Forms.Label(); + this._ParameterListParamNameBox = new System.Windows.Forms.CheckBox(); + this._ParameterListBox = new System.Windows.Forms.CheckBox(); + this._RegionItemBox = new System.Windows.Forms.CheckBox(); + this._PartialClassBox = new System.Windows.Forms.CheckBox(); + this._FieldValueBox = new System.Windows.Forms.CheckBox(); this._OptionTabs.SuspendLayout(); this.tabPage2.SuspendLayout(); + this.tabPage1.SuspendLayout(); this.SuspendLayout(); // // _OptionTabs @@ -48,6 +51,7 @@ private void InitializeComponent() { | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this._OptionTabs.Controls.Add(this.tabPage2); + this._OptionTabs.Controls.Add(this.tabPage1); this._OptionTabs.Location = new System.Drawing.Point(3, 3); this._OptionTabs.Name = "_OptionTabs"; this._OptionTabs.SelectedIndex = 0; @@ -56,15 +60,10 @@ private void InitializeComponent() { // // tabPage2 // + this.tabPage2.Controls.Add(this._StripNonLetterCharactersBox); + this.tabPage2.Controls.Add(this._RegionBox); 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); - this.tabPage2.Controls.Add(this._ParameterListBox); - this.tabPage2.Controls.Add(this._RegionBox); - this.tabPage2.Controls.Add(this._PartialClassBox); - this.tabPage2.Controls.Add(this._FieldValueBox); this.tabPage2.Controls.Add(this._ToolTipBox); this.tabPage2.Controls.Add(this._SyntaxNodesBox); this.tabPage2.Location = new System.Drawing.Point(4, 25); @@ -75,84 +74,33 @@ 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 + // label1 // - this.titleLabel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.titleLabel1.Location = new System.Drawing.Point(12, 89); - this.titleLabel1.Name = "titleLabel1"; - this.titleLabel1.Size = new System.Drawing.Size(488, 15); - this.titleLabel1.TabIndex = 3; - this.titleLabel1.Text = "Drop-down Item"; + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 128); + 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."; // // _RangeHighlightBox // this._RangeHighlightBox.AutoSize = true; this._RangeHighlightBox.Location = new System.Drawing.Point(15, 56); this._RangeHighlightBox.Name = "_RangeHighlightBox"; - this._RangeHighlightBox.Size = new System.Drawing.Size(189, 19); + this._RangeHighlightBox.Size = new System.Drawing.Size(269, 19); this._RangeHighlightBox.TabIndex = 2; - this._RangeHighlightBox.Text = "Code range highlight"; + this._RangeHighlightBox.Text = "Highlight node range in editor"; this._RangeHighlightBox.UseVisualStyleBackColor = true; // - // _ParameterListBox - // - this._ParameterListBox.AutoSize = true; - 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 = 3; - this._ParameterListBox.Text = "Method parameter"; - this._ParameterListBox.UseVisualStyleBackColor = true; - // - // _RegionBox - // - this._RegionBox.AutoSize = true; - 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 = 8; - this._RegionBox.Text = "#region directive"; - this._RegionBox.UseVisualStyleBackColor = true; - // - // _PartialClassBox - // - this._PartialClassBox.AutoSize = true; - 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 = 7; - this._PartialClassBox.Text = "Partial class members"; - this._PartialClassBox.UseVisualStyleBackColor = true; - // - // _FieldValueBox - // - this._FieldValueBox.AutoSize = true; - this._FieldValueBox.Location = new System.Drawing.Point(15, 166); - this._FieldValueBox.Name = "_FieldValueBox"; - this._FieldValueBox.Size = new System.Drawing.Size(117, 19); - this._FieldValueBox.TabIndex = 5; - this._FieldValueBox.Text = "Field value"; - this._FieldValueBox.UseVisualStyleBackColor = true; - // // _ToolTipBox // this._ToolTipBox.AutoSize = true; this._ToolTipBox.Location = new System.Drawing.Point(15, 31); this._ToolTipBox.Name = "_ToolTipBox"; - this._ToolTipBox.Size = new System.Drawing.Size(149, 19); + this._ToolTipBox.Size = new System.Drawing.Size(189, 19); this._ToolTipBox.TabIndex = 1; - this._ToolTipBox.Text = "Symbol tool tip"; + this._ToolTipBox.Text = "Show symbol info tip"; this._ToolTipBox.UseVisualStyleBackColor = true; // // _SyntaxNodesBox @@ -160,29 +108,106 @@ private void InitializeComponent() { this._SyntaxNodesBox.AutoSize = true; this._SyntaxNodesBox.Location = new System.Drawing.Point(15, 6); this._SyntaxNodesBox.Name = "_SyntaxNodesBox"; - this._SyntaxNodesBox.Size = new System.Drawing.Size(133, 19); + this._SyntaxNodesBox.Size = new System.Drawing.Size(173, 19); this._SyntaxNodesBox.TabIndex = 0; - this._SyntaxNodesBox.Text = "Syntax detail"; + this._SyntaxNodesBox.Text = "Show syntax detail"; this._SyntaxNodesBox.UseVisualStyleBackColor = true; // + // _RegionBox + // + this._RegionBox.AutoSize = true; + this._RegionBox.Location = new System.Drawing.Point(15, 81); + this._RegionBox.Name = "_RegionBox"; + this._RegionBox.Size = new System.Drawing.Size(165, 19); + this._RegionBox.TabIndex = 10; + this._RegionBox.Text = "Show #region name"; + this._RegionBox.UseVisualStyleBackColor = true; + // + // _StripNonLetterCharactersBox + // + this._StripNonLetterCharactersBox.AutoSize = true; + this._StripNonLetterCharactersBox.Location = new System.Drawing.Point(39, 106); + this._StripNonLetterCharactersBox.Name = "_StripNonLetterCharactersBox"; + this._StripNonLetterCharactersBox.Size = new System.Drawing.Size(237, 19); + this._StripNonLetterCharactersBox.TabIndex = 11; + this._StripNonLetterCharactersBox.Text = "Trim non-letter characters"; + this._StripNonLetterCharactersBox.UseVisualStyleBackColor = true; + // + // tabPage1 + // + this.tabPage1.Controls.Add(this._AutoPropertyValueBox); + this.tabPage1.Controls.Add(this._ParameterListParamNameBox); + this.tabPage1.Controls.Add(this._ParameterListBox); + this.tabPage1.Controls.Add(this._RegionItemBox); + this.tabPage1.Controls.Add(this._PartialClassBox); + this.tabPage1.Controls.Add(this._FieldValueBox); + this.tabPage1.Location = new System.Drawing.Point(4, 25); + this.tabPage1.Name = "tabPage1"; + this.tabPage1.Padding = new System.Windows.Forms.Padding(3); + this.tabPage1.Size = new System.Drawing.Size(524, 320); + this.tabPage1.TabIndex = 2; + this.tabPage1.Text = "Drop-down Menu"; + this.tabPage1.UseVisualStyleBackColor = true; + // // _AutoPropertyValueBox // this._AutoPropertyValueBox.AutoSize = true; - this._AutoPropertyValueBox.Location = new System.Drawing.Point(31, 191); + this._AutoPropertyValueBox.Location = new System.Drawing.Point(31, 81); this._AutoPropertyValueBox.Name = "_AutoPropertyValueBox"; - this._AutoPropertyValueBox.Size = new System.Drawing.Size(133, 19); - this._AutoPropertyValueBox.TabIndex = 6; - this._AutoPropertyValueBox.Text = "Auto property"; + this._AutoPropertyValueBox.Size = new System.Drawing.Size(181, 19); + this._AutoPropertyValueBox.TabIndex = 12; + this._AutoPropertyValueBox.Text = "Show property value"; this._AutoPropertyValueBox.UseVisualStyleBackColor = true; // - // label1 + // _ParameterListParamNameBox // - 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."; + this._ParameterListParamNameBox.AutoSize = true; + this._ParameterListParamNameBox.Location = new System.Drawing.Point(31, 31); + this._ParameterListParamNameBox.Name = "_ParameterListParamNameBox"; + this._ParameterListParamNameBox.Size = new System.Drawing.Size(309, 19); + this._ParameterListParamNameBox.TabIndex = 10; + this._ParameterListParamNameBox.Text = "Show parameter name instead of type"; + this._ParameterListParamNameBox.UseVisualStyleBackColor = true; + // + // _ParameterListBox + // + this._ParameterListBox.AutoSize = true; + this._ParameterListBox.Location = new System.Drawing.Point(15, 6); + this._ParameterListBox.Name = "_ParameterListBox"; + this._ParameterListBox.Size = new System.Drawing.Size(197, 19); + this._ParameterListBox.TabIndex = 9; + this._ParameterListBox.Text = "Show method parameter"; + this._ParameterListBox.UseVisualStyleBackColor = true; + // + // _RegionItemBox + // + this._RegionItemBox.AutoSize = true; + this._RegionItemBox.Location = new System.Drawing.Point(15, 131); + this._RegionItemBox.Name = "_RegionItemBox"; + this._RegionItemBox.Size = new System.Drawing.Size(205, 19); + this._RegionItemBox.TabIndex = 14; + this._RegionItemBox.Text = "Show #region directive"; + this._RegionItemBox.UseVisualStyleBackColor = true; + // + // _PartialClassBox + // + this._PartialClassBox.AutoSize = true; + this._PartialClassBox.Location = new System.Drawing.Point(15, 106); + this._PartialClassBox.Name = "_PartialClassBox"; + this._PartialClassBox.Size = new System.Drawing.Size(189, 19); + this._PartialClassBox.TabIndex = 13; + this._PartialClassBox.Text = "Include partial type"; + this._PartialClassBox.UseVisualStyleBackColor = true; + // + // _FieldValueBox + // + this._FieldValueBox.AutoSize = true; + this._FieldValueBox.Location = new System.Drawing.Point(15, 56); + this._FieldValueBox.Name = "_FieldValueBox"; + this._FieldValueBox.Size = new System.Drawing.Size(157, 19); + this._FieldValueBox.TabIndex = 11; + this._FieldValueBox.Text = "Show field value"; + this._FieldValueBox.UseVisualStyleBackColor = true; // // CSharpNaviBarPage // @@ -195,6 +220,8 @@ private void InitializeComponent() { this._OptionTabs.ResumeLayout(false); this.tabPage2.ResumeLayout(false); this.tabPage2.PerformLayout(); + this.tabPage1.ResumeLayout(false); + this.tabPage1.PerformLayout(); this.ResumeLayout(false); } @@ -202,16 +229,18 @@ private void InitializeComponent() { #endregion private System.Windows.Forms.TabControl _OptionTabs; private System.Windows.Forms.TabPage tabPage2; - private System.Windows.Forms.CheckBox _ParameterListBox; - private System.Windows.Forms.CheckBox _PartialClassBox; - private System.Windows.Forms.CheckBox _FieldValueBox; private System.Windows.Forms.CheckBox _SyntaxNodesBox; private System.Windows.Forms.CheckBox _ToolTipBox; - private System.Windows.Forms.CheckBox _RegionBox; 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; + private System.Windows.Forms.CheckBox _RegionBox; + private System.Windows.Forms.CheckBox _StripNonLetterCharactersBox; + private System.Windows.Forms.TabPage tabPage1; + private System.Windows.Forms.CheckBox _AutoPropertyValueBox; + private System.Windows.Forms.CheckBox _ParameterListParamNameBox; + private System.Windows.Forms.CheckBox _ParameterListBox; + private System.Windows.Forms.CheckBox _RegionItemBox; + private System.Windows.Forms.CheckBox _PartialClassBox; + private System.Windows.Forms.CheckBox _FieldValueBox; } } diff --git a/Codist/Options/CSharpNaviBarPage.cs b/Codist/Options/CSharpNaviBarPage.cs index 538d5657..3363fa94 100644 --- a/Codist/Options/CSharpNaviBarPage.cs +++ b/Codist/Options/CSharpNaviBarPage.cs @@ -30,7 +30,9 @@ void CSharpNaviBarPage_Load(object sender, EventArgs e) { _ParameterListParamNameBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.ParameterListShowParamName, _ParameterListParamNameBox.Checked)); _PartialClassBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.PartialClassMember, _PartialClassBox.Checked)); _RangeHighlightBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.RangeHighlight, _RangeHighlightBox.Checked)); - _RegionBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.Region, _RegionBox.Checked)); + _RegionBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.RegionOnBar, _StripNonLetterCharactersBox.Enabled = _RegionBox.Checked)); + _RegionItemBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.Region, _RegionItemBox.Checked)); + _StripNonLetterCharactersBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.StripRegionNonLetter, _StripNonLetterCharactersBox.Checked)); _SyntaxNodesBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.SyntaxDetail, _SyntaxNodesBox.Checked)); _ToolTipBox.CheckedChanged += _UI.HandleEvent(() => Config.Instance.Set(NaviBarOptions.SymbolToolTip, _ToolTipBox.Checked)); @@ -47,7 +49,9 @@ void LoadConfig(Config config) { _ParameterListParamNameBox.Checked = o.MatchFlags(NaviBarOptions.ParameterListShowParamName); _PartialClassBox.Checked = o.MatchFlags(NaviBarOptions.PartialClassMember); _RangeHighlightBox.Checked = o.MatchFlags(NaviBarOptions.RangeHighlight); - _RegionBox.Checked = o.MatchFlags(NaviBarOptions.Region); + _StripNonLetterCharactersBox.Enabled = _RegionBox.Checked = o.MatchFlags(NaviBarOptions.RegionOnBar); + _StripNonLetterCharactersBox.Checked = o.MatchFlags(NaviBarOptions.StripRegionNonLetter); + _RegionItemBox.Checked = o.MatchFlags(NaviBarOptions.Region); _SyntaxNodesBox.Checked = o.MatchFlags(NaviBarOptions.SyntaxDetail); _ToolTipBox.Checked = o.MatchFlags(NaviBarOptions.SymbolToolTip); }); diff --git a/Codist/SmartBars/CSharpSmartBar.cs b/Codist/SmartBars/CSharpSmartBar.cs index b2ed409b..75b74bcf 100644 --- a/Codist/SmartBars/CSharpSmartBar.cs +++ b/Codist/SmartBars/CSharpSmartBar.cs @@ -111,6 +111,9 @@ void AddContextualCommands(CancellationToken cancellationToken) { Replace(ctx, v => v == "true" ? "false" : "true", true); }); } + else if (node.IsRegionalDirective()) { + AddDirectiveCommands(); + } if (isDesignMode && isReadOnly == false) { if (node.IsKind(SyntaxKind.VariableDeclarator)) { if (node?.Parent?.Parent is MemberDeclarationSyntax) { @@ -145,6 +148,27 @@ void AddContextualCommands(CancellationToken cancellationToken) { AddCommands(MyToolBar, KnownImageIds.SelectFrame, "Expand selection...\nRight click: Duplicate...\nCtrl click item: Copy\nShift click item: Exclude whitespaces and comments", null, GetExpandSelectionCommands); } + void AddDirectiveCommands() { + AddCommand(MyToolBar, KnownImageIds.BlockSelection, "Select directive region", ctx => { + var a = _Context.NodeIncludeTrivia as DirectiveTriviaSyntax; + if (a == null) { + return; + } + DirectiveTriviaSyntax b; + if (a.IsKind(SyntaxKind.EndRegionDirectiveTrivia) || a.IsKind(SyntaxKind.EndIfDirectiveTrivia)) { + b = a; + a = b.GetPreviousDirective(); + if (a == null) { + return; + } + } + else { + b = a.GetNextDirective(); + } + ctx.View.SelectSpan(new SnapshotSpan(ctx.View.TextSnapshot, Span.FromBounds(a.FullSpan.Start, b.FullSpan.End))); + }); + } + void AddCommentCommands() { var token = _Context.Token; var triviaList = token.HasLeadingTrivia ? token.LeadingTrivia : token.HasTrailingTrivia ? token.TrailingTrivia : default; diff --git a/README.md b/README.md index d3fe1355..d6496ab4 100644 --- a/README.md +++ b/README.md @@ -304,6 +304,7 @@ I have learned a lot from the following extension projects. * UntabifyReplacement: https://github.com/cpmcgrath/UntabifyReplacement * Extensiblity Tools: https://github.com/madskristensen/ExtensibilityTools * CodeMaid: https://github.com/codecadwallader/codemaid +* Select Next Occurence: https://github.com/2mas/SelectNextOccurrence # License