Skip to content

Commit

Permalink
! Adopted AsyncPackage pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Sep 18, 2018
1 parent 26ece6b commit 77b927c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 31 deletions.
12 changes: 4 additions & 8 deletions Codist/CodistPackage.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using EnvDTE80;
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Shell.Events;

namespace Codist
{
Expand All @@ -28,8 +26,8 @@ namespace Codist
[ProvideOptionPage(typeof(Options.XmlStyle), CategorySyntaxHighlight, "XML", 0, 0, true, Sort = 30)]
[ProvideOptionPage(typeof(Options.CommentStyle), CategorySyntaxHighlight, "Comment", 0, 0, true, Sort = 60)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideAutoLoad(UIContextGuids.SolutionExists)]
[ProvideToolWindow(typeof(Codist.Commands.SymbolFinderWindow))]
[ProvideToolWindow(typeof(Commands.SymbolFinderWindow))]
[ProvideAutoLoad(Microsoft.VisualStudio.VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
sealed class CodistPackage : AsyncPackage
{
/// <summary>CodistPackage GUID string.</summary>
Expand All @@ -39,7 +37,6 @@ sealed class CodistPackage : AsyncPackage
const string CategoryScrollbarMarker = Constants.NameOfMe + "\\Scrollbar Marker";
const string CategorySyntaxHighlight = Constants.NameOfMe + "\\Syntax Highlight";
static EnvDTE.DTE _dte;
static EnvDTE.SolutionEvents _SolutionEvents;
//static VsDebugger _Debugger;

/// <summary>
Expand Down Expand Up @@ -87,8 +84,7 @@ protected override async System.Threading.Tasks.Task InitializeAsync(Cancellatio
VSColorTheme.ThemeChanged += (args) => {
ThemeHelper.RefreshThemeCache();
};
_SolutionEvents = DTE.Events.SolutionEvents;
_SolutionEvents.Opened += () => {
SolutionEvents.OnAfterOpenSolution += (s, args) => {
Classifiers.SymbolMarkManager.Clear();
};
}
Expand Down
5 changes: 4 additions & 1 deletion Codist/Helpers/ThemeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.VisualStudio.Imaging.Interop;
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using GdiColor = System.Drawing.Color;
using WpfBrush = System.Windows.Media.SolidColorBrush;
using WpfColor = System.Windows.Media.Color;
Expand All @@ -14,6 +13,10 @@ namespace Codist
{
static class ThemeHelper
{
static ThemeHelper() {
RefreshThemeCache();
}

public static GdiColor ToolWindowBackgroundColor { get; private set; }
public static WpfColor TitleBackgroundColor { get; private set; }
public static WpfBrush ToolTipTextBrush { get; private set; }
Expand Down
4 changes: 0 additions & 4 deletions Codist/Margins/CommentMarginElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,6 @@ void Dispose(bool disposing) {
public void Dispose() {
Dispose(true);
}

void IDisposable.Dispose() {
throw new NotImplementedException();
}
#endregion
}
}
2 changes: 1 addition & 1 deletion Codist/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.8.0.2068")]
[assembly: AssemblyFileVersion("3.8.0.2081")]
20 changes: 5 additions & 15 deletions Codist/SmartBars/SmartBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public SmartBar(IWpfTextView view) {
View.Selection.SelectionChanged += ViewSelectionChanged;
View.Closed += ViewClosed;
ToolBar = new ToolBar { BorderThickness = new Thickness(1), BorderBrush = Brushes.Gray, Band = 1, IsOverflowOpen = false }.HideOverflow();
ToolBar.SetResourceReference(Control.BackgroundProperty, VsBrushes.CommandBarGradientBeginKey);
ToolBar2 = new ToolBar { BorderThickness = new Thickness(1), BorderBrush = Brushes.Gray, Band = 2, IsOverflowOpen = false }.HideOverflow();
ToolBar2.SetResourceReference(Control.BackgroundProperty, VsBrushes.CommandBarGradientBeginKey);
_ToolBarTray = new ToolBarTray {
ToolBars = { ToolBar, ToolBar2 },
IsLocked = true,
Expand All @@ -51,8 +53,6 @@ public SmartBar(IWpfTextView view) {
_CreateToolBarTimer = new Timer(CreateToolBar);
_ToolBarLayer.AddAdornment(AdornmentPositioningBehavior.ViewportRelative, null, null, _ToolBarTray, null);
_ToolBarTray.Visibility = Visibility.Hidden;
VSColorTheme.ThemeChanged += ThemeChanged;
LoadThemeColor();
}

protected IWpfTextView View { get; }
Expand All @@ -61,19 +61,10 @@ public SmartBar(IWpfTextView view) {
protected ToolBar ToolBar2 { get; }

#region Event handlers
void ThemeChanged(ThemeChangedEventArgs args) {
LoadThemeColor();
}
void ToolBarSizeChanged(object sender, SizeChangedEventArgs e) {
SetToolBarPosition();
_ToolBarTray.SizeChanged -= ToolBarSizeChanged;
}
void LoadThemeColor() {
var b = new SolidColorBrush(ThemeHelper.TitleBackgroundColor);
b.Freeze();
ToolBar.Background = b;
ToolBar2.Background = b;
}
void ViewMouseMove(object sender, MouseEventArgs e) {
if (_ToolBarTray.IsVisible == false) {
return;
Expand Down Expand Up @@ -132,7 +123,6 @@ void ViewClosed(object sender, EventArgs e) {
View.VisualElement.MouseMove -= ViewMouseMove;
//View.LayoutChanged -= ViewLayoutChanged;
View.Closed -= ViewClosed;
VSColorTheme.ThemeChanged -= ThemeChanged;
}

void ToolBarMouseEnter(object sender, EventArgs e) {
Expand Down Expand Up @@ -266,7 +256,7 @@ protected virtual void AddCommands() {
}

static void ExecuteAndFind(CommandContext ctx, string command) {
Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
ThreadHelper.ThrowIfNotOnUIThread();
if (ctx.RightClick) {
ctx.View.ExpandSelectionToLine(false);
}
Expand All @@ -284,7 +274,7 @@ static void ExecuteAndFind(CommandContext ctx, string command) {
}

protected void AddEditorCommand(ToolBar toolBar, int imageId, string command, string tooltip) {
Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
ThreadHelper.ThrowIfNotOnUIThread();
if (CodistPackage.DTE.Commands.Item(command).IsAvailable) {
AddCommand(toolBar, imageId, tooltip, (ctx) => {
TextEditorHelper.ExecuteEditorCommand(command);
Expand All @@ -293,7 +283,7 @@ protected void AddEditorCommand(ToolBar toolBar, int imageId, string command, st
}
}
protected void AddEditorCommand(ToolBar toolBar, int imageId, string command, string tooltip, string command2) {
Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
ThreadHelper.ThrowIfNotOnUIThread();
if (CodistPackage.DTE.Commands.Item(command).IsAvailable) {
AddCommand(toolBar, imageId, tooltip, (ctx) => {
TextEditorHelper.ExecuteEditorCommand(ctx.RightClick ? command2 : command);
Expand Down
2 changes: 1 addition & 1 deletion Codist/SmartBars/SmartBarTextViewCreationListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal sealed class SmartBarTextViewCreationListener : IWpfTextViewCreationLis
[Export(typeof(AdornmentLayerDefinition))]
[Name(nameof(SmartBar))]
[Order(After = PredefinedAdornmentLayers.Caret)]
AdornmentLayerDefinition editorAdornmentLayer;
AdornmentLayerDefinition _EditorAdornmentLayer;

#pragma warning restore 649, 169

Expand Down
2 changes: 1 addition & 1 deletion Codist/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="Codist.WMJ.c7b93d20-621f-4b21-9d28-d51157ef0b94" Version="3.8.0.2068" Language="en-US" Publisher="WMJ" />
<Identity Id="Codist.WMJ.c7b93d20-621f-4b21-9d28-d51157ef0b94" Version="3.8.0.2070" Language="en-US" Publisher="WMJ" />
<DisplayName>Codist</DisplayName>
<Description xml:space="preserve">A Roslyn-powered C# coding experience enhancer with advanced syntax highlight, Super Quick Info (code tooltip), Smart Bar, Code Structure Markers on scrollbar, comment tagger, and more.</Description>
<MoreInfo>https://github.com/wmjordan/Codist</MoreInfo>
Expand Down

0 comments on commit 77b927c

Please sign in to comment.