Forcing View Settings
Usually, settings for core editor features, such as word wrap, selection margin, and virtual space, can be changed by the user as needed through settings in the Options dialog box. Sometimes, however, you might want to change these settings programmatically, such as when you are programming a tool that requires certain editor settings and you want to change them so that your users do not have to. Programmatically changing settings also is known as "forcing" the settings.
How Settings are Forced
Settings are forced by using the IVsTextEditorPropertyCategoryContainer interface. This interface allows objects like the text view to expose a set of text editor properties. The text view contains a category of properties (GUID_EditPropCategory_View_MasterSettings) that represents the group of forced settings for the text view. Once view settings have been forced, they cannot be manipulated in the Options dialog box until the forcing is removed.
Forcing View Settings
Following is the typical process for forcing view settings for an instance of the core editor.
Call QueryInterface on the IDE's view object (VsTextView) for the IVsTextEditorPropertyCategoryContainer interface.
Call the GetPropertyCategory method, specifying a value of GUID_EditPropCategory_View_MasterSettings for the rguidCategory parameter.
Doing this returns a pointer to the IVsTextEditorPropertyCategoryContainer interface, which contains the set of forced properties for the view. Any settings in this group are permanently forced. If a setting is not in this group, then it will follow the options specified in the Options dialog box or the user's commands.
Call the SetProperty method, specifying the appropriate settings value in the idprop parameter.
For example, to force word wrap, call SetProperty and specify a value of VSEDITPROPID_ViewLangOpt_WordWrap, vt for the idprop parameter. In this call, vt is a VARIANT of type VT_BOOL and vt.boolVal is VARIANT_TRUE.
Removing Forced View Settings
To remove any forced view setting for an instance of the core editor, call the RemoveProperty method and specify the appropriate setting value in the idprop parameter.
For example, to allow word wrap to float freely, you would remove it from the property category by calling RemoveProperty and specifying a value of VSEDITPROPID_ViewLangOpt_WordWrap for the idprop parameter.
To remove all forced settings for the core editor at once, specify a value of VSEDITPROPID_ViewComposite_AllCodeWindowDefaults, vt for the idprop parameter. In this call, vt is a VARIANT of type VT_BOOL and vt.boolVal is VARIANT_TRUE.
See Also
Concepts
Reference
Options Dialog Box (Visual Studio)