简体   繁体   English

VSIX(Visual Studio扩展)“字体和颜色”改变了事件

[英]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 );

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM