3 * Copyright (c) 2007 - 2008, 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"
18 #import "AppDelegate.h"
20 @interface BreakpointManager (Private
)
21 - (void)updateDisplaysForFile
:(NSString
*)file
;
24 @implementation BreakpointManager
26 @synthesize breakpoints
, connection
;
33 if (self = [super init
])
37 breakpoints
= [[NSMutableArray alloc
] init
];
44 * Returns the shared manager (singleton)
46 + (BreakpointManager
*)sharedManager
48 static BreakpointManager
*manager
;
51 manager
= [[BreakpointManager alloc
] init
];
57 * Registers a breakpoint at a given line
59 - (void)addBreakpoint
:(Breakpoint
*)bp
;
61 if (![breakpoints containsObject
:bp
])
63 [breakpoints addObject
:bp
];
64 [connection addBreakpoint
:bp
];
66 [self updateDisplaysForFile
:[bp file
]];
71 * Removes a breakpoint at a given line/file combination, or nil if nothing was removed
73 - (Breakpoint
*)removeBreakpointAt
:(int)line inFile
:(NSString
*)file
75 for (Breakpoint
*b
in breakpoints
)
77 if ([b line
] == line
&& [[b file
] isEqualToString
:file
])
79 [breakpoints removeObject
:b
];
80 [connection removeBreakpoint
:b
];
81 [self updateDisplaysForFile
:file
];
89 * Returns all the breakpoints for a given file
91 - (NSArray
*)breakpointsForFile
:(NSString
*)file
93 NSMutableArray
*matches
= [NSMutableArray array
];
94 for (Breakpoint
*b
in breakpoints
)
96 if ([[b file
] isEqualToString
:file
])
98 [matches addObject
:b
];
106 * Checks to see if a given file has a breakpoint on a given line
108 - (BOOL)hasBreakpointAt
:(int)line inFile
:(NSString
*)file
110 return [breakpoints containsObject
:[[Breakpoint alloc
] initWithLine
:line inFile
:file
]];
116 * This marks BSSourceView needsDisplay, rearranges the objects in the breakpoints controller,
117 * and sets the markers for the BSLineNumberView
119 - (void)updateDisplaysForFile
:(NSString
*)file
121 AppDelegate
*appDel
= [NSApp delegate
];
122 [[[appDel breakpoint
] arrayController
] rearrangeObjects
];
123 [[[appDel breakpoint
] sourceView
] setNeedsDisplay
:YES
];
124 [[[[appDel breakpoint
] sourceView
] numberView
] setMarkers
:[NSSet setWithArray
:[self breakpointsForFile
:file
]]];
125 [[[appDel debugger
] sourceViewer
] setNeedsDisplay
:YES
];
126 [[[[appDel debugger
] sourceViewer
] numberView
] setMarkers
:[NSSet setWithArray
:[self breakpointsForFile
:file
]]];