private void UpdateOptionsFromPolicy() { if (policyContainer == null) { ClearOptionValue(DefaultOptions.ConvertTabsToSpacesOptionName); ClearOptionValue(DefaultOptions.TabSizeOptionName); ClearOptionValue(DefaultOptions.IndentSizeOptionName); ClearOptionValue(DefaultOptions.NewLineCharacterOptionName); ClearOptionValue(DefaultOptions.TrimTrailingWhiteSpaceOptionName); #if !WINDOWS EditorOptions.ClearOptionValue(DefaultTextViewOptions.VerticalRulersName); #endif return; } var mimeTypes = IdeServices.DesktopService.GetMimeTypeInheritanceChain(MimeType); var currentPolicy = policyContainer.Get <TextStylePolicy> (mimeTypes); SetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionName, currentPolicy.TabsToSpaces); SetOptionValue(DefaultOptions.TabSizeOptionName, currentPolicy.TabWidth); SetOptionValue(DefaultOptions.IndentSizeOptionName, currentPolicy.IndentWidth); SetOptionValue(DefaultOptions.NewLineCharacterOptionName, currentPolicy.GetEolMarker()); SetOptionValue(DefaultOptions.TrimTrailingWhiteSpaceOptionName, currentPolicy.RemoveTrailingWhitespace); #if !WINDOWS EditorOptions.SetOptionValue( DefaultTextViewOptions.VerticalRulersName, PropertyService.Get <bool> ("ShowRuler") ? new [] { currentPolicy.FileWidth } : Array.Empty <int> ()); #endif }
EditorOptionsFactoryService([ImportMany] IEnumerable<EditorOptionDefinition> editorOptionDefinitions) { this.editorOptionDefinitions = new Dictionary<string, EditorOptionDefinition>(); foreach (var o in editorOptionDefinitions) { Debug.Assert(!this.editorOptionDefinitions.ContainsKey(o.Name)); this.editorOptionDefinitions[o.Name] = o; } GlobalOptions = new EditorOptions(this, null, null); GlobalOptions.SetOptionValue(DefaultTextViewOptions.WordWrapStyleId, WordWrapStylesConstants.DefaultValue); }
private Task UpdateOptionsFromEditorConfigAsync(object sender, CodingConventionsChangedEventArgs args) { // Set base options first, then override with editorconfig values UpdateOptionsFromPolicy(); if (editorConfigContext == null) { return(Task.CompletedTask); } if (editorConfigContext.CurrentConventions.UniversalConventions.TryGetIndentStyle(out var indentStyle)) { SetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionName, indentStyle == IndentStyle.Spaces); } if (editorConfigContext.CurrentConventions.UniversalConventions.TryGetTabWidth(out var tabWidth)) { SetOptionValue(DefaultOptions.TabSizeOptionName, tabWidth); } if (editorConfigContext.CurrentConventions.UniversalConventions.TryGetIndentSize(out var indentSize)) { SetOptionValue(DefaultOptions.IndentSizeOptionName, indentSize); } if (editorConfigContext.CurrentConventions.UniversalConventions.TryGetLineEnding(out var lineEnding)) { SetOptionValue(DefaultOptions.NewLineCharacterOptionName, lineEnding); } if (editorConfigContext.CurrentConventions.UniversalConventions.TryGetAllowTrailingWhitespace(out var allowTrailingWhitespace)) { SetOptionValue(DefaultOptions.TrimTrailingWhiteSpaceOptionName, !allowTrailingWhitespace); } var setVerticalRulers = false; int [] verticalRulers = null; // "Show column ruler" preference still needs to be checked, regardless of whether or not editorconfig // has a setting for where rulers should appear if (PropertyService.Get <bool> ("ShowRuler")) { if (editorConfigContext.CurrentConventions.TryGetConventionValue <string> (EditorConfigService.RulersConvention, out var rulers)) { setVerticalRulers = true; if (!string.IsNullOrEmpty(rulers)) { verticalRulers = Array.ConvertAll(rulers.Split(','), val => { if (int.TryParse(val, out var col)) { return(col); } return(0); }); } } else if (editorConfigContext.CurrentConventions.TryGetConventionValue <string> (EditorConfigService.MaxLineLengthConvention, out var maxLineLength)) { if (maxLineLength != "off" && int.TryParse(maxLineLength, out var i)) { setVerticalRulers = true; verticalRulers = new [] { i }; } else { setVerticalRulers = false; } } } #if !WINDOWS if (setVerticalRulers) { EditorOptions.SetOptionValue(DefaultTextViewOptions.VerticalRulersName, verticalRulers ?? Array.Empty <int> ()); } #endif return(Task.CompletedTask); }
void SetOptionValue(string optionName, object optionValue) { TextBufferOptions.SetOptionValue(optionName, optionValue); EditorOptions.SetOptionValue(optionName, optionValue); }