Skip to content

Commit

Permalink
Using outoload behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKert committed Apr 6, 2019
1 parent c5cc157 commit b0166af
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/BuildVision/Core/BuildVisionPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@
using Microsoft.VisualStudio.Shell.Interop;
using Task = System.Threading.Tasks.Task;
using Window = EnvDTE.Window;
using ui = Microsoft.VisualStudio.VSConstants.UICONTEXT;
using System.Threading.Tasks;

namespace BuildVision.Core
{
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
//[ProvideAutoLoad(UIContextGuids80.SolutionExists, flags: PackageAutoLoadFlags.BackgroundLoad)] // This will lead to a warning on startup
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionOpening_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(_loadContext, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideUIContextRule(_loadContext,
name: "Auto load",
expression: "HasDot & FullyLoaded & (SingleProject | MultipleProjects)",
termNames: new[] { "HasDot", "FullyLoaded", "SingleProject", "MultipleProjects" },
termValues: new[] { "HierSingleSelectionName:\\.(.+)$", ui.SolutionExistsAndFullyLoaded_string, ui.SolutionHasSingleProject_string, ui.SolutionHasMultipleProjects_string })]
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideToolWindow(typeof(BuildVisionPane))]
[Guid(PackageGuids.GuidBuildVisionPackageString)]
Expand All @@ -42,6 +48,8 @@ namespace BuildVision.Core
[ProvideOptionPage(typeof(ProjectItemSettingsDialogPage), "BuildVision", "Project Item", 0, 0, true)]
public sealed class BuildVisionPackage : AsyncPackage
{
private const string _loadContext = "dec9f70a-b8b1-4050-ae96-08f89c6eccd1";

private DTE _dte;
private DTE2 _dte2;
private CommandEvents _commandEvents;
Expand Down Expand Up @@ -108,10 +116,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
SolutionEvents_Opened();
}

var toolWindow = GetWindowPane(typeof(BuildVisionPane));
var windowStateService = await GetServiceAsync(typeof(IWindowStateService)) as IWindowStateService;
Assumes.Present(windowStateService);
windowStateService.Initialize(toolWindow);
InitToolWindow(this);
}

private void SolutionEvents_Opened()
Expand Down Expand Up @@ -173,9 +178,15 @@ private void CommandEvents_AfterExecute(string guid, int id, object customIn, ob
}
}

private ToolWindowPane GetWindowPane(Type windowType)
public static void InitToolWindow(AsyncPackage package)
{
return FindToolWindow(windowType, 0, false) ?? FindToolWindow(windowType, 0, true);
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);
});
}
}
}

0 comments on commit b0166af

Please sign in to comment.