From 77b927c897c3aac41e5cebeebc45b7ff13db1d49 Mon Sep 17 00:00:00 2001 From: WMJ Date: Tue, 18 Sep 2018 16:26:53 +0800 Subject: [PATCH] ! Adopted AsyncPackage pattern --- Codist/CodistPackage.cs | 12 ++++------- Codist/Helpers/ThemeHelper.cs | 5 ++++- Codist/Margins/CommentMarginElement.cs | 4 ---- Codist/Properties/AssemblyInfo.cs | 2 +- Codist/SmartBars/SmartBar.cs | 20 +++++-------------- .../SmartBarTextViewCreationListener.cs | 2 +- Codist/source.extension.vsixmanifest | 2 +- 7 files changed, 16 insertions(+), 31 deletions(-) diff --git a/Codist/CodistPackage.cs b/Codist/CodistPackage.cs index ef1ac676..460ebd0d 100644 --- a/Codist/CodistPackage.cs +++ b/Codist/CodistPackage.cs @@ -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 { @@ -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 { /// CodistPackage GUID string. @@ -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; /// @@ -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(); }; } diff --git a/Codist/Helpers/ThemeHelper.cs b/Codist/Helpers/ThemeHelper.cs index c3f3274b..ef66025b 100644 --- a/Codist/Helpers/ThemeHelper.cs +++ b/Codist/Helpers/ThemeHelper.cs @@ -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; @@ -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; } diff --git a/Codist/Margins/CommentMarginElement.cs b/Codist/Margins/CommentMarginElement.cs index dd1cd8e3..cac13de6 100644 --- a/Codist/Margins/CommentMarginElement.cs +++ b/Codist/Margins/CommentMarginElement.cs @@ -278,10 +278,6 @@ void Dispose(bool disposing) { public void Dispose() { Dispose(true); } - - void IDisposable.Dispose() { - throw new NotImplementedException(); - } #endregion } } diff --git a/Codist/Properties/AssemblyInfo.cs b/Codist/Properties/AssemblyInfo.cs index 5797b721..8efeec9d 100644 --- a/Codist/Properties/AssemblyInfo.cs +++ b/Codist/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Codist/SmartBars/SmartBar.cs b/Codist/SmartBars/SmartBar.cs index d7318c54..6d999c74 100644 --- a/Codist/SmartBars/SmartBar.cs +++ b/Codist/SmartBars/SmartBar.cs @@ -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, @@ -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; } @@ -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; @@ -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) { @@ -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); } @@ -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); @@ -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); diff --git a/Codist/SmartBars/SmartBarTextViewCreationListener.cs b/Codist/SmartBars/SmartBarTextViewCreationListener.cs index 5013bc4e..36b1d872 100644 --- a/Codist/SmartBars/SmartBarTextViewCreationListener.cs +++ b/Codist/SmartBars/SmartBarTextViewCreationListener.cs @@ -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 diff --git a/Codist/source.extension.vsixmanifest b/Codist/source.extension.vsixmanifest index 2c2d1fab..367bd655 100644 --- a/Codist/source.extension.vsixmanifest +++ b/Codist/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + Codist 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. https://github.com/wmjordan/Codist