3 * Copyright (c) 2007 - 2011, Blue Static <http://www.bluestatic.org>
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.
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.
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
17 #import "BreakpointManager.h"
19 #import "AppDelegate.h"
20 #import "PreferenceNames.h"
22 @interface BreakpointManager (Private
)
23 - (void)updateDisplaysForFile
:(NSString
*)file
;
26 @implementation BreakpointManager
28 @synthesize breakpoints
, connection
;
35 if (self = [super init
])
39 breakpoints
= [[NSMutableArray alloc
] init
];
42 savedBreakpoints
= [[[NSUserDefaults standardUserDefaults
] arrayForKey
:kPrefBreakpoints
] mutableCopy
];
45 for (NSDictionary
* d
in savedBreakpoints
)
47 [breakpoints addObject
:[[[Breakpoint alloc
] initWithDictionary
:d
] autorelease
]];
52 savedBreakpoints
= [NSMutableArray
new];
59 * Returns the shared manager (singleton)
61 + (BreakpointManager
*)sharedManager
63 static BreakpointManager
* manager
;
66 manager
= [[BreakpointManager alloc
] init
];
72 * Registers a breakpoint at a given line
74 - (void)addBreakpoint
:(Breakpoint
*)bp
;
76 if (![breakpoints containsObject
:bp
])
78 [self willChangeValueForKey
:@
"breakpoints"];
79 [breakpoints addObject
:bp
];
80 [self didChangeValueForKey
:@
"breakpoints"];
82 [connection addBreakpoint
:bp
];
84 [savedBreakpoints addObject
:[bp dictionary
]];
85 [[NSUserDefaults standardUserDefaults
] setObject
:savedBreakpoints forKey
:kPrefBreakpoints
];
87 [self updateDisplaysForFile
:[bp file
]];
92 * Removes a breakpoint at a given line/file combination, or nil if nothing was removed
94 - (Breakpoint
*)removeBreakpointAt
:(NSUInteger
)line inFile
:(NSString
*)file
96 for (Breakpoint
* b
in breakpoints
)
98 if ([b line
] == line
&& [[b file
] isEqualToString
:file
])
100 // Keep the breakpoint alive after it is removed from the breakpoints
102 [[b retain
] autorelease
];
104 [self willChangeValueForKey
:@
"breakpoints"];
105 [breakpoints removeObject
:b
];
106 [self didChangeValueForKey
:@
"breakpoints"];
108 [connection removeBreakpoint
:b
];
110 [savedBreakpoints removeObject
:[b dictionary
]];
111 [[NSUserDefaults standardUserDefaults
] setObject
:savedBreakpoints forKey
:kPrefBreakpoints
];
113 [self updateDisplaysForFile
:file
];
121 * Returns all the breakpoints for a given file
123 - (NSSet
<NSNumber
*>*)breakpointsForFile
:(NSString
*)file
125 NSMutableSet
<NSNumber
*>* matches
= [NSMutableSet set
];
126 for (Breakpoint
* b
in breakpoints
) {
127 if ([b.file isEqualToString
:file
]) {
128 [matches addObject
:@
(b.line
)];
136 * Checks to see if a given file has a breakpoint on a given line
138 - (BOOL)hasBreakpointAt
:(NSUInteger
)line inFile
:(NSString
*)file
140 return [breakpoints containsObject
:[[[Breakpoint alloc
] initWithLine
:line inFile
:file
] autorelease
]];
146 * This marks BSSourceView needsDisplay, rearranges the objects in the breakpoints controller,
147 * and sets the markers for the BSLineNumberView
149 - (void)updateDisplaysForFile
:(NSString
*)file
151 AppDelegate
* appDel
= [NSApp delegate
];
152 [[[appDel breakpoint
] arrayController
] rearrangeObjects
];
153 [[[appDel debugger
] sourceViewer
] setNeedsDisplay
:YES
];
154 [[[appDel debugger
] sourceViewer
] setMarkers
:[self breakpointsForFile
:file
]];