I'm trying to configure the tabs settings of a single document from within a VSIX extension, without touching the global settings of Visual Studio. While this works perfectly fine for XML documents, it doesn't work for CSharp files.
The settings are applied to both the IWpfTextView and ITextBuffer instances after a new document is opened, but Visual Studio still uses the global settings. Does anybody know what I'm doing wrong?
Relevant code:
public static void ApplyDataMinerIndentationSettings(ITextBuffer textBuffer)
{
if (textBuffer.Properties.TryGetProperty(typeof(IEditorOptions), out IEditorOptions options))
{
ApplyDataMinerIndentationSettings(options);
}
}
public static void ApplyDataMinerIndentationSettings(IWpfTextView textView)
{
if (textView.Properties.TryGetProperty(typeof(IEditorOptions), out IEditorOptions options))
{
ApplyDataMinerIndentationSettings(options);
}
}
public static void ApplyDataMinerIndentationSettings(IEditorOptions options)
{
options.SetOptionValue(DefaultOptions.IndentSizeOptionId, defaultIndentSizeOption);
options.SetOptionValue(DefaultOptions.TabSizeOptionId, defaultTabSizeOption);
options.SetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionId, defaultConvertTabsToSpacesOption);
options.OptionChanged += IEditorOptions_OptionChanged;
}
private static void IEditorOptions_OptionChanged(object sender, EditorOptionChangedEventArgs e)
{
IEditorOptions options = sender as IEditorOptions;
if (options != null)
{
if (e.OptionId == DefaultOptions.IndentSizeOptionId.Name)
{
if (options.GetOptionValue(DefaultOptions.IndentSizeOptionId) != defaultIndentSizeOption)
options.SetOptionValue(DefaultOptions.IndentSizeOptionId, defaultIndentSizeOption);
}
else if (e.OptionId == DefaultOptions.TabSizeOptionId.Name)
{
if (options.GetOptionValue(DefaultOptions.TabSizeOptionId) != defaultTabSizeOption)
options.SetOptionValue(DefaultOptions.TabSizeOptionId, defaultTabSizeOption);
}
else if (e.OptionId == DefaultOptions.ConvertTabsToSpacesOptionId.Name)
{
if (options.GetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionId) != defaultConvertTabsToSpacesOption)
options.SetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionId, defaultConvertTabsToSpacesOption);
}
}
}