/// <summary> /// Gets options for how brace completion should be executed /// </summary> /// <param name="textView"></param> /// <returns></returns> public static BraceOptions GetOptions(ITextView textView) { #if DEBUG DateTime start = DateTime.Now; #endif BraceOptions options = new BraceOptions(); //Get the language (datatype) from the textview options.Language = GetLanguage(textView); //Get language specific options if (PackageProperties == null) PackageProperties = DTE.get_Properties("Environment", "Brace Completion"); options.ImmediateCompletion = (bool)PackageProperties.Item("ImmediateCompletion").Value; options.SmartFormat = (bool)PackageProperties.Item("SmartFormat").Value; switch (options.Language) { case "CSharp": if (CSharpProperties == null) CSharpProperties = DTE.get_Properties("TextEditor", "CSharp-Specific"); options.CompleteBraces = (bool)PackageProperties.Item("CSharp").Value; options.IndentBraces = ParseBool(CSharpProperties.Item("Indent_Braces").Value); options.IndentBlock = ParseBool(CSharpProperties.Item("Indent_BlockContents").Value, true); break; case "C/C++": //As much as this is supposed to work, it doesn't :( //Properties langProperties = _dte.get_Properties("TextEditor", "C/C++ Specific"); //options.indentBraces = ParseValue(langProperties.Item("IndentBraces").Value); //options.indentBlock = true; options.CompleteBraces = (bool)PackageProperties.Item("Cpp").Value; options.IndentBraces = (bool)PackageProperties.Item("CppIndentBraces").Value; options.IndentBlock = true; break; case "CSS": options.CompleteBraces = (bool)PackageProperties.Item("Css").Value; break; case "JScript": options.CompleteBraces = (bool)PackageProperties.Item("JScript").Value; break; case "JavaScript": case "TypeScript": options.CompleteBraces = (bool)PackageProperties.Item("JavaScript").Value; break; case "plaintext": options.CompleteBraces = (bool)PackageProperties.Item("PlainText").Value; break; default: string[] otherLangs = ((string)PackageProperties.Item("OtherLanguages").Value).Split(','); options.CompleteBraces = false; //search for the language in OtherLanguages. If "All" is present, activate completion foreach (string activelang in otherLangs) { if (string.Compare(options.Language, activelang.Trim(), StringComparison.OrdinalIgnoreCase) == 0 || string.Compare("All", activelang.Trim(), StringComparison.OrdinalIgnoreCase) == 0) { options.CompleteBraces = true; break; } } break; } #if DEBUG TimeSpan span = DateTime.Now - start; Debug.Print("retrieve options: {0}ms", span.TotalMilliseconds); #endif return options; }
/// <summary> /// Loads settings from Visual Studio /// </summary> private void LoadSettings() { float version = 10; float.TryParse(Utils.DTE.Version, out version); // get the indentation options from Visual Studio _options = Utils.GetOptions(_textView); // set options to account for differences in Visual Studio's behavior between languages _languageUnindentsBraceBeforeBrace = new List<string> { "CSharp" }.Contains(_options.Language); _languageUsesSmartFormat = new List<string> { "CSharp" }.Contains(_options.Language); var doesNotUnindentBrace = new List<string> { "CSharp", "C/C++", "JavaScript", "TypeScript", "CSS" }; _languageAlwaysUnindentsBrace = !doesNotUnindentBrace.Contains(_options.Language); var doesNotNeedBlockIndent = new List<string> { "CSharp", "C/C++", "CSS", "TypeScript" }; _languageNeedsBlockIndent = !doesNotNeedBlockIndent.Contains(_options.Language); Debug.Print("Brace completion {0:enabled;disabled} in {1} TextView.", _options.CompleteBraces, _options.Language); }