/// <summary> /// This function is called when the user clicks the menu item that shows the /// tool window. See the Initialize method to see how the menu item is associated to /// this function using the OleMenuCommandService service and the MenuCommand class. /// </summary> private void ShowMergeToolWindow(object sender, EventArgs e) { IVsUIShell4 uiShell = GetService(typeof(SVsUIShell)) as IVsUIShell4; // Get the instance number 0 of this tool window. This window is single instance so this instance // is actually the only one. // The last flag is set to true so that if the tool window does not exists it will be created. ToolWindowPane window = this.FindToolWindow(typeof(vMergeMergeToolWindow), 0, true); if ((null == window) || (null == window.Frame)) { throw new NotSupportedException(Resources.CanNotCreateWindow); } IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); SetMergeToolWindowIsVisible(); var windowEvents = new ToolWindowEvents(windowFrame); windowEvents.OnClose = (options) => { MergeToolWindowIsVisible = false; if (_mergeToolWindowVisibilityChanged != null) { _mergeToolWindowVisibilityChanged(this, new EventArgs()); } windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, null); windowEvents.Dispose(); return(VSConstants.S_OK); }; windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, windowEvents); vMergeMergeToolWindow mergeToolWindow = (vMergeMergeToolWindow)window; }
private void SetMergeDiffWindowsToFloatOnly() { if (vMergePackage.MergeToolWindowIsVisible) { return; } IVsWindowFrame[] frames = new IVsWindowFrame[1]; uint numFrames; IEnumWindowFrames ppenum; UIShell.GetDocumentWindowEnum(out ppenum); while (ppenum.Next(1, frames, out numFrames) == VSConstants.S_OK && numFrames == 1) { var frame = frames[0] as IVsWindowFrame; object title; frame.GetProperty((int)__VSFPROPID.VSFPROPID_Caption, out title); var window = VsShellUtilities.GetWindowObject(frame); if (window.Caption.StartsWith("Merge - ") || window.Caption.StartsWith("Diff - ")) { if (!_attachedFrames.ContainsKey(frame)) { window.IsFloating = true; var windowEvents = new ToolWindowEvents(frame); windowEvents.OnDockableChange = (fDockable, x, y, w, h) => { if (_attachedFrames.ContainsKey(frame) && !_attachedFrames[frame]) { try { _attachedFrames[frame] = true; if (fDockable) { window.IsFloating = true; } } catch (Exception) { } finally { _attachedFrames[frame] = false; } } return(VSConstants.S_OK); }; windowEvents.OnClose = (options) => { windowEvents.OnDockableChange = null; windowEvents.OnClose = null; _attachedFrames.Remove(frame); windowEvents.Dispose(); return(VSConstants.S_OK); }; try { frame.SetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, windowEvents); _attachedFrames[frame] = false; } catch (Exception ex) { SimpleLogger.Log(ex, true); } } } } }