提交 9ed79e9b 编写于 作者: T Ty Overby

Merge pull request #9450 from TyOverby/hidepane-fix-future-stab

Revert "Merge pull request #8906 from amcasey/HidePane2"
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.VisualStudio.Imaging.Interop;
using Microsoft.VisualStudio.Shell.Interop;
namespace Microsoft.VisualStudio.InteractiveWindow.Shell
{
/// <summary>
/// Extends <see cref="IVsInteractiveWindow"/> with additional functionality.
/// </summary>
public interface IVsInteractiveWindow2 : IVsInteractiveWindow
{
/// <summary>
/// Gets the <see cref="IVsWindowFrame"/> associated with the <see cref="IVsInteractiveWindow2"/>.
/// </summary>
object WindowFrame { get; }
/// <summary>
/// Gets or sets the ImageMoniker for the icon for this tool window. This property
/// should be used instead of BitmapResource and BitmapIndex to allow for DPI-aware
/// icons.
/// </summary>
ImageMoniker BitmapImageMoniker { get; set; }
}
}
Microsoft.VisualStudio.InteractiveWindow.Shell.IVsInteractiveWindow2
Microsoft.VisualStudio.InteractiveWindow.Shell.IVsInteractiveWindow2.WindowFrame.get -> object
Microsoft.VisualStudio.InteractiveWindow.Shell.IVsInteractiveWindow2.BitmapImageMoniker.get -> Microsoft.VisualStudio.Imaging.Interop.ImageMoniker
Microsoft.VisualStudio.InteractiveWindow.Shell.IVsInteractiveWindow2.BitmapImageMoniker.set -> void
\ No newline at end of file
......@@ -52,9 +52,6 @@
<Reference Include="Microsoft.VisualStudio.Editor, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>false</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.VisualStudio.Language.Intellisense, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>false</Private>
</Reference>
......@@ -127,8 +124,6 @@
<Compile Include="AssemblyRedirects.cs" />
<Compile Include="CommandIds.cs" />
<Compile Include="Guids.cs" />
<Compile Include="IVsInteractiveWindow2.cs" />
<Compile Include="VsInteractiveWindowPane.cs" />
<Compile Include="VsInteractiveWindowEditorFactoryService.cs" />
<Compile Include="InteractiveWindowPackage.cs" />
<Compile Include="IVsInteractiveWindow.cs" />
......
......@@ -8,9 +8,12 @@
using System.Windows;
using System.Windows.Input;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Imaging.Interop;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Utilities;
namespace Microsoft.VisualStudio.InteractiveWindow.Shell
......@@ -27,56 +30,165 @@ namespace Microsoft.VisualStudio.InteractiveWindow.Shell
/// on the interactive window.
/// </summary>
[Guid(Guids.InteractiveToolWindowIdString)]
internal sealed class VsInteractiveWindow : IOleCommandTarget, IVsInteractiveWindow2, IDisposable
internal sealed class VsInteractiveWindow : ToolWindowPane, IOleCommandTarget, IVsInteractiveWindow
{
private readonly VsInteractiveWindowPane _windowPane;
// Keep in sync with Microsoft.VisualStudio.Editor.Implementation.EnableFindOptionDefinition.OptionName.
private const string EnableFindOptionName = "Enable Autonomous Find";
private readonly IComponentModel _componentModel;
private readonly IVsEditorAdaptersFactoryService _editorAdapters;
private IInteractiveWindow _window;
private IVsFindTarget _findTarget;
private IOleCommandTarget _commandTarget;
private IInteractiveEvaluator _evaluator;
private IWpfTextViewHost _textViewHost;
internal VsInteractiveWindow(IComponentModel model, Guid providerId, int instanceId, string title, IInteractiveEvaluator evaluator, __VSCREATETOOLWIN creationFlags)
{
_windowPane = new VsInteractiveWindowPane(model, providerId, instanceId, title, evaluator, creationFlags);
_componentModel = model;
this.Caption = title;
_editorAdapters = _componentModel.GetService<IVsEditorAdaptersFactoryService>();
_evaluator = evaluator;
// The following calls this.OnCreate:
Guid clsId = this.ToolClsid;
Guid empty = Guid.Empty;
Guid typeId = providerId;
IVsWindowFrame frame;
var vsShell = (IVsUIShell)ServiceProvider.GlobalProvider.GetService(typeof(SVsUIShell));
// we don't pass __VSCREATETOOLWIN.CTW_fMultiInstance because multi instance panes are
// destroyed when closed. We are really multi instance but we don't want to be closed.
ErrorHandler.ThrowOnFailure(
vsShell.CreateToolWindow(
(uint)(__VSCREATETOOLWIN.CTW_fInitNew | __VSCREATETOOLWIN.CTW_fToolbarHost | creationFlags),
(uint)instanceId,
this.GetIVsWindowPane(),
ref clsId,
ref typeId,
ref empty,
null,
title,
null,
out frame
)
);
var guid = GetType().GUID;
ErrorHandler.ThrowOnFailure(frame.SetGuidProperty((int)__VSFPROPID.VSFPROPID_CmdUIGuid, ref guid));
this.Frame = frame;
}
void IDisposable.Dispose() => _windowPane.Dispose();
public void SetLanguage(Guid languageServiceGuid, IContentType contentType)
{
_window.SetLanguage(languageServiceGuid, contentType);
}
int IOleCommandTarget.Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) =>
_windowPane.CommandTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
public IInteractiveWindow InteractiveWindow { get { return _window; } }
int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) =>
_windowPane.CommandTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
#region ToolWindowPane overrides
void IVsInteractiveWindow.SetLanguage(Guid languageServiceGuid, IContentType contentType) =>
InteractiveWindow.SetLanguage(languageServiceGuid, contentType);
protected override void OnCreate()
{
_window = _componentModel.GetService<IInteractiveWindowFactoryService>().CreateWindow(_evaluator);
_window.SubmissionBufferAdded += SubmissionBufferAdded;
_textViewHost = _window.GetTextViewHost();
var textView = _textViewHost.TextView;
textView.Options.SetOptionValue(EnableFindOptionName, true);
var viewAdapter = _editorAdapters.GetViewAdapter(textView);
_findTarget = viewAdapter as IVsFindTarget;
_commandTarget = viewAdapter as IOleCommandTarget;
}
void IVsInteractiveWindow.Show(bool focus)
private void SubmissionBufferAdded(object sender, SubmissionBufferAddedEventArgs e)
{
var windowFrame = (IVsWindowFrame)WindowFrame;
ErrorHandler.ThrowOnFailure(focus ? windowFrame.Show() : windowFrame.ShowNoActivate());
GetToolbarHost().ForceUpdateUI();
}
if (focus)
protected override void OnClose()
{
_window.Close();
base.OnClose();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
IInputElement input = InteractiveWindow.TextView as IInputElement;
if (input != null)
if (_window != null)
{
Keyboard.Focus(input);
_window.Dispose();
}
}
}
public IInteractiveWindow InteractiveWindow => _windowPane.InteractiveWindow;
/// <summary>
/// This property returns the control that should be hosted in the Tool Window. It can be
/// either a FrameworkElement (for easy creation of tool windows hosting WPF content), or it
/// can be an object implementing one of the IVsUIWPFElement or IVsUIWin32Element
/// interfaces.
/// </summary>
public override object Content
{
get { return _textViewHost; }
set { }
}
public override void OnToolWindowCreated()
{
Guid commandUiGuid = VSConstants.GUID_TextEditorFactory;
((IVsWindowFrame)Frame).SetGuidProperty((int)__VSFPROPID.VSFPROPID_InheritKeyBindings, ref commandUiGuid);
base.OnToolWindowCreated();
// add our toolbar which is defined in our VSCT file
var toolbarHost = GetToolbarHost();
Guid guidInteractiveCmdSet = Guids.InteractiveCommandSetId;
ErrorHandler.ThrowOnFailure(toolbarHost.AddToolbar(VSTWT_LOCATION.VSTWT_TOP, ref guidInteractiveCmdSet, (uint)MenuIds.InteractiveWindowToolbar));
}
#endregion
public object WindowFrame => _windowPane.Frame;
#region Window IOleCommandTarget
ImageMoniker IVsInteractiveWindow2.BitmapImageMoniker
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
{
get
{
return _windowPane.BitmapImageMoniker;
}
return _commandTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
}
set
public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
{
return _commandTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
}
#endregion
#region IVsInteractiveWindow
public void Show(bool focus)
{
var windowFrame = (IVsWindowFrame)Frame;
ErrorHandler.ThrowOnFailure(focus ? windowFrame.Show() : windowFrame.ShowNoActivate());
if (focus)
{
_windowPane.BitmapImageMoniker = value;
IInputElement input = _window.TextView as IInputElement;
if (input != null)
{
Keyboard.Focus(input);
}
}
}
private IVsToolWindowToolbarHost GetToolbarHost()
{
var frame = (IVsWindowFrame)Frame;
object result;
ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_ToolbarHost, out result));
return (IVsToolWindowToolbarHost)result;
}
#endregion
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
namespace Microsoft.VisualStudio.InteractiveWindow.Shell
{
/// <summary>
/// The backing type for <see cref="VsInteractiveWindow"/>. It subclasses <see cref="ToolWindowPane"/> so
/// that the instance handed out through the public API does not.
/// </summary>
internal sealed class VsInteractiveWindowPane : ToolWindowPane
{
// Keep in sync with Microsoft.VisualStudio.Editor.Implementation.EnableFindOptionDefinition.OptionName.
private const string EnableFindOptionName = "Enable Autonomous Find";
private readonly IComponentModel _componentModel;
private readonly IVsEditorAdaptersFactoryService _editorAdapters;
private readonly IInteractiveEvaluator _evaluator;
private IInteractiveWindow _window;
private IVsFindTarget _findTarget;
private IOleCommandTarget _commandTarget;
private IWpfTextViewHost _textViewHost;
internal VsInteractiveWindowPane(IComponentModel model, Guid providerId, int instanceId, string title, IInteractiveEvaluator evaluator, __VSCREATETOOLWIN creationFlags)
{
_componentModel = model;
this.Caption = title;
_editorAdapters = _componentModel.GetService<IVsEditorAdaptersFactoryService>();
_evaluator = evaluator;
// The following calls this.OnCreate:
Guid clsId = this.ToolClsid;
Guid empty = Guid.Empty;
Guid typeId = providerId;
IVsWindowFrame frame;
var vsShell = (IVsUIShell)ServiceProvider.GlobalProvider.GetService(typeof(SVsUIShell));
// we don't pass __VSCREATETOOLWIN.CTW_fMultiInstance because multi instance panes are
// destroyed when closed. We are really multi instance but we don't want to be closed.
ErrorHandler.ThrowOnFailure(
vsShell.CreateToolWindow(
(uint)(__VSCREATETOOLWIN.CTW_fInitNew | __VSCREATETOOLWIN.CTW_fToolbarHost | creationFlags),
(uint)instanceId,
this.GetIVsWindowPane(),
ref clsId,
ref typeId,
ref empty,
null,
title,
null,
out frame));
var guid = GetType().GUID;
ErrorHandler.ThrowOnFailure(frame.SetGuidProperty((int)__VSFPROPID.VSFPROPID_CmdUIGuid, ref guid));
this.Frame = frame;
}
internal IInteractiveWindow InteractiveWindow => _window;
internal IOleCommandTarget CommandTarget => _commandTarget;
#region ToolWindowPane overrides
protected override void OnCreate()
{
_window = _componentModel.GetService<IInteractiveWindowFactoryService>().CreateWindow(_evaluator);
_window.SubmissionBufferAdded += SubmissionBufferAdded;
_textViewHost = _window.GetTextViewHost();
var textView = _textViewHost.TextView;
textView.Options.SetOptionValue(EnableFindOptionName, true);
var viewAdapter = _editorAdapters.GetViewAdapter(textView);
_findTarget = viewAdapter as IVsFindTarget;
_commandTarget = viewAdapter as IOleCommandTarget;
}
private void SubmissionBufferAdded(object sender, SubmissionBufferAddedEventArgs e)
{
GetToolbarHost().ForceUpdateUI();
}
protected override void OnClose()
{
_window.Close();
base.OnClose();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (_window != null)
{
_window.Dispose();
}
}
}
/// <summary>
/// This property returns the control that should be hosted in the Tool Window. It can be
/// either a FrameworkElement (for easy creation of tool windows hosting WPF content), or it
/// can be an object implementing one of the IVsUIWPFElement or IVsUIWin32Element
/// interfaces.
/// </summary>
public override object Content
{
get { return _textViewHost; }
set { }
}
public override void OnToolWindowCreated()
{
Guid commandUiGuid = VSConstants.GUID_TextEditorFactory;
((IVsWindowFrame)Frame).SetGuidProperty((int)__VSFPROPID.VSFPROPID_InheritKeyBindings, ref commandUiGuid);
base.OnToolWindowCreated();
// add our toolbar which is defined in our VSCT file
var toolbarHost = GetToolbarHost();
Guid guidInteractiveCmdSet = Guids.InteractiveCommandSetId;
ErrorHandler.ThrowOnFailure(toolbarHost.AddToolbar(VSTWT_LOCATION.VSTWT_TOP, ref guidInteractiveCmdSet, (uint)MenuIds.InteractiveWindowToolbar));
}
#endregion
private IVsToolWindowToolbarHost GetToolbarHost()
{
var frame = (IVsWindowFrame)Frame;
object result;
ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_ToolbarHost, out result));
return (IVsToolWindowToolbarHost)result;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册