public static void OpenFileInPreviewTab(string file) { IVsNewDocumentStateContext newDocumentStateContext = null; try { IVsUIShellOpenDocument3 openDoc3 = Package.GetGlobalService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument3; Guid reason = VSConstants.NewDocumentStateReason.Navigation; newDocumentStateContext = openDoc3.SetNewDocumentState( (uint)__VSNEWDOCUMENTSTATE.NDS_Provisional, ref reason); VSFoldersPackage.DTE.ItemOperations.OpenFile(file); } catch (Exception ex) { } finally { if (newDocumentStateContext != null) { newDocumentStateContext.Restore(); } } }
public static void OpenFileInPreviewTab(string file) { IVsNewDocumentStateContext newDocumentStateContext = null; bool failedToOpen = false; try { var openDoc3 = Package.GetGlobalService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument3; Guid reason = VSConstants.NewDocumentStateReason.Navigation; newDocumentStateContext = openDoc3.SetNewDocumentState((uint)__VSNEWDOCUMENTSTATE.NDS_Provisional, ref reason); DTE.ItemOperations.OpenFile(file); } catch (COMException ex) { // Not sure why, but it's failing to open the documents in the preview tab when links are clicked // in the HTML view. All we get is an E_ABORT COM exception. They do open successfully in their // own tab though which we'll do below after restoring the state. System.Diagnostics.Debug.WriteLine(ex); failedToOpen = true; } finally { if (newDocumentStateContext != null) { newDocumentStateContext.Restore(); } if (failedToOpen) { DTE.ItemOperations.OpenFile(file); } } }
public static void OpenFileInPreviewTab(this DTE dte, string file, int?line, int?column) { IVsNewDocumentStateContext newDocumentStateContext = null; try { var openDoc3 = Package.GetGlobalService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument3; Guid reason = VSConstants.NewDocumentStateReason.Navigation; newDocumentStateContext = openDoc3.SetNewDocumentState((uint)__VSNEWDOCUMENTSTATE.NDS_Provisional, ref reason); file = System.IO.Path.GetFullPath(file); dte.ItemOperations.OpenFile(file); if (line.HasValue) { ((TextSelection)dte.ActiveDocument.Selection).MoveTo(line.Value, column.Value); } } finally { if (newDocumentStateContext != null) { newDocumentStateContext.Restore(); } } }
protected override void DisposeNativeResources() { if (_context != null) { _context.Restore(); } base.DisposeNativeResources(); }
public static void OpenFileInPreviewTab(IServiceProvider serviceProvider, string file) { IVsNewDocumentStateContext newDocumentStateContext = null; try { IVsUIShellOpenDocument3 openDoc3 = DartPackage.GetGlobalService <SVsUIShellOpenDocument>() as IVsUIShellOpenDocument3; Guid reason = VSConstants.NewDocumentStateReason.Navigation; newDocumentStateContext = openDoc3.SetNewDocumentState((uint)__VSNEWDOCUMENTSTATE.NDS_Provisional, ref reason); VsShellUtilities.OpenDocument(serviceProvider, file); } finally { if (newDocumentStateContext != null) { newDocumentStateContext.Restore(); } } }
private void OpenFileInPreviewTab(string file) { IVsNewDocumentStateContext newDocumentStateContext = null; try { IVsUIShellOpenDocument3 openDoc3 = EditorExtensionsPackage.GetGlobalService <SVsUIShellOpenDocument>() as IVsUIShellOpenDocument3; Guid reason = VSConstants.NewDocumentStateReason.Navigation; newDocumentStateContext = openDoc3.SetNewDocumentState((uint)__VSNEWDOCUMENTSTATE.NDS_Provisional, ref reason); EditorExtensionsPackage.DTE.ItemOperations.OpenFile(file); } finally { if (newDocumentStateContext != null) { newDocumentStateContext.Restore(); } } }
public static void OpenFileInPreviewTab(string file) { IVsNewDocumentStateContext context = null; try { IVsUIShellOpenDocument3 shell = SassyStudioPackage.GetGlobalService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument3; Guid reason = VSConstants.NewDocumentStateReason.Navigation; context = shell.SetNewDocumentState((uint)__VSNEWDOCUMENTSTATE.NDS_Provisional, ref reason); SassyStudioPackage.Instance.DTE.ItemOperations.OpenFile(file); } finally { if (context != null) { context.Restore(); } } }