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 [_savedBreakpoints addObjectsFromArray
:savedBreakpoints
];
43 for (NSDictionary
* d
in savedBreakpoints
) {
44 [_breakpoints addObject
:[[Breakpoint alloc
] initWithDictionary
:d
]];
52 * Registers a breakpoint at a given line
54 - (void)addBreakpoint
:(Breakpoint
*)bp
;
56 if (![_breakpoints containsObject
:bp
])
58 [self willChangeValueForKey
:@
"breakpoints"];
59 [_breakpoints addObject
:bp
];
60 [self didChangeValueForKey
:@
"breakpoints"];
62 [_connection addBreakpoint
:bp
];
64 [_savedBreakpoints addObject
:[bp dictionary
]];
65 [[NSUserDefaults standardUserDefaults
] setObject
:_savedBreakpoints forKey
:kPrefBreakpoints
];
67 [self updateDisplaysForFile
:[bp file
]];
71 - (Breakpoint
*)removeBreakpoint
:(Breakpoint
*)bp
73 // Use the -isEqual: test to find the object in |_breakpoints| that also has
74 // the debugger id and secure bookmark data.
75 NSUInteger idx
= [_breakpoints indexOfObject
:bp
];
76 if (idx
== NSNotFound
)
79 bp
= [_breakpoints objectAtIndex
:idx
];
81 [self willChangeValueForKey
:@
"breakpoints"];
82 [_breakpoints removeObject
:bp
];
83 [self didChangeValueForKey
:@
"breakpoints"];
85 [_connection removeBreakpoint
:bp
];
87 [_savedBreakpoints removeObject
:[bp dictionary
]];
88 [[NSUserDefaults standardUserDefaults
] setObject
:_savedBreakpoints forKey
:kPrefBreakpoints
];
91 [self updateDisplaysForFile
:bp.file
];
97 * Returns all the breakpoints for a given file
99 - (NSSet
<NSNumber
*>*)breakpointsForFile
:(NSString
*)file
101 NSMutableSet
<NSNumber
*>* matches
= [NSMutableSet set
];
102 for (Breakpoint
* b
in _breakpoints
) {
103 if ([b.file isEqualToString
:file
]) {
104 [matches addObject
:@
(b.line
)];
112 - (BOOL)hasBreakpoint
:(Breakpoint
*)breakpoint
114 return [_breakpoints containsObject
:breakpoint
];
120 * This marks BSSourceView needsDisplay, rearranges the objects in the breakpoints controller,
121 * and sets the markers for the BSLineNumberView
123 - (void)updateDisplaysForFile
:(NSString
*)file
125 AppDelegate
* appDel
= [NSApp delegate
];
126 [[[appDel breakpoint
] arrayController
] rearrangeObjects
];
127 [[[appDel debugger
] sourceViewer
] setNeedsDisplay
:YES
];
128 [[[appDel debugger
] sourceViewer
] setMarkers
:[self breakpointsForFile
:file
]];