From 02f7aa76f27b66cf5f73818f39ad5d4b80a84160 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 2 Apr 2008 14:55:06 -0400 Subject: [PATCH] Adding a new class called BreakpointManager so we don't clutter up AppDelegate * Source/AppDelegate.m/h: Removing the breakpoint code * Source/BSLineNumberView.m: ([BSLineNumberView mouseDown:]): We need to add the lineNumberRange so we get an accurate number * Source/DebuggerWindowController.m: Switching to BreakpointManager instead of AppDelegate for managing breakpoints * Source/BreakpointManager.m/h: New files * MacGDBp.xcodeproj: Project updates for BreakpointManager --- MacGDBp.xcodeproj/project.pbxproj | 6 ++ Source/AppDelegate.h | 5 -- Source/AppDelegate.m | 29 ---------- Source/BSLineNumberView.m | 2 +- Source/BreakpointManager.h | 30 ++++++++++ Source/BreakpointManager.m | 93 +++++++++++++++++++++++++++++++ Source/DebuggerWindowController.m | 6 +- 7 files changed, 133 insertions(+), 38 deletions(-) create mode 100644 Source/BreakpointManager.h create mode 100644 Source/BreakpointManager.m diff --git a/MacGDBp.xcodeproj/project.pbxproj b/MacGDBp.xcodeproj/project.pbxproj index 96425e9..56af8cb 100644 --- a/MacGDBp.xcodeproj/project.pbxproj +++ b/MacGDBp.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ 1E35FEA10C6599040030F527 /* base64.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E35FEA00C6599040030F527 /* base64.c */; }; 1E416FF80D36F821009A53A2 /* Connect.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1E416FF40D36F821009A53A2 /* Connect.xib */; }; 1E416FF90D36F821009A53A2 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1E416FF60D36F821009A53A2 /* MainMenu.xib */; }; + 1E4C7AF90DA401C7000A9DC7 /* BreakpointManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E4C7AF80DA401C7000A9DC7 /* BreakpointManager.m */; }; 1E7188680D839F6300969277 /* BSLineNumberView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E7188630D839F6300969277 /* BSLineNumberView.m */; }; 1E7188690D839F6300969277 /* BSSourceView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E7188650D839F6300969277 /* BSSourceView.m */; }; 1E71886A0D839F6300969277 /* BSSourceViewTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E7188670D839F6300969277 /* BSSourceViewTextView.m */; }; @@ -54,6 +55,8 @@ 1E35FFB00C65A74C0030F527 /* NSXMLElementAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NSXMLElementAdditions.h; path = Source/NSXMLElementAdditions.h; sourceTree = ""; }; 1E416FF50D36F821009A53A2 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/Connect.xib; sourceTree = ""; }; 1E416FF70D36F821009A53A2 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = ""; }; + 1E4C7AF70DA401C7000A9DC7 /* BreakpointManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BreakpointManager.h; path = Source/BreakpointManager.h; sourceTree = ""; }; + 1E4C7AF80DA401C7000A9DC7 /* BreakpointManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BreakpointManager.m; path = Source/BreakpointManager.m; sourceTree = ""; }; 1E7188620D839F6300969277 /* BSLineNumberView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BSLineNumberView.h; path = Source/BSLineNumberView.h; sourceTree = ""; }; 1E7188630D839F6300969277 /* BSLineNumberView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BSLineNumberView.m; path = Source/BSLineNumberView.m; sourceTree = ""; }; 1E7188640D839F6300969277 /* BSSourceView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BSSourceView.h; path = Source/BSSourceView.h; sourceTree = ""; }; @@ -109,6 +112,8 @@ 1EEBFD070D3599E8008F835B /* BSSplitView.m */, 1E822CDB0DA28AC30027A23F /* Breakpoint.h */, 1E822CDC0DA28AC30027A23F /* Breakpoint.m */, + 1E4C7AF70DA401C7000A9DC7 /* BreakpointManager.h */, + 1E4C7AF80DA401C7000A9DC7 /* BreakpointManager.m */, 1E71886C0D839F6C00969277 /* Source View */, ); name = Classes; @@ -312,6 +317,7 @@ 1E7188690D839F6300969277 /* BSSourceView.m in Sources */, 1E71886A0D839F6300969277 /* BSSourceViewTextView.m in Sources */, 1E822CDD0DA28AC30027A23F /* Breakpoint.m in Sources */, + 1E4C7AF90DA401C7000A9DC7 /* BreakpointManager.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Source/AppDelegate.h b/Source/AppDelegate.h index 389b221..e0258d8 100644 --- a/Source/AppDelegate.h +++ b/Source/AppDelegate.h @@ -16,16 +16,11 @@ #import #import "DebuggerConnection.h" -#import "Breakpoint.h" @interface AppDelegate : NSObject { - NSMutableDictionary *breakpoints; } - (IBAction)showConnectionWindow:(id)sender; -- (void)addBreakpoint:(Breakpoint *)bp; -- (NSSet *)breakpointsForFile:(NSString *)file; - @end diff --git a/Source/AppDelegate.m b/Source/AppDelegate.m index a54961e..7d62eea 100644 --- a/Source/AppDelegate.m +++ b/Source/AppDelegate.m @@ -26,7 +26,6 @@ { if (self = [super init]) { - breakpoints = [NSMutableDictionary dictionary]; } return self; } @@ -47,32 +46,4 @@ [[[ConnectWindowController sharedController] window] makeKeyAndOrderFront:self]; } -#pragma mark Breakpoints - -/** - * Registers a breakpoint at a given line - */ -- (void)addBreakpoint:(Breakpoint *)bp; -{ - NSMutableSet *lines = [breakpoints valueForKey:[bp file]]; - if (lines == nil) - { - lines = [NSMutableSet setWithObject:bp]; - [breakpoints setValue:lines forKey:[bp file]]; - } - else - { - [lines addObject:bp]; - } - NSLog(@"breakpoints = %@", breakpoints); -} - -/** - * Returns all the breakpoints for a given file - */ -- (NSSet *)breakpointsForFile:(NSString *)file -{ - return [breakpoints valueForKey:file]; -} - @end diff --git a/Source/BSLineNumberView.m b/Source/BSLineNumberView.m index 2b6a0cd..1996d60 100644 --- a/Source/BSLineNumberView.m +++ b/Source/BSLineNumberView.m @@ -109,7 +109,7 @@ fragRect.size.width = [self bounds].size.width; if (NSPointInRect(clickLoc, fragRect)) { - [[sourceView delegate] gutterClickedAtLine:line forFile:[sourceView file]]; + [[sourceView delegate] gutterClickedAtLine:(line + lineNumberRange.location - 1) forFile:[sourceView file]]; return; } diff --git a/Source/BreakpointManager.h b/Source/BreakpointManager.h new file mode 100644 index 0000000..e5bca81 --- /dev/null +++ b/Source/BreakpointManager.h @@ -0,0 +1,30 @@ +/* + * MacGDBp + * Copyright (c) 2007 - 2008, Blue Static + * + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program; if not, + * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#import +#import "Breakpoint.h" + +@interface BreakpointManager : NSObject +{ + NSMutableDictionary *breakpoints; +} + ++ (BreakpointManager *)sharedManager; +- (void)addBreakpoint:(Breakpoint *)bp; +- (NSSet *)breakpointsForFile:(NSString *)file; +- (BOOL)hasBreakpointAt:(int)line inFile:(NSString *)file; + +@end diff --git a/Source/BreakpointManager.m b/Source/BreakpointManager.m new file mode 100644 index 0000000..c840fa0 --- /dev/null +++ b/Source/BreakpointManager.m @@ -0,0 +1,93 @@ +/* + * MacGDBp + * Copyright (c) 2007 - 2008, Blue Static + * + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program; if not, + * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#import "BreakpointManager.h" + + +@implementation BreakpointManager + +/** + * Initializer + */ +- (id)init +{ + if (self = [super init]) + { + breakpoints = [NSMutableDictionary dictionary]; + } + return self; +} + +/** + * Returns the shared manager (singleton) + */ ++ (BreakpointManager *)sharedManager +{ + static BreakpointManager *manager; + if (!manager) + { + manager = [[BreakpointManager alloc] init]; + } + return manager; +} + +/** + * Registers a breakpoint at a given line + */ +- (void)addBreakpoint:(Breakpoint *)bp; +{ + NSMutableSet *lines = [breakpoints valueForKey:[bp file]]; + if (lines == nil) + { + lines = [NSMutableSet setWithObject:bp]; + [breakpoints setValue:lines forKey:[bp file]]; + } + else + { + [lines addObject:bp]; + } + NSLog(@"breakpoints = %@", breakpoints); +} + +/** + * Returns all the breakpoints for a given file + */ +- (NSSet *)breakpointsForFile:(NSString *)file +{ + return [breakpoints valueForKey:file]; +} + +/** + * Checks to see if a given file has a breakpoint on a given line + */ +- (BOOL)hasBreakpointAt:(int)line inFile:(NSString *)file +{ + NSSet *lines = [breakpoints valueForKey:file]; + if (!lines) + { + return NO; + } + for (Breakpoint *b in lines) + { + if ([b line] == line) + { + return YES; + } + } + return NO; +} + +@end diff --git a/Source/DebuggerWindowController.m b/Source/DebuggerWindowController.m index 28c0fe9..6814c9e 100644 --- a/Source/DebuggerWindowController.m +++ b/Source/DebuggerWindowController.m @@ -18,7 +18,7 @@ #import "DebuggerConnection.h" #import "NSXMLElementAdditions.h" #import "AppDelegate.h" -#import "Breakpoint.h" +#import "BreakpointManager.h" @interface DebuggerWindowController (Private) @@ -273,8 +273,8 @@ */ - (void)gutterClickedAtLine:(int)line forFile:(NSString *)file { - [[NSApp delegate] addBreakpoint:[[Breakpoint alloc] initWithLine:line inFile:file]]; - [[sourceViewer numberView] setMarkers:[[NSApp delegate] breakpointsForFile:file]]; + [[BreakpointManager sharedManager] addBreakpoint:[[Breakpoint alloc] initWithLine:line inFile:file]]; + [[sourceViewer numberView] setMarkers:[[BreakpointManager sharedManager] breakpointsForFile:file]]; [[sourceViewer numberView] setNeedsDisplay:YES]; } -- 2.22.5