private void WindowEvents_WindowActivated(Window gotFocus, Window lostFocus) { // Wire up reference for Caret events var textViewHost = GetCurrentViewHost(); if (textViewHost != null) { _control.TextView = textViewHost.TextView; textViewHost.TextView.Caret.PositionChanged += Caret_PositionChanged; // Subscribe to Outlining events var outliningManager = OutliningHelper.GetManager(Package as CodeNavToolWindowPackage, GetCurrentViewHost().TextView); if (outliningManager == null) { return; } _control.OutliningManager = outliningManager; outliningManager.RegionsExpanded -= OutliningManager_RegionsExpanded; outliningManager.RegionsExpanded += OutliningManager_RegionsExpanded; outliningManager.RegionsCollapsed -= OutliningManager_RegionsCollapsed; outliningManager.RegionsCollapsed += OutliningManager_RegionsCollapsed; } UpdateDocument(gotFocus, gotFocus != lostFocus); }
/// <summary> /// Creates an <see cref="IWpfTextViewMargin"/> for the given <see cref="IWpfTextViewHost"/>. /// </summary> /// <param name="wpfTextViewHost">The <see cref="IWpfTextViewHost"/> for which to create the <see cref="IWpfTextViewMargin"/>.</param> /// <param name="marginContainer">The margin that will contain the newly-created margin.</param> /// <returns>The <see cref="IWpfTextViewMargin"/>. /// The value may be null if this <see cref="IWpfTextViewMarginProvider"/> does not participate for this context. /// </returns> public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin marginContainer) { if (Settings.Default.MarginSide != MarginSideEnum.Right) { return(null); } var dte = (DTE)_serviceProvider.GetService(typeof(DTE)); var outliningManager = OutliningHelper.GetManager(_serviceProvider, wpfTextViewHost.TextView); Logger.Initialize(_serviceProvider, "CodeNav"); var codeNav = new CodeNavMargin(wpfTextViewHost, dte, outliningManager, Workspace, MarginSideEnum.Right); return(codeNav); }