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"
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
];
40 savedBreakpoints
= [[[NSUserDefaults standardUserDefaults
] mutableArrayValueForKey
:@
"Breakpoints"] retain
];
43 for (NSDictionary
* d
in savedBreakpoints
)
45 [breakpoints addObject
:[[[Breakpoint alloc
] initWithDictionary
:d
] autorelease
]];
53 * Returns the shared manager (singleton)
55 + (BreakpointManager
*)sharedManager
57 static BreakpointManager
* manager
;
60 manager
= [[BreakpointManager alloc
] init
];
66 * Registers a breakpoint at a given line
68 - (void)addBreakpoint
:(Breakpoint
*)bp
;
70 if (![breakpoints containsObject
:bp
]) {
71 [breakpoints addObject
:bp
];
73 [connection addBreakpoint
:bp
];
75 [savedBreakpoints addObject
:[bp dictionary
]];
76 [[NSUserDefaults standardUserDefaults
] setValue
:savedBreakpoints forKey
:@
"Breakpoints"];
79 [self updateDisplaysForFile
:[bp file
]];
84 * Removes a breakpoint at a given line/file combination, or nil if nothing was removed
86 - (Breakpoint
*)removeBreakpointAt
:(int)line inFile
:(NSString
*)file
88 for (Breakpoint
* b
in breakpoints
)
90 if ([b line
] == line
&& [[b file
] isEqualToString
:file
])
92 [breakpoints removeObject
:b
];
94 [connection removeBreakpoint
:b
];
96 [savedBreakpoints removeObject
:[b dictionary
]];
97 [[NSUserDefaults standardUserDefaults
] setValue
:savedBreakpoints forKey
:@
"Breakpoints"];
99 [self updateDisplaysForFile
:file
];
107 * Returns all the breakpoints for a given file
109 - (NSArray
*)breakpointsForFile
:(NSString
*)file
111 NSMutableArray
* matches
= [NSMutableArray array
];
112 for (Breakpoint
* b
in breakpoints
)
114 if ([[b file
] isEqualToString
:file
] && [b line
] > 0)
116 [matches addObject
:b
];
124 * Checks to see if a given file has a breakpoint on a given line
126 - (BOOL)hasBreakpointAt
:(int)line inFile
:(NSString
*)file
128 return [breakpoints containsObject
:[[[Breakpoint alloc
] initWithLine
:line inFile
:file
] autorelease
]];
134 * This marks BSSourceView needsDisplay, rearranges the objects in the breakpoints controller,
135 * and sets the markers for the BSLineNumberView
137 - (void)updateDisplaysForFile
:(NSString
*)file
139 AppDelegate
* appDel
= [NSApp delegate
];
140 [[[appDel breakpoint
] arrayController
] rearrangeObjects
];
141 [[[appDel breakpoint
] sourceView
] setNeedsDisplay
:YES
];
142 [[[[appDel breakpoint
] sourceView
] numberView
] setMarkers
:[NSSet setWithArray
:[self breakpointsForFile
:file
]]];
143 [[[appDel debugger
] sourceViewer
] setNeedsDisplay
:YES
];
144 [[[[appDel debugger
] sourceViewer
] numberView
] setMarkers
:[NSSet setWithArray
:[self breakpointsForFile
:file
]]];