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
* _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
] autorelease
]];
52 [_breakpoints release
];
53 [_savedBreakpoints release
];
58 * Registers a breakpoint at a given line
60 - (void)addBreakpoint
:(Breakpoint
*)bp
;
62 if (![_breakpoints containsObject
:bp
])
64 [self willChangeValueForKey
:@
"breakpoints"];
65 [_breakpoints addObject
:bp
];
66 [self didChangeValueForKey
:@
"breakpoints"];
68 [_connection addBreakpoint
:bp
];
70 [_savedBreakpoints addObject
:[bp dictionary
]];
71 [[NSUserDefaults standardUserDefaults
] setObject
:_savedBreakpoints forKey
:kPrefBreakpoints
];
73 [self updateDisplaysForFile
:[bp file
]];
77 - (Breakpoint
*)removeBreakpoint
:(Breakpoint
*)bp
79 if ([_breakpoints containsObject
:bp
]) {
80 // Keep the breakpoint alive after it is removed from the breakpoints
82 [[bp retain
] autorelease
];
84 [self willChangeValueForKey
:@
"breakpoints"];
85 [_breakpoints removeObject
:bp
];
86 [self didChangeValueForKey
:@
"breakpoints"];
88 [_connection removeBreakpoint
:bp
];
90 [_savedBreakpoints removeObject
:[bp dictionary
]];
91 [[NSUserDefaults standardUserDefaults
] setObject
:_savedBreakpoints forKey
:kPrefBreakpoints
];
94 [self updateDisplaysForFile
:bp.file
];
102 * Returns all the breakpoints for a given file
104 - (NSSet
<NSNumber
*>*)breakpointsForFile
:(NSString
*)file
106 NSMutableSet
<NSNumber
*>* matches
= [NSMutableSet set
];
107 for (Breakpoint
* b
in _breakpoints
) {
108 if ([b.file isEqualToString
:file
]) {
109 [matches addObject
:@
(b.line
)];
117 - (BOOL)hasBreakpoint
:(Breakpoint
*)breakpoint
119 return [_breakpoints containsObject
:breakpoint
];
123 * Checks to see if a given file has a breakpoint on a given line
125 - (BOOL)hasBreakpointAt
:(NSUInteger
)line inFile
:(NSString
*)file
127 return [self hasBreakpoint
:[Breakpoint breakpointAtLine
:line inFile
:file
]];
133 * This marks BSSourceView needsDisplay, rearranges the objects in the breakpoints controller,
134 * and sets the markers for the BSLineNumberView
136 - (void)updateDisplaysForFile
:(NSString
*)file
138 AppDelegate
* appDel
= [NSApp delegate
];
139 [[[appDel breakpoint
] arrayController
] rearrangeObjects
];
140 [[[appDel debugger
] sourceViewer
] setNeedsDisplay
:YES
];
141 [[[appDel debugger
] sourceViewer
] setMarkers
:[self breakpointsForFile
:file
]];