visual-studio-2012 - 在 VSPackage 中设置值后如何刷新 Visual Studio 设置

标签 visual-studio-2012 vspackage

在 Visual Studio 扩展中,我定义了一个 VSPackage,其中包含许多命令。在其中一个命令的处理程序中,我使用以下代码设置了用户设置:

SettingsManager settingsManager = new ShellSettingsManager(this);
WritableSettingsStore userSettingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);

userSettingsStore.SetBoolean("Text Editor", "Visible Whitespace", true);

这成功地设置了注册表中的值(在隔离 shell 的情况下为 HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0Exp\Text Editor),但编辑器不会自动收到更改通知,即空白保持隐藏。此外,编辑 > 高级 > 显示空白处的菜单选项保持关闭状态。重新启动 Visual Studio 会进行更改。

如何告诉 Visual Studio 刷新其用户设置的状态,以便其他所有内容都收到更改通知?

最佳答案

ITextView 出现时,我得到了正确的命令。被打开。如果 ITextView,这是重要的原因它没有打开在我看来命令只是失败了。更快的方法是创建一个 Editor Margin 扩展项目(必须安装 VS SDK)。关于 EditorMargin类这样做:

    [Import]
    private SVsServiceProvider _ServiceProvider;

    private DTE2 _DTE2;

    public EditorMargin1(IWpfTextView textView)
    {
        // [...]

        _DTE2 = (DTE2)_ServiceProvider.GetService(typeof(DTE));

        textView.GotAggregateFocus += new EventHandler(textView_GotAggregateFocus);
    }

    void textView_GotAggregateFocus(object sender, EventArgs e)
    {
        _DTE2.Commands.Raise(VSConstants.CMDSETID.StandardCommandSet2K_string,
            (int)VSConstants.VSStd2KCmdID.TOGGLEVISSPACE, null, null);

        //  The following is probably the same
        // _DET2.ExecuteCommand("Edit.ViewWhiteSpace");
    }

注:IWpfTextViewCreationListener如果您不想创建 Margin,应该足够了。了解 MEF 扩展以使用它。

现在,这个设置可能是在 VS2010 之前的 Tools -> Options 页面中控制的。该页面的其他选项可以通过 DTE 自动化进行控制:

_DTE2.Properties["TextEditor", "General"].Item("DetectUTF8WithoutSignature").Value = true;
_DTE2.Properties["Environment", "Documents"].Item("CheckLineEndingsOnLoad").Value = true;
ShellSettingsManager只是关于写入注册表,没有设置刷新功能(如果存在,无论如何它都不会有效,因为它必须重新加载整个设置集合)。以前的那些是我正在寻找的。解决您的问题是一个奖励:)

关于visual-studio-2012 - 在 VSPackage 中设置值后如何刷新 Visual Studio 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14615524/

相关文章:

.net - 如何在 Visual Studio 2013/TFS 中管理类库演变?

c# - 如何从 ClearCase 下载文件?

MySQL 查询 - 使用前后通配符和输入参数进行搜索。 Visual Studio 2012 - VB.NET

c++ - 使用基于 ATL 的库的 Windows 应用商店应用程序认证失败

c# - Visual Studio Extensions - 支持多个版本的 VS

.net - 将项目附加到解决方案资源管理器中解决方案或项目节点的添加菜单

c# - Visual Studio Shell 14 升级破坏了 VSPackage 中的命令捕获

c# - 如何在 VSPackage 中获取 IVsExpansionClient 的实例?

c++ - 在 VS2012 项目上编译 Boost C++ 库

c# - 向 IElisonBuffer 添加语法突出显示