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 [breakpoints addObject
:bp
];
79 [connection addBreakpoint
:bp
];
81 [savedBreakpoints addObject
:[bp dictionary
]];
82 [[NSUserDefaults standardUserDefaults
] setObject
:savedBreakpoints forKey
:kPrefBreakpoints
];
84 [self updateDisplaysForFile
:[bp file
]];
89 * Removes a breakpoint at a given line/file combination, or nil if nothing was removed
91 - (Breakpoint
*)removeBreakpointAt
:(NSUInteger
)line inFile
:(NSString
*)file
93 for (Breakpoint
* b
in breakpoints
)
95 if ([b line
] == line
&& [[b file
] isEqualToString
:file
])
97 // Keep the breakpoint alive after it is removed from the breakpoints
99 [[b retain
] autorelease
];
101 [breakpoints removeObject
:b
];
102 [connection removeBreakpoint
:b
];
104 [savedBreakpoints removeObject
:[b dictionary
]];
105 [[NSUserDefaults standardUserDefaults
] setObject
:savedBreakpoints forKey
:kPrefBreakpoints
];
107 [self updateDisplaysForFile
:file
];
115 * Returns all the breakpoints for a given file
117 - (NSSet
<NSNumber
*>*)breakpointsForFile
:(NSString
*)file
119 NSMutableSet
<NSNumber
*>* matches
= [NSMutableSet set
];
120 for (Breakpoint
* b
in breakpoints
) {
121 if ([b.file isEqualToString
:file
]) {
122 [matches addObject
:@
(b.line
)];
130 * Checks to see if a given file has a breakpoint on a given line
132 - (BOOL)hasBreakpointAt
:(NSUInteger
)line inFile
:(NSString
*)file
134 return [breakpoints containsObject
:[[[Breakpoint alloc
] initWithLine
:line inFile
:file
] autorelease
]];
140 * This marks BSSourceView needsDisplay, rearranges the objects in the breakpoints controller,
141 * and sets the markers for the BSLineNumberView
143 - (void)updateDisplaysForFile
:(NSString
*)file
145 AppDelegate
* appDel
= [NSApp delegate
];
146 [[[appDel breakpoint
] arrayController
] rearrangeObjects
];
147 [[[appDel breakpoint
] sourceView
] setNeedsDisplay
:YES
];
148 [[[appDel breakpoint
] sourceView
] setMarkers
:[self breakpointsForFile
:file
]];
149 [[[appDel debugger
] sourceViewer
] setNeedsDisplay
:YES
];
150 [[[appDel debugger
] sourceViewer
] setMarkers
:[self breakpointsForFile
:file
]];