diff --git a/Source/NSView.m b/Source/NSView.m index 083981c13..4c8facd2a 100644 --- a/Source/NSView.m +++ b/Source/NSView.m @@ -70,14 +70,23 @@ static NSString *nsview_thread_key = @"NSViewThreadKey"; if (stack == nil) { - stack = [[NSMutableDictionary alloc] initWithCapacity: 4]; + stack = [[NSMutableArray alloc] initWithCapacity: 4]; [dict setObject: stack forKey: nsview_thread_key]; [stack release]; } [stack addObject: focusView]; } + else + { + [NSException raise: NSInternalInconsistencyException + format: @"Attempt to push a 'nil' focus view on to stack."]; + } } +/* + * Remove the top focusView for the current thread from the stack + * and return the new focusView (or nil if the stack is now empty). + */ + (NSView *)popFocusView { NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary]; @@ -88,10 +97,13 @@ static NSString *nsview_thread_key = @"NSViewThreadKey"; { unsigned count = [stack count]; + if (count > 0) + { + [stack removeObjectAtIndex: --count]; + } if (count > 0) { v = [stack objectAtIndex: --count]; - [stack removeObjectAtIndex: count]; } } return v;