From ecad1a1f90030035190f8098b5c4cd663f23a266 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 9 Mar 2008 14:37:46 -0400 Subject: [PATCH] We now highlight the break'd line * Source/BSSourceView.h: New prop-ivar markedLine * Source/BSSourceView.m: ditto * Source/BSSourceViewTextView.m: ([BSSourceViewTextView drawRect:]): Highlight the line * Source/DebuggerWindowContrller.m: ([DebuggerWindowController updateSourceViewer]): Call [sourceViewer setMarkedLine:] --- Source/BSSourceView.h | 3 +++ Source/BSSourceView.m | 2 +- Source/BSSourceViewTextView.m | 19 +++++++++++++++++++ Source/DebuggerWindowController.m | 4 +++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Source/BSSourceView.h b/Source/BSSourceView.h index 03a306c..28193f5 100644 --- a/Source/BSSourceView.h +++ b/Source/BSSourceView.h @@ -23,11 +23,14 @@ BSLineNumberView *numberView; BSSourceViewTextView *textView; NSScrollView *scrollView; + + int markedLine; } @property(readwrite, assign) BSLineNumberView *numberView; @property(readwrite, assign) BSSourceViewTextView *textView; @property(readwrite, assign) NSScrollView *scrollView; +@property(readwrite, assign) int markedLine; - (void)scrollToLine:(int)line; diff --git a/Source/BSSourceView.m b/Source/BSSourceView.m index 30214fe..a3278c2 100644 --- a/Source/BSSourceView.m +++ b/Source/BSSourceView.m @@ -22,7 +22,7 @@ @implementation BSSourceView -@synthesize numberView, textView, scrollView; +@synthesize numberView, textView, scrollView, markedLine; /** * Initializes the source view with the path of a file diff --git a/Source/BSSourceViewTextView.m b/Source/BSSourceViewTextView.m index 76d5a85..15964b5 100644 --- a/Source/BSSourceViewTextView.m +++ b/Source/BSSourceViewTextView.m @@ -27,6 +27,25 @@ - (void)drawRect:(NSRect)rect { [super drawRect:rect]; + + unsigned i = 0, line = 1; + while (i < [[self layoutManager] numberOfGlyphs]) + { + NSRange fragRange; + NSRect fragRect = [self convertRect:[[self layoutManager] lineFragmentRectForGlyphAtIndex:i effectiveRange:&fragRange] fromView:self]; + fragRect.origin.x = rect.origin.x; // horizontal scrolling matters not + + if ([sourceView markedLine] == line) + { + [[[NSColor redColor] colorWithAlphaComponent:0.25] set]; + [NSBezierPath fillRect:fragRect]; + break; + } + + i += fragRange.length; + line++; + } + [[sourceView numberView] setNeedsDisplay:YES]; } diff --git a/Source/DebuggerWindowController.m b/Source/DebuggerWindowController.m index cca867e..4806ce9 100644 --- a/Source/DebuggerWindowController.m +++ b/Source/DebuggerWindowController.m @@ -219,7 +219,9 @@ NSString *text = [NSString stringWithContentsOfFile:filename]; [[sourceViewer textView] setString:text]; - [sourceViewer scrollToLine:[[[stack objectAtIndex:selection] valueForKey:@"lineno"] intValue]]; + int line = [[[stack objectAtIndex:selection] valueForKey:@"lineno"] intValue]; + [sourceViewer setMarkedLine:line]; + [sourceViewer scrollToLine:line]; // make sure the font stays Monaco //[sourceViewer setFont:[NSFont fontWithName:@"Monaco" size:10.0]]; -- 2.22.5