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); } }
/// <summary> /// "Run" button was clicked /// </summary> private void RunClick(object sender, EventArgs args) { int checkedRows = panel.ToolGrid.CheckedRowsCount; int rowCount = panel.ToolGrid.Rows.Count; int rowErrors = 0; try { VLDocumentViewsManager.ReleaseLocks(); // unlock the documents MenuManager.OperationInProgress = false; // permit other operations bool usingFullName = currentNamespacePolicy == NAMESPACE_POLICY_ITEMS[1]; // whether full references will be used bool markUncheckedStringsWithComment = currentRememberOption == REMEMBER_OPTIONS[1]; // whether unchecked strings will be marked with "no-localization" comment BatchMover mover = new BatchMover(usingFullName, markUncheckedStringsWithComment); mover.Move(panel.ToolGrid.GetData(), ref rowErrors); // run the mover } catch (Exception ex) { VLOutputWindow.VisualLocalizerPane.WriteException(ex); VisualLocalizer.Library.Components.MessageBox.ShowException(ex); } finally { IVsWindowFrame frame = ((IVsWindowFrame)this.Frame); if (frame != null) { frame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave); // close the toolwindow } panel.ToolGrid.Clear(); VLOutputWindow.VisualLocalizerPane.Activate(); VLOutputWindow.VisualLocalizerPane.WriteLine("Batch Move to Resources command completed - selected {0} rows of {1}, {2} rows processed successfully", checkedRows, rowCount, checkedRows - rowErrors); } }
/// <include file='doc\WindowPane.uex' path='docs/doc[@for="WindowPane.Dispose1"]' /> /// <devdoc> /// Called when this tool window pane is being disposed. /// </devdoc> override protected void Dispose(bool disposing) { if (disposing) { if (control != null) { try { if (control is IDisposable) { control.Dispose(); } } catch (Exception e) { System.Diagnostics.Debug.Fail(String.Format("Failed to dispose {0} controls.\n{1}", this.GetType().FullName, e.Message)); } control = null; } IVsWindowFrame windowFrame = (IVsWindowFrame)this.Frame; if (windowFrame != null) { // Note: don't check for the return code here. windowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_SaveIfDirty); } } base.Dispose(disposing); }
public void Close() { CPListTW window = package.FindToolWindow(typeof(ChartPoints.CPListTW), 0, true) as CPListTW; IVsWindowFrame frame = window?.Frame as IVsWindowFrame; frame?.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave); }
private void ViewModelClosed(object sender, Utility.Managers.View.ViewModelFinishedEventArgs e) { vMergePackage.SetMergeToolWindowIsVisible(false); ((PrepareMergeViewModel)((ContentControl)Content).DataContext).Finished -= ViewModelClosed; IVsWindowFrame windowFrame = (IVsWindowFrame)Frame; windowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_SaveIfDirty); }
public int OnClose(ref uint pgrfSaveOptions) { var result = _subFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_PromptSave); splitContainer1.Visible = false; return(result); }
//public void UpdateView() //{ // if (window == null) // Activate(); // //window.UpdateView(); //} public void Close() { if (window == null) { window = package.FindToolWindow(typeof(ChartPoints.CPChartViewTW), 0, true) as CPChartViewTW; } IVsWindowFrame frame = window?.Frame as IVsWindowFrame; frame?.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave); }
protected override void OnClose() { ThreadHelper.ThrowIfNotOnUIThread(); // BUGFIX!!! Use FRAMECLOSE_PromptSave, so we get a save prompt // when file is dirty/modified sourceFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_PromptSave); designerFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_PromptSave); base.OnClose(); }
private void closeView(ToolWindowPane window) { if ((null == window) || (null == window.Frame)) { throw new NotSupportedException("Cannot create tool window"); } IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_PromptSave)); }
protected static void CloseWindowFrame(ref IVsWindowFrame windowFrame) { if (windowFrame != null) { try { ErrorHandler.ThrowOnFailure(windowFrame.CloseFrame(0)); } finally { windowFrame = null; } } }
private void LoadScript(string scriptName) { if (_childWindowFrame != null) { _childWindowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_SaveIfDirty); } _TextViewHost = null; _ViewAdapter = null; _docData = null; HostCSharpEditor(); }
public static void CloseFrame() { ToolWindowPane listFunctionsWindow = TalkCodePackage.currentPackage.FindToolWindow(typeof(About), 0, true); if ((null == listFunctionsWindow) || (null == listFunctionsWindow.Frame)) { return; } IVsWindowFrame windowFrame = (IVsWindowFrame)listFunctionsWindow.Frame; windowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave); }
public static void CloseFrame() { ToolWindowPane talkpointWindow = TalkCodePackage.currentPackage.FindToolWindow(typeof(CodeTalkOptions), 0, true); if ((null == talkpointWindow) || (null == talkpointWindow.Frame)) { return; } IVsWindowFrame windowFrame = (IVsWindowFrame)talkpointWindow.Frame; windowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave); }
public /*protected, but public for FSharp.Project.dll*/ void CloseWindowFrame(ref IVsWindowFrame windowFrame) { if (windowFrame != null) { try { ErrorHandler.ThrowOnFailure(windowFrame.CloseFrame(0)); } finally { windowFrame = null; } } }
bool DetectClosedWindow() { if (_disposed) { return(true); } if (VSConstants.S_FALSE == _frame.IsVisible()) { _frame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave); Dispose(); } return(false); }
public void CloseAllResourceManagerWindow(Package package) { foreach (KeyValuePair <string, int> entry in projectIdMap) { ToolWindowPane window = package.FindToolWindow(typeof(ResourceManager), entry.Value, false); if ((null == window)) { continue; } IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; windowFrame.CloseFrame((int)__FRAMECLOSE.FRAMECLOSE_SaveIfDirty); } projectIdMap.Clear(); }
// Teardown Logic /// <summary> /// Tells the editor to call close on the existing window frame. /// </summary> /// <returns>True if the close was successful, false if the window is still open</returns> public async Task <bool> CanCloseWindowAsync() { // We can't switch to editor closing here because there's still the chance that some other action can cancel // the editor closing, without notifying us. A later callback will get hit once the close is guaranteed to happen. // We do, however, assert that we're not in NoEditor, Initializing, or EditorClosing; being in any of those states // here would indicate a bug. lock (_lock) { Assumes.False(_currentState == EditorState.NoEditor || _currentState == EditorState.Initializing || _currentState == EditorState.EditorClosing); } await _threadingService.SwitchToUIThread(); return(_windowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_PromptSave) == VSConstants.S_OK); }
protected override void Dispose(bool disposing) { if (!IsDisposed) { if (disposing) { IVsWindowFrame frame = (IVsWindowFrame)base.Frame; if (frame != null) { frame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_SaveIfDirty); } } } base.Dispose(disposing); this.IsDisposed = true; }
private HierarchyNode AddFile(string path, string location) { using (HierarchyNode folder = new HierarchyNode(VSSolution).FindOrCreateSolutionFolder(location)) if (folder != null) { using (ProjectNode folderProject = new ProjectNode(VSSolution, folder.ProjectGuid)) { // Add xsd HierarchyNode item = folderProject.AddItem(path); Debug.Assert(item != null, "Upps the PMT item could not be added"); IVsWindowFrame wnd = folderProject.OpenItem(item); Debug.Assert(wnd != null, "Upps the PMT.xsd item could not be opened"); wnd.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_SaveIfDirty); return(item); } } return(null); }
public void CloseToolWindow(AnkhToolWindow toolWindow, int id, FrameCloseMode close) { ToolWindowPane pane = FindToolWindow(GetPaneType(toolWindow), id, false); if (pane == null) { return; } IVsWindowFrame frame = pane.Frame as IVsWindowFrame; if (frame == null) { return; } Marshal.ThrowExceptionForHR(frame.CloseFrame((uint)close)); }
public static void CloseFrame() { ToolWindowPane talkpointWindow = TalkCodePackage.currentPackage.FindToolWindow(typeof(TalkpointToolWindow), 0, true); if ((null == talkpointWindow) || (null == talkpointWindow.Frame)) { return; } var control = (TalkpointToolWindowControl)talkpointWindow.Content; if (null != control) { control.ClearAll(); } IVsWindowFrame windowFrame = (IVsWindowFrame)talkpointWindow.Frame; windowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave); }
public void OpenFile(string filePath, bool isReadOnly) { ThreadHelper.ThrowIfNotOnUIThread(); var rdt = new RunningDocumentTable(_serviceProvider); IVsWindowFrame?windowFrame = null; try { // Open the document. VsShellUtilities.OpenDocument( _serviceProvider, filePath, VSConstants.LOGVIEWID_Primary, out _, out _, out windowFrame); // Set it as read only if necessary. if (isReadOnly) { RunningDocumentInfo rdtInfo = rdt.GetDocumentInfo(filePath); // Set it as read only if necessary. if (rdtInfo.DocData is IVsTextBuffer textBuffer) { textBuffer.GetStateFlags(out uint flags); textBuffer.SetStateFlags(flags | (uint)BUFFERSTATEFLAGS.BSF_USER_READONLY); } } // Show the document window if (windowFrame != null) { ErrorHandler.ThrowOnFailure(windowFrame.Show()); } } catch (Exception ex) when(!ex.IsCritical()) { windowFrame?.CloseFrame(0); } }
public void CloseProjectResourceManagerWindow(Package package, Project project) { string projPath = project.FullName; if (!projectIdMap.ContainsKey(projPath)) { return; } ToolWindowPane window = package.FindToolWindow(typeof(ResourceManager), projectIdMap[projPath], false); projectIdMap.Remove(projPath); if ((null == window)) { return; } IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; windowFrame.CloseFrame((int)__FRAMECLOSE.FRAMECLOSE_SaveIfDirty); }
private async Task ExecuteUpgradeNuGetProjectCommandAsync(object sender, EventArgs e) { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (ShouldMEFBeInitialized()) { await InitializeMEFAsync(); } var project = VsMonitorSelection.GetActiveProject(); if (!await NuGetProjectUpgradeUtility.IsNuGetProjectUpgradeableAsync(null, project)) { MessageHelper.ShowWarningMessage(Resources.ProjectMigrateErrorMessage, Resources.ErrorDialogBoxTitle); return; } string uniqueName = await project.GetCustomUniqueNameAsync(); // Close NuGet Package Manager if it is open for this project IVsWindowFrame windowFrame = await FindExistingWindowFrameAsync(project); windowFrame?.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_SaveIfDirty); IServiceBroker serviceBroker = await ServiceBrokerProvider.Value.GetAsync(); NuGetProject nuGetProject = await SolutionManager.Value.GetNuGetProjectAsync(uniqueName); IProjectContextInfo projectContextInfo = await ProjectContextInfo.CreateAsync(nuGetProject, CancellationToken.None); using (INuGetUI uiController = await UIFactory.Value.CreateAsync(serviceBroker, projectContextInfo)) { await uiController.UIContext.UIActionEngine.UpgradeNuGetProjectAsync(uiController, projectContextInfo); uiController.UIContext.UserSettingsManager.PersistSettings(); } }
/// <summary> /// Opens a difference window with <code>IVsDifferenceService</code> when a DocumentNode is double clicked. /// </summary> private void MouseDoubleClickHandler(object sender, MouseButtonEventArgs e) { if (DocumentListBox.SelectedItem == null) { return; } var node = (DocumentNode)DocumentListBox.SelectedItem; Debug.Assert(File.Exists(node.RepositoryPath)); Debug.Assert(File.Exists(node.OriginalPath)); Debug.Assert(node.OriginalPath == LatestDocument.OriginalPath); // Close the last comparison because we only want 1 open at a time if (differenceFrame != null) { differenceFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave); } // Get the Difference Service we will use to do the comparison if (differenceService == null) { differenceService = (IVsDifferenceService)Package.GetGlobalService(typeof(SVsDifferenceService)); } // Open a comparison between the old file and the current file differenceFrame = differenceService.OpenComparisonWindow2( node.RepositoryPath, LatestDocument.RepositoryPath, node.FileName + " " + node.TimeStamp + " vs Now", node.FileName + " " + node.TimeStamp + " vs Now", node.FileName + " " + node.TimeStamp, LatestDocument.FileName + " Now", node.FileName + " " + node.TimeStamp + " vs Now", null, 0); }
// -------------------------------------------------------------------------------------------- /// <summary> /// Closes a window. /// </summary> /// <param name="grfSaveOptions"> /// Save options whose values are taken from the __FRAMECLOSE. /// </param> /// <returns> /// If the method succeeds, it returns S_OK. If it fails, it returns an error code. /// </returns> // -------------------------------------------------------------------------------------------- int IVsWindowFrame.CloseFrame(uint grfSaveOptions) { return(_Frame.CloseFrame(grfSaveOptions)); }
public Task <bool> TryHandleCommandAsync(IImmutableSet <IProjectTree> items, long commandId, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut) { if (IsOpenCommand(commandId) && items.All(CanOpenFile)) { OpenItems(); return(TaskResult.True); } return(TaskResult.False); void OpenItems() { Assumes.NotNull(_configuredProject.UnconfiguredProject.Services.HostObject); var hierarchy = (IVsUIHierarchy)_configuredProject.UnconfiguredProject.Services.HostObject; var rdt = new RunningDocumentTable(_serviceProvider); // Open all items. RunAllAndAggregateExceptions(items, OpenItem); void OpenItem(IProjectTree item) { IVsWindowFrame?windowFrame = null; try { // Open the document. Guid logicalView = IsOpenWithCommand(commandId) ? LOGVIEWID_UserChooseView : LOGVIEWID.Primary_guid; IntPtr docData = IntPtr.Zero; ErrorHandler.ThrowOnFailure( _uiShellOpenDocument.Value.OpenStandardEditor( (uint)__VSOSEFLAGS.OSE_ChooseBestStdEditor, item.FilePath, ref logicalView, item.Caption, hierarchy, item.GetHierarchyId(), docData, _oleServiceProvider.Value, out windowFrame)); RunningDocumentInfo rdtInfo = rdt.GetDocumentInfo(item.FilePath); // Set it as read only if necessary. bool isReadOnly = item.Flags.Contains(ImportTreeProvider.ProjectImportImplicit); if (isReadOnly && rdtInfo.DocData is IVsTextBuffer textBuffer) { textBuffer.GetStateFlags(out uint flags); textBuffer.SetStateFlags(flags | (uint)BUFFERSTATEFLAGS.BSF_USER_READONLY); } // Detach the document from this project. // Ignore failure. It may be that we've already transferred the item to Miscellaneous Files. _externalFilesManager.Value.TransferDocument(item.FilePath, item.FilePath, windowFrame); // Show the document window if (windowFrame != null) { ErrorHandler.ThrowOnFailure(windowFrame.Show()); } } catch { windowFrame?.CloseFrame(0); throw; } } } }
private void close() { IVsWindowFrame windowFrame = (IVsWindowFrame)this.ParentPane.Frame; windowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave); }
private void Close() { _editorFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave); }
/// <include file='doc\Hierarchy.uex' path='docs/doc[@for="HierarchyNode.OpenItem3"]/*' /> public static void OpenItem(IServiceProvider site, bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr punkDocDataExisting, IVsHierarchy pHierarchy, uint hierarchyId, out IVsWindowFrame windowFrame) { windowFrame = null; IntPtr docData = punkDocDataExisting; Exception error = null; try { uint itemid = hierarchyId; object pvar; NativeMethods.ThrowOnFailure(pHierarchy.GetProperty(hierarchyId, (int)__VSHPROPID.VSHPROPID_Caption, out pvar)); string caption = (string)pvar; string fullPath = null; if (punkDocDataExisting != IntPtr.Zero) { fullPath = VsShell.GetFilePath(punkDocDataExisting); } if (fullPath == null) { string dir; NativeMethods.ThrowOnFailure(pHierarchy.GetProperty(NativeMethods.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectDir, out pvar)); dir = (string)pvar; NativeMethods.ThrowOnFailure(pHierarchy.GetProperty(hierarchyId, (int)__VSHPROPID.VSHPROPID_SaveName, out pvar)); // todo: what if the path is a URL? fullPath = dir != null ? Path.Combine(dir, (string)pvar) : (string)pvar; } IVsUIHierarchy pRootHierarchy = null; NativeMethods.ThrowOnFailure(pHierarchy.GetProperty(NativeMethods.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_Root, out pvar)); IntPtr ptr; if (pvar == null) { pRootHierarchy = (IVsUIHierarchy)pHierarchy; } else { ptr = (IntPtr)pvar; pRootHierarchy = (IVsUIHierarchy)Marshal.GetTypedObjectForIUnknown(ptr, typeof(IVsUIHierarchy)); Marshal.Release(ptr); } IVsUIHierarchy pVsUIHierarchy = pRootHierarchy; IVsUIShellOpenDocument doc = site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; const uint OSE_ChooseBestStdEditor = 0x20000000; const uint OSE_UseOpenWithDialog = 0x10000000; const uint OSE_OpenAsNewFile = 0x40000000; if (openWith) { IOleServiceProvider psp = site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider; NativeMethods.ThrowOnFailure(doc.OpenStandardEditor(OSE_UseOpenWithDialog, fullPath, ref logicalView, caption, pVsUIHierarchy, itemid, docData, psp, out windowFrame)); } else { // First we see if someone else has opened the requested view of the file. IVsRunningDocumentTable pRDT = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; if (pRDT != null) { uint docCookie; IVsHierarchy ppIVsHierarchy; NativeMethods.ThrowOnFailure(pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, fullPath, out ppIVsHierarchy, out itemid, out docData, out docCookie)); if (ppIVsHierarchy != null && docCookie != (uint)ShellConstants.VSDOCCOOKIE_NIL && pHierarchy != ppIVsHierarchy && pVsUIHierarchy != ppIVsHierarchy) { // not opened by us, so call IsDocumentOpen with the right IVsUIHierarchy so we avoid the // annoying "This document is opened by another project" message prompt. pVsUIHierarchy = (IVsUIHierarchy)ppIVsHierarchy; itemid = (uint)NativeMethods.VSITEMID_SELECTION; } ppIVsHierarchy = null; } uint openFlags = 0; if (newFile) openFlags |= OSE_OpenAsNewFile; //NOTE: we MUST pass the IVsProject in pVsUIHierarchy and the itemid // of the node being opened, otherwise the debugger doesn't work. IOleServiceProvider psp = site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider; int retryCount = 1; while (retryCount > 0) { try { if (editorType != Guid.Empty) { NativeMethods.ThrowOnFailure(doc.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, pRootHierarchy, hierarchyId, docData, psp, out windowFrame)); } else { openFlags |= OSE_ChooseBestStdEditor; NativeMethods.ThrowOnFailure(doc.OpenStandardEditor(openFlags, fullPath, ref logicalView, caption, pRootHierarchy, hierarchyId, docData, psp, out windowFrame)); } break; } catch (Exception e) { if (e is COMException) { COMException ce = (COMException)e; if (ce.ErrorCode == NativeMethods.OLE_E_PROMPTSAVECANCELLED) { break; } } // perhaps the editor is not compatible with an existing one. // try OpenStandardEditor. if (editorType != Guid.Empty) { editorType = Guid.Empty; } else { throw e; } } } } if (windowFrame != null) { if (newFile) { object var; NativeMethods.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var)); IVsPersistDocData ppd = (IVsPersistDocData)var; NativeMethods.ThrowOnFailure(ppd.SetUntitledDocPath(fullPath)); } } if (windowFrame != null) NativeMethods.ThrowOnFailure(windowFrame.Show()); } catch (Exception e) { error = e; } if (error != null) { string msg = error.Message; if (logicalView != Guid.Empty) { if (editorType != Guid.Empty) { msg = String.Format(SR.GetString(SR.EditorViewError), logicalView.ToString(), editorType.ToString()) + "\r\n" + msg; } else { msg = String.Format(SR.GetString(SR.StandardEditorViewError), logicalView.ToString()) + "\r\n" + msg; } } else if (editorType != Guid.Empty) { msg = String.Format(SR.GetString(SR.StandardEditorViewError), logicalView.ToString()) + "\r\n" + msg; } MessageBox.Show(msg, SR.GetString(SR.Error), MessageBoxButtons.OK, MessageBoxIcon.Error); if (windowFrame != null) { try { NativeMethods.ThrowOnFailure(windowFrame.CloseFrame(0)); } catch { } windowFrame = null; } } if (docData != punkDocDataExisting && docData != IntPtr.Zero) { Marshal.Release(docData); } }
protected static void CloseWindowFrame(ref IVsWindowFrame windowFrame) { if (windowFrame != null) { try { windowFrame.CloseFrame(0); } finally { windowFrame = null; } } }
private void CloseWindow(object sender, EventArgs e) { IVsWindowFrame windowFrame = (IVsWindowFrame)this.Frame; windowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave); }
public static void OpenItem(IServiceProvider site, bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr punkDocDataExisting, IVsHierarchy pHierarchy, uint hierarchyId, out IVsWindowFrame windowFrame) { windowFrame = null; IntPtr docData = punkDocDataExisting; try { uint itemid = hierarchyId; object pvar; pHierarchy.GetProperty(hierarchyId, (int)__VSHPROPID.VSHPROPID_Caption, out pvar); string caption = (string)pvar; string fullPath = null; if (punkDocDataExisting != IntPtr.Zero && punkDocDataExisting.ToInt64() != -1L) { fullPath = VsShell.GetFilePath(punkDocDataExisting); } if (fullPath == null) { string dir; pHierarchy.GetProperty((uint)VsConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectDir, out pvar); dir = (string)pvar; pHierarchy.GetProperty(hierarchyId, (int)__VSHPROPID.VSHPROPID_SaveName, out pvar); // todo: what if the path is a URL? fullPath = dir != null ? Path.Combine(dir,(string)pvar) : (string)pvar; } HierarchyNode node = pHierarchy as HierarchyNode; IVsUIHierarchy pRootHierarchy = node == null ? (IVsUIHierarchy) pHierarchy : node.projectMgr; IVsUIHierarchy pVsUIHierarchy = pRootHierarchy; IVsUIShellOpenDocument doc = site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; const uint OSE_ChooseBestStdEditor = 0x20000000; const uint OSE_UseOpenWithDialog = 0x10000000; const uint OSE_OpenAsNewFile = 0x40000000; if (openWith) { IOleServiceProvider psp = site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider; doc.OpenStandardEditor(OSE_UseOpenWithDialog, fullPath, ref logicalView, caption, pVsUIHierarchy, itemid, docData, psp, out windowFrame); } else { // First we see if someone else has opened the requested view of the file. IVsRunningDocumentTable pRDT = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; if (pRDT != null) { uint docCookie; IVsHierarchy ppIVsHierarchy; pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, fullPath, out ppIVsHierarchy, out itemid, out docData, out docCookie); if (ppIVsHierarchy != null && docCookie != VsConstants.VSDOCCOOKIE_NIL && pHierarchy != ppIVsHierarchy && pVsUIHierarchy != ppIVsHierarchy) { // not opened by us, so call IsDocumentOpen with the right IVsUIHierarchy so we avoid the // annoying "This document is opened by another project" message prompt. pVsUIHierarchy = (IVsUIHierarchy)ppIVsHierarchy; itemid = (uint)VsConstants.VSITEMID_SELECTION; } ppIVsHierarchy = null; } IVsUIHierarchy ppHierOpen; uint[] pitemidOpen = new uint[1]; int pfOpen; doc.IsDocumentOpen(pVsUIHierarchy, itemid, fullPath, ref logicalView, (uint)__VSIDOFLAGS.IDO_ActivateIfOpen, out ppHierOpen, pitemidOpen, out windowFrame, out pfOpen); if (pfOpen == 1 && editorType != Guid.Empty) { if (windowFrame != null) { Guid currentEditor; windowFrame.GetGuidProperty((int)__VSFPROPID.VSFPROPID_guidEditorType, out currentEditor); if (currentEditor == editorType) { goto done; } } windowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_PromptSave); windowFrame = null; pfOpen = 0; } if (pfOpen != 1) { uint openFlags = 0; if (newFile) openFlags |= OSE_OpenAsNewFile; //NOTE: we MUST pass the IVsProject in pVsUIHierarchy and the itemid // of the node being opened, otherwise the debugger doesn't work. IOleServiceProvider psp = site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider; if (editorType != Guid.Empty) { doc.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, pRootHierarchy, hierarchyId, docData, psp, out windowFrame); } else { openFlags |= OSE_ChooseBestStdEditor; doc.OpenStandardEditor(openFlags, fullPath, ref logicalView, caption, pRootHierarchy, hierarchyId, docData, psp, out windowFrame); } if (windowFrame != null) { if (newFile) { object var; windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var); IVsPersistDocData ppd = (IVsPersistDocData)var; ppd.SetUntitledDocPath(fullPath); } } } } done: if (windowFrame != null) windowFrame.Show(); } catch (COMException e) { if ((uint)e.ErrorCode != (uint)OleErrors.OLE_E_PROMPTSAVECANCELLED) { #if DEBUG MessageBox.Show(e.Message); #endif } } catch (Exception e) { if (e != null) { #if DEBUG MessageBox.Show(e.Message); #endif } if (docData != punkDocDataExisting && docData != IntPtr.Zero) { Marshal.Release(docData); } } }