1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.Windows;
|
---|
24 | using System.Windows.Media;
|
---|
25 | using System.Windows.Shapes;
|
---|
26 | using ICSharpCode.AvalonEdit.Document;
|
---|
27 | using ICSharpCode.AvalonEdit.Rendering;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Problems.GPDL.Views {
|
---|
30 | public class ColorizeErrors : DocumentColorizingTransformer {
|
---|
31 | private Dictionary<int, string> synErrors = new Dictionary<int, string>();
|
---|
32 | private Dictionary<int, string> lexErrors = new Dictionary<int, string>();
|
---|
33 |
|
---|
34 | protected override void ColorizeLine(DocumentLine line) {
|
---|
35 | if (lexErrors.ContainsKey(line.LineNumber)) {
|
---|
36 | ChangeLinePart(line.Offset, line.Offset + line.Length, ChangeLexError);
|
---|
37 | } else if (synErrors.ContainsKey(line.LineNumber)) {
|
---|
38 | ChangeLinePart(line.Offset, line.Offset + line.Length, ChangeSynError);
|
---|
39 | }
|
---|
40 | //int lineStartOffset = line.Offset;
|
---|
41 | //string text = CurrentContext.Document.GetText(line);
|
---|
42 | //int start = 0;
|
---|
43 | //int index;
|
---|
44 | //while ((index = text.IndexOf("AvalonEdit", start)) >= 0) {
|
---|
45 | // base.ChangeLinePart(
|
---|
46 | // lineStartOffset + index, // startOffset
|
---|
47 | // lineStartOffset + index + 10, // endOffset
|
---|
48 | // (VisualLineElement element) => {
|
---|
49 | // // This lambda gets called once for every VisualLineElement
|
---|
50 | // // between the specified offsets.
|
---|
51 | // Typeface tf = element.TextRunProperties.Typeface;
|
---|
52 | // // Replace the typeface with a modified version of
|
---|
53 | // // the same typeface
|
---|
54 | // element.TextRunProperties.SetTypeface(new Typeface(
|
---|
55 | // tf.FontFamily,
|
---|
56 | // FontStyles.Italic,
|
---|
57 | // FontWeights.Bold,
|
---|
58 | // tf.Stretch
|
---|
59 | // ));
|
---|
60 | // });
|
---|
61 | // start = index + 1; // search for next occurrence
|
---|
62 | //}
|
---|
63 | }
|
---|
64 |
|
---|
65 | private void ChangeSynError(VisualLineElement element) {
|
---|
66 |
|
---|
67 |
|
---|
68 | var wigglePath = new Path();
|
---|
69 | wigglePath.Data = Geometry.Parse("M 0,1 C 1,0 2,2 3,1");
|
---|
70 | wigglePath.Stroke = Brushes.Red;
|
---|
71 | wigglePath.StrokeThickness = 0.2;
|
---|
72 | wigglePath.StrokeEndLineCap = PenLineCap.Square;
|
---|
73 | wigglePath.StrokeStartLineCap = PenLineCap.Square;
|
---|
74 |
|
---|
75 | var wigglyBrush = new VisualBrush();
|
---|
76 | wigglyBrush.Viewbox = new Rect(0, 0, 3, 2);
|
---|
77 | wigglyBrush.ViewboxUnits = BrushMappingMode.Absolute;
|
---|
78 | wigglyBrush.Viewport = new Rect(0, 0.8, 6, 4);
|
---|
79 | wigglyBrush.ViewportUnits = BrushMappingMode.Absolute;
|
---|
80 | wigglyBrush.TileMode = TileMode.Tile;
|
---|
81 | wigglyBrush.Visual = wigglePath;
|
---|
82 |
|
---|
83 |
|
---|
84 | var wigglyPen = new Pen(wigglyBrush, 6.0);
|
---|
85 | var decorations = new TextDecorationCollection();
|
---|
86 | decorations.Add(new TextDecoration(0, wigglyPen, 0, TextDecorationUnit.Pixel, TextDecorationUnit.Pixel));
|
---|
87 | element.TextRunProperties.SetTextDecorations(decorations);
|
---|
88 | //element.TextRunProperties.SetTypeface(new Typeface(
|
---|
89 | // tf.FontFamily,
|
---|
90 | // FontStyles.Italic,
|
---|
91 | // FontWeights.Bold,
|
---|
92 | // tf.Stretch
|
---|
93 | //));
|
---|
94 | }
|
---|
95 |
|
---|
96 | private void ChangeLexError(VisualLineElement element) {
|
---|
97 |
|
---|
98 | var wigglePath = new Path();
|
---|
99 | wigglePath.Data = Geometry.Parse("M 0,1 C 1,0 2,2 3,1");
|
---|
100 | wigglePath.Stroke = Brushes.Red;
|
---|
101 | wigglePath.StrokeThickness = 0.2;
|
---|
102 | wigglePath.StrokeEndLineCap = PenLineCap.Square;
|
---|
103 | wigglePath.StrokeStartLineCap = PenLineCap.Square;
|
---|
104 |
|
---|
105 | var wigglyBrush = new VisualBrush();
|
---|
106 | wigglyBrush.Viewbox = new Rect(0, 0, 3, 2);
|
---|
107 | wigglyBrush.ViewboxUnits = BrushMappingMode.Absolute;
|
---|
108 | wigglyBrush.Viewport = new Rect(0, 0.8, 6, 4);
|
---|
109 | wigglyBrush.ViewportUnits = BrushMappingMode.Absolute;
|
---|
110 | wigglyBrush.TileMode = TileMode.Tile;
|
---|
111 | wigglyBrush.Visual = wigglePath;
|
---|
112 |
|
---|
113 |
|
---|
114 | var wigglyPen = new Pen(wigglyBrush, 6.0);
|
---|
115 | var decorations = new TextDecorationCollection();
|
---|
116 | decorations.Add(new TextDecoration(0, wigglyPen, 0, TextDecorationUnit.Pixel, TextDecorationUnit.Pixel));
|
---|
117 | element.TextRunProperties.SetTextDecorations(decorations);
|
---|
118 |
|
---|
119 | //element.TextRunProperties.SetTypeface(new Typeface(
|
---|
120 | // tf.FontFamily,
|
---|
121 | // FontStyles.Italic,
|
---|
122 | // FontWeights.Bold,
|
---|
123 | // tf.Stretch
|
---|
124 | //));
|
---|
125 | }
|
---|
126 |
|
---|
127 | internal void MarkSynError(string msg, int line, int col) {
|
---|
128 | if (!synErrors.ContainsKey(line)) {
|
---|
129 | synErrors.Add(line, msg);
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | internal void MarkLexError(string msg, int line, int col) {
|
---|
134 | if (!lexErrors.ContainsKey(line)) {
|
---|
135 | lexErrors.Add(line, msg);
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 | internal void ClearErrors() {
|
---|
140 | synErrors.Clear();
|
---|
141 | lexErrors.Clear();
|
---|
142 | }
|
---|
143 | }
|
---|
144 | }
|
---|