From 405fbefb4a5387b7b6d8d94b468c7cde7b6ef8b0 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 12 Jan 2011 11:01:16 -0500 Subject: [PATCH] Move |-computeLineIndex| from BSSourceView to BSLineNumberRulerView --- MacGDBp.xcodeproj/project.pbxproj | 8 ++-- Source/BSLineNumberRulerView.h | 6 ++- ...erRulerView.m => BSLineNumberRulerView.mm} | 43 +++++++++++++++++ Source/BSSourceView.h | 5 +- Source/BSSourceView.mm | 48 ++++--------------- 5 files changed, 63 insertions(+), 47 deletions(-) rename Source/{BSLineNumberRulerView.m => BSLineNumberRulerView.mm} (60%) diff --git a/MacGDBp.xcodeproj/project.pbxproj b/MacGDBp.xcodeproj/project.pbxproj index f25179a..d8d145d 100644 --- a/MacGDBp.xcodeproj/project.pbxproj +++ b/MacGDBp.xcodeproj/project.pbxproj @@ -36,7 +36,7 @@ 1EC6965812BBC6A700A8D984 /* modp_b64.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1EC6965212BBC6A700A8D984 /* modp_b64.cc */; }; 1EC6965912BBC6A700A8D984 /* README.bluestatic in Resources */ = {isa = PBXBuildFile; fileRef = 1EC6965512BBC6A700A8D984 /* README.bluestatic */; }; 1EC6965A12BBC6A700A8D984 /* README.chromium in Resources */ = {isa = PBXBuildFile; fileRef = 1EC6965612BBC6A700A8D984 /* README.chromium */; }; - 1EDA9CF812DD13B300596211 /* BSLineNumberRulerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EDA9CF712DD13B300596211 /* BSLineNumberRulerView.m */; }; + 1EDA9CF812DD13B300596211 /* BSLineNumberRulerView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1EDA9CF712DD13B300596211 /* BSLineNumberRulerView.mm */; }; 1EEBFBE50D34C793008F835B /* Debugger.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1EEBFBE30D34C793008F835B /* Debugger.xib */; }; 1EEBFC2B0D358EBD008F835B /* StepIn.png in Resources */ = {isa = PBXBuildFile; fileRef = 1EEBFC2A0D358EBD008F835B /* StepIn.png */; }; 1EEBFC370D358F1B008F835B /* StepOut.png in Resources */ = {isa = PBXBuildFile; fileRef = 1EEBFC360D358F1B008F835B /* StepOut.png */; }; @@ -114,7 +114,7 @@ 1EC6965512BBC6A700A8D984 /* README.bluestatic */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.bluestatic; sourceTree = ""; }; 1EC6965612BBC6A700A8D984 /* README.chromium */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.chromium; sourceTree = ""; }; 1EDA9CF612DD13B300596211 /* BSLineNumberRulerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BSLineNumberRulerView.h; path = Source/BSLineNumberRulerView.h; sourceTree = ""; }; - 1EDA9CF712DD13B300596211 /* BSLineNumberRulerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BSLineNumberRulerView.m; path = Source/BSLineNumberRulerView.m; sourceTree = ""; }; + 1EDA9CF712DD13B300596211 /* BSLineNumberRulerView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = BSLineNumberRulerView.mm; path = Source/BSLineNumberRulerView.mm; sourceTree = ""; }; 1EEBFBE40D34C793008F835B /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/Debugger.xib; sourceTree = ""; }; 1EEBFC2A0D358EBD008F835B /* StepIn.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = StepIn.png; path = Icons/StepIn.png; sourceTree = ""; }; 1EEBFC360D358F1B008F835B /* StepOut.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = StepOut.png; path = Icons/StepOut.png; sourceTree = ""; }; @@ -256,7 +256,7 @@ 1E7188640D839F6300969277 /* BSSourceView.h */, 1E7188650D839F6300969277 /* BSSourceView.mm */, 1EDA9CF612DD13B300596211 /* BSLineNumberRulerView.h */, - 1EDA9CF712DD13B300596211 /* BSLineNumberRulerView.m */, + 1EDA9CF712DD13B300596211 /* BSLineNumberRulerView.mm */, ); name = "Source View"; sourceTree = ""; @@ -461,7 +461,7 @@ 1EC6965812BBC6A700A8D984 /* modp_b64.cc in Sources */, 1EFBE63012C515C200F96D6E /* NetworkConnection.mm in Sources */, 1EFBE66B12C51E3900F96D6E /* NetworkCallbackController.mm in Sources */, - 1EDA9CF812DD13B300596211 /* BSLineNumberRulerView.m in Sources */, + 1EDA9CF812DD13B300596211 /* BSLineNumberRulerView.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Source/BSLineNumberRulerView.h b/Source/BSLineNumberRulerView.h index f2493f4..ece4300 100644 --- a/Source/BSLineNumberRulerView.h +++ b/Source/BSLineNumberRulerView.h @@ -15,14 +15,18 @@ */ #import +#include // The NSRulerView that draws line numbers on the BSSourceView. @interface BSLineNumberRulerView : NSRulerView { - + @private + std::vector lineIndex_; } // Designated initializer. - (id)initWithScrollView:(NSScrollView*)scrollView; +- (void)performLayout; + @end diff --git a/Source/BSLineNumberRulerView.m b/Source/BSLineNumberRulerView.mm similarity index 60% rename from Source/BSLineNumberRulerView.m rename to Source/BSLineNumberRulerView.mm index c70d209..6102375 100644 --- a/Source/BSLineNumberRulerView.m +++ b/Source/BSLineNumberRulerView.mm @@ -16,6 +16,10 @@ #import "BSLineNumberRulerView.h" +@interface BSLineNumberRulerView (Private) +- (void)computeLineIndex; +@end + @implementation BSLineNumberRulerView @@ -44,4 +48,43 @@ toPoint:NSMakePoint(NSMaxX(rect), NSMaxY(rect))]; } +- (void)performLayout +{ + [self computeLineIndex]; +} + +// Private ///////////////////////////////////////////////////////////////////// + +/** + * Iterates over the text storage system and computes a map of line numbers to + * first character index for a line's frame rectangle. + */ +- (void)computeLineIndex +{ + lineIndex_.clear(); + + NSView* view = [self clientView]; + if (![view isKindOfClass:[NSTextView class]]) + return; + + NSString* text = [(NSTextView*)view string]; + NSUInteger stringLength = [text length]; + NSUInteger index = 0; + + while (index < stringLength) { + lineIndex_.push_back(index); + index = NSMaxRange([text lineRangeForRange:NSMakeRange(index, 0)]); + } + + NSUInteger lineEnd, contentEnd; + [text getLineStart:NULL + end:&lineEnd + contentsEnd:&contentEnd + forRange:NSMakeRange(lineIndex_.back(), 0)]; + if (contentEnd < lineEnd) + lineIndex_.push_back(index); + + NSLog(@"line count = %d", lineIndex_.size()); +} + @end diff --git a/Source/BSSourceView.h b/Source/BSSourceView.h index cb53f19..c2494d6 100644 --- a/Source/BSSourceView.h +++ b/Source/BSSourceView.h @@ -15,20 +15,19 @@ */ #import -#include #import "BSLineNumberView.h" +@class BSLineNumberRulerView; @protocol BSSourceViewDelegate; @interface BSSourceView : NSView { @private NSTextView* textView_; + BSLineNumberRulerView* ruler_; NSScrollView* scrollView_; - std::vector lineIndex_; - NSSet* markers_; NSString* file; diff --git a/Source/BSSourceView.mm b/Source/BSSourceView.mm index a762803..31ab6cd 100644 --- a/Source/BSSourceView.mm +++ b/Source/BSSourceView.mm @@ -22,7 +22,6 @@ - (void)setupViews; - (void)errorHighlightingFile:(NSNotification*)notif; - (void)setPlainTextStringFromFile:(NSString*)filePath; -- (void)computeLineIndex; @end @implementation BSSourceView @@ -108,7 +107,7 @@ [self setPlainTextStringFromFile:f]; } - [self computeLineIndex]; + [ruler_ performLayout]; } /** @@ -139,7 +138,7 @@ file = [path copy]; } - [self computeLineIndex]; + [ruler_ performLayout]; } /** @@ -196,14 +195,6 @@ [[scrollView_ contentView] setAutoresizesSubviews:YES]; [self addSubview:scrollView_]; - // Set up the ruler. - BSLineNumberRulerView* lineNumberView = - [[[BSLineNumberRulerView alloc] initWithScrollView:scrollView_] autorelease]; - [scrollView_ setVerticalRulerView:lineNumberView]; - [scrollView_ setHasHorizontalRuler:NO]; - [scrollView_ setHasVerticalRuler:YES]; - [scrollView_ setRulersVisible:YES]; - // add the text view to the scroll view NSRect textFrame; textFrame.origin = NSMakePoint(0.0, 0.0); @@ -221,6 +212,13 @@ [textView_ setAutoresizingMask:NSViewNotSizable]; [scrollView_ setDocumentView:textView_]; + // Set up the ruler. + ruler_ = [[[BSLineNumberRulerView alloc] initWithScrollView:scrollView_] autorelease]; + [scrollView_ setVerticalRulerView:ruler_]; + [scrollView_ setHasHorizontalRuler:NO]; + [scrollView_ setHasVerticalRuler:YES]; + [scrollView_ setRulersVisible:YES]; + NSArray* types = [NSArray arrayWithObject:NSFilenamesPboardType]; [self registerForDraggedTypes:types]; } @@ -242,34 +240,6 @@ [textView_ setString:contents]; } -/** - * Iterates over the text storage system and computes a map of line numbers to - * first character index for a line's frame rectangle. - */ -- (void)computeLineIndex -{ - lineIndex_.clear(); - - NSString* text = [textView_ string]; - NSUInteger stringLength = [text length]; - NSUInteger index = 0; - - while (index < stringLength) { - lineIndex_.push_back(index); - index = NSMaxRange([text lineRangeForRange:NSMakeRange(index, 0)]); - } - - NSUInteger lineEnd, contentEnd; - [text getLineStart:NULL - end:&lineEnd - contentsEnd:&contentEnd - forRange:NSMakeRange(lineIndex_.back(), 0)]; - if (contentEnd < lineEnd) - lineIndex_.push_back(index); - - NSLog(@"line count = %d", lineIndex_.size()); -} - // Drag Handlers /////////////////////////////////////////////////////////////// /** -- 2.43.5