From afb62ac9816eded1374c00e0261ce41ff03083cd Mon Sep 17 00:00:00 2001 From: Stefan Kert Date: Sat, 6 Apr 2019 14:21:06 +0200 Subject: [PATCH] Seems like toolwindow is working properly --- src/BuildVision/Core/BuildVisionPackage.cs | 35 ++++++++++++------- .../Services/WindowStateService.cs | 11 +++++- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/BuildVision/Core/BuildVisionPackage.cs b/src/BuildVision/Core/BuildVisionPackage.cs index e13e2003..cbd0e5cc 100644 --- a/src/BuildVision/Core/BuildVisionPackage.cs +++ b/src/BuildVision/Core/BuildVisionPackage.cs @@ -29,9 +29,11 @@ namespace BuildVision.Core { [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] - [ProvideAutoLoad(UIContextGuids80.SolutionExists)] + [ProvideAutoLoad(ui.SolutionOpening_string, flags: PackageAutoLoadFlags.BackgroundLoad)] + [ProvideToolWindow(typeof(BuildVisionPane))] + [ProvideToolWindow(typeof(BuildVisionPane), Transient = true, MultiInstances = false)] + [ProvideToolWindowVisibility(typeof(BuildVisionPane), ui.SolutionOpening_string)] [ProvideMenuResource("Menus.ctmenu", 1)] - [ProvideToolWindow(typeof(BuildVisionPane))] [Guid(PackageGuids.GuidBuildVisionPackageString)] [ProvideBindingPath] [ProvideBindingPath(SubPath = "Lib")] @@ -41,7 +43,7 @@ namespace BuildVision.Core [ProvideOptionPage(typeof(GridSettingsDialogPage), "BuildVision", "Projects Grid", 0, 0, true)] [ProvideOptionPage(typeof(BuildMessagesSettingsDialogPage), "BuildVision", "Build Messages", 0, 0, true)] [ProvideOptionPage(typeof(ProjectItemSettingsDialogPage), "BuildVision", "Project Item", 0, 0, true)] - public sealed class BuildVisionPackage : AsyncPackage + public sealed class BuildVisionPackage : AsyncPackage, IVsPackageDynamicToolOwnerEx { private const string _loadContext = "dec9f70a-b8b1-4050-ae96-08f89c6eccd1"; @@ -59,6 +61,8 @@ public sealed class BuildVisionPackage : AsyncPackage private ISolutionProvider _solutionProvider; private Window _activeProjectContext; + public static ToolWindowPane ToolWindowPane { get; set; } + public ControlSettings ControlSettings { get; set; } @@ -113,7 +117,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke SolutionEvents_Opened(); } - InitToolWindow(this); + //InitToolWindow(this); } private void SolutionEvents_Opened() @@ -175,15 +179,22 @@ private void CommandEvents_AfterExecute(string guid, int id, object customIn, ob } } - public static void InitToolWindow(AsyncPackage package) + public int QueryShowTool(ref Guid rguidPersistenceSlot, uint dwId, out int pfShowTool) { - package.JoinableTaskFactory.RunAsync(async () => - { - var window = package.FindToolWindow(typeof(BuildVisionPane), 0, false) ?? package.FindToolWindow(typeof(BuildVisionPane), 0, true); - var windowStateService = await package.GetServiceAsync(typeof(IWindowStateService)) as IWindowStateService; - Assumes.Present(windowStateService); - windowStateService.Initialize(window); - }); + ToolWindowPane = FindToolWindow(typeof(BuildVisionPane), 0, false) ?? FindToolWindow(typeof(BuildVisionPane), 0, true); + pfShowTool = 1; + return 0; } + + //public static void InitToolWindow(AsyncPackage package) + //{ + // package.JoinableTaskFactory.RunAsync(async () => + // { + // var window = package.FindToolWindow(typeof(BuildVisionPane), 0, false) ?? package.FindToolWindow(typeof(BuildVisionPane), 0, true); + // var windowStateService = await package.GetServiceAsync(typeof(IWindowStateService)) as IWindowStateService; + // Assumes.Present(windowStateService); + // windowStateService.Initialize(window); + // }); + //} } } diff --git a/src/BuildVision/Services/WindowStateService.cs b/src/BuildVision/Services/WindowStateService.cs index a3e99372..301cbeaa 100644 --- a/src/BuildVision/Services/WindowStateService.cs +++ b/src/BuildVision/Services/WindowStateService.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel.Composition; +using BuildVision.Core; using BuildVision.UI.Settings.Models.ToolWindow; using EnvDTE; using Microsoft; @@ -11,7 +12,7 @@ namespace BuildVision.Tool.Building { [Export(typeof(IWindowStateService))] - [PartCreationPolicy(CreationPolicy.Shared)] + [PartCreationPolicy(CreationPolicy.NonShared)] public class WindowStateService : IWindowStateService { private DTE _dte; @@ -127,6 +128,8 @@ private void ApplyToolWindowStateAction(WindowState windowState) public void Initialize(ToolWindowPane toolWindowPane) { + if (toolWindowPane == null) + return; if (_window == null || _windowFrame == null) { ThreadHelper.ThrowIfNotOnUIThread(); @@ -141,6 +144,12 @@ public void Initialize(ToolWindowPane toolWindowPane) public void ApplyToolWindowStateAction(WindowStateAction windowStateAction) { + if(BuildVisionPackage.ToolWindowPane == null) + { + return; + } + Initialize(BuildVisionPackage.ToolWindowPane); + ApplyToolWindowStateAction(windowStateAction.State); } }