private void Hide() { if (!IsVisible()) { return; } var window = _window; switch (window.WindowState) { case vsWindowState.vsWindowStateNormal: if (!window.IsFloating) { MinimizeToolWindow(); } else { _windowFrame.Hide(); } break; case vsWindowState.vsWindowStateMaximize: _windowFrame.Hide(); break; case vsWindowState.vsWindowStateMinimize: break; default: throw new InvalidOperationException(); } }
void Display(bool show, bool force) { ToolWindowPane window = this.FindToolWindow(typeof(JStockWindow), 0, true); if ((null == window) || (null == window.Frame)) { throw new NotSupportedException(Resources.CanNotCreateWindow); } IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; if (force) { if (show) { windowFrame.Show(); } else { windowFrame.Hide(); } } else { if (windowFrame.IsVisible() == VSConstants.S_OK) { windowFrame.Hide(); } else { windowFrame.Show(); } } }
private bool AddFile(ProjectNode projectNode, string file, string content) { // add the file to the project HierarchyNode node = projectNode.AddItem(file); if (node == null) { return(false); } using (node) { // Hide the file already added IVsWindowFrame frame = projectNode.OpenItem(node); frame.Hide(); using (DocData docData = new DocData(serviceProvider, node.Path)) { docData.CheckoutFile(serviceProvider); using (DocDataTextWriter writer = new DocDataTextWriter(docData)) { writer.Write(content); } } frame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_SaveIfDirty); return(true); } }
private void ShowHideWindowMenuItemCallback(object sender, EventArgs e) { ToolWindowPane window = this.FindToolWindow(typeof(JStockWindow), 0, true); if ((null == window) || (null == window.Frame)) { throw new NotSupportedException(Resources.CanNotCreateWindow); } IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; if (windowFrame.IsVisible() == VSConstants.S_OK) { if (isFirst) { StockService.Start(); isFirst = false; } else { Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Hide()); StockService.Stop(); } } else { Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); StockService.ReStart(); } }
private void inputWindowShow(SchemaInfo schemaInfo, Action callbackOption) { ThreadHelper.ThrowIfNotOnUIThread("InputWindow"); logger.Info("InputWindow called"); ToolWindowPane toolWindowPane = package.FindToolWindow(typeof(InputWindow), 0, create: true); if (toolWindowPane == null || toolWindowPane.Frame == null) { logger.Error("Cannot create tool Input window"); throw new NotSupportedException("Cannot create tool Input window"); } inputWindowControl = (toolWindowPane.Content as InputWindowControl); windowInputFrame = (IVsWindowFrame)toolWindowPane.Frame; toolWindowPane.Caption = "Input Class/Method"; ErrorHandler.ThrowOnFailure(windowInputFrame.Show()); inputWindowControl.SetInterfaceMapperWithClassControlInput(new InputWindowControlInput { ProjectNames = ClassFinder.FindProjects(dte.Solution), CallbackOption = callbackOption, SchemaInfoCommon = schemaInfoCommon, SchemaInfo = schemaInfo, Close = () => { ThreadHelper.ThrowIfNotOnUIThread("interfaceClassMapping"); ErrorHandler.ThrowOnFailure(windowInputFrame.Hide()); }, LastRunFound = File.Exists(schemaInfo.FullMethodBasedUniqueName) ? Json.Decode <SchemaInfo>(File.ReadAllText(schemaInfo.FullMethodBasedUniqueName)) : null, }); }
/// <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 async void ShowToolWindow(object sender, EventArgs e) { await JoinableTaskFactory.SwitchToMainThreadAsync(DisposalToken); // 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 = await this.FindToolWindowAsync(typeof(MyToolWindow), 0, true, new CancellationToken(true)); if (window?.Frame == null) { throw new NotSupportedException(Resources.CanNotCreateWindow); } IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; if (windowFrame.IsVisible() == VSConstants.S_OK) { ErrorHandler.ThrowOnFailure(windowFrame.Hide()); } else { ErrorHandler.ThrowOnFailure(windowFrame.Show()); } }
private void callMethod(SchemaInfo schemaInfo, List <ClassInfo> depandancyClasses, List <InputValue> inputValues) { logger.Info("callMethod called"); schemaInfo.DepandancyClasses = depandancyClasses; schemaInfo.InputValues = inputValues.ToArray(); schemaInfoCommon.SetFileData(Json.Encode(schemaInfoCommon.SchemaInfo)); ThreadHelper.ThrowIfNotOnUIThread("callMethod"); logger.Info("fileCopyAndDebug called"); if (windowFrame != null && windowFrame.IsVisible() == 0) { interfaceMapperWithClassControl.UseDefault = false; ErrorHandler.ThrowOnFailure(windowFrame.Hide()); } inputWindowShow(schemaInfo, () => { if (windowInputFrame != null && windowInputFrame.IsVisible() == 0) { //interfaceMapperWithClassControl.UseDefault = false; ErrorHandler.ThrowOnFailure(windowInputFrame.Hide()); } fileCopyAndDebug(schemaInfo); }); }
private void HideToolWindow() { if (m_windowFrame == null) { return; } m_windowFrame.Hide(); m_menuItem.Checked = false; }
private ToolWindowPane createDetailsWindow(Type toolWindowType, out IVsWindowFrame windowFrame) { ToolWindowPane window = FindToolWindow(toolWindowType, 0, true); if ((null == window) || (null == window.Frame)) { throw new NotSupportedException(Resources.CanNotCreateWindow); } windowFrame = (IVsWindowFrame)window.Frame; ErrorHandler.ThrowOnFailure(windowFrame.Hide()); return(window); }
private void CloseMostRecentToolWindow(object sender, EventArgs e) { IVsWindowFrame windowFrame = GetMostRecentToolWindow(bFindOpenWindow: true); if (windowFrame == null) { return; } // Perform Close Window operation System.Diagnostics.Debug.WriteLine($"Closing window: {GetWindowTitle(windowFrame)}"); windowFrame.Hide(); }
// Hides the tool window, except when docked. public void HideToolWindow() { if (null != Frame) { IVsWindowFrame parentWindowFrame = (IVsWindowFrame)Frame; object frameMode; parentWindowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, out frameMode); VSFRAMEMODE frameModeEnum = (VSFRAMEMODE)frameMode; if (frameModeEnum == VSFRAMEMODE.VSFM_Float || frameModeEnum == VSFRAMEMODE.VSFM_FloatOnly) { parentWindowFrame.Hide(); } } }
private void HostCSharpEditor() { if (_TextViewHost == null) { InitializeEditor(_CurrentScriptName); } if (_childWindowFrame != null) { //because VsShellUtilities.OpenDocumentWithSpecificEditor call Show, i should cause hide, before changing parent _childWindowFrame.Hide(); var window = VsShellUtilities.GetWindowObject(parentWindowFrame); _childWindowFrame.SetProperty((int)__VSFPROPID2.VSFPROPID_ParentHwnd, window.HWnd); _childWindowFrame.SetProperty((int)__VSFPROPID2.VSFPROPID_ParentFrame, parentWindowFrame); } }
/// <summary> /// Manage the closing of the window. /// </summary> public int OnClose(ref uint pgrfSaveOptions) { // abort close if there are open solutions that are not saved if (CanClose() == false) { return(VSConstants.E_ABORT); } if (DesignerWindow != null) { DesignerWindow.CloseNoPromptAllItems(); IVsWindowFrame windowFrame = (IVsWindowFrame)DesignerWindow.Frame; windowFrame.Hide(); } FindReplaceMgr.Instance.CloseWindow(); Control.CloseAllSolutions(true, false); return(VSConstants.S_OK); }
private void interfaceClassMapping(SchemaInfo schemaInfo, ClassInfo[] classInfos, Action <CodeClass[]> callbackOption) { ThreadHelper.ThrowIfNotOnUIThread("interfaceClassMapping"); logger.Info("interfaceClassMapping called"); ToolWindowPane toolWindowPane = package.FindToolWindow(typeof(InterfaceMapperWithClass), 0, create: true); if (toolWindowPane == null || toolWindowPane.Frame == null) { throw new NotSupportedException("Cannot create tool window"); } interfaceMapperWithClassControl = (toolWindowPane.Content as InterfaceMapperWithClassControl); windowFrame = (IVsWindowFrame)toolWindowPane.Frame; toolWindowPane.Caption = "Interface Class Mapper"; ErrorHandler.ThrowOnFailure(windowFrame.Show()); interfaceMapperWithClassControl.SetInterfaceMapperWithClassControlInput(new InterfaceMapperWithClassControlInput { ClassInfos = classInfos, ProjectNames = ClassFinder.FindProjects(dte.Solution), GetClasses = ((Project project) => ClassFinder.FindProjectClass(project)), GetRefClasses = ((Project project) => ClassFinder.FindProjectReferance(project)), CallbackOption = callbackOption, SchemaInfoCommon = schemaInfoCommon, Close = () => { ThreadHelper.ThrowIfNotOnUIThread("interfaceClassMapping"); ErrorHandler.ThrowOnFailure(windowFrame.Hide()); }, ClearCache = () => { ClassFinder.ClearCache(); }, LastRunFound = File.Exists(schemaInfo.FullMethodBasedUniqueName), CallbackLastRunOption = () => { var tempSchemaInfo = Json.Decode <SchemaInfo>(File.ReadAllText(schemaInfo.FullMethodBasedUniqueName)); fileCopyAndDebug(tempSchemaInfo); } }); }
private void ShowSccProviderToolWindow() { MsVsShell.ToolWindowPane window = this.FindToolWindow(typeof(SccProviderToolWindow), 0, true); IVsWindowFrame windowFrame = null; if (window != null && window.Frame != null) { windowFrame = (IVsWindowFrame)window.Frame; } if (windowFrame == null) { throw new InvalidOperationException("No valid window frame object was returned from Toolwindow pane"); } if (sccService.Active) { ErrorHandler.ThrowOnFailure(windowFrame.Show()); } else { ErrorHandler.ThrowOnFailure(windowFrame.Hide()); } }
/// <summary> /// Display the SCC Provider Toolwindow if it is not already visible /// </summary> private void ShowSccProviderToolWindow() { IVsWindowFrame windowFrame = null; try { // This function is called when the package is auto-loaded (as result of our command UI context // guidSccProvider being set active). This can happen on startup, if this scc provider was active // last time the shell was started. // However, at that time we cannot create the toolwindow because the shell is not fully initialized // and the window profile is not yet loaded. We need to protect MsVsShell.ToolWindowPane window = FindToolWindow(typeof(SccProviderToolWindow), 0, true); if (window != null && window.Frame != null) { windowFrame = (IVsWindowFrame)window.Frame; } } catch (COMException e) { if (e.ErrorCode != VSConstants.E_UNEXPECTED) { throw; } } if (windowFrame == null) { return; } if (sccService.Active) { ErrorHandler.ThrowOnFailure(windowFrame.Show()); } else { ErrorHandler.ThrowOnFailure(windowFrame.Hide()); } }
///-------------------------------------------------------------------------------- /// <summary>This method determines if visual studio can close.</summary> ///-------------------------------------------------------------------------------- public int get_CanClose(out bool pfCanClose) { pfCanClose = true; try { // cancel close if either solution designer or solution builder cannot close SolutionDesignerWindow solutionDesigner = this.FindToolWindow(typeof(SolutionDesignerWindow), 0, false) as SolutionDesignerWindow; if (solutionDesigner != null) { if (solutionDesigner.CanClose() == false) { pfCanClose = false; return(VSConstants.E_ABORT); } solutionDesigner.Control.DesignerView.CloseNoPromptAllItems(); IVsWindowFrame windowFrame = (IVsWindowFrame)solutionDesigner.Frame; windowFrame.Hide(); } SolutionBuilderWindow solutionBuilder = this.FindToolWindow(typeof(SolutionBuilderWindow), 0, false) as SolutionBuilderWindow; if (solutionBuilder != null) { if (solutionBuilder.CanClose() == false) { pfCanClose = false; return(VSConstants.E_ABORT); } solutionBuilder.Control.CloseAllSolutions(true); IVsWindowFrame windowFrame = (IVsWindowFrame)solutionBuilder.Frame; windowFrame.Hide(); } } catch (System.Exception ex) { // put exception message in output pane SolutionBuilderPane.OutputString(ex.Message); } return(VSConstants.S_OK); }
/// <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 ShowToolWindow(object sender, EventArgs e) { // 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(MyToolWindow), 0, true); if (window?.Frame == null) { throw new NotSupportedException(Resources.CanNotCreateWindow); } IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; if (windowFrame.IsVisible() == VSConstants.S_OK) { ErrorHandler.ThrowOnFailure(windowFrame.Hide()); } else { ErrorHandler.ThrowOnFailure(windowFrame.Show()); } }
protected override void Initialize() { base.Initialize(); var componentModel = this.GetService <SComponentModel, IComponentModel>(); componentModel.DefaultCompositionService.SatisfyImportsOnce(this); this.NServiceBusDiagramAdapter.CloseWindow = () => { IVsWindowFrame windowFrame = (IVsWindowFrame)this.Frame; windowFrame.Hide(); }; var pane = new Diagram(this.NServiceBusDiagramAdapter); this.Content = pane; //pane.CaptionHasChanged += (s, e) => //{ // this.Caption = pane.Caption; //}; }
private int OpenItem(bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction) { frame = null; if (this.ProjectMgr == null || this.ProjectMgr.IsClosed) { return VSConstants.E_FAIL; } int result = VSConstants.S_OK; uint[] ppItemId = new uint[1]; ppItemId[0] = this.ID; int open; IVsUIHierarchy project; string fullPath = GetMkDocument(); // check if the file exists if (!System.IO.File.Exists(fullPath)) { // TODO Inform clients that we have an invalid item (wrong icon) //// Inform clients that we have an invalid item (wrong icon) //this.Node.OnInvalidateItems(this.Node.Parent); return VSConstants.S_FALSE; } IVsUIShellOpenDocument sod = (this.ProjectMgr as CogaenEditProject).Site.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument; if (sod != null) { try { // try to get hold of the open file sod.IsDocumentOpen(this.ProjectMgr , this.ID , GetMkDocument() , ref logicalView /* LOGVIEWID_Code to show xml behind */ , (uint)__VSIDOFLAGS.IDO_ActivateIfOpen , out project , ppItemId , out frame , out open); // file is not open if (open == 0) { // TODO load doc data Load(fullPath, 0, 0); docDataExisting = Marshal.GetIUnknownForObject(ObjectBuilder); if (openWith) { result = sod.OpenStandardEditor((uint)__VSOSEFLAGS.OSE_UseOpenWithDialog//(uint)__VSOSEFLAGS.OSE_ChooseBestStdEditor , GetMkDocument() , ref logicalView /* VSConstants.LOGVIEWID.Code_guid for xml behind*/ , Caption , this.ProjectMgr , this.ID // TODO pass docData!!!! , docDataExisting , this.ProjectMgr.Site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider , out frame); } else { __VSOSEFLAGS openFlags = 0; if (newFile) { openFlags |= __VSOSEFLAGS.OSE_OpenAsNewFile; } openFlags |= __VSOSEFLAGS.OSE_ChooseBestStdEditor; if (editorType != Guid.Empty) { result = sod.OpenSpecificEditor(editorFlags , fullPath , ref editorType , physicalView , ref logicalView , Caption , this.ProjectMgr , this.ID , docDataExisting , this.ProjectMgr.Site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider , out frame); } else { result = sod.OpenStandardEditor((uint)openFlags , GetMkDocument() , ref logicalView /* VSConstants.LOGVIEWID.Code_guid for xml behind*/ , Caption , this.ProjectMgr , this.ID , docDataExisting , this.ProjectMgr.Site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider , out frame); } } if (result != VSConstants.S_OK && result != VSConstants.S_FALSE && result != VSConstants.OLE_E_PROMPTSAVECANCELLED) { ErrorHandler.ThrowOnFailure(result); } // eventually show window if (frame != null) { object var; if (newFile) { ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var)); IVsPersistDocData persistDocData = (IVsPersistDocData)var; ErrorHandler.ThrowOnFailure(persistDocData.SetUntitledDocPath(fullPath)); } var = null; ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var)); this.DocCookie = (uint)(int)var; if (windowFrameAction == WindowFrameShowAction.Show) { ErrorHandler.ThrowOnFailure(frame.Show()); } else if (windowFrameAction == WindowFrameShowAction.ShowNoActivate) { ErrorHandler.ThrowOnFailure(frame.ShowNoActivate()); } else if (windowFrameAction == WindowFrameShowAction.Hide) { ErrorHandler.ThrowOnFailure(frame.Hide()); } } } // file is already open else { ObjectBuilder = Marshal.GetObjectForIUnknown(docDataExisting) as ObjectBuilder; Marshal.Release(docDataExisting); if (frame != null) { if (windowFrameAction == WindowFrameShowAction.Show) { ErrorHandler.ThrowOnFailure(frame.Show()); } else if (windowFrameAction == WindowFrameShowAction.ShowNoActivate) { ErrorHandler.ThrowOnFailure(frame.ShowNoActivate()); } else if (windowFrameAction == WindowFrameShowAction.Hide) { ErrorHandler.ThrowOnFailure(frame.Hide()); } } } } catch (COMException e) { Trace.WriteLine("Exception e:" + e.Message); result = e.ErrorCode; CloseWindowFrame(ref frame); } } return result; }
internal void HideGuidanceNavigatorWindow() { IVsWindowFrame windowFrame = GetGuidanceNavigatorWindowFrame(); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Hide()); }
private int Open(bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction) { windowFrame = null; if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed) { return(VSConstants.E_FAIL); } Debug.Assert(this.Node != null, "No node has been initialized for the document manager"); Debug.Assert(this.Node.ProjectMgr != null, "No project manager has been initialized for the document manager"); Debug.Assert(this.Node is FileNode, "Node is not FileNode object"); int returnValue = VSConstants.S_OK; string caption = this.GetOwnerCaption(); string fullPath = this.GetFullPathForDocument(); // Make sure that the file is on disk before we open the editor and display message if not found if (!((FileNode)this.Node).IsFileOnDisk(true)) { // Inform clients that we have an invalid item (wrong icon) this.Node.OnInvalidateItems(this.Node.Parent); // Bail since we are not able to open the item return(VSConstants.E_FAIL); } IVsUIShellOpenDocument uiShellOpenDocument = this.Node.ProjectMgr.Site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; IOleServiceProvider serviceProvider = this.Node.ProjectMgr.Site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider; try { this.Node.ProjectMgr.OnOpenItem(fullPath); int result = VSConstants.E_FAIL; if (openWith) { result = uiShellOpenDocument.OpenStandardEditor((uint)__VSOSEFLAGS.OSE_UseOpenWithDialog, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } else { __VSOSEFLAGS openFlags = 0; if (newFile) { openFlags |= __VSOSEFLAGS.OSE_OpenAsNewFile; } //NOTE: we MUST pass the IVsProject in pVsUIHierarchy and the itemid // of the node being opened, otherwise the debugger doesn't work. if (editorType != Guid.Empty) { result = uiShellOpenDocument.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } else { openFlags |= __VSOSEFLAGS.OSE_ChooseBestStdEditor; result = uiShellOpenDocument.OpenStandardEditor((uint)openFlags, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } } if (result != VSConstants.S_OK && result != VSConstants.S_FALSE && result != VSConstants.OLE_E_PROMPTSAVECANCELLED) { ErrorHandler.ThrowOnFailure(result); } if (windowFrame != null) { object var; if (newFile) { ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var)); IVsPersistDocData persistDocData = (IVsPersistDocData)var; ErrorHandler.ThrowOnFailure(persistDocData.SetUntitledDocPath(fullPath)); } var = null; ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var)); this.Node.DocCookie = (uint)(int)var; if (windowFrameAction == WindowFrameShowAction.Show) { ErrorHandler.ThrowOnFailure(windowFrame.Show()); } else if (windowFrameAction == WindowFrameShowAction.ShowNoActivate) { ErrorHandler.ThrowOnFailure(windowFrame.ShowNoActivate()); } else if (windowFrameAction == WindowFrameShowAction.Hide) { ErrorHandler.ThrowOnFailure(windowFrame.Hide()); } } } catch (COMException e) { Trace.WriteLine("Exception e:" + e.Message); returnValue = e.ErrorCode; this.CloseWindowFrame(ref windowFrame); } return(returnValue); }
// -------------------------------------------------------------------------------------------- /// <summary> /// Hides a window. /// </summary> /// <returns> /// If the method succeeds, it returns S_OK. If it fails, it returns an error code. /// </returns> // -------------------------------------------------------------------------------------------- int IVsWindowFrame.Hide() { return(_Frame.Hide()); }
private void Instance_HideYourself() { _windowFrame.Hide(); }
private int Open(bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction) { windowFrame = null; if(this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed) { return VSConstants.E_FAIL; } Debug.Assert(this.Node != null, "No node has been initialized for the document manager"); Debug.Assert(this.Node.ProjectMgr != null, "No project manager has been initialized for the document manager"); Debug.Assert(this.Node is FileNode, "Node is not FileNode object"); int returnValue = VSConstants.S_OK; string caption = this.GetOwnerCaption(); string fullPath = this.GetFullPathForDocument(); // Make sure that the file is on disk before we open the editor and display message if not found if(!((FileNode)this.Node).IsFileOnDisk(true)) { // Inform clients that we have an invalid item (wrong icon) this.Node.OnInvalidateItems(this.Node.Parent); // Bail since we are not able to open the item // Do not return an error code otherwise an internal error message is shown. The scenario for this operation // normally is already a reaction to a dialog box telling that the item has been removed. return VSConstants.S_FALSE; } IVsUIShellOpenDocument uiShellOpenDocument = this.Node.ProjectMgr.Site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; IOleServiceProvider serviceProvider = this.Node.ProjectMgr.Site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider; try { this.Node.ProjectMgr.OnOpenItem(fullPath); int result = VSConstants.E_FAIL; if(openWith) { result = uiShellOpenDocument.OpenStandardEditor((uint)__VSOSEFLAGS.OSE_UseOpenWithDialog, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } else { __VSOSEFLAGS openFlags = 0; if(newFile) { openFlags |= __VSOSEFLAGS.OSE_OpenAsNewFile; } //NOTE: we MUST pass the IVsProject in pVsUIHierarchy and the itemid // of the node being opened, otherwise the debugger doesn't work. if(editorType != Guid.Empty) { result = uiShellOpenDocument.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } else { openFlags |= __VSOSEFLAGS.OSE_ChooseBestStdEditor; result = uiShellOpenDocument.OpenStandardEditor((uint)openFlags, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } } if(result != VSConstants.S_OK && result != VSConstants.S_FALSE && result != VSConstants.OLE_E_PROMPTSAVECANCELLED) { ErrorHandler.ThrowOnFailure(result); } if(windowFrame != null) { object var; if(newFile) { ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var)); IVsPersistDocData persistDocData = (IVsPersistDocData)var; ErrorHandler.ThrowOnFailure(persistDocData.SetUntitledDocPath(fullPath)); } var = null; ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var)); this.Node.DocCookie = (uint)(int)var; if(windowFrameAction == WindowFrameShowAction.Show) { ErrorHandler.ThrowOnFailure(windowFrame.Show()); } else if(windowFrameAction == WindowFrameShowAction.ShowNoActivate) { ErrorHandler.ThrowOnFailure(windowFrame.ShowNoActivate()); } else if(windowFrameAction == WindowFrameShowAction.Hide) { ErrorHandler.ThrowOnFailure(windowFrame.Hide()); } } } catch(COMException e) { Trace.WriteLine("Exception e:" + e.Message); returnValue = e.ErrorCode; CloseWindowFrame(ref windowFrame); } return returnValue; }
protected int Open(bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction, bool reopen = false) { windowFrame = null; if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed) { return(VSConstants.E_FAIL); } Debug.Assert(this.Node != null, "No node has been initialized for the document manager"); Debug.Assert(this.Node.ProjectMgr != null, "No project manager has been initialized for the document manager"); Debug.Assert(this.Node is FileNode, "Node is not FileNode object"); int returnValue = VSConstants.S_OK; string caption = this.GetOwnerCaption(); string fullPath = this.GetFullPathForDocument(); IVsUIShellOpenDocument uiShellOpenDocument = this.Node.ProjectMgr.Site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; Assumes.Present(uiShellOpenDocument); IOleServiceProvider serviceProvider = this.Node.ProjectMgr.Site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider; Assumes.Present(serviceProvider); var openState = uiShellOpenDocument as IVsUIShellOpenDocument3; bool showDialog = !reopen && (openState == null || !((__VSNEWDOCUMENTSTATE)openState.NewDocumentState).HasFlag(__VSNEWDOCUMENTSTATE.NDS_Provisional)); // Make sure that the file is on disk before we open the editor and display message if not found if (!((FileNode)this.Node).IsFileOnDisk(showDialog)) { // Bail since we are not able to open the item // Do not return an error code otherwise an internal error message is shown. The scenario for this operation // normally is already a reaction to a dialog box telling that the item has been removed. return(VSConstants.S_FALSE); } try { this.Node.ProjectMgr.OnOpenItem(fullPath); int result = VSConstants.E_FAIL; if (openWith) { result = uiShellOpenDocument.OpenStandardEditor((uint)__VSOSEFLAGS.OSE_UseOpenWithDialog, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } else { __VSOSEFLAGS openFlags = 0; if (newFile) { openFlags |= __VSOSEFLAGS.OSE_OpenAsNewFile; } //NOTE: we MUST pass the IVsProject in pVsUIHierarchy and the itemid // of the node being opened, otherwise the debugger doesn't work. if (editorType != Guid.Empty) { result = uiShellOpenDocument.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } else { openFlags |= __VSOSEFLAGS.OSE_ChooseBestStdEditor; result = uiShellOpenDocument.OpenStandardEditor((uint)openFlags, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } } if (result != VSConstants.S_OK && result != VSConstants.S_FALSE && result != VSConstants.OLE_E_PROMPTSAVECANCELLED) { ErrorHandler.ThrowOnFailure(result); } if (windowFrame != null) { object var; if (newFile) { ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var)); IVsPersistDocData persistDocData = (IVsPersistDocData)var; ErrorHandler.ThrowOnFailure(persistDocData.SetUntitledDocPath(fullPath)); } var = null; ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var)); this.Node.DocCookie = (uint)(int)var; if (windowFrameAction == WindowFrameShowAction.Show) { ErrorHandler.ThrowOnFailure(windowFrame.Show()); } else if (windowFrameAction == WindowFrameShowAction.ShowNoActivate) { ErrorHandler.ThrowOnFailure(windowFrame.ShowNoActivate()); } else if (windowFrameAction == WindowFrameShowAction.Hide) { ErrorHandler.ThrowOnFailure(windowFrame.Hide()); } } } catch (COMException e) { XSharpProjectPackage.Instance.DisplayException(e); returnValue = e.ErrorCode; CloseWindowFrame(ref windowFrame); } return(returnValue); }
public void Close() { _windowFrame.Hide(); }