コード例 #1
0
 /// <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.TextRunProperties.SetBackgroundBrush(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
                                                   ));
     }
 }
コード例 #2
0
ファイル: HighlightedLine.cs プロジェクト: arkanoid1/Yanitta
 public HtmlElement(int offset, int nesting, bool isEnd, HighlightingColor color)
 {
     Offset  = offset;
     Nesting = nesting;
     IsEnd   = isEnd;
     Color   = color;
 }
コード例 #3
0
 internal static void ApplyColorToElement(VisualLineElement element, HighlightingColor color, ITextRunConstructionContext context)
 {
     if (color.Foreground != null)
     {
         Brush b = color.Foreground.GetBrush(context);
         if (b != null)
         {
             element.TextRunProperties.SetForegroundBrush(b);
         }
     }
     if (color.Background != null)
     {
         Brush b = color.Background.GetBrush(context);
         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
                                                   ));
     }
     if (color.Underline ?? false)
     {
         element.TextRunProperties.SetTextDecorations(TextDecorations.Underline);
     }
 }
コード例 #4
0
 public HtmlElement(int offset, int nesting, bool isEnd, HighlightingColor color)
 {
     this.Offset  = offset;
     this.Nesting = nesting;
     this.IsEnd   = isEnd;
     this.Color   = color;
 }
コード例 #5
0
 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;
     }
 }
コード例 #6
0
 void BeginColorSpan()
 {
     WriteIndentationIfNecessary();
     colorStack.Push(currentColor);
     currentColor      = currentColor.Clone();
     currentColorBegin = documentTextWriter.InsertionOffset;
 }
コード例 #7
0
		void BeginColorSpan()
		{
			WriteIndentationIfNecessary();
			colorStack.Push(currentColor);
			currentColor = currentColor.Clone();
			currentColorBegin = documentTextWriter.InsertionOffset;
		}
コード例 #8
0
        /// <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");
            }
            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.FontStyle != null)
                {
                    state.Style = color.FontStyle;
                }
                if (color.FontWeight != null)
                {
                    state.Weight = color.FontWeight;
                }
            }
        }
コード例 #9
0
        /// <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.FontStyle != null)
                {
                    state.Style = color.FontStyle;
                }
                if (color.FontWeight != null)
                {
                    state.Weight = color.FontWeight;
                }
            }
        }
コード例 #10
0
 /// <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.TextRunProperties.SetBackgroundBrush(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
         ));
     }
 }
コード例 #11
0
ファイル: DebuggerColors.cs プロジェクト: arkanoid1/dnSpy
		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;
		}
コード例 #12
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()));
 }
コード例 #13
0
ファイル: DebuggerColors.cs プロジェクト: GreenDamTan/dnSpy
		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();
		}
コード例 #14
0
ファイル: RichText.cs プロジェクト: Zolniu/DigitalRune
		internal RichText(string text, int[] offsets, HighlightingColor[] states)
		{
			this.text = text;
			Debug.Assert(offsets[0] == 0);
			Debug.Assert(offsets.Last() <= text.Length);
			this.stateChangeOffsets = offsets;
			this.stateChanges = states;
		}
コード例 #15
0
		static AstNodeHelper() {
			var highlightingDefinition 	= HighlightingManager.Instance.GetDefinition("C#");
			
			nameSpaceHighLighting 		= highlightingDefinition.NamedHighlightingColors.First( x => x.Name == "NamespaceKeywords");
			regionHighLighting 			= highlightingDefinition.NamedHighlightingColors.First( x => x.Name == "Preprocessor");
			classHighLighting 			= highlightingDefinition.NamedHighlightingColors.First( x => x.Name == "ReferenceTypeKeywords");
			interfaceHighLighting 		= highlightingDefinition.NamedHighlightingColors.First( x => x.Name == "ReferenceTypeKeywords");
			methodHighLighting 			= highlightingDefinition.NamedHighlightingColors.First( x => x.Name == "MethodCall");
		}
コード例 #16
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);
 }
コード例 #17
0
 public HighlightingDefinition AddRule(string expression, HighlightingColor color)
 {
     var rule = new HighlightingRule
     {
         Regex = expression.ToRegex(),
         Color = color
     };
     return AddRule(rule);
 }
コード例 #18
0
		/// <summary>
		/// Creates a new RichTextModelWriter that inserts into document, starting at insertionOffset.
		/// </summary>
		public RichTextModelWriter(RichTextModel richTextModel, IDocument document, int insertionOffset)
			: base(new DocumentTextWriter(document, insertionOffset))
		{
			if (richTextModel == null)
				throw new ArgumentNullException("richTextModel");
			this.richTextModel = richTextModel;
			this.documentTextWriter = (DocumentTextWriter)base.textWriter;
			currentColor = richTextModel.GetHighlightingAt(Math.Max(0, insertionOffset - 1));
		}
コード例 #19
0
ファイル: HtmlOptions.cs プロジェクト: Paccc/SharpDevelop
		/// <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=\"");
			WebUtility.HtmlEncode(color.ToCss(), writer);
			writer.Write('"');
		}
コード例 #20
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;
		}
コード例 #21
0
 /// <summary>
 /// Creates a new RichTextModelWriter that inserts into document, starting at insertionOffset.
 /// </summary>
 public RichTextModelWriter(RichTextModel richTextModel, IDocument document, int insertionOffset)
     : base(new DocumentTextWriter(document, insertionOffset))
 {
     if (richTextModel == null)
     {
         throw new ArgumentNullException("richTextModel");
     }
     this.richTextModel      = richTextModel;
     this.documentTextWriter = (DocumentTextWriter)base.textWriter;
     currentColor            = richTextModel.GetHighlightingAt(Math.Max(0, insertionOffset - 1));
 }
コード例 #22
0
ファイル: Syntax.cs プロジェクト: anaimi/farawla
        protected HighlightingColor GetColor()
        {
            var color = new HighlightingColor();

            color.Foreground = GetForeground();
            color.FontWeight = GetFontWeight();
            color.FontStyle = GetFontStyle();
            color.Name = Name;

            return color;
        }
コード例 #23
0
		public SearchResultMatch(FileName fileName, TextLocation startLocation, TextLocation endLocation, int offset, int length, RichText displayText, HighlightingColor defaultTextColor)
		{
			if (fileName == null)
				throw new ArgumentNullException("fileName");
			this.fileName = fileName;
			this.startLocation = startLocation;
			this.endLocation = endLocation;
			this.offset = offset;
			this.length = length;
			this.displayText = displayText;
			this.defaultTextColor = defaultTextColor;
		}
コード例 #24
0
		/// <inheritdoc/>
		public override void BeginSpan(HighlightingColor highlightingColor)
		{
			WriteIndentationAndSpace();
			if (options.ColorNeedsSpanForStyling(highlightingColor)) {
				htmlWriter.Write("<span");
				options.WriteStyleAttributeForColor(htmlWriter, highlightingColor);
				htmlWriter.Write('>');
				endTagStack.Push("</span>");
			} else {
				endTagStack.Push(null);
			}
		}
コード例 #25
0
        /// <summary>
        /// Sets the HighlightingColor for the specified range of text,
        /// completely replacing the existing highlighting in that area.
        /// </summary>
        public void SetHighlighting(int offset, int length, HighlightingColor color)
        {
            if (length <= 0)
            {
                return;
            }
            int startIndex = GetIndexForOffset(offset);
            int endIndex   = GetIndexForOffset(offset + length);

            stateChanges[startIndex] = color != null?color.Clone() : new HighlightingColor();

            stateChanges.RemoveRange(startIndex + 1, endIndex - (startIndex + 1));
            stateChangeOffsets.RemoveRange(startIndex + 1, endIndex - (startIndex + 1));
        }
コード例 #26
0
 /// <summary>
 /// Creates WPF Run instances that can be used for TextBlock.Inlines.
 /// </summary>
 /// <param name="textSource">The text source that holds the text for this RichTextModel.</param>
 public Run[] CreateRuns(ITextSource textSource)
 {
     Run[] runs = new Run[stateChanges.Count];
     for (int i = 0; i < runs.Length; i++)
     {
         int startOffset         = stateChangeOffsets[i];
         int endOffset           = i + 1 < stateChangeOffsets.Count ? stateChangeOffsets[i + 1] : textSource.TextLength;
         Run r                   = new Run(textSource.GetText(startOffset, endOffset - startOffset));
         HighlightingColor state = stateChanges[i];
         RichText.ApplyColorToTextElement(r, state);
         runs[i] = r;
     }
     return(runs);
 }
コード例 #27
0
ファイル: HtmlClipboard.cs プロジェクト: arkanoid1/Yanitta
 /// <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(nameof(writer));
     }
     if (color == null)
     {
         throw new ArgumentNullException(nameof(color));
     }
     writer.Write(" style=\"");
     writer.Write(color.ToCss());
     writer.Write("\"");
 }
コード例 #28
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=\"");
     WebUtility.HtmlEncode(color.ToCss(), writer);
     writer.Write('"');
 }
コード例 #29
0
 /// <summary>
 /// Creates WPF Run instances that can be used for TextBlock.Inlines.
 /// </summary>
 public Run[] CreateRuns()
 {
     Run[] runs = new Run[stateChanges.Length];
     for (int i = 0; i < runs.Length; i++)
     {
         int startOffset         = stateChangeOffsets[i];
         int endOffset           = i + 1 < stateChangeOffsets.Length ? stateChangeOffsets[i + 1] : text.Length;
         Run r                   = new Run(text.Substring(startOffset, endOffset - startOffset));
         HighlightingColor state = stateChanges[i];
         ApplyColorToTextElement(r, state);
         runs[i] = r;
     }
     return(runs);
 }
コード例 #30
0
ファイル: ExtensionMethods.cs プロジェクト: lovebanyi/dnSpy
 /// <summary>
 /// Converts <paramref name="self"/> to a <see cref="HighlightingColor"/> instance or null
 /// if input is null
 /// </summary>
 /// <param name="self">This</param>
 /// <returns></returns>
 public static HighlightingColor ToHighlightingColor(this IThemeColor self)
 {
     if (self == null)
         return null;
     var hl = new HighlightingColor {
         Name = self.Name,
         FontWeight = self.FontWeight,
         FontStyle = self.FontStyle,
         Underline = null,
         Foreground = MyHighlightingBrush.Create(self.Foreground),
         Background = MyHighlightingBrush.Create(self.Background),
     };
     hl.Freeze();
     return hl;
 }
コード例 #31
0
		/// <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");
			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.FontStyle != null)
					state.Style = color.FontStyle;
				if (color.FontWeight != null)
					state.Weight = color.FontWeight;
			}
		}
コード例 #32
0
        /// <summary>
        /// Applies the HighlightingColor to the specified range of text.
        /// If the color specifies <c>null</c> for some properties, existing highlighting is preserved.
        /// </summary>
        public void ApplyHighlighting(int offset, int length, HighlightingColor color)
        {
            if (color == null || color.IsEmptyForMerge)
            {
                // 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++)
            {
                stateChanges[i].MergeWith(color);
            }
        }
コード例 #33
0
 internal static void ApplyColorToTextElement(TextElement r, HighlightingColor state)
 {
     if (state.Foreground != null)
     {
         r.Foreground = state.Foreground.GetBrush(null);
     }
     if (state.Background != null)
     {
         r.Background = state.Background.GetBrush(null);
     }
     if (state.FontWeight != null)
     {
         r.FontWeight = state.FontWeight.Value;
     }
     if (state.FontStyle != null)
     {
         r.FontStyle = state.FontStyle.Value;
     }
 }
コード例 #34
0
		/// <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.FontStyle != null)
					state.Style = color.FontStyle;
				if (color.FontWeight != null)
					state.Weight = color.FontWeight;
			}
		}
コード例 #35
0
        void Insert(ref int pos, ref int newSectionStart, int insertionEndPos, HighlightingColor color, Stack <int> insertionStack)
        {
            if (newSectionStart >= insertionEndPos)
            {
                // nothing to insert here
                return;
            }

            while (insertionStack.Peek() <= newSectionStart)
            {
                insertionStack.Pop();
            }
            while (insertionStack.Peek() < insertionEndPos)
            {
                int end = insertionStack.Pop();
                // insert the portion from newSectionStart to end
                if (end > newSectionStart)
                {
                    this.Sections.Insert(pos++, new HighlightedSection {
                        Offset = newSectionStart,
                        Length = end - newSectionStart,
                        Color  = color
                    });
                    newSectionStart = end;
                }
            }
            if (insertionEndPos > newSectionStart)
            {
                this.Sections.Insert(pos++, new HighlightedSection {
                    Offset = newSectionStart,
                    Length = insertionEndPos - newSectionStart,
                    Color  = color
                });
                newSectionStart = insertionEndPos;
            }
        }
コード例 #36
0
ファイル: NitraTextEditor.cs プロジェクト: rsdn/nitra
 private void ApplyColorToElement(VisualLineElement element, HighlightingColor color)
 {
   if (color.Foreground != null)
   {
     Brush brush = color.Foreground.GetBrush(base.CurrentContext);
     if (brush != null)
     {
       element.TextRunProperties.SetForegroundBrush(brush);
     }
   }
   if (color.Background != null)
   {
     Brush brush2 = color.Background.GetBrush(base.CurrentContext);
     if (brush2 != null)
     {
       element.TextRunProperties.SetBackgroundBrush(brush2);
     }
   }
   if (color.FontStyle.HasValue || color.FontWeight.HasValue)
   {
     Typeface typeface = element.TextRunProperties.Typeface;
     element.TextRunProperties.SetTypeface(new Typeface(typeface.FontFamily, color.FontStyle ?? typeface.Style, color.FontWeight ?? typeface.Weight, typeface.Stretch));
   }
 }
コード例 #37
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;
 }
コード例 #38
0
		internal static HighlightingColor CustomizeColor(HighlightingColor color, IEnumerable<CustomizedHighlightingColor> customizations)
		{
			if (color == null || color.Name == null)
				return color;
			return CustomizeColor(color.Name, customizations) ?? color;
		}
コード例 #39
0
ファイル: NewTextEditor.cs プロジェクト: lovebanyi/dnSpy
 bool CanAddColor(HighlightingColor color)
 {
     return color != null &&
         (color.FontWeight != null || color.FontStyle != null ||
         color.Foreground != null || color.Background != null);
 }
コード例 #40
0
ファイル: RichTextModel.cs プロジェクト: Paccc/SharpDevelop
		/// <summary>
		/// Sets the HighlightingColor for the specified range of text,
		/// completely replacing the existing highlighting in that area.
		/// </summary>
		public void SetHighlighting(int offset, int length, HighlightingColor color)
		{
			if (length <= 0)
				return;
			int startIndex = GetIndexForOffset(offset);
			int endIndex = GetIndexForOffset(offset + length);
			stateChanges[startIndex] = color != null ? color.Clone() : new HighlightingColor();
			stateChanges.RemoveRange(startIndex + 1, endIndex - (startIndex + 1));
			stateChangeOffsets.RemoveRange(startIndex + 1, endIndex - (startIndex + 1));
		}
コード例 #41
0
ファイル: RichTextModel.cs プロジェクト: Paccc/SharpDevelop
		/// <summary>
		/// Appends another RichTextModel after this one.
		/// </summary>
		internal void Append(int offset, int[] newOffsets, HighlightingColor[] newColors)
		{
			Debug.Assert(newOffsets.Length == newColors.Length);
			Debug.Assert(newOffsets[0] == 0);
			// remove everything before offset:
			while (stateChangeOffsets.Count > 0 && stateChangeOffsets.Last() <= offset) {
				stateChangeOffsets.RemoveAt(stateChangeOffsets.Count - 1);
				stateChanges.RemoveAt(stateChanges.Count - 1);
			}
			// Append the new segments
			for (int i = 0; i < newOffsets.Length; i++) {
				stateChangeOffsets.Add(offset + newOffsets[i]);
				stateChanges.Add(newColors[i]);
			}
		}
コード例 #42
0
 private void AddColor(HighlightingColor color)
 {
     if (color != null && !string.IsNullOrEmpty(color.Name) && !_namedColors.ContainsKey(color.Name)) _namedColors.Add(color.Name, color);
 }
コード例 #43
0
 public HighlightingDefinition AddSpan(string startExpression, string endExpression, HighlightingColor color)
 {
     var span = new HighlightingSpan
     {
         StartExpression = startExpression.ToRegex(),
         EndExpression = endExpression.ToRegex(),
         SpanColor = color,
         SpanColorIncludesStart = true,
         SpanColorIncludesEnd = true
     };
     return AddSpan(span);
 }
コード例 #44
0
 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;
     }
 }
コード例 #45
0
 /// <summary>
 /// Applies a highlighting color to a visual line element.
 /// </summary>
 protected virtual void ApplyColorToElement(VisualLineElement element, HighlightingColor color)
 {
     ApplyColorToElement(element, color, CurrentContext);
 }
コード例 #46
0
 internal static void ApplyColorToElement(VisualLineElement element, HighlightingColor color, ITextRunConstructionContext context)
 {
     if (color.Foreground != null) {
         Brush b = color.Foreground.GetBrush(context);
         if (b != null)
             element.TextRunProperties.SetForegroundBrush(b);
     }
     if (color.Background != null) {
         Brush b = color.Background.GetBrush(context);
         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
         ));
     }
     if(color.Underline ?? false)
        element.TextRunProperties.SetTextDecorations(TextDecorations.Underline);
 }
コード例 #47
0
		/// <inheritdoc/>
		public override void BeginSpan(HighlightingColor highlightingColor)
		{
			WriteIndentationAndSpace();
			if (options.ColorNeedsSpanForStyling(highlightingColor)) {
				htmlWriter.Write("<span");
				options.WriteStyleAttributeForColor(htmlWriter, highlightingColor);
				htmlWriter.Write('>');
				endTagStack.Push("</span>");
			} else {
				endTagStack.Push(null);
			}
		}
コード例 #48
0
 /// <inheritdoc/>
 public override void EndSpan()
 {
     currentColor      = colorStack.Pop();
     currentColorBegin = documentTextWriter.InsertionOffset;
 }
コード例 #49
0
        /// <summary>
        /// Creates a new CodeLanguage Implementation for AHK v 1.1
        /// </summary>
        public CodeLanguageAHKv1()
            : base("ahk-v1.1")
        {
            Name = "AHK v 1.1";

            SELFREF_CAN_BE_OMITTED = false;
            SUPPORTS_STARTUP_CODEDOCUMENT = true;

            if(File.Exists(_settingsFilePath)){
                _settings = SerializerHelper.DeserializeObjectFromFile<AHKSettings>(_settingsFilePath);
                _settings.SettingsSerialisationPath = _settingsFilePath;
            }else{
                // load default settings
                _settings = new AHKSettings(_settingsFilePath);
                _settings.Save();
            }

            var viewmodelMapping = ServiceLocator.Instance.Resolve<IWorkBenchService>().MappingService;

            viewmodelMapping.RegisterMapping(typeof(CodeLanguageSettingsViewModel), typeof(CodeLanguageSettingsView));

            #region Define Language Syntax
            // todo
            // those data is actually thougt to be read out of confic files
            //

            this.LanguageKeywords.AddRange(new CodeKeyWord[]
                {
                    new CodeKeyWord("if"), new CodeKeyWord("else"),
                    new CodeKeyWord("class"), new CodeKeyWord("new"), new CodeKeyWord("this"),new CodeKeyWord("base"), new CodeKeyWord("extends"),
                    new CodeKeyWord("return"), new CodeKeyWord("break"), new CodeKeyWord("continue"),
                    new CodeKeyWord("global"), new CodeKeyWord("static"), new CodeKeyWord("local"), new CodeKeyWord("byref"),
                     new CodeKeyWord("GoTo"), new CodeKeyWord("GoSub"),
                    new CodeKeyWord("loop"), new CodeKeyWord("for"), new CodeKeyWord("while"), new CodeKeyWord("in")
                });

            this.LanguageDirectives.AddRange(CodeLanguageAHKBuildinMethods.GetDirectives());

            var buildins = CodeLanguageAHKBuildinMethods.ReadMembers();
            BuildInMembers.AddRange(buildins);

            #endregion

            #region Load Syntax Definition of AHK

            IHighlightingDefinition customHighlighting;

            Brush b = new SolidColorBrush(Colors.GreenYellow);
            var greenYellowBrush = new HighlightingBrushStaticColor(b);
            var orangeBrush = new HighlightingBrushStaticColor(new SolidColorBrush(Colors.Orange));

            var sr = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Syntax\\Autohotkey.xshd"));
            using(var reader = new XmlTextReader(sr)) {
                customHighlighting = ICSharpCode.AvalonEdit.Highlighting.Xshd.
                    HighlightingLoader.Load(reader, HighlightingManager.Instance);
            }

            var commandColor = new HighlightingColor()
                {
                    Foreground = orangeBrush,
                    FontWeight = FontWeights.Bold
                };
            var directiveColor = new HighlightingColor()
                {
                    Foreground = greenYellowBrush
                };

            string regexstr = "";
            foreach(var m in buildins) {
                var command = m as CodeMemberMethodExAHK;
                if(command != null && command.IsTraditionalCommand && !command.IsFlowCommand) {
                    //regexstr += command.Name.ToLowerInvariant() + "|";
                    // Add custom but static highligning rule
                    customHighlighting.MainRuleSet.Rules.Add(new HighlightingRule()
                    {
                        Color = commandColor,
                        Regex = GetRegexForCommand(command.Name.ToLowerInvariant())
                    });
                }
            }

            HighlightingManager.Instance.RegisterHighlighting("ahk-v1.1", new string[] { ".ahk" }, customHighlighting);

            #endregion

            _emptyTemplate = new ProjectTemplateEmpty(this);
            _templates = new ProjectTemplate[] { _emptyTemplate, new ProjectTemplateDemo(this) };
        }
コード例 #50
0
ファイル: RichTextModel.cs プロジェクト: Paccc/SharpDevelop
		/// <summary>
		/// Applies the HighlightingColor to the specified range of text.
		/// If the color specifies <c>null</c> for some properties, existing highlighting is preserved.
		/// </summary>
		public void ApplyHighlighting(int offset, int length, HighlightingColor color)
		{
			if (color == null || color.IsEmptyForMerge) {
				// 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++) {
				stateChanges[i].MergeWith(color);
			}
		}
コード例 #51
0
 /// <inheritdoc/>
 public override void BeginSpan(HighlightingColor highlightingColor)
 {
     BeginColorSpan();
     currentColor.MergeWith(highlightingColor);
     currentColor.Freeze();
 }
コード例 #52
0
ファイル: RichTextModel.cs プロジェクト: Paccc/SharpDevelop
		/// <summary>
		/// Creates a RichTextModel from a CONTIGUOUS list of HighlightedSections.
		/// </summary>
		internal RichTextModel(int[] stateChangeOffsets, HighlightingColor[] stateChanges)
		{
			Debug.Assert(stateChangeOffsets[0] == 0);
			this.stateChangeOffsets.AddRange(stateChangeOffsets);
			this.stateChanges.AddRange(stateChanges);
		}
コード例 #53
0
 /// <summary>
 /// Applies a highlighting color to a visual line element.
 /// </summary>
 protected virtual void ApplyColorToElement(VisualLineElement element, HighlightingColor color)
 {
     ApplyColorToElement(element, color, CurrentContext);
 }