Skip to content

Commit

Permalink
Listening for windows popup event
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKert committed Jul 17, 2020
1 parent 2795501 commit 0304ebe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
31 changes: 31 additions & 0 deletions src/BuildVision/Core/BuildVisionPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using BuildVision.Common.Diagnostics;
using BuildVision.Common.Logging;
using BuildVision.Exports.Providers;
using BuildVision.Helpers;
using BuildVision.Tool;
using BuildVision.UI;
using BuildVision.UI.Settings.Models;
Expand All @@ -23,6 +24,7 @@
using Serilog;
using Task = System.Threading.Tasks.Task;
using ui = Microsoft.VisualStudio.VSConstants.UICONTEXT;
using Window = EnvDTE.Window;

namespace BuildVision.Core
{
Expand All @@ -45,6 +47,7 @@ public sealed class BuildVisionPackage : AsyncPackage
private DTE2 _dte2;
private CommandEvents _commandEvents;
private SolutionEvents _solutionEvents;
private WindowEvents _windowEvents;
private IVsSolutionBuildManager2 _solutionBuildManager;
private IVsSolutionBuildManager5 _solutionBuildManager4;
private IBuildInformationProvider _buildInformationProvider;
Expand All @@ -54,6 +57,7 @@ public sealed class BuildVisionPackage : AsyncPackage
private ISolutionProvider _solutionProvider;
private ServiceProvider _serviceProvider;
private ILogger _logger = LogManager.ForContext<BuildVisionPackage>();
private Window _activeProjectContext;

public static BuildVisionPackage BuildVisionPackageInstance { get; set; }

Expand Down Expand Up @@ -129,12 +133,39 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
_solutionEvents.AfterClosing += SolutionEvents_AfterClosing;
_solutionEvents.Opened += SolutionEvents_Opened;

_windowEvents = _dte.Events.WindowEvents;
_windowEvents.WindowActivated += WindowEvents_WindowActivated;

if (_dte2.Solution?.IsOpen == true)
{
SolutionEvents_Opened();
}
}


private void WindowEvents_WindowActivated(Window gotFocus, Window lostFocus)
{
if (gotFocus == null)
return;

switch (gotFocus.Type)
{
case vsWindowType.vsWindowTypeSolutionExplorer:
_activeProjectContext = gotFocus;
break;

case vsWindowType.vsWindowTypeDocument:
case vsWindowType.vsWindowTypeDesigner:
case vsWindowType.vsWindowTypeCodeWindow:
if (gotFocus.Project != null && !gotFocus.Project.IsHidden())
_activeProjectContext = gotFocus;
break;

default:
return;
}
}

private void SolutionEvents_Opened()
{
ThreadHelper.ThrowIfNotOnUIThread();
Expand Down
18 changes: 6 additions & 12 deletions src/BuildVision/Services/WindowStateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class WindowStateService : IWindowStateService
private IVsWindowFrame _windowFrame;
private Window _window;
private Window _currentActiveWindow;
private Document _currentActiveDocument;
private readonly IServiceProvider _serviceProvider;

[ImportingConstructor]
Expand Down Expand Up @@ -76,16 +75,13 @@ private void MinimizeToolWindow()
_window.AutoHides = true;

var win = _currentActiveWindow;
if (win != null && win != _window)
if (_dte.ActiveWindow == _window)
{
win.Activate();
return;
}

var doc = _currentActiveDocument;
if (doc != null)
{
doc.Activate();
if (win != null && win != _window)
{
win.Activate();
return;
}
}
}

Expand All @@ -112,12 +108,10 @@ private void ApplyToolWindowStateAction(WindowState windowState)
break;
case WindowState.Show:
_currentActiveWindow = _dte.ActiveWindow;
_currentActiveDocument = _dte.ActiveDocument;
_windowFrame.Show();
break;
case WindowState.ShowNoActivate:
_currentActiveWindow = _dte.ActiveWindow;
_currentActiveDocument = _dte.ActiveDocument;
_windowFrame.ShowNoActivate();
break;
case WindowState.Hide:
Expand Down

0 comments on commit 0304ebe

Please sign in to comment.