Changeset 11657 for trunk/sources/HeuristicLab.CodeEditor
- Timestamp:
- 12/04/14 17:14:01 (10 years ago)
- Location:
- trunk/sources/HeuristicLab.CodeEditor/3.3
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CodeEditor/3.3/CodeEditor.Designer.cs
r7967 r11657 46 46 // textEditor 47 47 // 48 this.textEditor.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 49 | System.Windows.Forms.AnchorStyles.Left)50 48 this.textEditor.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 49 | System.Windows.Forms.AnchorStyles.Left) 50 | System.Windows.Forms.AnchorStyles.Right))); 51 51 this.textEditor.ConvertTabsToSpaces = true; 52 52 this.textEditor.IndentStyle = ICSharpCode.TextEditor.Document.IndentStyle.Auto; 53 53 this.textEditor.IsIconBarVisible = true; 54 54 this.textEditor.IsReadOnly = false; 55 this.textEditor.LineViewerStyle = ICSharpCode.TextEditor.Document.LineViewerStyle.FullRow; 55 56 this.textEditor.Location = new System.Drawing.Point(0, 0); 56 57 this.textEditor.Name = "textEditor"; … … 97 98 this.sharpDevelopLabel.Text = "powered by #develop"; 98 99 this.sharpDevelopLabel.ToolTipText = "Syntax highlighting and code completion facilities provided through #develop libr" + 99 100 "aries"; 100 101 this.sharpDevelopLabel.Click += new System.EventHandler(this.toolStripStatusLabel1_Click); 101 102 // … … 108 109 // CodeEditor 109 110 // 110 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);111 111 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 112 112 this.Controls.Add(this.textEditor); -
trunk/sources/HeuristicLab.CodeEditor/3.3/CodeEditor.cs
r11436 r11657 46 46 47 47 #region Fields & Properties 48 private static Color WarningColor = Color.Blue; 49 private static Color ErrorColor = Color.Red; 48 50 49 51 internal Dom.ProjectContentRegistry projectContentRegistry; … … 127 129 } 128 130 set { 131 if (Doc.TextContent == value) return; 129 132 Doc.Replace(prefix.Length, Doc.TextLength - suffix.Length - prefix.Length, value); 130 133 Doc.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); … … 141 144 142 145 public event EventHandler TextEditorValidated; 143 144 146 protected void OnTextEditorValidated() { 145 147 if (TextEditorValidated != null) … … 148 150 149 151 public event EventHandler TextEditorTextChanged; 150 151 152 protected void OnTextEditorTextChanged() { 152 153 if (TextEditorTextChanged != null) … … 159 160 textEditor.ActiveTextAreaControl.TextEditorProperties.SupportReadOnlySegments = true; 160 161 161 textEditor.SetHighlighting("C#"); 162 textEditor.ShowEOLMarkers = false; 163 textEditor.ShowInvalidLines = false; 162 LoadHighlightingStrategy(); 164 163 HostCallbackImplementation.Register(this); 165 164 CodeCompletionKeyHandler.Attach(this, textEditor); … … 192 191 return; 193 192 194 textEditor.ActiveTextAreaControl.TextArea.KeyEventHandler += new ICSharpCode.TextEditor.KeyEventHandler(TextArea_KeyEventHandler); 195 textEditor.ActiveTextAreaControl.TextArea.DoProcessDialogKey += new DialogKeyProcessor(TextArea_DoProcessDialogKey); 196 197 parserThread = new Thread(ParserThread); 198 parserThread.IsBackground = true; 193 textEditor.ActiveTextAreaControl.TextArea.KeyEventHandler += TextArea_KeyEventHandler; 194 textEditor.ActiveTextAreaControl.TextArea.DoProcessDialogKey += TextArea_DoProcessDialogKey; 195 196 parserThread = new Thread(ParserThread) { IsBackground = true }; 199 197 parserThread.Start(); 200 198 201 textEditor.Validated += (s, a) => { OnTextEditorValidated(); }; 202 textEditor.TextChanged += (s, a) => { OnTextEditorTextChanged(); }; 199 textEditor.Validated += (s, a) => OnTextEditorValidated(); 200 textEditor.TextChanged += (s, a) => { 201 Doc.MarkerStrategy.RemoveAll(m => errorMarkers.Contains(m)); errorMarkers.Clear(); 202 Doc.BookmarkManager.RemoveMarks(m => errorBookmarks.Contains(m)); errorBookmarks.Clear(); 203 Doc.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); 204 Doc.CommitUpdate(); 205 OnTextEditorTextChanged(); 206 }; 203 207 InitializeImageList(); 208 } 209 210 private void LoadHighlightingStrategy() { 211 var strategy = (DefaultHighlightingStrategy)HighlightingManager.Manager.FindHighlighter("C#"); 212 strategy.SetColorFor("CaretMarker", new HighlightColor(Color.Beige, false, false)); 213 Doc.HighlightingStrategy = strategy; 204 214 } 205 215 … … 216 226 217 227 #region keyboard handlers: filter input in read-only areas 218 219 228 bool TextArea_KeyEventHandler(char ch) { 220 229 int caret = textEditor.ActiveTextAreaControl.Caret.Offset; … … 232 241 return false; 233 242 } 234 235 243 #endregion 236 244 … … 240 248 } 241 249 250 public void ScrollToPosition(int line, int column) { 251 var segment = GetSegmentAtOffset(line, column); 252 var position = Doc.OffsetToPosition(segment.Offset + segment.Length); 253 var caret = textEditor.ActiveTextAreaControl.Caret; 254 caret.Position = position; 255 textEditor.ActiveTextAreaControl.CenterViewOn(line, 0); 256 } 257 242 258 private List<TextMarker> errorMarkers = new List<TextMarker>(); 243 259 private List<Bookmark> errorBookmarks = new List<Bookmark>(); 244 260 public void ShowCompileErrors(CompilerErrorCollection compilerErrors, string filename) { 245 Doc.MarkerStrategy.RemoveAll(m => errorMarkers.Contains(m));246 Doc.BookmarkManager.RemoveMarks(m => errorBookmarks.Contains(m));247 errorMarkers.Clear();248 errorBookmarks.Clear();249 261 errorLabel.Text = ""; 250 262 errorLabel.ToolTipText = null; … … 273 285 private void AddErrorMarker(CompilerError error) { 274 286 var segment = GetSegmentAtOffset(error.Line, error.Column); 275 Color color = error.IsWarning ? Color.Blue : Color.Red;287 Color color = error.IsWarning ? WarningColor : ErrorColor; 276 288 var marker = new TextMarker(segment.Offset, segment.Length, TextMarkerType.WaveLine, color) { 277 289 ToolTip = error.ErrorText, … … 282 294 283 295 private void AddErrorBookmark(CompilerError error) { 284 var bookmark = new ErrorBookmark(Doc, new TextLocation(error.Column, error.Line - 1)); 296 Color color = error.IsWarning ? WarningColor : ErrorColor; 297 var bookmark = new ErrorBookmark(Doc, new TextLocation(error.Column, error.Line - 1), color); 285 298 errorBookmarks.Add(bookmark); 286 299 Doc.BookmarkManager.AddMark(bookmark); … … 288 301 289 302 private AbstractSegment GetSegmentAtOffset(int lineNr, int columnNr) { 290 lineNr = Math.Max(Doc.OffsetToPosition(prefix.Length).Line, lineNr );303 lineNr = Math.Max(Doc.OffsetToPosition(prefix.Length).Line, lineNr - 1); 291 304 lineNr = Math.Min(Doc.OffsetToPosition(Doc.TextLength - suffix.Length).Line, lineNr); 292 var line = Doc.GetLineSegment(lineNr - 1);293 columnNr = Math.Max(0, columnNr );305 var line = Doc.GetLineSegment(lineNr); 306 columnNr = Math.Max(0, columnNr - 1); 294 307 columnNr = Math.Min(line.Length, columnNr); 295 308 var word = line.GetWord(columnNr); … … 299 312 segment.Length = word.Length; 300 313 } else { 301 segment.Offset = line.Offset + columnNr - 1;314 segment.Offset = line.Offset + columnNr; 302 315 segment.Length = 1; 303 316 } -
trunk/sources/HeuristicLab.CodeEditor/3.3/ErrorBookmark.cs
r11171 r11657 25 25 namespace HeuristicLab.CodeEditor { 26 26 public class ErrorBookmark : Bookmark { 27 private readonly Brush brush; 27 28 28 29 public override bool CanToggle { get { return false; } } 29 30 30 31 public ErrorBookmark(IDocument document, TextLocation location) 32 : this(document, location, Color.Red) { } 33 34 public ErrorBookmark(IDocument document, TextLocation location, Color color) 31 35 : base(document, location) { 36 brush = new SolidBrush(color); 32 37 } 33 38 34 public override void Draw(IconBarMargin margin, System.Drawing.Graphics g, System.Drawing.Point p) {39 public override void Draw(IconBarMargin margin, Graphics g, Point p) { 35 40 int delta = margin.TextArea.TextView.FontHeight / 4; 36 41 Rectangle rect = new Rectangle( … … 39 44 margin.DrawingPosition.Width - 6, 40 45 margin.TextArea.TextView.FontHeight - delta * 2); 41 g.FillRectangle( Brushes.Red, rect);46 g.FillRectangle(brush, rect); 42 47 g.DrawRectangle(Pens.White, rect); 43 48 } -
trunk/sources/HeuristicLab.CodeEditor/3.3/HeuristicLab.CodeEditor-3.3.csproj
r11623 r11657 151 151 <ItemGroup> 152 152 <Compile Include="CodeCompletionData.cs" /> 153 <EmbeddedResource Include="CodeEditor.resx">154 <DependentUpon>CodeEditor.cs</DependentUpon>155 </EmbeddedResource>156 153 <EmbeddedResource Include="CodeViewer.resx"> 157 154 <DependentUpon>CodeViewer.cs</DependentUpon>
Note: See TracChangeset
for help on using the changeset viewer.