]> src.bluestatic.org Git - macgdbp.git/blob - Source/BreakpointManager.m
Move |-computeLineIndex| from BSSourceView to BSLineNumberRulerView
[macgdbp.git] / Source / BreakpointManager.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2007 - 2011, Blue Static <http://www.bluestatic.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17 #import "BreakpointManager.h"
18 #import "AppDelegate.h"
19
20 @interface BreakpointManager (Private)
21 - (void)updateDisplaysForFile:(NSString*)file;
22 @end
23
24 @implementation BreakpointManager
25
26 @synthesize breakpoints, connection;
27
28 /**
29 * Initializer
30 */
31 - (id)init
32 {
33 if (self = [super init])
34 {
35 if (!breakpoints)
36 {
37 breakpoints = [[NSMutableArray alloc] init];
38 }
39
40 savedBreakpoints = [[[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:@"Breakpoints"] retain];
41 if (savedBreakpoints)
42 {
43 for (NSDictionary* d in savedBreakpoints)
44 {
45 [breakpoints addObject:[[[Breakpoint alloc] initWithDictionary:d] autorelease]];
46 }
47 }
48 }
49 return self;
50 }
51
52 /**
53 * Returns the shared manager (singleton)
54 */
55 + (BreakpointManager*)sharedManager
56 {
57 static BreakpointManager* manager;
58 if (!manager)
59 {
60 manager = [[BreakpointManager alloc] init];
61 }
62 return manager;
63 }
64
65 /**
66 * Registers a breakpoint at a given line
67 */
68 - (void)addBreakpoint:(Breakpoint*)bp;
69 {
70 if (![breakpoints containsObject:bp])
71 {
72 [breakpoints addObject:bp];
73 [connection addBreakpoint:bp];
74
75 [savedBreakpoints addObject:[bp dictionary]];
76 [[NSUserDefaults standardUserDefaults] setValue:savedBreakpoints forKey:@"Breakpoints"];
77
78 [self updateDisplaysForFile:[bp file]];
79 }
80 }
81
82 /**
83 * Removes a breakpoint at a given line/file combination, or nil if nothing was removed
84 */
85 - (Breakpoint*)removeBreakpointAt:(int)line inFile:(NSString*)file
86 {
87 for (Breakpoint* b in breakpoints)
88 {
89 if ([b line] == line && [[b file] isEqualToString:file])
90 {
91 [breakpoints removeObject:b];
92 [connection removeBreakpoint:b];
93
94 [savedBreakpoints removeObject:[b dictionary]];
95 [[NSUserDefaults standardUserDefaults] setValue:savedBreakpoints forKey:@"Breakpoints"];
96
97 [self updateDisplaysForFile:file];
98 return b;
99 }
100 }
101 return nil;
102 }
103
104 /**
105 * Returns all the breakpoints for a given file
106 */
107 - (NSArray*)breakpointsForFile:(NSString*)file
108 {
109 NSMutableArray* matches = [NSMutableArray array];
110 for (Breakpoint* b in breakpoints)
111 {
112 if ([[b file] isEqualToString:file])
113 {
114 [matches addObject:b];
115 }
116 }
117
118 return matches;
119 }
120
121 /**
122 * Checks to see if a given file has a breakpoint on a given line
123 */
124 - (BOOL)hasBreakpointAt:(int)line inFile:(NSString*)file
125 {
126 return [breakpoints containsObject:[[[Breakpoint alloc] initWithLine:line inFile:file] autorelease]];
127 }
128
129 #pragma mark Private
130
131 /**
132 * This marks BSSourceView needsDisplay, rearranges the objects in the breakpoints controller,
133 * and sets the markers for the BSLineNumberView
134 */
135 - (void)updateDisplaysForFile:(NSString*)file
136 {
137 AppDelegate* appDel = [NSApp delegate];
138 [[[appDel breakpoint] arrayController] rearrangeObjects];
139 [[[appDel breakpoint] sourceView] setNeedsDisplay:YES];
140 [[[appDel breakpoint] sourceView] setMarkers:[NSSet setWithArray:[self breakpointsForFile:file]]];
141 [[[appDel debugger] sourceViewer] setNeedsDisplay:YES];
142 [[[appDel debugger] sourceViewer] setMarkers:[NSSet setWithArray:[self breakpointsForFile:file]]];
143 }
144
145 @end