From 40dc04107c2f054aa5124fba4295232f560878de Mon Sep 17 00:00:00 2001 From: WMJ Date: Fri, 14 Dec 2018 11:21:46 +0800 Subject: [PATCH] + Added command to access Search Declaration menu in the Navi Bar --- Codist/Codist.csproj | 1 + Codist/CodistPackage.cs | 12 +++++ Codist/Commands/CodistPackage.vsct | 31 +++++++++++-- .../Commands/IncrementVsixVersionCommand.cs | 10 +--- .../NaviBarSearchDeclarationCommand.cs | 46 +++++++++++++++++++ Codist/Commands/ScreenshotCommand.cs | 9 +--- Codist/NaviBar/CSharpBar.cs | 7 ++- 7 files changed, 94 insertions(+), 22 deletions(-) create mode 100644 Codist/Commands/NaviBarSearchDeclarationCommand.cs diff --git a/Codist/Codist.csproj b/Codist/Codist.csproj index 29579409..8d53254a 100644 --- a/Codist/Codist.csproj +++ b/Codist/Codist.csproj @@ -86,6 +86,7 @@ + diff --git a/Codist/CodistPackage.cs b/Codist/CodistPackage.cs index b0cffc53..f697f838 100644 --- a/Codist/CodistPackage.cs +++ b/Codist/CodistPackage.cs @@ -5,6 +5,7 @@ using Microsoft.VisualStudio.PlatformUI; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Events; +using Microsoft.VisualStudio.Shell.Interop; namespace Codist { @@ -92,6 +93,16 @@ public static DebuggerStatus DebuggerStatus { } } + public static void ShowErrorMessageBox(string message, string title, bool error) { + VsShellUtilities.ShowMessageBox( + Instance, + message, + title ?? nameof(Codist), + error ? OLEMSGICON.OLEMSGICON_WARNING : OLEMSGICON.OLEMSGICON_INFO, + OLEMSGBUTTON.OLEMSGBUTTON_OK, + OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); + } + #region Package Members /// /// Initialization of the package; this method is called right after the package is sited, so this is the place @@ -121,6 +132,7 @@ protected override async System.Threading.Tasks.Task InitializeAsync(Cancellatio await Commands.SymbolFinderWindowCommand.InitializeAsync(this); Commands.ScreenshotCommand.Initialize(this); Commands.IncrementVsixVersionCommand.Initialize(this); + Commands.NaviBarSearchDeclarationCommand.Initialize(this); } #endregion diff --git a/Codist/Commands/CodistPackage.vsct b/Codist/Commands/CodistPackage.vsct index f33e24af..34c3b3ea 100644 --- a/Codist/Commands/CodistPackage.vsct +++ b/Codist/Commands/CodistPackage.vsct @@ -46,6 +46,9 @@ + + + @@ -88,7 +91,17 @@ TextChanges IconIsMoniker - Increment version + Increment Version + + + @@ -103,7 +116,10 @@ --> - + + + + @@ -119,10 +135,15 @@ - - + + - + + + + + + diff --git a/Codist/Commands/IncrementVsixVersionCommand.cs b/Codist/Commands/IncrementVsixVersionCommand.cs index 6f0b5529..a95089b7 100644 --- a/Codist/Commands/IncrementVsixVersionCommand.cs +++ b/Codist/Commands/IncrementVsixVersionCommand.cs @@ -17,7 +17,7 @@ internal static class IncrementVsixVersionCommand /// /// Command menu group (command set GUID). /// - public static readonly Guid CommandSet = new Guid("eb9f9d42-d000-4d82-874a-4688ddd26dbe"); + public static readonly Guid CommandSet = new Guid("EB9F9D42-D000-4D82-874A-4688DDD26DBE"); public static void Initialize(AsyncPackage package) { var menuItem = new OleMenuCommand(Execute, new CommandID(CommandSet, CommandId)); @@ -59,13 +59,7 @@ static void Execute(object sender, EventArgs e) { error = true; } - VsShellUtilities.ShowMessageBox( - CodistPackage.Instance, - message, - "Increment Version", - error ? OLEMSGICON.OLEMSGICON_WARNING : OLEMSGICON.OLEMSGICON_INFO, - OLEMSGBUTTON.OLEMSGBUTTON_OK, - OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); + CodistPackage.ShowErrorMessageBox(message, "Increment Version", error); } static ProjectItem GetSelectedProjectItem() { diff --git a/Codist/Commands/NaviBarSearchDeclarationCommand.cs b/Codist/Commands/NaviBarSearchDeclarationCommand.cs new file mode 100644 index 00000000..4b000dde --- /dev/null +++ b/Codist/Commands/NaviBarSearchDeclarationCommand.cs @@ -0,0 +1,46 @@ +using System; +using System.ComponentModel.Design; +using Microsoft.VisualStudio.Shell; + +namespace Codist.Commands +{ + /// + /// Command handler + /// + internal static class NaviBarSearchDeclarationCommand + { + /// + /// Command ID. + /// + public const int CommandId = 4130; + + /// + /// Command menu group (command set GUID). + /// + public static readonly Guid CommandSet = new Guid("5EF88028-C0FC-4849-9883-10F4BD2217B3"); + + public static void Initialize(AsyncPackage package) { + var menuItem = new OleMenuCommand(Execute, new CommandID(CommandSet, CommandId)); + menuItem.BeforeQueryStatus += (s, args) => { + ThreadHelper.ThrowIfNotOnUIThread(); + var c = s as OleMenuCommand; + c.Enabled = CodistPackage.DTE.ActiveDocument != null; + }; + CodistPackage.MenuService.AddCommand(menuItem); + } + + static void Execute(object sender, EventArgs e) { + ThreadHelper.ThrowIfNotOnUIThread(); + var doc = CodistPackage.DTE.ActiveDocument; + if (doc == null) { + return; + } + var docWindow = CodistPackage.Instance.GetActiveWpfDocumentView(); + if (docWindow == null + || docWindow.Properties.TryGetProperty(nameof(NaviBar), out var bar) == false) { + return; + } + bar.ShowRootItemMenu(); + } + } +} diff --git a/Codist/Commands/ScreenshotCommand.cs b/Codist/Commands/ScreenshotCommand.cs index 1b29acf4..00ed19f4 100644 --- a/Codist/Commands/ScreenshotCommand.cs +++ b/Codist/Commands/ScreenshotCommand.cs @@ -1,7 +1,6 @@ using System; using System.ComponentModel.Design; using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Shell.Interop; namespace Codist.Commands { @@ -50,13 +49,7 @@ static void Execute(object sender, EventArgs e) { WpfHelper.ScreenShot(g, f.FileName, (int)g.ActualWidth, (int)g.ActualHeight); } catch (Exception ex) { - VsShellUtilities.ShowMessageBox( - CodistPackage.Instance, - "Failed to save screenshot for " + doc.Name + "\n" + ex.Message, - nameof(Codist), - OLEMSGICON.OLEMSGICON_INFO, - OLEMSGBUTTON.OLEMSGBUTTON_OK, - OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); + CodistPackage.ShowErrorMessageBox("Failed to save screenshot for " + doc.Name + "\n" + ex.Message, null, true); } } } diff --git a/Codist/NaviBar/CSharpBar.cs b/Codist/NaviBar/CSharpBar.cs index 7f24f98b..36536d71 100644 --- a/Codist/NaviBar/CSharpBar.cs +++ b/Codist/NaviBar/CSharpBar.cs @@ -32,6 +32,7 @@ public CSharpBar(IWpfTextView textView) { _Adornment = _View.GetAdornmentLayer(nameof(CSharpBar)); _SemanticContext = textView.Properties.GetOrCreateSingletonProperty(() => new SemanticContext(textView)); this.SetBackgroundForCrispImage(ThemeHelper.TitleBackgroundColor); + textView.Properties.AddProperty(nameof(NaviBar), this); Name = nameof(CSharpBar); Resources = SharedDictionaryManager.Menu; SetResourceReference(BackgroundProperty, VsBrushes.CommandBarMenuBackgroundGradientKey); @@ -82,6 +83,10 @@ protected override void OnMouseMove(MouseEventArgs e) { } } + internal void ShowRootItemMenu() { + (Items[0] as RootItem).IsSubmenuOpen = true; + } + void HighlightNodeRanges(SyntaxNode node, Microsoft.VisualStudio.Text.SnapshotSpan span) { _Adornment.AddAdornment(span, null, new GeometryAdornment(ThemeHelper.MenuHoverBackgroundColor, _View.TextViewLines.GetMarkerGeometry(span), 3)); var p = _View.Caret.Position.BufferPosition; @@ -309,7 +314,7 @@ void ControlMenuSelection(object sender, KeyEventArgs e) { sealed class NaviItem : ThemedMenuItem, IMemberFilterable { readonly CSharpBar _Bar; - bool _NodeIsExternal, _ShowNodeDetail; + bool _NodeIsExternal; readonly int _ImageId; public NaviItem(CSharpBar bar, SyntaxNode node) : this (bar, node, false, false) { }