1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/UniqueWindowController.m Thu Mar 20 09:05:58 2008 -0700
1.3 @@ -0,0 +1,47 @@
1.4 +//
1.5 +// UniqueWindowController.m
1.6 +// Cloudy
1.7 +//
1.8 +// Created by Jens Alfke on 3/14/08.
1.9 +// Copyright 2008 __MyCompanyName__. All rights reserved.
1.10 +//
1.11 +
1.12 +#import "UniqueWindowController.h"
1.13 +
1.14 +
1.15 +@implementation UniqueWindowController
1.16 +
1.17 +
1.18 ++ (UniqueWindowController*) instanceWith: (id)model
1.19 +{
1.20 + for( NSWindow *window in [NSApp windows] ) {
1.21 + id delegate = window.delegate;
1.22 + if( window.isVisible && [delegate isKindOfClass: [self class]] ) {
1.23 + UniqueWindowController *c = delegate;
1.24 + if( c.model == model )
1.25 + return c;
1.26 + }
1.27 + }
1.28 + return nil;
1.29 +}
1.30 +
1.31 +
1.32 ++ (UniqueWindowController*) openWith: (id)model
1.33 +{
1.34 + UniqueWindowController *w = [self instanceWith: model];
1.35 + if( ! w ) {
1.36 + w = [[self alloc] initWith: model];
1.37 + [w showWindow: self];
1.38 + }
1.39 + [w.window makeKeyAndOrderFront: self];
1.40 + return w;
1.41 +}
1.42 +
1.43 +
1.44 +- (void) windowWillClose: (NSNotification*)n
1.45 +{
1.46 + [self autorelease];
1.47 +}
1.48 +
1.49 +
1.50 +@end