public static IVsHierarchy GetHierarchy(Project project) { IVsHierarchy ppHierarchy; ErrorHandler.ThrowOnFailure(VisualStudioServices.GetService <SVsSolution, IVsSolution>().GetProjectOfUniqueName(project.UniqueName, out ppHierarchy)); return(ppHierarchy); }
///////////////////////////////////////////////////////////////////////////// // Overridden Package Implementation #region Package Members /// <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() { Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); base.Initialize(); VisualStudioServices.Initialize(this); this.CreateToolWindow(typeof(SearchLocalsToolWindow), 0); //KnownUIContexts.DebuggingContext.UIContextChanged += DebuggingContext_UIContextChanged; CreateMenuCommands(); AddMenuCommands(); }
/// <summary> /// This function is the callback used to execute a command when the a menu item is clicked. /// 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 MenuItemCallback(object sender, EventArgs e) { IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); Guid clsid = Guid.Empty; IVsTextManager txtMgr = VisualStudioServices.GetService <SVsTextManager, IVsTextManager>(); int mustHaveFocus = 1; IVsTextView vTextView = null; txtMgr.GetActiveView(mustHaveFocus, null, out vTextView); string textUnderCursor = CodeUnderCursor.GetExpression(vTextView); ShowToolWindow(textUnderCursor); }