How to refresh Visual Studio settings after setting a value in a VSPackage

こ雲淡風輕ζ 提交于 2019-12-05 13:23:35

I got it raising the right command when a ITextView is opened. This is important cause if a ITextView it's not opened it seems to me the command just fails. The quicker way is to create an Editor Margin extension project (VS SDK must be installed). On the EditorMargin class do this:

    [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");
    }

Note: IWpfTextViewCreationListener should be enough if you don't want to create a Margin. Learn about MEF extensions to use it.

Now, this setting was probably controlled in Tools -> Options page prior to VS2010 . Other options of that page can be controlled with DTE automation:

_DTE2.Properties["TextEditor", "General"].Item("DetectUTF8WithoutSignature").Value = true;
_DTE2.Properties["Environment", "Documents"].Item("CheckLineEndingsOnLoad").Value = true;

ShellSettingsManager is only about writing to the registry, there's no settings refresh function (if it exists, it would be not efficient anyway cause it would have to reload the entire collection of settings). The previous ones were what I was looking for. Solving your problem was a bonus :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!