mirror of
https://github.com/microtherion/VocalEasel.git
synced 2024-12-22 19:23:59 +00:00
Properly clean up observers
This commit is contained in:
parent
f41c28ff25
commit
b6c9141e52
|
@ -26,6 +26,7 @@
|
|||
NSNumber * songTempo;
|
||||
NSString * tmpPath;
|
||||
NSFileWrapper * vcsWrapper;
|
||||
NSMutableArray* observers;
|
||||
int repeatVolta;
|
||||
bool brandNew;
|
||||
|
||||
|
@ -59,6 +60,7 @@
|
|||
- (void) changedFileWrapper;
|
||||
- (void) willChangeSong;
|
||||
- (void) didChangeSong;
|
||||
- (void) addObserver:(id)observer;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -74,6 +74,7 @@
|
|||
vcsWrapper = nil;
|
||||
repeatVolta = 2;
|
||||
brandNew = true;
|
||||
observers = [[NSMutableArray alloc] init];
|
||||
[self setHasUndoManager:YES];
|
||||
undo =
|
||||
[[VLKeyValueUndo alloc] initWithOwner:self
|
||||
|
@ -89,6 +90,17 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (void) addObserver:(id)observer
|
||||
{
|
||||
[observers addObject:observer];
|
||||
}
|
||||
|
||||
- (void) close
|
||||
{
|
||||
[observers makeObjectsPerformSelector:@selector(removeObservers:) withObject:self];
|
||||
[super close];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
delete song;
|
||||
|
@ -100,7 +112,8 @@
|
|||
[songArranger release];
|
||||
[vcsWrapper release];
|
||||
[undo release];
|
||||
|
||||
[observers release];
|
||||
|
||||
if (tmpPath) {
|
||||
[[NSFileManager defaultManager] removeFileAtPath:tmpPath handler:nil];
|
||||
[tmpPath release];
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
owner = o;
|
||||
keysAndNames = [kn retain];
|
||||
|
||||
[owner addObserver:self];
|
||||
for (NSEnumerator * e = [keysAndNames keyEnumerator];
|
||||
NSString * key = [e nextObject];
|
||||
)
|
||||
|
@ -26,13 +27,16 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
- (void)removeObservers:(id)target
|
||||
{
|
||||
for (NSEnumerator * e = [keysAndNames keyEnumerator];
|
||||
NSString * key = [e nextObject];
|
||||
)
|
||||
[owner removeObserver:self forKeyPath:key];
|
||||
[target removeObserver:self forKeyPath:key];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[keysAndNames release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
|
|
@ -891,12 +891,20 @@ static int8_t sSharpAcc[] = {
|
|||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
[[self document] addObserver:self];
|
||||
[[self document] addObserver:self forKeyPath:@"song" options:0 context:nil];
|
||||
[[self document] addObserver:self forKeyPath:@"songKey" options:0 context:nil];
|
||||
[[self document] addObserver:self forKeyPath:@"songGroove" options:0 context:nil];
|
||||
[self setGrooveMenu:[[self document] valueForKey:@"songGroove"]];
|
||||
}
|
||||
|
||||
- (void)removeObservers:(id)target
|
||||
{
|
||||
[target removeObserver:self forKeyPath:@"song"];
|
||||
[target removeObserver:self forKeyPath:@"songKey"];
|
||||
[target removeObserver:self forKeyPath:@"songGroove"];
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)o change:(NSDictionary *)c context:(id)ctx
|
||||
{
|
||||
if ([keyPath isEqual:@"songKey"]) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user