public static void ShowContextMenu(ContextMenuStrip contextMenu, DTE dte) { try { var serviceProvider = new ServiceProvider(dte as IServiceProvider); IVsUIShellOpenDocument sod = (IVsUIShellOpenDocument)serviceProvider.GetService(typeof(SVsUIShellOpenDocument)); IVsUIHierarchy targetHier; uint[] targetId = new uint[1]; IVsWindowFrame targetFrame; int isOpen; Guid viewId = new Guid(LogicalViewID.Primary); sod.IsDocumentOpen(null, 0, dte.ActiveWindow.Document.FullName, ref viewId, 0, out targetHier, targetId, out targetFrame, out isOpen); IVsTextView textView = VsShellUtilities.GetTextView(targetFrame); TextSelection selection = (TextSelection)dte.ActiveWindow.Document.Selection; Microsoft.VisualStudio.OLE.Interop.POINT[] interopPoint = new Microsoft.VisualStudio.OLE.Interop.POINT[1]; textView.GetPointOfLineColumn(selection.ActivePoint.Line, selection.ActivePoint.LineCharOffset, interopPoint); POINT p = new POINT(interopPoint[0].x, interopPoint[0].y); ClientToScreen(textView.GetWindowHandle(), p); contextMenu.Show(new Point(p.x, p.y)); } catch (Exception) { contextMenu.Show(); } }
public static bool TryGetHierarchy(string filePath, out IVsHierarchy vsHierarchy, out uint vsItemId) { bool result = true; vsHierarchy = null; vsItemId = (uint)VSConstants.VSITEMID.Nil; IVsUIShellOpenDocument vsUIShellOpenDocument = ServiceProvider.GlobalProvider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; IOleServiceProvider serviceProviderUnused = null; int docInProject = 0; IVsUIHierarchy uiHier = null; int hr = vsUIShellOpenDocument.IsDocumentInAProject(filePath, out uiHier, out vsItemId, out serviceProviderUnused, out docInProject); if (ErrorHandler.Succeeded(hr) && uiHier != null) { vsHierarchy = uiHier as IVsHierarchy; } else { vsHierarchy = null; vsItemId = (uint)VSConstants.VSITEMID.Nil; result = false; } return(result); }
private void OpenDocumentAndNavigateTo(string path, int startLine, int startColumn, int?endLine = null, int?endColumn = null) { IVsUIShellOpenDocument openDoc = Package.GetGlobalService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument; if (openDoc == null) { return; } Guid logicalView = VSConstants.LOGVIEWID_Code; IVsWindowFrame frame; try { Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp; IVsUIHierarchy hier; uint itemid; openDoc.OpenDocumentViaProject(path, ref logicalView, out sp, out hier, out itemid, out frame); } catch (Exception) { return; } object docData; frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData); // Get the VsTextBuffer VsTextBuffer buffer = docData as VsTextBuffer; if (buffer == null) { IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider; if (bufferProvider != null) { IVsTextLines lines; try { bufferProvider.GetTextBuffer(out lines); } catch (Exception) { return; } buffer = lines as VsTextBuffer; Debug.Assert(buffer != null, "IVsTextLines does not implement IVsTextBuffer"); } } IVsTextManager mgr = Package.GetGlobalService(typeof(VsTextManagerClass)) as IVsTextManager; if (mgr == null) { return; } mgr.NavigateToLineAndColumn(buffer, ref logicalView, startLine - 1, startColumn - 1, (endLine ?? startLine) - 1, (endColumn ?? startColumn) - 1); }
public DeferredInitializationState(VisualStudioWorkspaceImpl workspace, IServiceProvider serviceProvider) : base(assertIsForeground: true) { ServiceProvider = serviceProvider; ShellOpenDocumentService = (IVsUIShellOpenDocument)serviceProvider.GetService(typeof(SVsUIShellOpenDocument)); ProjectTracker = new VisualStudioProjectTracker(serviceProvider, workspace.Services); // Ensure the document tracking service is initialized on the UI thread var documentTrackingService = (VisualStudioDocumentTrackingService)workspace.Services.GetService <IDocumentTrackingService>(); var documentProvider = new DocumentProvider(ProjectTracker, serviceProvider, documentTrackingService); var metadataReferenceProvider = workspace.Services.GetService <VisualStudioMetadataReferenceManager>(); var ruleSetFileProvider = workspace.Services.GetService <VisualStudioRuleSetManager>(); ProjectTracker.InitializeProviders(documentProvider, metadataReferenceProvider, ruleSetFileProvider); var workspaceHost = new VisualStudioWorkspaceHost(workspace); ProjectTracker.RegisterWorkspaceHost(workspaceHost); ProjectTracker.StartSendingEventsToWorkspaceHost(workspaceHost); var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); var saveEventsService = componentModel.GetService <SaveEventsService>(); saveEventsService.StartSendingSaveEvents(); VisualStudioProjectCacheHostServiceFactory.ConnectProjectCacheServiceToDocumentTracking(workspace.Services, (ProjectCacheService)workspace.CurrentSolution.Services.CacheService); // Ensure the options factory services are initialized on the UI thread workspace.Services.GetService <IOptionService>(); }
public async Task <Uri> GetProjectPathAsync(Uri documentFilePath, CancellationToken cancellationToken) { if (documentFilePath == null) { throw new ArgumentNullException(nameof(documentFilePath)); } _foregroundDispatcher.AssertBackgroundThread(); await _joinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); if (_openDocumentShell == null) { _openDocumentShell = ServiceProvider.GlobalProvider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; } var hostDocumentFilePath = _session.ConvertSharedUriToLocalPath(documentFilePath); var hr = _openDocumentShell.IsDocumentInAProject(hostDocumentFilePath, out var hierarchy, out _, out _, out _); if (ErrorHandler.Succeeded(hr) && hierarchy != null) { ErrorHandler.ThrowOnFailure(((IVsProject)hierarchy).GetMkDocument((uint)VSConstants.VSITEMID.Root, out var path), VSConstants.E_NOTIMPL); return(_session.ConvertLocalPathToSharedUri(path)); } return(null); }
/// <summary> /// Close an open document window /// </summary> /// <param name="closeFlag">Decides how to close the document</param> /// <returns>S_OK if successful, otherwise an error is returned</returns> public virtual int Close(__FRAMECLOSE closeFlag) { if (this.node == null || this.node.ProjectMgr == null || this.node.ProjectMgr.IsClosed) { return(VSConstants.E_FAIL); } if (IsOpenedByUs) { IVsUIShellOpenDocument shell = this.Node.ProjectMgr.Site.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument; Guid logicalView = Guid.Empty; uint grfIDO = 0; IVsUIHierarchy pHierOpen; uint[] itemIdOpen = new uint[1]; IVsWindowFrame windowFrame; int fOpen; ErrorHandler.ThrowOnFailure(shell.IsDocumentOpen(this.Node.ProjectMgr, this.Node.ID, this.Node.Url, ref logicalView, grfIDO, out pHierOpen, itemIdOpen, out windowFrame, out fOpen)); if (windowFrame != null) { return(windowFrame.CloseFrame((uint)closeFlag)); } } return(VSConstants.S_OK); }
private void openProblemInEditor(object sender, MainToolWindowUI.OpenProblemInEditorEventArgs e) { Problem problem = e.Problem; IVsUIShellOpenDocument shellOpenDocument = (IVsUIShellOpenDocument)GetService(typeof(IVsUIShellOpenDocument)); Debug.Assert(shellOpenDocument != null); Guid guidCodeView = VSConstants.LOGVIEWID.Code_guid; Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = null; IVsUIHierarchy hierarchy = null; uint itemId = 0; IVsWindowFrame windowFrame = null; if (shellOpenDocument.OpenDocumentViaProject(problem.FilePath, ref guidCodeView, out sp, out hierarchy, out itemId, out windowFrame) != VSConstants.S_OK) { Debug.WriteLine("Error opening file " + problem.FilePath); return; } Debug.Assert(windowFrame != null); windowFrame.Show(); EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(SDTE)); Debug.Assert(dte != null); Debug.Assert(dte.ActiveDocument != null); var selection = (EnvDTE.TextSelection)dte.ActiveDocument.Selection; Debug.Assert(selection != null); selection.GotoLine(problem.Line > 0 ? problem.Line : 1); // Line cannot be 0 here }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { base.Initialize(); AppDomain.CurrentDomain.UnhandledException += (sender, e) => Helpers.LogException(e.ExceptionObject as Exception); solutionService = (IVsSolution)GetService(typeof(SVsSolution)); solutionService.AdviseSolutionEvents(this, out var cookie); var tpdService = (IVsTrackProjectDocuments2)GetService(typeof(SVsTrackProjectDocuments)); tpdService.AdviseTrackProjectDocumentsEvents(this, out var tpdCookie); UiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); InitializeOptionsStorage(); runningDocumentTable = GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; runningDocumentTable.AdviseRunningDocTableEvents(this, out var rdtCookie); shellOpenDocument = GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; InitializeMenu(); InitializeCommands(); var componentModel = (IComponentModel)GetService(typeof(SComponentModel)); var editorAdaptersFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>(); var textManager = (IVsTextManager)GetService(typeof(SVsTextManager)); BookmarksManager.InitializeAfterPackageInitialization(editorAdaptersFactoryService, textManager); }
internal static void NavigateTo(string view, Guid docViewGuidType, int line, int col) { IVsTextManager textMgr = (IVsTextManager)Instance.GetService(typeof(SVsTextManager)); var model = Instance.GetService(typeof(SComponentModel)) as IComponentModel; var adapter = model.GetService <IVsEditorAdaptersFactoryService>(); IVsTextView viewAdapter; IVsUIShellOpenDocument uiShellOpenDocument = Instance.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; IVsUIHierarchy hierarchy; uint itemid; IVsWindowFrame pWindowFrame; VsShellUtilities.OpenDocument( Instance, view, Guid.Empty, out hierarchy, out itemid, out pWindowFrame, out viewAdapter); ErrorHandler.ThrowOnFailure(pWindowFrame.Show()); // Set the cursor at the beginning of the declaration. ErrorHandler.ThrowOnFailure(viewAdapter.SetCaretPos(line, col)); // Make sure that the text is visible. viewAdapter.CenterLines(line, 1); /*TextSpan visibleSpan = new TextSpan(); * visibleSpan.iStartLine = line; * visibleSpan.iStartIndex = col; * visibleSpan.iEndLine = line; * visibleSpan.iEndIndex = col + 1;*/ //ErrorHandler.ThrowOnFailure(viewAdapter.EnsureSpanVisible(visibleSpan)); }
//========================================================================================== // Methods //========================================================================================== /// <summary> /// Closes the document that this node represents. Does not save the document before closing. /// </summary> public override void Close() { DocumentInfo docInfo = Context.RunningDocumentTable.FindByPath(this.AbsolutePath); // We only want to close the file if it's open and our hierarchy owns it. if (docInfo != null && docInfo.IsOpen && docInfo.VisualStudioHierarhcy == this.Hierarchy) { // We have to retrieve the window frame so we can close it. We do that through // querying IVsUIShellOpenDocument.IsDocumentOpen. IVsUIShellOpenDocument shellOpenDoc = (IVsUIShellOpenDocument)this.Hierarchy.ServiceProvider.GetServiceOrThrow(typeof(SVsUIShellOpenDocument), typeof(IVsUIShellOpenDocument), classType, "Close"); // These are all of the out parameters to the shell call. Guid logicalView = Guid.Empty; IVsUIHierarchy openDocUIHierarchy; uint[] openDocHierarchyId = new uint[1]; IVsWindowFrame openDocWindowFrame; int isOpen; // Make the shell call to ultimately get the window frame. int hr = shellOpenDoc.IsDocumentOpen(this.Hierarchy, this.HierarchyId, this.AbsolutePath, ref logicalView, 0, out openDocUIHierarchy, openDocHierarchyId, out openDocWindowFrame, out isOpen); NativeMethods.ThrowOnFailure(hr); // Close the window frame. if (openDocWindowFrame != null) { hr = openDocWindowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave); NativeMethods.ThrowOnFailure(hr); } } base.Close(); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { Guid xmlGuid = GuidList.ConfigModuleEditorFactory; IVsUIShellOpenDocument shellOpenDocument = (IVsUIShellOpenDocument)ServiceProvider.GetService(typeof(IVsUIShellOpenDocument)); string physicalView = null; Guid logicalViewGuid = VSConstants.LOGVIEWID_Primary; Microsoft.VisualStudio.OLE.Interop.IServiceProvider ppSP; IVsUIHierarchy ppHier; IVsWindowFrame ppWindowFrame; uint pitemid; shellOpenDocument.OpenDocumentViaProjectWithSpecific(_fileName, (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_DoOpen, ref xmlGuid, physicalView, ref logicalViewGuid, out ppSP, out ppHier, out pitemid, out ppWindowFrame); if (ppWindowFrame != null) { ppWindowFrame.Show(); } }
/// <summary> /// Get the window frame associated with this location. /// </summary> /// <param name="openIfClosed">Should the frame be opened if it is not yet open?</param> /// <returns></returns> public IVsWindowFrame GetWindowFrame(bool openIfClosed) { Validate(); IVsWindowFrame windowFrame = null; IVsUIShellOpenDocument doc = Common.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; if (doc != null) { IVsUIHierarchy uihier = project as IVsUIHierarchy; // also works if project==null Guid textViewGuid = new Guid(LogicalViewID.TextView); IVsWindowFrame frame; IVsUIHierarchy uiHierOpen; uint[] itemIds = { 0 }; int open; //note: we explicitly only look at a *text* views belonging to the correct project // we do not want a designer form, or a view opened from another project that might // have been build using different settings. However, this code also works if the // project and itemid are unknown, but in that case we just pick the first best text // view. int hr = doc.IsDocumentOpen(uihier, itemId, FilePath, ref textViewGuid , 0, out uiHierOpen, itemIds, out frame, out open); //success if ((open != 0) && (frame != null) && (project == null || uihier == uiHierOpen) && (itemId == Nil || itemId == itemIds[0])) { windowFrame = frame; } // failure: try to open it. else if (openIfClosed) { if (ValidProject()) { hr = project.OpenItem(itemId, ref textViewGuid, IntPtr.Zero, out frame); if (hr == 0 && frame != null) { windowFrame = frame; } } else { Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp; uint item; hr = doc.OpenDocumentViaProject(FilePath, ref textViewGuid, out sp, out uiHierOpen, out item, out frame); if (hr == 0 && frame != null) { project = uiHierOpen as IVsProject; if (project != null) { itemId = item; } windowFrame = frame; } } } } return(windowFrame); }
private static void OpenDocument(string filename, out IVsTextView viewAdapter, out IVsWindowFrame pWindowFrame) { IVsTextManager textMgr = (IVsTextManager)Instance.GetService(typeof(SVsTextManager)); IVsUIShellOpenDocument uiShellOpenDocument = Instance.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; IVsUIHierarchy hierarchy; uint itemid; try { VsShellUtilities.OpenDocument( Instance, filename, Guid.Empty, out hierarchy, out itemid, out pWindowFrame, out viewAdapter); } catch (Exception ex) { viewAdapter = null; pWindowFrame = null; if (Instance != null) { Instance.ShowDialog("Error opening file", string.Format("Error opening file {0}: \n{1}", filename, ex.Message)); } } }
/// <summary> /// Close an open document window /// </summary> /// <param name="closeFlag">Decides how to close the document</param> /// <returns>S_OK if successful, otherwise an error is returned</returns> public virtual int Close(__FRAMECLOSE closeFlag) { if (this.node == null || this.node.ProjectMgr == null || this.node.ProjectMgr.IsClosed) { return(VSConstants.E_FAIL); } // Get info about the document bool isDirty, isOpen, isOpenedByUs; uint docCookie; IVsPersistDocData ppIVsPersistDocData; this.GetDocInfo(out isOpen, out isDirty, out isOpenedByUs, out docCookie, out ppIVsPersistDocData); if (isOpenedByUs) { IVsUIShellOpenDocument shell = this.Node.ProjectMgr.Site.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument; Guid logicalView = Guid.Empty; uint grfIDO = 0; IVsUIHierarchy pHierOpen; uint[] itemIdOpen = new uint[1]; IVsWindowFrame windowFrame; int fOpen; ErrorHandler.ThrowOnFailure(shell.IsDocumentOpen(this.Node.ProjectMgr.InteropSafeIVsUIHierarchy, this.Node.ID, this.Node.Url, ref logicalView, grfIDO, out pHierOpen, itemIdOpen, out windowFrame, out fOpen)); if (windowFrame != null) { docCookie = 0; return(windowFrame.CloseFrame((uint)closeFlag)); } } return(VSConstants.S_OK); }
/// <summary> /// Open the file and jump to a line (and optional column) /// </summary> public static void OpenAndNavigateTo(string fileName, int line, int column = 0) { IVsUIShellOpenDocument uishellOpenDocument = Package.GetGlobalService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument; if (uishellOpenDocument != null) { Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider; IVsWindowFrame frame; IVsUIHierarchy hierarchy; uint itemId; Guid logicalView = VSConstants.LOGVIEWID_Code; if (ErrorHandler.Succeeded(uishellOpenDocument.OpenDocumentViaProject(fileName, ref logicalView, out serviceProvider, out hierarchy, out itemId, out frame))) { object document; frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out document); VsTextBuffer buffer = document as VsTextBuffer; if (buffer == null) { IVsTextBufferProvider bufferProvider = document as IVsTextBufferProvider; if (bufferProvider != null) { IVsTextLines lines; ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines)); buffer = lines as VsTextBuffer; } } if (buffer != null) { IVsTextManager textManager = Package.GetGlobalService(typeof(VsTextManagerClass)) as IVsTextManager; textManager.NavigateToLineAndColumn(buffer, ref logicalView, line, column, line, column); } } } }
private IServiceProvider CreateServiceProvider(IVsUIShellOpenDocument vsUiShellOpenDocument) { var serviceProvider = new Mock <IServiceProvider>(); serviceProvider.Setup(x => x.GetService(typeof(SVsUIShellOpenDocument))).Returns(vsUiShellOpenDocument); return(serviceProvider.Object); }
/// <summary> /// Rename document in the running document table from oldName to newName. /// </summary> /// <param name="provider">The service provider.</param> /// <param name="oldName">Full path to the old name of the document.</param> /// <param name="newName">Full path to the new name of the document.</param> /// <param name="newItemId">The new item id of the document</param> public static void RenameDocument(IServiceProvider site, string oldName, string newName, uint newItemId) { Utilities.ArgumentNotNull("site", site); if (String.IsNullOrEmpty(oldName)) { throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty), "oldName"); } if (String.IsNullOrEmpty(newName)) { throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty), "newName"); } if (newItemId == VSConstants.VSITEMID_NIL) { throw new ArgumentNullException("newItemId"); } IVsRunningDocumentTable pRDT = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; IVsUIShellOpenDocument doc = site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; if (pRDT == null || doc == null) { return; } IVsHierarchy pIVsHierarchy; uint itemId; IntPtr docData; uint uiVsDocCookie; ErrorHandler.ThrowOnFailure(pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, oldName, out pIVsHierarchy, out itemId, out docData, out uiVsDocCookie)); if (docData != IntPtr.Zero && pIVsHierarchy != null) { try { IntPtr pUnk = Marshal.GetIUnknownForObject(pIVsHierarchy); Guid iid = typeof(IVsHierarchy).GUID; IntPtr pHier; Marshal.QueryInterface(pUnk, ref iid, out pHier); try { ErrorHandler.ThrowOnFailure(pRDT.RenameDocument(oldName, newName, pHier, newItemId)); } finally { if (pHier != IntPtr.Zero) { Marshal.Release(pHier); } if (pUnk != IntPtr.Zero) { Marshal.Release(pUnk); } } } finally { Marshal.Release(docData); } } }
public static void RenameDocument(ServiceProvider site, string oldName, string newName) { IVsRunningDocumentTable pRDT = (IVsRunningDocumentTable)site.QueryService(VsConstants.SID_SVsRunningDocumentTable, typeof(IVsRunningDocumentTable)); IVsUIShellOpenDocument doc = (IVsUIShellOpenDocument)site.QueryService(VsConstants.SID_VsUIShellOpenDocument, typeof(IVsUIShellOpenDocument)); IVsUIShell uiShell = (IVsUIShell)site.QueryService(VsConstants.guidShellIID, typeof(IVsUIShell)); if (pRDT == null || doc == null) { return; } IVsHierarchy pIVsHierarchy; uint itemId; IntPtr docData; uint uiVsDocCookie; pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, oldName, out pIVsHierarchy, out itemId, out docData, out uiVsDocCookie); if (docData != IntPtr.Zero) { IntPtr pUnk = Marshal.GetIUnknownForObject(pIVsHierarchy); Guid iid = typeof(IVsHierarchy).GUID; IntPtr pHier; Marshal.QueryInterface(pUnk, ref iid, out pHier); try { pRDT.RenameDocument(oldName, newName, pHier, itemId); } finally { Marshal.Release(pHier); Marshal.Release(pUnk); } string newCaption = Path.GetFileName(newName); // now we need to tell the windows to update their captions. IEnumWindowFrames ppenum; uiShell.GetDocumentWindowEnum(out ppenum); IVsWindowFrame[] rgelt = new IVsWindowFrame[1]; uint fetched; while (ppenum.Next(1, rgelt, out fetched) == 0 && fetched == 1) { IVsWindowFrame windowFrame = rgelt[0]; object data; windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out data); IntPtr ptr = Marshal.GetIUnknownForObject(data); if (ptr == docData) { windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_OwnerCaption, newCaption); } Marshal.Release(ptr); } Marshal.Release(docData); } }
public static void OpenDocumentAndNavigateTo(string path, int line, int column) { IVsUIShellOpenDocument openDoc = Package.GetGlobalService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument; if (openDoc == null) { return; } IVsWindowFrame frame; Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp; IVsUIHierarchy hier; uint itemid; Guid logicalView = VSConstants.LOGVIEWID_Code; if (ErrorHandler.Failed( openDoc.OpenDocumentViaProject(path, ref logicalView, out sp, out hier, out itemid, out frame)) || frame == null) { return; } object docData; frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData); // Get the VsTextBuffer VsTextBuffer buffer = docData as VsTextBuffer; if (buffer == null) { IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider; if (bufferProvider != null) { IVsTextLines lines; ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines)); buffer = lines as VsTextBuffer; Debug.Assert(buffer != null, "IVsTextLines does not implement IVsTextBuffer"); if (buffer == null) { return; } } } // Finally, perform the navigation. IVsTextManager mgr = Package.GetGlobalService(typeof(VsTextManagerClass)) as IVsTextManager; if (mgr == null) { return; } mgr.NavigateToLineAndColumn(buffer, ref logicalView, line, column, line, column); }
public BuildLoggingToolWindow() { var componentModel = (IComponentModel)GetService(typeof(SComponentModel)); _dataSource = componentModel.GetService <IFrontEndBuildTableDataSource>(); _openDocument = (IVsUIShellOpenDocument)GetService(typeof(SVsUIShellOpenDocument)); ResetTableControl(); }
private void OpenEditor() { IVsUIShellOpenDocument shell = MySqlDataProviderPackage.GetGlobalService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; IVsWindowFrame winFrame = null; object editor = GetEditor(); object coreEditor = editor; editorGuid = editor.GetType().GUID; if (editor is VSCodeEditor) { coreEditor = (editor as VSCodeEditor).CodeWindow; } IntPtr viewPunk = Marshal.GetIUnknownForObject(coreEditor); IntPtr dataPunk = Marshal.GetIUnknownForObject(this); Guid viewGuid = VSConstants.LOGVIEWID_TextView; // Initialize IDE editor infrastracture int result = shell.InitializeEditorInstance( (uint)0, // Initialization flags. We need default behavior here viewPunk, // View object reference (should implement IVsWindowPane) dataPunk, // Docuemnt object reference (should implement IVsPersistDocData) Moniker, // Document moniker ref editorGuid, // GUID of the editor type null, // Name of the physical view. We use default ref viewGuid, // GUID identifying the logical view. null, // Initial caption defined by the document owner. Will be initialized by the editor later null, // Initial caption defined by the document editor. Will be initialized by the editor later // Pointer to the IVsUIHierarchy interface of the project that contains the document HierarchyAccessor.Hierarchy, (uint)ItemId, // UI hierarchy item identifier of the document in the project system IntPtr.Zero, // Pointer to the IUnknown interface of the document data object if the document data object already exists in the running document table // Project-specific service provider. HierarchyAccessor.ServiceProvider as Microsoft.VisualStudio.OLE.Interop.IServiceProvider, ref commandGroupGuid, // Command UI GUID of the commands to display for this editor. out winFrame // The window frame that contains the editor ); Debug.Assert(winFrame != null && ErrorHandler.Succeeded(result), "Failed to initialize editor"); // if our editor is a text buffer then hook up our language service //if (editor is TextBufferEditor) //{ // // now we tell our text buffer what language service to use // Guid langSvcGuid = typeof(MySqlLanguageService).GUID; // (editor as TextBufferEditor).TextBuffer.SetLanguageServiceID(ref langSvcGuid); //} winFrame.Show(); }
public static void OpenDocument(ServiceProvider provider, string fullPath, out IVsUIHierarchy hierarchy, out uint itemID, out IVsWindowFrame windowFrame, out IVsTextView view) { view = null; windowFrame = null; itemID = VsConstants.VSITEMID_NIL; hierarchy = null; //open document IVsUIShellOpenDocument shellOpenDoc = (IVsUIShellOpenDocument)provider.QueryService(VsConstants.SID_SVsUIShellOpenDocument, typeof(IVsUIShellOpenDocument)); IVsRunningDocumentTable pRDT = (IVsRunningDocumentTable)provider.QueryService(VsConstants.SID_SVsRunningDocumentTable, typeof(IVsRunningDocumentTable)); if (pRDT != null) { IntPtr punkDocData; uint docCookie; uint pitemid; IVsHierarchy ppIVsHierarchy; pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, fullPath, out ppIVsHierarchy, out pitemid, out punkDocData, out docCookie); if (punkDocData == IntPtr.Zero) { Microsoft.VisualStudio.OLE.Interop.IServiceProvider psp; uint itemid; Guid logicalView = Guid.Empty; shellOpenDoc.OpenDocumentViaProject(fullPath, ref logicalView, out psp, out hierarchy, out itemid, out windowFrame); if (windowFrame != null) { windowFrame.Show(); } psp = null; } else { Marshal.Release(punkDocData); Guid logicalView = Guid.Empty; int pfOpen; shellOpenDoc.IsDocumentOpen((IVsUIHierarchy)ppIVsHierarchy, pitemid, fullPath, ref logicalView, (uint)__VSIDOFLAGS.IDO_IgnoreLogicalView, out hierarchy, out itemID, out windowFrame, out pfOpen); if (windowFrame != null) { windowFrame.Show(); } } } //return objects WindowFrameGetTextView(windowFrame, out view); }
public bool JumpToView(string full_path, int start, int length) { if (m_open_document == null) { m_open_document = m_provider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; } if (m_open_document == null) { return(false); } return(ALanguageUtility.OpenFile(m_open_document, m_adapters_factory, full_path, start, length)); }
private IVsWindowFrame CreateChildEditorFrame(Guid guidEditorFactory, SplitterPanel panel) { ThreadHelper.ThrowIfNotOnUIThread(); IVsUIShellOpenDocument vsUISHOD = GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; IVsWindowFrame childFrame = null; IVsUIHierarchy vsUIHier; uint itemid; int fOpen; Guid guidLogEditorView = Guid.Empty; IOleServiceProvider oleServiceProvider; int hr = vsUISHOD.IsSpecificDocumentViewOpen((IVsUIHierarchy)this.vsHierarchy, this.itemid, this.fileName, ref guidEditorFactory, null, 0, out vsUIHier, out itemid, out childFrame, out fOpen); if (ErrorHandler.Succeeded(hr) && fOpen != 0) { // if already open, create a copy hr = vsUISHOD.OpenCopyOfStandardEditor(childFrame, ref guidLogEditorView, out childFrame); } else { hr = vsUISHOD.OpenDocumentViaProjectWithSpecific(fileName, (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_UseEditor | (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_DoOpen, ref guidEditorFactory, null, ref guidLogEditorView, out oleServiceProvider, out vsUIHier, out itemid, out childFrame); } if (ErrorHandler.Failed(hr)) { Debug.Fail("Failed to create/open editor!!!"); Marshal.ThrowExceptionForHR(hr); } IVsWindowFrame parentFrame = GetService(typeof(SVsWindowFrame)) as IVsWindowFrame; if (parentFrame == null) { throw new System.InvalidOperationException("could not retrieve the parent Window Frame"); } childFrame.SetProperty((int)__VSFPROPID2.VSFPROPID_ParentFrame, parentFrame); childFrame.SetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, this); childFrame.SetProperty((int)__VSFPROPID3.VSFPROPID_NotifyOnActivate, true); childFrame.SetProperty((int)__VSFPROPID5.VSFPROPID_DontAutoOpen, true); childFrame.SetProperty((int)__VSFPROPID2.VSFPROPID_ParentHwnd, panel.Handle); Guid cmdUITextEditorGuid = VSConstants.GUID_TextEditorFactory; childFrame.SetGuidProperty((int)__VSFPROPID.VSFPROPID_InheritKeyBindings, ref cmdUITextEditorGuid); return(childFrame); }
private void NavigateTo(object sender, EventArgs arguments) { Microsoft.VisualStudio.Shell.Task task = sender as Microsoft.VisualStudio.Shell.Task; if (task == null) throw new ArgumentException("sender"); // Get the doc data for the task's document if (String.IsNullOrEmpty(task.Document)) return; IVsUIShellOpenDocument openDoc = serviceProvider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument; if (openDoc == null) return; IVsWindowFrame frame; IOleServiceProvider sp; IVsUIHierarchy hier; uint itemid; Guid logicalView = VSConstants.LOGVIEWID_Code; if (Microsoft.VisualStudio.ErrorHandler.Failed(openDoc.OpenDocumentViaProject(task.Document, ref logicalView, out sp, out hier, out itemid, out frame)) || frame == null) return; object docData; frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData); // Get the VsTextBuffer VsTextBuffer buffer = docData as VsTextBuffer; if (buffer == null) { IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider; if (bufferProvider != null) { IVsTextLines lines; Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines)); buffer = lines as VsTextBuffer; Debug.Assert(buffer != null, "IVsTextLines does not implement IVsTextBuffer"); if (buffer == null) return; } } // Finally, perform the navigation. IVsTextManager mgr = serviceProvider.GetService(typeof(VsTextManagerClass)) as IVsTextManager; if (mgr == null) return; mgr.NavigateToLineAndColumn(buffer, ref logicalView, task.Line, task.Column, task.Line, task.Column); }
public PreviewTabEditorManager(Lifetime lifetime, ProjectModelSynchronizer projectModelSynchronizer, IVsUIShellOpenDocument vsUiShellOpenDocument, VsDocumentManagerSynchronization vsDocumentManagerSynchronization, ITextControlManager textControlManager, IFrameFocusHelper frameFocusHelper, DocumentManager documentManager, DocumentTransactionManager documentTransactionManager, IThreading threading) : base(lifetime, projectModelSynchronizer, vsUiShellOpenDocument, vsDocumentManagerSynchronization, textControlManager, frameFocusHelper, documentManager) { this.documentTransactionManager = documentTransactionManager; this.threading = threading; previewTabRequests = 0; }
/// <summary> /// Opens the file via the project instead of as a misc file. /// </summary> public async Task OpenDocumentViaProjectAsync(string fileName) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsUIShellOpenDocument openDoc = await VS.GetRequiredServiceAsync <SVsUIShellOpenDocument, IVsUIShellOpenDocument>(); System.Guid viewGuid = VSConstants.LOGVIEWID_TextView; if (ErrorHandler.Succeeded(openDoc.OpenDocumentViaProject(fileName, ref viewGuid, out _, out _, out _, out IVsWindowFrame frame))) { if (frame != null) { frame.Show(); } } }
/// <include file='doc\ShellTextBuffer.uex' path='docs/doc[@for="ShellTextBuffer.GetWindowFrame"]/*' /> /// <devdoc> /// This will retrieve a code editor window for this document. It /// will ask VS to create the code editor if it doesn't already /// exist. /// </devdoc> private IVsWindowFrame GetWindowFrame(Guid logview) { // Open the editor // IVsUIShellOpenDocument openDoc = (IVsUIShellOpenDocument)serviceProvider. GetService(typeof(IVsUIShellOpenDocument)); // This should never happen // if (openDoc == null) { Debug.Fail("Cannot show document - could not get IVsUIShellOpenDocument service"); throw new COMException("Required IVsUIShellOpenDocument service does not exist.", NativeMethods.E_UNEXPECTED); } return(openDoc.OpenDocumentViaProject(FileName, ref logview, null, null, null)); }
private static void OpenDocument(string filename, out IVsTextView viewAdapter, out IVsWindowFrame pWindowFrame) { IVsTextManager textMgr = (IVsTextManager)Current.GetService(typeof(SVsTextManager)); IVsUIShellOpenDocument uiShellOpenDocument = Current.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; IVsUIHierarchy hierarchy; uint itemid; VsShellUtilities.OpenDocument( Current, filename, Guid.Empty, out hierarchy, out itemid, out pWindowFrame, out viewAdapter); }
public override void NavigateToFileAndPosition(string file, int line, int col, int lineEnd = 0, int columnEnd = 0) { IVsUIShellOpenDocument openDoc = AspectPackage.GetGlobalService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument; IVsWindowFrame frame; Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp; IVsUIHierarchy hier; uint itemid; Guid logicalView = VSConstants.LOGVIEWID_Code; if (ErrorHandler.Failed(openDoc.OpenDocumentViaProject(file, ref logicalView, out sp, out hier, out itemid, out frame)) || frame == null) { return; } object docData; frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData); // Get the VsTextBuffer VsTextBuffer buffer = docData as VsTextBuffer; if (buffer == null) { IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider; if (bufferProvider != null) { IVsTextLines lines; ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines)); buffer = lines as VsTextBuffer; if (buffer == null) { return; } } } IVsTextManager mgr = AspectPackage.GetGlobalService(typeof(VsTextManagerClass)) as IVsTextManager; if (lineEnd == 0) { lineEnd = line; columnEnd = col; } mgr.NavigateToLineAndColumn(buffer, ref logicalView, line - 1, col, lineEnd - 1, columnEnd); }
public override int OpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction) { frame = null; Debug.Assert(editorType == VSConstants.GUID_ProjectDesignerEditor, "Cannot open project designer with guid " + editorType.ToString()); if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed) { 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; if (serviceProvider != null && uiShellOpenDocument != null) { string fullPath = this.GetFullPathForDocument(); string caption = this.GetOwnerCaption(); IVsUIHierarchy parentHierarchy = this.Node.ProjectMgr.GetProperty((int)__VSHPROPID.VSHPROPID_ParentHierarchy) as IVsUIHierarchy; IntPtr parentHierarchyItemId = (IntPtr)this.Node.ProjectMgr.GetProperty((int)__VSHPROPID.VSHPROPID_ParentHierarchyItemid); //add code 不显示工程属性界面,打开Setting界面 BabePackage.WindowManager.ShowSettingWindow(); if (Babe.Lua.ToolWindows.SettingWndPane.Current != null) { Babe.Lua.ToolWindows.SettingWndPane.Current.ShowToLuaFolder(); } return(VSConstants.S_FALSE); /* * ErrorHandler.ThrowOnFailure(uiShellOpenDocument.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, parentHierarchy, (uint)(parentHierarchyItemId.ToInt32()), docDataExisting, serviceProvider, out frame)); * * if (frame != null) * { * if (windowFrameAction == WindowFrameShowAction.Show) * { * ErrorHandler.ThrowOnFailure(frame.Show()); * } * }*/ } return(VSConstants.S_OK); }
/// <summary> /// Constructor stores DataViewHierarchyAccessor reference in the private variable. /// </summary> /// <param name="hierarchy">DataViewHierarchyAccessor reference.</param> public ServerExplorerFacade(DataViewHierarchyAccessor hierarchy) { if (hierarchy == null) throw new ArgumentNullException("hierarchy"); if (hierarchy.Connection == null) throw new ArgumentException(Resources.Error_InvalidAccessorNoConnection, "hierarchy"); // Store hierarchy accessor reference hierarchyAccessor = hierarchy; //Extract connection wrapper connectionWrapper = new DataConnectionWrapper(hierarchy.Connection); // Get UI shell object uiShell = Package.GetGlobalService(typeof(IVsUIShell)) as IVsUIShell; Debug.Assert(uiShell != null, "Unable to get UI shell"); if (uiShell == null) throw new Exception(Resources.Error_UnableToGetUIShell); // Retrieve IVsUIShellOpenDocument interface shell = Package.GetGlobalService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; Debug.Assert(shell != null, "Unable to get IVsUIShellOpenDocument reference!"); if (shell == null) throw new Exception(Resources.Error_UnableToGetOpenDocumentShell); // Get RDT interface rdt = Package.GetGlobalService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; Debug.Assert(rdt != null, "Unable to get Running Document Table interface reference!"); if (rdt == null) throw new Exception(Resources.Error_UnableToGetRdt); // Get RDT2 interface rdt2 = rdt as IVsRunningDocumentTable2; Debug.Assert(rdt2 != null, "Unable to get Running Document Table extended interface reference!"); if (rdt2 == null) throw new Exception(Resources.Error_UnableToGetRdt); }