diff --git a/src/TextMateSharp.Demo/Program.cs b/src/TextMateSharp.Demo/Program.cs index 0878ccc..8967132 100644 --- a/src/TextMateSharp.Demo/Program.cs +++ b/src/TextMateSharp.Demo/Program.cs @@ -72,7 +72,7 @@ static void Main(string[] args) int foreground = -1; int background = -1; - int fontStyle = -1; + FontStyle fontStyle = FontStyle.NotSet; foreach (var themeRule in theme.Match(token.Scopes)) { @@ -82,7 +82,7 @@ static void Main(string[] args) if (background == -1 && themeRule.background > 0) background = themeRule.background; - if (fontStyle == -1 && themeRule.fontStyle > 0) + if (fontStyle == FontStyle.NotSet && themeRule.fontStyle > 0) fontStyle = themeRule.fontStyle; } @@ -103,7 +103,7 @@ static void Main(string[] args) Console.WriteLine("ERROR: " + ex.Message); } } - static void WriteToken(string text, int foreground, int background, int fontStyle, Theme theme) + static void WriteToken(string text, int foreground, int background, FontStyle fontStyle, Theme theme) { if (foreground == -1) { @@ -130,7 +130,7 @@ static Color GetColor(int colorId, Theme theme) return HexToColor(theme.GetColor(colorId)); } - static Decoration GetDecoration(int fontStyle) + static Decoration GetDecoration(FontStyle fontStyle) { Decoration result = Decoration.None; diff --git a/src/TextMateSharp.Tests/Internal/Grammars/EncodedTokenAttributesTests.cs b/src/TextMateSharp.Tests/Internal/Grammars/EncodedTokenAttributesTests.cs index f631777..728c484 100644 --- a/src/TextMateSharp.Tests/Internal/Grammars/EncodedTokenAttributesTests.cs +++ b/src/TextMateSharp.Tests/Internal/Grammars/EncodedTokenAttributesTests.cs @@ -86,7 +86,7 @@ public void StackElementMetadata_Should_Work_At_Max_Values() int maxLangId = 255; int maxTokenType = StandardTokenType.Comment | StandardTokenType.Other | StandardTokenType.RegEx | StandardTokenType.String; - int maxFontStyle = FontStyle.Bold | FontStyle.Italic | FontStyle.Underline; + FontStyle maxFontStyle = FontStyle.Bold | FontStyle.Italic | FontStyle.Underline; int maxForeground = 511; int maxBackground = 254; @@ -109,7 +109,7 @@ static void AssertMetadataHasProperties( int languageId, /*StandardTokenType*/ int tokenType, bool containsBalancedBrackets, - int fontStyle, + FontStyle fontStyle, int foreground, int background) { diff --git a/src/TextMateSharp/Internal/Grammars/AttributedScopeStack.cs b/src/TextMateSharp/Internal/Grammars/AttributedScopeStack.cs index 82338dc..3d869ab 100644 --- a/src/TextMateSharp/Internal/Grammars/AttributedScopeStack.cs +++ b/src/TextMateSharp/Internal/Grammars/AttributedScopeStack.cs @@ -124,7 +124,7 @@ public static int MergeAttributes( return existingTokenAttributes; } - int fontStyle = FontStyle.NotSet; + FontStyle fontStyle = FontStyle.NotSet; int foreground = 0; int background = 0; diff --git a/src/TextMateSharp/Internal/Grammars/EncodedTokenAttributes.cs b/src/TextMateSharp/Internal/Grammars/EncodedTokenAttributes.cs index af77af9..0ad09f9 100644 --- a/src/TextMateSharp/Internal/Grammars/EncodedTokenAttributes.cs +++ b/src/TextMateSharp/Internal/Grammars/EncodedTokenAttributes.cs @@ -36,10 +36,10 @@ public static bool ContainsBalancedBrackets(int metadata) return (uintValue & MetadataConsts.BALANCED_BRACKETS_MASK) != 0; } - public static int GetFontStyle(int metadata) + public static FontStyle GetFontStyle(int metadata) { uint uintValue = (uint)metadata; - return (int)((uintValue & MetadataConsts.FONT_STYLE_MASK) >> MetadataConsts.FONT_STYLE_OFFSET); + return (FontStyle)((uintValue & MetadataConsts.FONT_STYLE_MASK) >> MetadataConsts.FONT_STYLE_OFFSET); } public static int GetForeground(int metadata) @@ -59,7 +59,7 @@ public static int Set( int languageId, /*OptionalStandardTokenType*/ int tokenType, bool? containsBalancedBrackets, - int fontStyle, + FontStyle fontStyle, int foreground, int background) { @@ -74,7 +74,7 @@ public static int Set( return ((languageId << MetadataConsts.LANGUAGEID_OFFSET) | (tokenType << MetadataConsts.TOKEN_TYPE_OFFSET) | (containsBalancedBracketsBit << MetadataConsts.BALANCED_BRACKETS_OFFSET) - | (fontStyle << MetadataConsts.FONT_STYLE_OFFSET) + | ((int)fontStyle << MetadataConsts.FONT_STYLE_OFFSET) | (foreground << MetadataConsts.FOREGROUND_OFFSET) | (background << MetadataConsts.BACKGROUND_OFFSET)) >> 0; } diff --git a/src/TextMateSharp/Themes/FontStyle.cs b/src/TextMateSharp/Themes/FontStyle.cs index 02edf56..690f132 100644 --- a/src/TextMateSharp/Themes/FontStyle.cs +++ b/src/TextMateSharp/Themes/FontStyle.cs @@ -1,14 +1,17 @@ +using System; + namespace TextMateSharp.Themes { - public class FontStyle + [Flags] + public enum FontStyle { - public const int NotSet = -1; + NotSet = -1, // This can are bit-flags, so it can be `Italic | Bold` - public const int None = 0; - public const int Italic = 1; - public const int Bold = 2; - public const int Underline = 4; - public const int Strikethrough = 8; + None = 0, + Italic = 1, + Bold = 2, + Underline = 4, + Strikethrough = 8 } } \ No newline at end of file diff --git a/src/TextMateSharp/Themes/ParsedThemeRule.cs b/src/TextMateSharp/Themes/ParsedThemeRule.cs index 3010e33..cb924e8 100644 --- a/src/TextMateSharp/Themes/ParsedThemeRule.cs +++ b/src/TextMateSharp/Themes/ParsedThemeRule.cs @@ -11,11 +11,11 @@ public class ParsedThemeRule public int index; // -1 if not set.An or mask of `FontStyle` otherwise. - public int fontStyle; + public FontStyle fontStyle; public string foreground; public string background; - public ParsedThemeRule(string name, string scope, List parentScopes, int index, int fontStyle, string foreground, string background) + public ParsedThemeRule(string name, string scope, List parentScopes, int index, FontStyle fontStyle, string foreground, string background) { this.name = name; this.scope = scope; @@ -31,7 +31,7 @@ public override int GetHashCode() int prime = 31; int result = 1; result = prime * result + ((background == null) ? 0 : background.GetHashCode()); - result = prime * result + fontStyle; + result = prime * result + (int)fontStyle; result = prime * result + ((foreground == null) ? 0 : foreground.GetHashCode()); result = prime * result + index; result = prime * result + ((parentScopes == null) ? 0 : parentScopes.GetHashCode()); diff --git a/src/TextMateSharp/Themes/Theme.cs b/src/TextMateSharp/Themes/Theme.cs index 7da84d3..4b6eba7 100644 --- a/src/TextMateSharp/Themes/Theme.cs +++ b/src/TextMateSharp/Themes/Theme.cs @@ -147,7 +147,7 @@ static void LookupThemeRules( scopes.Add(""); } - int fontStyle = FontStyle.NotSet; + FontStyle fontStyle = FontStyle.NotSet; object settingsFontStyle = entry.GetSetting().GetFontStyle(); if (settingsFontStyle is string) { @@ -159,16 +159,16 @@ static void LookupThemeRules( switch (segment) { case "italic": - fontStyle = fontStyle | FontStyle.Italic; + fontStyle |= FontStyle.Italic; break; case "bold": - fontStyle = fontStyle | FontStyle.Bold; + fontStyle |= FontStyle.Bold; break; case "underline": - fontStyle = fontStyle | FontStyle.Underline; + fontStyle |= FontStyle.Underline; break; case "strikethrough": - fontStyle = fontStyle | FontStyle.Strikethrough; + fontStyle |= FontStyle.Strikethrough; break; } } @@ -240,7 +240,7 @@ static ParsedTheme ResolveParsedThemeRules( }); // Determine defaults - int defaultFontStyle = FontStyle.None; + FontStyle defaultFontStyle = FontStyle.None; string defaultForeground = "#000000"; string defaultBackground = "#ffffff"; while (parsedThemeRules.Count >= 1 && "".Equals(parsedThemeRules[0].scope)) diff --git a/src/TextMateSharp/Themes/ThemeTrieElement.cs b/src/TextMateSharp/Themes/ThemeTrieElement.cs index ee1b13d..94e67db 100644 --- a/src/TextMateSharp/Themes/ThemeTrieElement.cs +++ b/src/TextMateSharp/Themes/ThemeTrieElement.cs @@ -106,7 +106,7 @@ public List Match(string scope) return ThemeTrieElement.SortBySpecificity(arr); } - public void Insert(string name, int scopeDepth, string scope, List parentScopes, int fontStyle, int foreground, + public void Insert(string name, int scopeDepth, string scope, List parentScopes, FontStyle fontStyle, int foreground, int background) { if ("".Equals(scope)) @@ -144,7 +144,7 @@ public void Insert(string name, int scopeDepth, string scope, List paren child.Insert(name, scopeDepth + 1, tail, parentScopes, fontStyle, foreground, background); } - private void DoInsertHere(string name, int scopeDepth, List parentScopes, int fontStyle, int foreground, + private void DoInsertHere(string name, int scopeDepth, List parentScopes, FontStyle fontStyle, int foreground, int background) { diff --git a/src/TextMateSharp/Themes/ThemeTrieElementRule.cs b/src/TextMateSharp/Themes/ThemeTrieElementRule.cs index f90ab1f..4d3d36c 100644 --- a/src/TextMateSharp/Themes/ThemeTrieElementRule.cs +++ b/src/TextMateSharp/Themes/ThemeTrieElementRule.cs @@ -9,12 +9,12 @@ public class ThemeTrieElementRule public int scopeDepth; public List parentScopes; - public int fontStyle; + public FontStyle fontStyle; public int foreground; public int background; public string name; - public ThemeTrieElementRule(string name, int scopeDepth, List parentScopes, int fontStyle, int foreground, + public ThemeTrieElementRule(string name, int scopeDepth, List parentScopes, FontStyle fontStyle, int foreground, int background) { this.name = name; @@ -41,7 +41,7 @@ public static List cloneArr(List arr return r; } - public void AcceptOverwrite(string name, int scopeDepth, int fontStyle, int foreground, int background) + public void AcceptOverwrite(string name, int scopeDepth, FontStyle fontStyle, int foreground, int background) { if (this.scopeDepth > scopeDepth) {