Skip to content

Commit

Permalink
+ Added smart bar buttons for C/C++ code file type
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Dec 20, 2018
1 parent f1d011f commit f2f1e25
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions Codist/Codist.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
<Compile Include="QuickInfo\ColorQuickInfo.cs" />
<Compile Include="Helpers\SymbolFormatter.cs" />
<Compile Include="Helpers\XmlDocRenderer.cs" />
<Compile Include="SmartBars\CppSmartBar.cs" />
<Compile Include="SmartBars\CSharpSmartBar.cs" />
<Compile Include="SmartBars\OutputSmartBar.cs" />
<Compile Include="SmartBars\MarkdownSmartBar.cs" />
Expand Down
1 change: 1 addition & 0 deletions Codist/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ static partial class Constants

public static class CodeTypes
{
public const string CPlusPlus = "C/C++";
public const string Code = nameof(Code);
public const string CSharp = nameof(CSharp);
public const string Text = nameof(Text);
Expand Down
57 changes: 57 additions & 0 deletions Codist/SmartBars/CppSmartBar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows.Controls;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Operations;

namespace Codist.SmartBars
{
sealed class CppSmartBar : SmartBar
{
readonly ITextStructureNavigator _TextStructureNavigator;
public CppSmartBar(IWpfTextView textView, ITextSearchService2 textSearchService) : base(textView, textSearchService) {
_TextStructureNavigator = ServicesHelper.Instance.TextStructureNavigator.GetTextStructureNavigator(textView.TextBuffer);
}

ToolBar MyToolBar => ToolBar2;

protected override void AddCommands(CancellationToken cancellationToken) {
base.AddCommands(cancellationToken);
AddCommand(MyToolBar, KnownImageIds.GoToDefinition, "Go to definition", ctx => {
TextEditorHelper.ExecuteEditorCommand("Edit.GoToDefinition", GetCurrentWord(ctx.View));
});
AddCommand(MyToolBar, KnownImageIds.GoToDeclaration, "Go to declaration", ctx => {
TextEditorHelper.ExecuteEditorCommand("Edit.GoToDeclaration", GetCurrentWord(ctx.View));
});
var mode = CodistPackage.DebuggerStatus;
if (mode != DebuggerStatus.Running) {
//AddEditorCommand(MyToolBar, KnownImageIds.IntellisenseLightBulb, "EditorContextMenus.CodeWindow.QuickActionsForPosition", "Quick actions for position");
AddCommand(MyToolBar, KnownImageIds.CommentCode, "Comment selection\nRight click: Comment line", ctx => {
if (ctx.RightClick) {
ctx.View.ExpandSelectionToLine();
}
TextEditorHelper.ExecuteEditorCommand("Edit.CommentSelection");
});
AddEditorCommand(MyToolBar, KnownImageIds.UncommentCode, "Edit.UncommentSelection", "Uncomment selection");
}
else if (mode != DebuggerStatus.Design) {
AddCommands(MyToolBar, KnownImageIds.BreakpointEnabled, "Debugger...\nLeft click: Toggle breakpoint\nRight click: Debugger menu...", ctx => TextEditorHelper.ExecuteEditorCommand("Debug.ToggleBreakpoint"), GetDebugCommands);
}
}

CommandItem[] GetDebugCommands(CommandContext ctx) {
return new CommandItem[] {
new CommandItem(KnownImageIds.Watch, "Add Watch", c => TextEditorHelper.ExecuteEditorCommand("Debug.AddWatch")),
new CommandItem(KnownImageIds.Watch, "Add Parallel Watch", c => TextEditorHelper.ExecuteEditorCommand("Debug.AddParallelWatch")),
new CommandItem(KnownImageIds.DeleteBreakpoint, "Delete All Breakpoints", c => TextEditorHelper.ExecuteEditorCommand("Debug.DeleteAllBreakpoints"))
};
}

string GetCurrentWord(ITextView view) {
return _TextStructureNavigator.GetExtentOfWord(view.Selection.Start.Position).Span.GetText();
}
}
}
3 changes: 3 additions & 0 deletions Codist/SmartBars/SmartBarTextViewCreationListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public void TextViewCreated(IWpfTextView textView) {
) {
new OutputSmartBar(textView, _TextSearchService);
}
else if (contentType.IsOfType(Constants.CodeTypes.CPlusPlus)) {
new CppSmartBar(textView, _TextSearchService);
}
else {
new SmartBar(textView, _TextSearchService);
}
Expand Down

0 comments on commit f2f1e25

Please sign in to comment.