Skip to content

Commit

Permalink
+ Added command to access Search Declaration menu in the Navi Bar
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Dec 14, 2018
1 parent 3284c32 commit 40dc041
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 22 deletions.
1 change: 1 addition & 0 deletions Codist/Codist.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<Compile Include="Classifiers\XmlClassificationDefinitions.cs" />
<Compile Include="Classifiers\XmlFormats.cs" />
<Compile Include="Commands\IncrementVsixVersionCommand.cs" />
<Compile Include="Commands\NaviBarSearchDeclarationCommand.cs" />
<Compile Include="Controls\MemberFilterBox.cs" />
<Compile Include="Controls\StateButton.cs" />
<Compile Include="Controls\ThemedMenuItem.cs" />
Expand Down
12 changes: 12 additions & 0 deletions Codist/CodistPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Events;
using Microsoft.VisualStudio.Shell.Interop;

namespace Codist
{
Expand Down Expand Up @@ -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
/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
Expand Down Expand Up @@ -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
Expand Down
31 changes: 26 additions & 5 deletions Codist/Commands/CodistPackage.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<Group guid="guidCodistPackageCmdSet3" id="EDIT_PROJECT_GROUP_ID" priority="0x017F">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE" />
</Group>
<Group guid="guidCodistPackageCmdSet4" id="IDG_VS_EDIT_GOTO" priority="0x0800">
<Parent guid="guidSHLMainMenu" id="IDM_VS_EDITOR_FIND_MENU" />
</Group>
</Groups>

<!--Buttons section. -->
Expand Down Expand Up @@ -88,7 +91,17 @@
<CommandFlag>TextChanges</CommandFlag>
<CommandFlag>IconIsMoniker</CommandFlag>
<Strings>
<ButtonText>Increment version</ButtonText>
<ButtonText>Increment Version</ButtonText>
</Strings>
</Button>
<Button guid="guidCodistPackageCmdSet4" id="NaviBarSearchDeclarationId" priority="0x0100" type="Button">
<Parent guid="guidCodistPackageCmdSet4" id="IDG_VS_EDIT_GOTO" />
<Icon guid="ImageCatalogGuid" id="SearchMember" />
<CommandFlag>DefaultDisabled</CommandFlag>
<CommandFlag>IconIsMoniker</CommandFlag>
<Strings>
<ButtonText>Search Declaration</ButtonText>
<CanonicalName>CodistNaviBarSearchDeclaration</CanonicalName>
</Strings>
</Button>
</Buttons>
Expand All @@ -103,7 +116,10 @@
<Bitmap guid="guidImages" href="Resources\ScreenshotCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
</Bitmaps>-->
</Commands>

<KeyBindings>
<!--Bind NaviBar.SearchDeclaration to Ctrl + ` -->
<KeyBinding guid="guidCodistPackageCmdSet4" id="NaviBarSearchDeclarationId" editor="guidVSStd97" mod1="Control" key1="0xC0" />
</KeyBindings>
<Symbols>
<!-- This is the package guid. -->
<GuidSymbol name="guidCodistPackage" value="{c7b93d20-621f-4b21-9d28-d51157ef0b94}" />
Expand All @@ -119,10 +135,15 @@
<IDSymbol name="IDG_VS_VIEW_DEFINEVIEWS" value="0x1020" />
<IDSymbol name="SymbolFinderWindowCommandId" value="4129" />
</GuidSymbol>
<GuidSymbol value="{eb9f9d42-d000-4d82-874a-4688ddd26dbe}" name="guidCodistPackageCmdSet3">

<GuidSymbol name="guidCodistPackageCmdSet3" value="{eb9f9d42-d000-4d82-874a-4688ddd26dbe}">
<IDSymbol name="EDIT_PROJECT_GROUP_ID" value="0x1000" />
<IDSymbol value="4128" name="EDIT_VSIXMANIFEST_ID" />
<IDSymbol name="EDIT_VSIXMANIFEST_ID" value="4128" />
</GuidSymbol>

<GuidSymbol name="guidCodistPackageCmdSet4" value="{5EF88028-C0FC-4849-9883-10F4BD2217B3}">
<IDSymbol name="NaviBarSearchDeclarationId" value="4130" />
</GuidSymbol>

</Symbols>
</CommandTable>
10 changes: 2 additions & 8 deletions Codist/Commands/IncrementVsixVersionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static class IncrementVsixVersionCommand
/// <summary>
/// Command menu group (command set GUID).
/// </summary>
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));
Expand Down Expand Up @@ -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() {
Expand Down
46 changes: 46 additions & 0 deletions Codist/Commands/NaviBarSearchDeclarationCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.ComponentModel.Design;
using Microsoft.VisualStudio.Shell;

namespace Codist.Commands
{
/// <summary>
/// Command handler
/// </summary>
internal static class NaviBarSearchDeclarationCommand
{
/// <summary>
/// Command ID.
/// </summary>
public const int CommandId = 4130;

/// <summary>
/// Command menu group (command set GUID).
/// </summary>
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<NaviBar.CSharpBar>(nameof(NaviBar), out var bar) == false) {
return;
}
bar.ShowRootItemMenu();
}
}
}
9 changes: 1 addition & 8 deletions Codist/Commands/ScreenshotCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.ComponentModel.Design;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace Codist.Commands
{
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion Codist/NaviBar/CSharpBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) { }
Expand Down

0 comments on commit 40dc041

Please sign in to comment.