简体   繁体   中英

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.

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:

Dispatcher.CurrentDispatcher.BeginInvoke(
    new Action( () => {
        DTE.Events.WindowEvents.WindowCreated += WindowEvents_WindowCreated;
    } ), DispatcherPriority.ApplicationIdle, null );

The event you are looking for is 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.

To get this interface you will need to import IEditorFormatMapFactoryService . This service provides a mapping from ITextView -> IEditorFormatMap

Thanks for all the input. I think I found something useful. I have a 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. That is exactly what I needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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