From 3e27df8da017a462136384d5835b66845225002d Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Tue, 22 Oct 2019 12:24:41 +0200 Subject: [PATCH] - Added partial support for loading the Nifty Perforce extension in the background (from jgvincen ) - Add reference to Microsoft.VisualStudio.SDK.EmbedInteropTypes to fix the assemblies being referenced instead of linked - Update VSSDK BuildTools reference version - Bump to 2.0.9 --- NiftyPerforce/NiftyPerforce.csproj | 3 ++- NiftyPerforce/NiftyPerforcePackage.cs | 30 ++++++++++++--------- NiftyPerforce/source.extension.vsixmanifest | 2 +- Shared/AuroraCore.csproj | 1 + 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/NiftyPerforce/NiftyPerforce.csproj b/NiftyPerforce/NiftyPerforce.csproj index 6c32f1c..4258d69 100644 --- a/NiftyPerforce/NiftyPerforce.csproj +++ b/NiftyPerforce/NiftyPerforce.csproj @@ -141,7 +141,8 @@ - + + diff --git a/NiftyPerforce/NiftyPerforcePackage.cs b/NiftyPerforce/NiftyPerforcePackage.cs index abaa984..968d5f4 100644 --- a/NiftyPerforce/NiftyPerforcePackage.cs +++ b/NiftyPerforce/NiftyPerforcePackage.cs @@ -20,6 +20,9 @@ using Aurora; using System.Windows.Forms; +using System.Threading; +using Task = System.Threading.Tasks.Task; + namespace NiftyPerforce { /// @@ -39,12 +42,12 @@ namespace NiftyPerforce /// To get loaded into VS, the package must be referred by <Asset Type="Microsoft.VisualStudio.VsPackage" ...> in .vsixmanifest file. /// /// - [PackageRegistration(UseManagedResourcesOnly = true)] + [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About - [ProvideAutoLoad(Microsoft.VisualStudio.VSConstants.UICONTEXT.NoSolution_string)] // Note: the package must be loaded on startup to create and bind commands + [ProvideAutoLoad(Microsoft.VisualStudio.VSConstants.UICONTEXT.NoSolution_string, PackageAutoLoadFlags.BackgroundLoad)] // Note: the package must be loaded on startup to create and bind commands [Guid(NiftyPerforcePackage.PackageGuidString)] [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")] - public sealed class NiftyPerforcePackage : Package + public sealed class NiftyPerforcePackage : AsyncPackage { /// /// Package GUID string. @@ -69,19 +72,22 @@ public NiftyPerforcePackage() /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// - protected override void Initialize() + protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress progress) { - base.Initialize(); + await base.InitializeAsync(cancellationToken, progress); + + // Every plugin needs a command bar. + DTE2 application = await base.GetServiceAsync(typeof(DTE)).ConfigureAwait(false) as DTE2; + IVsProfferCommands3 profferCommands3 = await base.GetServiceAsync(typeof(SVsProfferCommands)) as IVsProfferCommands3; + OleMenuCommandService oleMenuCommandService = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; + + // Switches to the UI thread in order to consume some services used in command initialization + await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); // Load up the options from file. string optionsFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "NiftyPerforce.xml"); Config options = Config.Load(optionsFileName); - // Every plugin needs a command bar. - DTE2 application = GetGlobalService(typeof(DTE)) as DTE2; - IVsProfferCommands3 profferCommands3 = base.GetService(typeof(SVsProfferCommands)) as IVsProfferCommands3; - OleMenuCommandService oleMenuCommandService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; - ImageList icons = new ImageList(); icons.Images.AddStrip(Properties.Resources.Icons); m_plugin = new Plugin(application, profferCommands3, icons, oleMenuCommandService, "NiftyPerforce", "Aurora.NiftyPerforce.Connect", options); @@ -176,7 +182,7 @@ protected override void Initialize() /// private void Cleanup() { - IVsProfferCommands3 profferCommands3 = base.GetService(typeof(SVsProfferCommands)) as IVsProfferCommands3; + IVsProfferCommands3 profferCommands3 = base.GetServiceAsync(typeof(SVsProfferCommands)) as IVsProfferCommands3; RemoveCommandBar("NiftyPerforceCmdBar", profferCommands3); RemoveCommandBar("NiftyPerforce", profferCommands3); @@ -261,7 +267,7 @@ private void RemoveCommand(string name, IVsProfferCommands3 profferCommands3) } } } - + private void RemoveCommandBar(string name, IVsProfferCommands3 profferCommands3) { // Remove a command bar and contained controls diff --git a/NiftyPerforce/source.extension.vsixmanifest b/NiftyPerforce/source.extension.vsixmanifest index 0c7c645..be5ffa0 100644 --- a/NiftyPerforce/source.extension.vsixmanifest +++ b/NiftyPerforce/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + NiftyPerforce Simple Perforce integration for Visual Studio https://github.com/belkiss/niftyplugins diff --git a/Shared/AuroraCore.csproj b/Shared/AuroraCore.csproj index dfa4e04..257419d 100644 --- a/Shared/AuroraCore.csproj +++ b/Shared/AuroraCore.csproj @@ -62,6 +62,7 @@ +