[英]VSIX (Visual Studio Extension) “Fonts and Colors” changed event
我正在編寫Visual Studio 2012/2013擴展,出於性能原因,緩存了所有配置值。
要在實時可見的“字體和顏色”中進行更改,我需要知道,當用戶更改選項時。
如果用戶更改了任何選項設置,是否有通知方法?
目前我有一個解決方法,並在我的Initialize方法中使用Windows.WindowCreated
事件:
Dispatcher.CurrentDispatcher.BeginInvoke(
new Action( () => {
DTE.Events.WindowEvents.WindowCreated += WindowEvents_WindowCreated;
} ), DispatcherPriority.ApplicationIdle, null );
您可以使用IVsTextManagerEvents.OnUserPreferencesChanged事件。 請參閱VS包 - 接收選項字體和顏色更改事件以獲取代碼示例。
您正在尋找的事件是IEditorFormatMap::FormatMappingChanged
。 當“字體和顏色”部分中的值更改時,將觸發此操作。 此接口特定於特定的ITextView
實例,但您可以輕松地在創建的所有ITextView
實例上聚合它。
要獲得此接口,您需要導入IEditorFormatMapFactoryService
。 此服務提供來自ITextView
- > IEditorFormatMap
的映射
感謝所有的投入。 我想我發現了一些有用的東西。 我有一個IWpfTextViewCreationListener
。 我添加了以下代碼行:
[Import]
public IEditorFormatMapService FormatMapService = null; // MEF
public void TextViewCreated( IWpfTextView textView ) {
IEditorFormatMap editorFormatMap = FormatMapService.GetEditorFormatMap( textView );
editorFormatMap.FormatMappingChanged += FormatMapChanged;
}
void FormatMapChanged( object sender, FormatItemsEventArgs e ) {
/* do something */
}
FormatItemsEventArgs
包含所有已更改的字體和顏色。 這正是我所需要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.