Visual Studio Color Changing Performance with Custom Add-in

I am creating an add-in for Visual Studio 2008 that will allow me to switch between color schemes using a hotkey.

I got it to successfully load the color scheme and apply it, but it is very slow.

Here is the code that applies the circuit:

// The Theme class is a holder for a color scheme private static void LoadTheme(Theme theme, DTE2 application) { var items = GetItems(application); foreach (var item in items) { if (!theme.Properties.ContainsKey(item.Name)) continue; var prop = theme.Properties[item.Name]; item.Background = prop.Background; item.Foreground = prop.Foreground; item.Bold = prop.Bold; } } private static IEnumerable<ColorableItems> GetItems(DTE2 application) { var fontsAndColorsItems = (FontsAndColorsItems) application .get_Properties("FontsAndColors", "TextEditor") .Item("FontsAndColorsItems") .Object; return fontsAndColorsItems.Cast<ColorableItems>(); } 

Basically, GetItems gets a list of ColorableItems from Visual Studio options. When you set a property on one of these elements, the change is immediately applied to VS. Since the color scheme can contain more than a hundred properties, this leads to 300+ update operations, and it takes a lot of time (10 seconds on my laptop).

I would like to tell VS somehow that I do not want it to be updated while I am updating the properties, and when I finish, say that it is updated, but I cannot find a way to do this.

Ideally, the whole process will take 1 or 2 seconds, similar to running the import / export settings using the VS wizard.

I am also open to alternative approaches. I had the idea of ​​just overwriting the registry settings, but then I need a way to get VS to reload it.

+4
source share
1 answer

Ok, I found a solution that works very well. I can just call the actual Visual Studio import / export functions, for example:

 application.ExecuteCommand( "Tools.ImportandExportSettings", string.Format("/import:\"{0}\"", file)); 

Where file is the full path to the vssettings file. This takes about 1 second.

This will require some changes to my add-in, but it’s actually easier.

+3
source

Source: https://habr.com/ru/post/1347033/


All Articles