繁体   English   中英

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

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

您正在寻找的事件是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.

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