[英]VSIX (Visual Studio Extension) “Fonts and Colors” changed event
I am writing a Visual Studio 2012/2013 Extension and for performance reasons, all the configuration values are cached. 我正在编写Visual Studio 2012/2013扩展,出于性能原因,缓存了所有配置值。
To make changes in "Fonts and Colors" visible in real-time i need to know, when the options where changed by the user. 要在实时可见的“字体和颜色”中进行更改,我需要知道,当用户更改选项时。
Is there a way to be notified if any option settings were changed by the user? 如果用户更改了任何选项设置,是否有通知方法?
At the moment I have a workaround and use the Windows.WindowCreated
event in my Initialize method: 目前我有一个解决方法,并在我的Initialize方法中使用
Windows.WindowCreated
事件:
Dispatcher.CurrentDispatcher.BeginInvoke(
new Action( () => {
DTE.Events.WindowEvents.WindowCreated += WindowEvents_WindowCreated;
} ), DispatcherPriority.ApplicationIdle, null );
You can use the IVsTextManagerEvents.OnUserPreferencesChanged event. 您可以使用IVsTextManagerEvents.OnUserPreferencesChanged事件。 See VS Package - Receiving Option Fonts and Color Change Events for a code sample.
请参阅VS包 - 接收选项字体和颜色更改事件以获取代码示例。
The event you are looking for is IEditorFormatMap::FormatMappingChanged
. 您正在寻找的事件是
IEditorFormatMap::FormatMappingChanged
。 This will fire when a value in the "Fonts and Colors" section is changed. 当“字体和颜色”部分中的值更改时,将触发此操作。 This interface is specific to a particular
ITextView
instance but you could easily aggregate it over all ITextView
instances that are created. 此接口特定于特定的
ITextView
实例,但您可以轻松地在创建的所有ITextView
实例上聚合它。
To get this interface you will need to import IEditorFormatMapFactoryService
. 要获得此接口,您需要导入
IEditorFormatMapFactoryService
。 This service provides a mapping from ITextView
-> IEditorFormatMap
此服务提供来自
ITextView
- > IEditorFormatMap
的映射
Thanks for all the input. 感谢所有的投入。 I think I found something useful.
我想我发现了一些有用的东西。 I have a
IWpfTextViewCreationListener
. 我有一个
IWpfTextViewCreationListener
。 I added following code lines: 我添加了以下代码行:
[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 */
}
The FormatItemsEventArgs
include all the changed fonts and colors. FormatItemsEventArgs
包含所有已更改的字体和颜色。 That is exactly what I needed. 这正是我所需要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.