未验证 提交 7a977ac1 编写于 作者: D David Kean 提交者: GitHub

Merge pull request #26230 from davkean/OutputPane

Avoid stealing focus from the active output window pane
......@@ -49,26 +49,64 @@ private IVsOutputWindowPane OutputPane
{
var outputWindow = (IVsOutputWindow)_serviceProvider.GetService(typeof(SVsOutputWindow));
// Try to get the workspace pane if it has already been registered
var workspacePaneGuid = s_workspacePaneGuid;
var hr = outputWindow.GetPane(ref workspacePaneGuid, out _doNotAccessDirectlyOutputPane);
// Output Window panes have two states; initialized and active. The former is used to indicate that the pane
// can be made active ("selected") by the user, the latter indicates that the pane is currently active.
// There's no way to only initialize a pane without also making it active so we remember the last active pane
// and reactivate it after we've created ourselves to avoid stealing focus away from it.
var lastActivePane = GetActivePane(outputWindow);
// If the workspace pane has not been registered before, create it
if (_doNotAccessDirectlyOutputPane == null || hr != VSConstants.S_OK)
_doNotAccessDirectlyOutputPane = CreateOutputPane(outputWindow);
if (lastActivePane != Guid.Empty)
{
if (ErrorHandler.Failed(outputWindow.CreatePane(ref workspacePaneGuid, ServicesVSResources.IntelliSense, fInitVisible: 1, fClearWithSolution: 1)) ||
ErrorHandler.Failed(outputWindow.GetPane(ref workspacePaneGuid, out _doNotAccessDirectlyOutputPane)))
{
return null;
}
// Must activate the workspace pane for it to show up in the output window
_doNotAccessDirectlyOutputPane.Activate();
ActivatePane(outputWindow, lastActivePane);
}
}
return _doNotAccessDirectlyOutputPane;
}
}
private IVsOutputWindowPane CreateOutputPane(IVsOutputWindow outputWindow)
{
AssertIsForeground();
// Try to get the workspace pane if it has already been registered
var workspacePaneGuid = s_workspacePaneGuid;
// If the pane has already been created, CreatePane returns it
if (ErrorHandler.Succeeded(outputWindow.CreatePane(ref workspacePaneGuid, ServicesVSResources.IntelliSense, fInitVisible: 1, fClearWithSolution: 1)) &&
ErrorHandler.Succeeded(outputWindow.GetPane(ref workspacePaneGuid, out var pane)))
{
return pane;
}
return null;
}
private Guid GetActivePane(IVsOutputWindow outputWindow)
{
AssertIsForeground();
if (outputWindow is IVsOutputWindow2 outputWindow2)
{
if (ErrorHandler.Succeeded(outputWindow2.GetActivePaneGUID(out var activePaneGuid)))
{
return activePaneGuid;
}
}
return Guid.Empty;
}
private void ActivatePane(IVsOutputWindow outputWindow, Guid paneGuid)
{
AssertIsForeground();
if (ErrorHandler.Succeeded(outputWindow.GetPane(ref paneGuid, out var pane)))
{
pane.Activate();
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册