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