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
{
27 NSMutableArray
* _breakpoints
;
28 NSMutableArray
* _savedBreakpoints
;
30 DebuggerBackEnd
* __weak _connection
;
35 if (self = [super init
])
37 _breakpoints
= [[NSMutableArray alloc
] init
];
38 _savedBreakpoints
= [[NSMutableArray alloc
] init
];
40 NSArray
* savedBreakpoints
= [[NSUserDefaults standardUserDefaults
] arrayForKey
:kPrefBreakpoints
];
41 if (savedBreakpoints
) {
42 for (NSDictionary
* d
in savedBreakpoints
) {
43 Breakpoint
* bp
= [[Breakpoint alloc
] initWithDictionary
:d
];
44 [_breakpoints addObject
:bp
];
45 [_savedBreakpoints addObject
:[bp dictionary
]];
53 * Registers a breakpoint at a given line
55 - (void)addBreakpoint
:(Breakpoint
*)bp
;
57 if (![_breakpoints containsObject
:bp
])
59 [self willChangeValueForKey
:@
"breakpoints"];
60 [_breakpoints addObject
:bp
];
61 [self didChangeValueForKey
:@
"breakpoints"];
63 [_connection addBreakpoint
:bp
];
65 [_savedBreakpoints addObject
:[bp dictionary
]];
66 [[NSUserDefaults standardUserDefaults
] setObject
:_savedBreakpoints forKey
:kPrefBreakpoints
];
68 [self updateDisplaysForFile
:[bp file
]];
72 - (Breakpoint
*)removeBreakpoint
:(Breakpoint
*)bp
74 // Use the -isEqual: test to find the object in |_breakpoints| that also has
75 // the debugger id and secure bookmark data.
76 NSUInteger idx
= [_breakpoints indexOfObject
:bp
];
77 if (idx
== NSNotFound
)
80 bp
= [_breakpoints objectAtIndex
:idx
];
82 [self willChangeValueForKey
:@
"breakpoints"];
83 [_breakpoints removeObject
:bp
];
84 [self didChangeValueForKey
:@
"breakpoints"];
86 [_connection removeBreakpoint
:bp
];
88 [_savedBreakpoints removeObject
:[bp dictionary
]];
89 [[NSUserDefaults standardUserDefaults
] setObject
:_savedBreakpoints forKey
:kPrefBreakpoints
];
92 [self updateDisplaysForFile
:bp.file
];
98 * Returns all the breakpoints for a given file
100 - (NSSet
<NSNumber
*>*)breakpointsForFile
:(NSString
*)file
102 NSMutableSet
<NSNumber
*>* matches
= [NSMutableSet set
];
103 for (Breakpoint
* b
in _breakpoints
) {
104 if ([b.file isEqualToString
:file
]) {
105 [matches addObject
:@
(b.line
)];
113 - (BOOL)hasBreakpoint
:(Breakpoint
*)breakpoint
115 return [_breakpoints containsObject
:breakpoint
];
121 * This marks BSSourceView needsDisplay, rearranges the objects in the breakpoints controller,
122 * and sets the markers for the BSLineNumberView
124 - (void)updateDisplaysForFile
:(NSString
*)file
126 AppDelegate
* appDel
= [NSApp delegate
];
127 [[[appDel breakpoint
] arrayController
] rearrangeObjects
];
128 [[[appDel debugger
] sourceViewer
] setNeedsDisplay
:YES
];
129 [[[appDel debugger
] sourceViewer
] setMarkers
:[self breakpointsForFile
:file
]];