private static void UpdateHilightingColor(HighlightingColor highlightingColor, Highlight highlight)
 {
     highlightingColor.Foreground = new HighlightBrush(highlight.Foreground);
     highlightingColor.Background = new HighlightBrush(highlight.Background);
     highlightingColor.FontStyle  = ConvertFontStyle(highlight.FontStyle);
     highlightingColor.FontWeight = ConvertFontWeight(highlight.FontWeight);
 }
            public object VisitColor(XshdColor color)
            {
                HighlightingColor c;

                if (color.Name != null)
                {
                    c = _def._colorDict[color.Name];
                }
                else if (color.Foreground == null && color.FontStyle == null && color.FontWeight == null)
                {
                    return(null);
                }
                else
                {
                    c = new HighlightingColor();
                }

                c.Name          = color.Name;
                c.Foreground    = color.Foreground;
                c.Background    = color.Background;
                c.Underline     = color.Underline;
                c.Strikethrough = color.Strikethrough;
                c.FontStyle     = color.FontStyle;
                c.FontWeight    = color.FontWeight;
                c.FontFamily    = color.FontFamily;
                c.FontSize      = color.FontSize;
                return(c);
            }
 private void AddColor(HighlightingColor color)
 {
     if (color != null && !string.IsNullOrEmpty(color.Name) && !_namedColors.ContainsKey(color.Name))
     {
         _namedColors.Add(color.Name, color);
     }
 }
Example #4
0
 internal void ApplyColorToElement(VisualLineElement element, HighlightingColor color)
 {
     if (color.Foreground != null)
     {
         Brush b = color.Foreground.GetBrush(CurrentContext);
         if (b != null)
         {
             element.TextRunProperties.SetForegroundBrush(b);
         }
     }
     if (color.Background != null)
     {
         Brush b = color.Background.GetBrush(CurrentContext);
         if (b != null)
         {
             element.BackgroundBrush = b;
         }
     }
     if (color.FontStyle != null || color.FontWeight != null)
     {
         Typeface tf = element.TextRunProperties.Typeface;
         element.TextRunProperties.SetTypeface(new Typeface(
                                                   tf.FontFamily,
                                                   color.FontStyle ?? tf.Style,
                                                   color.FontWeight ?? tf.Weight,
                                                   tf.Stretch
                                                   ));
     }
 }
Example #5
0
            private HighlightingColor Wrap(HighlightingColor color)
            {
                if (color is null)
                {
                    return(null);
                }

                if (!String.IsNullOrEmpty(color.Name) &&
                    NamedColors.TryGetValue(color.Name, out var cachedColor))
                {
                    return(cachedColor);
                }

                var copyColor = color.Clone();

                copyColor.Foreground = color.Foreground is null ?
                                       null : new MixHighlightingBrush(color.Foreground, foreColor);

                if (!String.IsNullOrEmpty(copyColor.Name))
                {
                    NamedColors[copyColor.Name] = copyColor;
                }

                return(copyColor);
            }
 public static void AdjustHighlightingColour(HighlightingColor current, Color desired)
 {
     if (!desired.Equals(current.Foreground.GetColor(_colourContext)))
     {
         current.Foreground = new CustomHighlightingBrush(desired);
     }
 }
 internal void Colorize(TextLocation start, TextLocation end, HighlightingColor color)
 {
     if (color == null)
     {
         return;
     }
     if (start.Line <= lineNumber && end.Line >= lineNumber)
     {
         int lineStartOffset = line.DocumentLine.Offset;
         int lineEndOffset   = lineStartOffset + line.DocumentLine.Length;
         int startOffset     = lineStartOffset + (start.Line == lineNumber ? start.Column - 1 : 0);
         int endOffset       = lineStartOffset + (end.Line == lineNumber ? end.Column - 1 : line.DocumentLine.Length);
         // For some parser errors, the mcs parser produces grossly wrong locations (e.g. miscounting the number of newlines),
         // so we need to coerce the offsets to valid values within the line
         startOffset = startOffset.CoerceValue(lineStartOffset, lineEndOffset);
         endOffset   = endOffset.CoerceValue(lineStartOffset, lineEndOffset);
         if (line.Sections.Count > 0)
         {
             HighlightedSection prevSection = line.Sections.Last();
             if (startOffset < prevSection.Offset + prevSection.Length)
             {
                 // The mcs parser sometimes creates strange ASTs with duplicate nodes
                 // when there are syntax errors (e.g. "int A() public static void Main() {}"),
                 // so we'll silently ignore duplicate colorization.
                 return;
                 //throw new InvalidOperationException("Cannot create unordered highlighting section");
             }
         }
         line.Sections.Add(new HighlightedSection {
             Offset = startOffset,
             Length = endOffset - startOffset,
             Color  = color
         });
     }
 }
            public object VisitSpan(XshdSpan span)
            {
                string endRegex = span.EndRegex;

                if (string.IsNullOrEmpty(span.BeginRegex) && string.IsNullOrEmpty(span.EndRegex))
                {
                    throw Error(span, "Span has no start/end regex.");
                }
                if (!span.Multiline)
                {
                    if (endRegex == null)
                    {
                        endRegex = "$";
                    }
                    else if (span.EndRegexType == XshdRegexType.IgnorePatternWhitespace)
                    {
                        endRegex = "($|" + endRegex + "\n)";
                    }
                    else
                    {
                        endRegex = "($|" + endRegex + ")";
                    }
                }
                HighlightingColor wholeSpanColor = GetColor(span, span.SpanColorReference);

                return(new HighlightingSpan {
                    StartExpression = CreateRegex(span, span.BeginRegex, span.BeginRegexType),
                    EndExpression = CreateRegex(span, endRegex, span.EndRegexType),
                    RuleSet = GetRuleSet(span, span.RuleSetReference),
                    StartColor = MergeColor(wholeSpanColor, GetColor(span, span.BeginColorReference)),
                    SpanColor = wholeSpanColor,
                    EndColor = MergeColor(wholeSpanColor, GetColor(span, span.EndColorReference)),
                });
            }
Example #9
0
        public Component_ShaderScript_DocumentWindow()
        {
            InitializeComponent();

            if (WinFormsUtility.IsDesignerHosted(this))
            {
                return;
            }

            UpdateHighlightingScheme();
            UpdateBackgroundForeground();
            UpdateFont();

            HighlightingColor defaultNamedColor = null;

            if (loadedHighlightingDefinition != null)
            {
                defaultNamedColor = loadedHighlightingDefinition.GetNamedColor("Default");
            }

            if (defaultNamedColor != null)
            {
                avalonTextEditor.Editor.Foreground = defaultNamedColor.Foreground.GetBrush(null);
            }

            avalonTextEditor.Editor.PreviewMouseWheel += Editor_PreviewMouseWheel;

            avalonTextEditor.InstallSearchReplacePanel();
            //searchReplacePanel = SearchReplacePanel.Install( avalonTextEditor.Editor.TextArea );
        }
#pragma warning disable IDE0051 // Remove unused private members -- this will be used later
        private void SetBackgroundColor(string colorName, Color newColor)
#pragma warning restore IDE0051 // Remove unused private members
        {
            HighlightingColor color = cottleHighlightingDef.GetNamedColor(colorName);

            color.Background = new SimpleHighlightingBrush(newColor);
        }
            public object VisitColor(XshdColor color)
            {
                HighlightingColor c;

                if (color.Name != null)
                {
                    c = def.colorDict[color.Name];
                }
                else if (color.Foreground == null && color.FontStyle == null && color.FontWeight == null)
                {
                    return(null);
                }
                else
                {
                    c = new HighlightingColor();
                }

                c.Name       = color.Name;
                c.Foreground = color.Foreground;
                c.Background = color.Background;
                c.Underline  = color.Underline;
                c.FontStyle  = color.FontStyle;
                c.FontWeight = color.FontWeight;
                return(c);
            }
 internal static HighlightingColor CustomizeColor(HighlightingColor color, IEnumerable <CustomizedHighlightingColor> customizations)
 {
     if (color == null || color.Name == null)
     {
         return(color);
     }
     return(CustomizeColor(color.Name, customizations) ?? color);
 }
Example #13
0
 public static HighlightingColor AsFrozen(this HighlightingColor color)
 {
     if (!color.IsFrozen)
     {
         color.Freeze();
     }
     return(color);
 }
 private static HighlightingColor AsFrozen(HighlightingColor color)
 {
     if (!color.IsFrozen)
     {
         color.Freeze();
     }
     return(color);
 }
Example #15
0
        public void TestRoundTripColor()
        {
            HighlightingColor color      = highlighter.GetNamedColor("Comment");
            string            jsonString = JsonConvert.SerializeObject(color);

            HighlightingColor color2 = JsonConvert.DeserializeObject <HighlightingColor>(jsonString);

            Assert.AreEqual(color, color2);
        }
Example #16
0
        void OnThemeUpdated(IThemeManager themeManager)
        {
            var theme = themeManager.Theme;

            CodeBreakpointHighlightingColor         = theme.GetTextColor(ColorType.BreakpointStatement).ToHighlightingColor();
            CodeBreakpointDisabledHighlightingColor = theme.GetTextColor(ColorType.DisabledBreakpointStatement).ToHighlightingColor();
            StackFrameCurrentHighlightingColor      = theme.GetTextColor(ColorType.CurrentStatement).ToHighlightingColor();
            StackFrameReturnHighlightingColor       = theme.GetTextColor(ColorType.ReturnStatement).ToHighlightingColor();
            StackFrameSelectedHighlightingColor     = theme.GetTextColor(ColorType.SelectedReturnStatement).ToHighlightingColor();
        }
Example #17
0
 /// <summary>
 /// Gets whether the color is empty (has no effect on a VisualLineTextElement).
 /// For example, the C# "Punctuation" is an empty color.
 /// </summary>
 internal static bool IsEmptyColor(HighlightingColor color)
 {
     if (color == null)
     {
         return(true);
     }
     return(color.Background == null && color.Foreground == null &&
            color.FontStyle == null && color.FontWeight == null &&
            color.Underline == null);
 }
Example #18
0
        static void OnThemeUpdated()
        {
            var theme = dntheme.Themes.Theme;

            CodeBreakpointHighlightingColor         = theme.GetColor(dntheme.ColorType.BreakpointStatement).TextInheritedColor;
            CodeBreakpointDisabledHighlightingColor = theme.GetColor(dntheme.ColorType.DisabledBreakpointStatement).TextInheritedColor;
            StackFrameCurrentHighlightingColor      = theme.GetColor(dntheme.ColorType.CurrentStatement).TextInheritedColor;
            StackFrameReturnHighlightingColor       = theme.GetColor(dntheme.ColorType.ReturnStatement).TextInheritedColor;
            StackFrameSelectedHighlightingColor     = theme.GetColor(dntheme.ColorType.SelectedReturnStatement).TextInheritedColor;
        }
Example #19
0
 public SearchResultMatch(FileName fileName, Location startLocation, Location endLocation, int offset, int length, HighlightedInlineBuilder builder, HighlightingColor defaultTextColor)
 {
     this.fileName         = fileName;
     this.startLocation    = startLocation;
     this.endLocation      = endLocation;
     this.offset           = offset;
     this.length           = length;
     this.builder          = builder;
     this.defaultTextColor = defaultTextColor;
 }
        public HighlightingDefinition AddRule(string expression, HighlightingColor color)
        {
            var rule = new HighlightingRule
            {
                Regex = expression.ToRegex(),
                Color = color
            };

            return(AddRule(rule));
        }
        private void EndSpan()
        {
            if (textOutput != null)
            {
                textOutput.EndSpan();
                return;
            }

            HighlightingModel.SetHighlighting(currentColorBegin, locatable.Length - currentColorBegin, currentColor);
            currentColor      = colorStack.Pop();
            currentColorBegin = locatable.Length;
        }
 private Brush GetHCBrush(HighlightingColor color, DependencyProperty prop)
 {
     if (prop == TextElement.ForegroundProperty)
     {
         return((Brush) new BrushConverter().ConvertFromInvariantString(color.Foreground.ToString()));
     }
     if (prop == TextElement.BackgroundProperty)
     {
         return((Brush) new BrushConverter().ConvertFromInvariantString(color.Background.ToString()));
     }
     throw new Exception("Incorrect property");
 }
Example #23
0
        private void ChangeFontWeight(string colorName, FontWeight weight)
        {
            HighlightingColor targetColor = TextEditor1.SyntaxHighlighting.NamedHighlightingColors.GetByName(colorName);

            if (null != targetColor)
            {
                targetColor.FontWeight = weight;
            }
            else
            {
                Console.WriteLine("HighlightingColor not found {0}", colorName);
            }
        }
Example #24
0
        private void ChangeNamedHighlightingColor(string colorName, System.Drawing.Color color)
        {
            HighlightingColor targetColor = TextEditor1.SyntaxHighlighting.NamedHighlightingColors.GetByName(colorName);

            if (null != targetColor)
            {
                targetColor.Foreground = new CustomBrush(color);
            }
            else
            {
                Console.WriteLine("HighlightingColor not found {0}", colorName);
            }
        }
Example #25
0
 public void BeginSpan(HighlightingColor highlightingColor)
 {
     WriteIndent();
     if (currentColorBegin > -1)
     {
         HighlightingModel.SetHighlighting(currentColorBegin, b.Length - currentColorBegin, currentColor);
     }
     colorStack.Push(currentColor);
     currentColor      = currentColor.Clone();
     currentColorBegin = b.Length;
     currentColor.MergeWith(highlightingColor);
     currentColor.Freeze();
 }
        public override void WritePrimitiveType(string type)
        {
            HighlightingColor color = null;

            switch (type)
            {
            case "new":
            case "notnull":
                // Not sure if reference type or value type
                color = referenceTypeKeywordsColor;
                break;

            case "bool":
            case "byte":
            case "char":
            case "decimal":
            case "double":
            case "enum":
            case "float":
            case "int":
            case "long":
            case "sbyte":
            case "short":
            case "struct":
            case "uint":
            case "ushort":
            case "ulong":
            case "unmanaged":
            case "nint":
            case "nuint":
                color = valueTypeKeywordsColor;
                break;

            case "class":
            case "object":
            case "string":
            case "void":
            case "dynamic":
                color = referenceTypeKeywordsColor;
                break;
            }
            if (color != null)
            {
                BeginSpan(color);
            }
            base.WritePrimitiveType(type);
            if (color != null)
            {
                EndSpan();
            }
        }
 HighlightingColor GetColor(XshdElement position, XshdReference<XshdColor> colorReference)
 {
     if (colorReference.InlineElement != null) {
         return (HighlightingColor)colorReference.InlineElement.AcceptVisitor(this);
     } else if (colorReference.ReferencedElement != null) {
         IHighlightingDefinition definition = GetDefinition(position, colorReference.ReferencedDefinition);
         HighlightingColor color = definition.GetNamedColor(colorReference.ReferencedElement);
         if (color == null)
             throw Error(position, "Could not find color named '" + colorReference.ReferencedElement + "'.");
         return color;
     } else {
         return null;
     }
 }
 static HighlightingColor MergeColor(HighlightingColor baseColor, HighlightingColor newColor)
 {
     if (baseColor == null)
     {
         return(newColor);
     }
     if (newColor == null)
     {
         return(baseColor);
     }
     return(new HighlightingColor {
         Foreground = newColor.Foreground ?? baseColor.Foreground,
         FontWeight = newColor.FontWeight ?? baseColor.FontWeight,
         FontStyle = newColor.FontStyle ?? baseColor.FontStyle,
     });
 }
Example #29
0
        private void UpdateHighlightingStyles(AsyncServerMessage.LanguageLoaded languageInfo)
        {
            _highlightingStyles[CurrentAstSpanClassId] = new HighlightingColor {
                Background = new SimpleHighlightingBrush(Brushes.LightCyan)
            };

            foreach (var spanClassInfo in languageInfo.spanClassInfos)
            {
                _highlightingStyles[spanClassInfo.Id] =
                    new HighlightingColor
                {
                    Foreground = new SimpleHighlightingBrush(ColorFromArgb(spanClassInfo.ForegroundColor))
                }
            }
            ;
        }
        public override void WritePrimitiveType(string type)
        {
            HighlightingColor color = null;

            switch (type)
            {
            case "new":
                color = typeKeywordsColor;
                break;

            case "bool":
            case "byte":
            case "char":
            case "decimal":
            case "double":
            case "enum":
            case "float":
            case "int":
            case "long":
            case "sbyte":
            case "short":
            case "struct":
            case "uint":
            case "ushort":
            case "ulong":
                color = valueTypeKeywordsColor;
                break;

            case "class":
            case "object":
            case "string":
            case "void":
                color = referenceTypeKeywordsColor;
                break;
            }
            if (color != null)
            {
                textOutput.BeginSpan(color);
            }
            base.WritePrimitiveType(type);
            if (color != null)
            {
                textOutput.EndSpan();
            }
        }
 /// <summary>
 /// Applies a highlighting color to a visual line element.
 /// </summary>
 protected virtual void ApplyColorToElement(VisualLineElement element, HighlightingColor color)
 {
     if (color.Foreground != null) {
         Brush b = color.Foreground.GetBrush(CurrentContext);
         if (b != null)
             element.TextRunProperties.SetForegroundBrush(b);
     }
     if (color.Background != null) {
         Brush b = color.Background.GetBrush(CurrentContext);
         if (b != null)
             element.BackgroundBrush = b;
     }
     if (color.FontStyle != null || color.FontWeight != null) {
         Typeface tf = element.TextRunProperties.Typeface;
         element.TextRunProperties.SetTypeface(new Typeface(
             tf.FontFamily,
             color.FontStyle ?? tf.Style,
             color.FontWeight ?? tf.Weight,
             tf.Stretch
         ));
     }
 }
 private static HighlightingColor MergeColor(HighlightingColor baseColor, HighlightingColor newColor)
 {
     if (baseColor == null)
         return newColor;
     if (newColor == null)
         return baseColor;
     return new HighlightingColor
     {
         Foreground = newColor.Foreground ?? baseColor.Foreground,
         FontWeight = newColor.FontWeight ?? baseColor.FontWeight,
         FontStyle = newColor.FontStyle ?? baseColor.FontStyle,
     };
 }
Example #33
0
 /// <summary>
 /// Gets whether the color needs to be written out to HTML.
 /// </summary>
 public virtual bool ColorNeedsSpanForStyling(HighlightingColor color)
 {
     if (color == null)
         throw new ArgumentNullException("color");
     return !string.IsNullOrEmpty(color.ToCss());
 }
 /// <summary>
 /// Gets whether the color is empty (has no effect on a VisualLineTextElement).
 /// For example, the C# "Punctuation" is an empty color.
 /// </summary>
 bool IsEmptyColor(HighlightingColor color)
 {
     if (color == null)
         return true;
     return color.Background == null && color.Foreground == null
         && color.FontStyle == null && color.FontWeight == null;
 }
 void PushColor(HighlightingColor color)
 {
     if (highlightedLine == null)
         return;
     if (color == null) {
         highlightedSectionStack.Push(null);
     } else if (lastPoppedSection != null && lastPoppedSection.Color == color
                && lastPoppedSection.Offset + lastPoppedSection.Length == position + lineStartOffset)
     {
         highlightedSectionStack.Push(lastPoppedSection);
         lastPoppedSection = null;
     } else {
         HighlightedSection hs = new HighlightedSection {
             Offset = position + lineStartOffset,
             Color = color
         };
         highlightedLine.Sections.Add(hs);
         highlightedSectionStack.Push(hs);
         lastPoppedSection = null;
     }
 }
            public object VisitColor(XshdColor color)
            {
                HighlightingColor c;
                if (color.Name != null)
                    c = def.colorDict[color.Name];
                else if (color.Foreground == null && color.FontStyle == null && color.FontWeight == null)
                    return null;
                else
                    c = new HighlightingColor();

                c.Name = color.Name;
                c.Foreground = color.Foreground;
                c.Background = color.Background;
                c.Underline = color.Underline;
                c.FontStyle = color.FontStyle;
                c.FontWeight = color.FontWeight;
                c.FontFamily = color.FontFamily;
                c.FontSize = color.FontSize;
                return c;
            }
 /// <summary>
 /// Applies the properties from the HighlightingColor to the specified text segment.
 /// </summary>
 public void SetHighlighting(int offset, int length, HighlightingColor color)
 {
     if (color == null)
         throw new ArgumentNullException("color");
     if (color.Foreground == null && color.FontStyle == null && color.FontWeight == null) {
         // Optimization: don't split the HighlightingState when we're not changing
         // any property. For example, the "Punctuation" color in C# is
         // empty by default.
         return;
     }
     int startIndex = GetIndexForOffset(offset);
     int endIndex = GetIndexForOffset(offset + length);
     for (int i = startIndex; i < endIndex; i++) {
         HighlightingState state = stateChanges[i];
         if (color.Foreground != null)
             state.Foreground = color.Foreground.GetBrush(null);
         if (color.Background != null)
             state.Background = color.Background.GetBrush(null);
         if (color.FontStyle != null)
             state.Style = color.FontStyle;
         if (color.FontWeight != null)
             state.Weight = color.FontWeight;
     }
 }
Example #38
0
 /// <summary>
 /// Writes the HTML attribute for the style to the text writer.
 /// </summary>
 public virtual void WriteStyleAttributeForColor(TextWriter writer, HighlightingColor color)
 {
     if (writer == null)
         throw new ArgumentNullException("writer");
     if (color == null)
         throw new ArgumentNullException("color");
     writer.Write(" style=\"");
     writer.Write(color.ToCss());
     writer.Write("\"");
 }