Fixed the warning popover issues YAY
This commit is contained in:
parent
f1e0eb1755
commit
4904db549c
|
@ -11,8 +11,8 @@
|
||||||
@public
|
@public
|
||||||
id onBegin;
|
id onBegin;
|
||||||
id onEnd;
|
id onEnd;
|
||||||
NSWindow *parent;
|
|
||||||
id textfield;
|
id textfield;
|
||||||
|
NSTextView *tv;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -45,8 +45,8 @@
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:self->onEnd];
|
[[NSNotificationCenter defaultCenter] removeObserver:self->onEnd];
|
||||||
self->onEnd = nil;
|
self->onEnd = nil;
|
||||||
}
|
}
|
||||||
if (self->parent != nil)
|
if (self->tv != nil)
|
||||||
[self->parent removeObserver:self forKeyPath:@"firstResponder"];
|
[self->tv removeObserver:self forKeyPath:@"delegate"];
|
||||||
[super close];
|
[super close];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,20 +62,9 @@
|
||||||
|
|
||||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
||||||
{
|
{
|
||||||
// see https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/EventHandlingBasics/EventHandlingBasics.html#//apple_ref/doc/uid/10000060i-CH5-SW23 and http://stackoverflow.com/a/25562783/3408572
|
if ([self->tv delegate] == self->textfield)
|
||||||
if ([[self->parent firstResponder] isKindOfClass:[NSTextView class]] &&
|
|
||||||
[self->parent fieldEditor:NO forObject:nil] != nil) {
|
|
||||||
id tf;
|
|
||||||
|
|
||||||
tf = [[self->parent firstResponder] delegate];
|
|
||||||
NSLog(@"%p %p", [[self->parent fieldEditor:NO forObject:nil] delegate], self->textfield);
|
|
||||||
if (tf == self->textfield) {
|
|
||||||
NSLog(@"orderFront:");
|
|
||||||
[self orderFront:self];
|
[self orderFront:self];
|
||||||
return;
|
else
|
||||||
}
|
|
||||||
// else fall through
|
|
||||||
}
|
|
||||||
[self orderOut:self];
|
[self orderOut:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,8 +149,9 @@ void warningPopoverShow(id popover, id control)
|
||||||
vr = [[v superview] convertRect:[v frame] toView:nil];
|
vr = [[v superview] convertRect:[v frame] toView:nil];
|
||||||
vo = [[v window] convertRectToScreen:vr].origin;
|
vo = [[v window] convertRectToScreen:vr].origin;
|
||||||
[p setFrameOrigin:NSMakePoint(vo.x, vo.y - [p frame].size.height)];
|
[p setFrameOrigin:NSMakePoint(vo.x, vo.y - [p frame].size.height)];
|
||||||
p->parent = [v window];
|
|
||||||
p->textfield = control;
|
p->textfield = control;
|
||||||
[p->parent addObserver:p forKeyPath:@"firstResponder" options:NSKeyValueObservingOptionNew context:NULL];
|
p->tv = (NSTextView *) [[v window] fieldEditor:NO forObject:nil];
|
||||||
|
// thanks to http://stackoverflow.com/a/25562783/3408572 for suggesting KVO here
|
||||||
|
[p->tv addObserver:p forKeyPath:@"delegate" options:NSKeyValueObservingOptionNew context:NULL];
|
||||||
[p orderFront:p];
|
[p orderFront:p];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue