【问题标题】:Performance of changing Visual Studio colors with custom add-in使用自定义加载项更改 Visual Studio 颜色的性能
【发布时间】:2011-04-07 04:36:39
【问题描述】:

我正在为 Visual Studio 2008 创建一个插件,它允许我使用热键在配色方案之间切换。

我让它成功加载配色方案并应用它,但速度很慢。

这是应用方案的代码:

// 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>();
}

基本上,GetItems 从 Visual Studio 的选项中获取 ColorableItems 的列表。在其中一项上设置属性会立即将更改应用到 VS。由于一个配色方案可以包含一百多个属性,这会导致 300 多个更新操作,并且需要很长时间(在我的笔记本电脑上需要 10 多秒)。

我想以某种方式告诉 VS,我不希望它在我更新属性时刷新,当我完成时告诉它更新,但我找不到这样做的方法。

理想情况下,整个过程需要 1 或 2 秒,类似于使用 VS 向导运行导入/导出设置。

我也对其他方法持开放态度。我有一个简单地覆盖注册表设置的想法,但是我需要一种强制 VS 重新加载它的设置的方法。

【问题讨论】:

    标签: visual-studio performance visual-studio-addins envdte vs-extensibility


    【解决方案1】:

    嗯,我找到了一个非常有效的解决方案。我可以简单地调用 Visual Studio 的实际导入/导出设置功能,如下所示:

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

    file 是 vssettings 文件的完整路径。这将在大约 1 秒内运行。

    这需要对我的加载项的工作方式进行一些更改,但这种方式实际上更简单。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-25
      • 1970-01-01
      • 1970-01-01
      • 2013-09-10
      • 1970-01-01
      相关资源
      最近更新 更多