///------------------------------------------------------------------------------------------------------------- /// <summary> /// Returns the current contents of a document /// </summary> ///------------------------------------------------------------------------------------------------------------- public string GetDocumentText() { string text = null; IVsPersistDocData docData = null; try { // Get or create the buffer IVsTextLines buffer = GetRunningDocumentTextBuffer(); if (buffer == null) { docData = CreateDocumentData(); buffer = docData as IVsTextLines; } // get the text from the buffer if (buffer != null) { IVsTextStream textStream = buffer as IVsTextStream; if (textStream != null) { int length; int hr = textStream.GetSize(out length); if (ErrorHandler.Succeeded(hr)) { if (length > 0) { IntPtr pText = Marshal.AllocCoTaskMem((length + 1) * 2); try { hr = textStream.GetStream(0, length, pText); if (ErrorHandler.Succeeded(hr)) { text = Marshal.PtrToStringUni(pText); } } finally { Marshal.FreeCoTaskMem(pText); } } else { text = string.Empty; } } } } } finally { if (docData != null) { docData.Close(); } } return(text); }
/// <summary> /// Called by the shell when a node has been renamed from the GUI /// </summary> /// <param name="label">The name of the new label.</param> /// <returns>A success or failure value.</returns> public override int SetEditLabel(string label) { int result = this.DelegateSetPropertyToNested((int)__VSHPROPID.VSHPROPID_EditLabel, label); if (ErrorHandler.Succeeded(result)) { this.RenameNestedProjectInParentProject(label); } return(result); }
private bool IsEDMPackageLoaded() { var vsShell = (IVsShell)GetService(typeof(SVsShell)); Debug.Assert(vsShell != null, "unexpected null value for vsShell"); if (vsShell != null) { var packageGuid = guidEscherPkg; IVsPackage package = null; var hr = vsShell.IsPackageLoaded(ref packageGuid, out package); if (VSErrorHandler.Succeeded(hr) && package != null) { return(true); } } return(false); }
/// <summary> /// Delegates Getproperty calls to the inner nested. /// </summary> /// <param name="propID">The property to delegate.</param> /// <returns>The return of the GetProperty from nested.</returns> private object DelegateGetPropertyToNested(int propID) { if (!this.ProjectMgr.IsClosed) { Debug.Assert(this.nestedHierarchy != null, "The nested hierarchy object must be created before calling this method"); object returnValue; // Do not throw since some project types will return E_FAIL if they do not support a property. int result = this.nestedHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, propID, out returnValue); if (ErrorHandler.Succeeded(result)) { return(returnValue); } } return(null); }
internal void VisitHierarchy(IVsHierarchy root) { if (root == null) { throw new ArgumentNullException("root"); } object pvar; Url baseUri = null; var hr = root.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectDir, out pvar); var projectDir = pvar as string; if (VSErrorHandler.Succeeded(hr) && projectDir != null) { baseUri = new Url(projectDir + Path.DirectorySeparatorChar); } VisitHierarchyItems(root, VSConstants.VSITEMID_ROOT, baseUri, _handler, true); }
public void Show() { var sonarLintOutputPane = VsShellUtils.GetOrCreateSonarLintOutputPane(serviceProvider); Debug.Assert(sonarLintOutputPane != null, "Failed to create SonarLint pane"); if (sonarLintOutputPane == null) { return; } var hr = sonarLintOutputPane.Activate(); Debug.Assert(ErrorHandler.Succeeded(hr), "Failed to activate SonarLint pane: " + hr); if (ErrorHandler.Succeeded(hr)) { toolWindowService.Show(VSConstants.StandardToolWindows.Output); } }
///------------------------------------------------------------------------------------------------------------- /// <summary> /// Creates and loads the document data /// (You must Close() it when done) /// </summary> ///------------------------------------------------------------------------------------------------------------- public IVsPersistDocData CreateDocumentData() { if (IsFile()) { string fullPath = FullPath(); if (!string.IsNullOrEmpty(fullPath)) { IOleServiceProvider serviceProvider = (IOleServiceProvider)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(IOleServiceProvider)); IVsPersistDocData docData = WAUtilities.CreateSitedInstance <IVsPersistDocData>(serviceProvider, typeof(VsTextBufferClass).GUID); if (docData != null) { int hr = docData.LoadDocData(fullPath); if (ErrorHandler.Succeeded(hr)) { return(docData); } } } } return(null); }
private void VisitHierarchyItems(IVsHierarchy hierarchy, uint id, Url baseUrl, HierarchyHandler handler, bool isRootItem) { // Note: some root items (e.g. for a C# .NET Fwk project as of VS2019) say they are not searchable but they are if (!isRootItem && !IsSearchable(hierarchy, id)) { return; } object pvar; var hr = hierarchy.GetProperty(id, (int)__VSHPROPID.VSHPROPID_SaveName, out pvar); var path = pvar as string; if (VSErrorHandler.Succeeded(hr) && path != null) { // Dev10 Bug 653879: Retrieving project item absolute URL is expensive so retrieve when we actually need it. handler(hierarchy, id, new VsProjectItemPath(baseUrl, path)); } hr = hierarchy.GetProperty(id, (int)__VSHPROPID.VSHPROPID_FirstChild, out pvar); if (VSErrorHandler.Succeeded(hr)) { var childId = GetItemId(pvar); while (childId != VSConstants.VSITEMID_NIL) { VisitHierarchyItems(hierarchy, childId, baseUrl, handler, false); hr = hierarchy.GetProperty(childId, (int)__VSHPROPID.VSHPROPID_NextSibling, out pvar); if (VSErrorHandler.Succeeded(hr)) { childId = GetItemId(pvar); } else { break; } } } }
//-------------------------------------------------------------------------------------------- /// <summary> /// Locates the item in the provided hierarchy using the provided moniker /// and return a VsHierarchyItem for it /// </summary> //-------------------------------------------------------------------------------------------- internal static VsHierarchyItem CreateFromMoniker(string moniker, IVsHierarchy hier) { VsHierarchyItem item = null; if (!string.IsNullOrEmpty(moniker) && hier != null) { IVsProject proj = hier as IVsProject; if (proj != null) { int hr; int isFound = 0; uint itemid = VSConstants.VSITEMID_NIL; VSDOCUMENTPRIORITY[] priority = new VSDOCUMENTPRIORITY[1]; hr = proj.IsDocumentInProject(moniker, out isFound, priority, out itemid); if (ErrorHandler.Succeeded(hr) && isFound != 0 && itemid != VSConstants.VSITEMID_NIL) { item = new VsHierarchyItem(itemid, hier); } } } return(item); }
/// <summary> /// Initializes the DTE and the code outline file manager, and hooks up events. /// </summary> private void InitializeSourceOutlinerToolWindow() { var dte = GetService(typeof(_DTE)) as DTE; sourceOutlinerWindow = (SourceOutlineToolWindow)FindToolWindow(typeof(SourceOutlineToolWindow), 0, true); sourceOutlinerWindow.Package = this; OLECRINFO[] crinfo = new OLECRINFO[1]; crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO)); crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime | (uint)_OLECRF.olecrfNeedAllActiveNotifs | (uint)_OLECRF.olecrfNeedSpecActiveNotifs; crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff; crinfo[0].uIdleTimeInterval = 500; // fix a bug that component id not called. if (!HasComponent("sourceOutlinerWindow")) { uint componentID = 0; int hr = componentManager.FRegisterComponent(sourceOutlinerWindow, crinfo, out componentID); if (componentID != 0) { AddComponentToAutoReleasePool("sourceOutlinerWindow", componentID); } if (!ErrorHandler.Succeeded(hr)) { Trace.WriteLine("Initialize->IOleComponent registration failed"); } } sourceOutlinerWindow.InitializeDTE(dte); sourceOutlinerWindow.AddWindowEvents(); sourceOutlinerWindow.AddSolutionEvents(); }
internal static bool IsSearchable(IVsHierarchy hierarchy, uint itemid) { object pvar; var hr = hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_IsNonSearchable, out pvar); var isNonSearchable = pvar as bool?; if (VSErrorHandler.Succeeded(hr) && isNonSearchable != null) { return(!isNonSearchable.Value); } object pvar2; hr = hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_HasEnumerationSideEffects, out pvar2); var hasEnumerationSideEffects = pvar2 as bool?; if (VSErrorHandler.Succeeded(hr) && hasEnumerationSideEffects != null) { return(!hasEnumerationSideEffects.Value); } return(true); }