How to cancel IVsWindowFrame close via VSPackage
毅磊 朱
1
Reputation point
I saw a workaround about how to cancel a ToolWindowPane close operation via a VSPackage, but ToolWindowPane is still closed when canceling the close.
Create a windowpane:
IVsWindowFrame windowframe;
ThreadHelper.ThrowIfNotOnUIThread();
var uiShell = (IVsUIShell) Package.GetGlobalService(typeof(SVsUIShell));
var result = uiShell.CreateToolWindow((uint) __VSCREATETOOLWIN.CTW_fMultiInstance,
(uint) id, editorPane.Control, ref guidNull,
ref toolWindowPersistenceGuid,
ref guidNull, null, editorPane.Caption, position, out windowFrame);
ErrorHandler.ThrowOnFailure(result);
windowFrame.SetProperty((int) __VSFPROPID.VSFPROPID_FrameMode, VSFRAMEMODE.VSFM_MdiChild);
ToolWindowListener implement IVsWindowFrameNotify and IVsWindowFrameNotify3:
Advise Event:
private void SubscribeForEvents()
{
if (WindowPane == null)
throw new InvalidOperationException();
ThreadHelper.ThrowIfNotOnUIThread();
// ReSharper disable once SuspiciousTypeConversion.Global
var frame = WindowPane.Frame as IVsWindowFrame2;
if (frame == null)
throw new InvalidOperationException();
if (_cookie != 0U)
throw new InvalidOperationException();
ErrorHandler.ThrowOnFailure(frame.Advise(this, out _cookie));
}
On Close:
public int OnClose(ref uint pgrfSaveOptions)
{
if (MessageBox.Show("Closed?", "", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
return VSConstants.S_OK;
}
else
{
return VSConstants.E_ABORT;
}
}
What do i miss in code?