~ubuntu-branches/ubuntu/feisty/monodevelop/feisty

« back to all changes in this revision

Viewing changes to Unused/TextEditor/Gui/Editor/ErrorDrawer.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-08-18 00:51:23 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060818005123-5iit07y0j7wjg55f
Tags: 0.11+svn20060818-0ubuntu1
* New SVN snapshot
  + Works with Gtk# 2.9.0
* debian/control:
  + Updated Build-Depends
* debian/patches/use_nunit2.2.dpatch,
  debian/patches/use_real_libs.dpatch:
  + Updated
* debian/patches/versioncontrol_buildfix.dpatch:
  + Fix build failure in the version control addin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//// <file>
 
2
////     <copyright see="prj:///doc/copyright.txt"/>
 
3
////     <license see="prj:///doc/license.txt"/>
 
4
////     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
 
5
////     <version value="$version"/>
 
6
//// </file>
 
7
//
 
8
//using System;
 
9
//using System.Collections;
 
10
//using System.Drawing;
 
11
//using System.Drawing.Text;
 
12
//
 
13
//using MonoDevelop.TextEditor.Document;
 
14
//using MonoDevelop.Core;
 
15
//using MonoDevelop.Core.Gui;
 
16
//using MonoDevelop.TextEditor;
 
17
//
 
18
//namespace MonoDevelop.DefaultEditor.Gui.Editor
 
19
//{
 
20
//      /// <summary>
 
21
//      /// reperesents a visual error, this class is needed by the errordrawer.
 
22
//      /// </summary>
 
23
//      public class VisualError
 
24
//      {
 
25
//              int    offset;
 
26
//              int    length;
 
27
//              string description;
 
28
//              
 
29
//              public int Offset {
 
30
//                      get {
 
31
//                              return offset;
 
32
//                      }
 
33
//                      set {
 
34
//                              offset = value;
 
35
//                      }
 
36
//              }
 
37
//              
 
38
//              public int Length {
 
39
//                      get {
 
40
//                              return length;
 
41
//                      }
 
42
//                      set {
 
43
//                              length = value;
 
44
//                      }
 
45
//              }
 
46
//              
 
47
//              public string Description {
 
48
//                      get {
 
49
//                              return description;
 
50
//                      }
 
51
//              }
 
52
//              
 
53
//              public VisualError(int offset, int length, string description)
 
54
//              {
 
55
//                      this.offset      = offset;
 
56
//                      this.length      = length;
 
57
//                      this.description = description;
 
58
//              }
 
59
//      }
 
60
//      
 
61
//      /// <summary>
 
62
//      /// This class draws error underlines.
 
63
//      /// </summary>
 
64
//      public class ErrorDrawer
 
65
//      {
 
66
//              ArrayList       errors = new ArrayList();
 
67
//              TextAreaControl textarea;
 
68
//              
 
69
//              public ErrorDrawer(TextAreaControl textarea)
 
70
//              {
 
71
//                      this.textarea = textarea;
 
72
//                      textarea.Document.DocumentChanged += new DocumentAggregatorEventHandler(MoveIndices);
 
73
//                      textarea.TextAreaPainter.ToolTipEvent += new ToolTipEvent(ToolTip);
 
74
//                      textarea.TextAreaPainter.LinePainter += new LinePainter(ErrorPainter);
 
75
//                      
 
76
//                      TaskService taskService = (TaskService)MonoDevelop.Core.ServiceManager.Services.GetService(typeof(TaskService));
 
77
//                      taskService.TasksChanged += new EventHandler(SetErrors);
 
78
//                      textarea.FileNameChanged += new EventHandler(SetErrors);
 
79
//              }
 
80
//              
 
81
//              public void MoveIndices(object sender, DocumentAggregatorEventArgs e)
 
82
//              {
 
83
//                      ArrayList newerrors = new ArrayList();
 
84
//                      bool redraw = false;
 
85
//                      lock (this) {
 
86
//                              foreach (VisualError error in errors) {
 
87
//                                      if (e.Length == -1) {        // insert
 
88
//                                              if (e.Offset <= error.Offset) {
 
89
//                                                      error.Offset += e.Text.Length;
 
90
//                                                      redraw = true;
 
91
//                                              } else if (e.Offset < error.Offset + error.Length) {
 
92
//                                                      error.Length += e.Text.Length;
 
93
//                                                      redraw = true;
 
94
//                                              }
 
95
//                                      } else if (e.Text == null) { // remove
 
96
//                                              if (e.Offset < error.Offset) {
 
97
//                                                      error.Offset -= e.Length;
 
98
//                                                      redraw = true;
 
99
//                                              } else if (e.Offset == error.Offset) {
 
100
//                                                      error.Length -= e.Length;
 
101
//                                              } else if (e.Offset <= error.Offset + error.Length) {
 
102
//                                                      if (e.Offset + e.Length <= error.Offset + error.Length) {
 
103
//                                                              error.Length = error.Length - e.Length;
 
104
//                                                      } else {
 
105
//                                                              error.Length = e.Offset - error.Offset;
 
106
//                                                      }
 
107
//                                              }
 
108
//                                      } else { // replace
 
109
//                                              if (e.Offset <= error.Offset) {
 
110
//                                                      error.Offset -= e.Length;
 
111
//                                                      error.Offset += e.Text.Length;
 
112
//                                                      redraw = true;
 
113
//                                              } 
 
114
//                                      }
 
115
//                                      if (error.Offset > 0 && error.Offset + error.Length < e.Document.TextLength) {
 
116
//                                              newerrors.Add(error);
 
117
//                                      }
 
118
//                              }
 
119
//                              errors = newerrors;
 
120
//                      }
 
121
//                      
 
122
//                      if (redraw) {
 
123
//                              textarea.Refresh();
 
124
//                      }
 
125
//              }
 
126
//              
 
127
//              void ClearErrors()
 
128
//              {
 
129
//                      ArrayList lines = new ArrayList();
 
130
//                      foreach (VisualError error in errors) {
 
131
//                              lines.Add(textarea.Document.GetLineNumberForOffset(error.Offset));
 
132
//                      }
 
133
//                      lock (this) {
 
134
//                              errors.Clear();
 
135
//                      }
 
136
//                      foreach (int line in lines) {
 
137
//                              textarea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, new Point(0, line)));
 
138
//                      }
 
139
//                      textarea.Document.CommitUpdate();
 
140
//              }
 
141
//              
 
142
//              void SetErrors(object sender, EventArgs e)
 
143
//              {
 
144
//                      ClearErrors();
 
145
//                      TaskService taskService = (TaskService)MonoDevelop.Core.ServiceManager.Services.GetService(typeof(TaskService));
 
146
//                      foreach (Task task in taskService.Tasks) {
 
147
//                              if (task.FileName == textarea.FileName && (task.TaskType == TaskType.Warning || 
 
148
//                                                                         task.TaskType == TaskType.Error)) {
 
149
//                                      if (task.Line >= 0 && task.Line < textarea.Document.TotalNumberOfLines) {
 
150
//                                              LineSegment line = textarea.Document.GetLineSegment(task.Line);
 
151
//                                              int offset = Math.Min(textarea.Document.TextLength, line.Offset + task.Column);
 
152
//                                              int length = Math.Max(1, TextUtilities.FindWordEnd(textarea.Document, offset) - offset);
 
153
//                                              AddError(new VisualError(offset, length, task.Description));
 
154
//                                      }
 
155
//                              }
 
156
//                      }
 
157
//                      
 
158
//                      textarea.Refresh();
 
159
//              }
 
160
//              
 
161
//              bool AddError(VisualError newerror)
 
162
//              {
 
163
////                    Console.WriteLine("Add Error");                 
 
164
//                      lock (this) {
 
165
//                              
 
166
//                              foreach (VisualError error in errors) {
 
167
//                                      if (error.Offset == newerror.Offset && error.Length == newerror.Length) {
 
168
//                                              return false;
 
169
//                                      }
 
170
//                              }
 
171
//                              
 
172
//                              errors.Add(newerror);
 
173
//                      }
 
174
//                      
 
175
//                      int lineNr = textarea.Document.GetLineNumberForOffset(newerror.Offset);
 
176
//                      textarea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, new Point(0, lineNr)));
 
177
//                      textarea.Document.CommitUpdate();
 
178
////                    Console.WriteLine("Add Error .DONE");
 
179
//                      return true;
 
180
//              }
 
181
//              
 
182
//              void ToolTip(int xpos, int ypos, ref bool toolTipSet)
 
183
//              {
 
184
////                    Console.WriteLine("Tool Tip");
 
185
//                      
 
186
//                      lock (this) {
 
187
//                              foreach (VisualError error in errors) {
 
188
//                                      Point errorpos  = textarea.Document.OffsetToView(error.Offset);
 
189
//                                      Rectangle r = new Rectangle((int)(errorpos.X * textarea.TextAreaPainter.FontWidth), 
 
190
//                                                                                              (int)(errorpos.Y * textarea.TextAreaPainter.FontHeight), 
 
191
//                                                                          (int)(error.Length * textarea.TextAreaPainter.FontWidth), 
 
192
//                                                                      (int)textarea.TextAreaPainter.FontHeight);
 
193
//                                      if (r.Contains(xpos, ypos)) {
 
194
//                                              textarea.TextAreaPainter.ToolTip.SetToolTip(textarea.TextAreaPainter, error.Description);
 
195
//                                              toolTipSet = true;
 
196
//                                              break;
 
197
//                                      }
 
198
//                              }
 
199
//                      }
 
200
////                    Console.WriteLine("Tool Tip .DONE");
 
201
//              }
 
202
//              
 
203
//              void DrawWaveLine(Graphics g, int from, int to, int ypos)
 
204
//              {
 
205
//                      Pen pen = Pens.Red;
 
206
//                      for (int i = from; i < to; i+= 6) {
 
207
//                              g.DrawLine(pen, i,     ypos + 3, i + 3, ypos + 1);
 
208
//                              g.DrawLine(pen, i + 3, ypos + 1, i + 6, ypos + 3);
 
209
//                      }
 
210
//              }
 
211
//
 
212
//              void ErrorPainter(Graphics g, int line, RectangleF rect, PointF pos, int virtualLeft, int virtualTop)
 
213
//              {
 
214
////                    Console.WriteLine("Paint");
 
215
//                      if (textarea.Properties.GetProperty("ShowErrors", true)) {
 
216
//                              lock(this) {
 
217
//                                      foreach (VisualError error in errors) {
 
218
//                                              try {
 
219
//                                                      int offsetLineNumber = textarea.Document.GetLineNumberForOffset(error.Offset);
 
220
//                                                      
 
221
//                                                      if (offsetLineNumber == line) {
 
222
//                                                              LineSegment lineSegment = textarea.Document.GetLineSegment(offsetLineNumber);
 
223
//                                                              int xPos = error.Offset - lineSegment.Offset;
 
224
//                                                              DrawWaveLine(g,
 
225
//                                                                      (int)(pos.X + textarea.TextAreaPainter.CalculateVisualXPos(offsetLineNumber, xPos) - virtualLeft),
 
226
//                                                                      (int)(pos.X + textarea.TextAreaPainter.CalculateVisualXPos(offsetLineNumber, xPos + error.Length) - virtualLeft), 
 
227
//                                                                      (int)(pos.Y + textarea.TextAreaPainter.FontHeight - 3) - virtualTop);
 
228
//                                                      } 
 
229
//                                              } catch (Exception) {}
 
230
//                                      }
 
231
//                              }
 
232
//                      }
 
233
////                    Console.WriteLine("Paint .DONE");
 
234
//              }
 
235
//      }
 
236
//}