author | Jens Alfke <jens@mooseyard.com> |
Sun Apr 06 19:13:27 2008 -0700 (2008-04-06) | |
changeset 3 | 8fad19466c59 |
parent 2 | 3d3dcc3116d5 |
child 6 | 2d492d8c2053 |
permissions | -rw-r--r-- |
jens@1 | 1 |
// |
jens@1 | 2 |
// UniqueWindowController.m |
jens@1 | 3 |
// Cloudy |
jens@1 | 4 |
// |
jens@1 | 5 |
// Created by Jens Alfke on 3/14/08. |
jens@1 | 6 |
// Copyright 2008 __MyCompanyName__. All rights reserved. |
jens@1 | 7 |
// |
jens@1 | 8 |
|
jens@1 | 9 |
#import "UniqueWindowController.h" |
jens@2 | 10 |
#import "GraphicsUtils.h" |
jens@1 | 11 |
|
jens@1 | 12 |
|
jens@1 | 13 |
@implementation UniqueWindowController |
jens@1 | 14 |
|
jens@1 | 15 |
|
jens@3 | 16 |
+ (BOOL) isModel: (id)model1 equalToModel: (id)model2 |
jens@3 | 17 |
{ |
jens@3 | 18 |
return model1==model2; |
jens@3 | 19 |
} |
jens@3 | 20 |
|
jens@3 | 21 |
|
jens@1 | 22 |
+ (UniqueWindowController*) instanceWith: (id)model |
jens@1 | 23 |
{ |
jens@2 | 24 |
for( NSWindow *window in OpenWindowsWithDelegateClass(self) ) { |
jens@2 | 25 |
UniqueWindowController *c = window.delegate; |
jens@3 | 26 |
if( [self isModel: c.model equalToModel: model] ) |
jens@2 | 27 |
return c; |
jens@1 | 28 |
} |
jens@1 | 29 |
return nil; |
jens@1 | 30 |
} |
jens@1 | 31 |
|
jens@1 | 32 |
|
jens@1 | 33 |
+ (UniqueWindowController*) openWith: (id)model |
jens@1 | 34 |
{ |
jens@1 | 35 |
UniqueWindowController *w = [self instanceWith: model]; |
jens@1 | 36 |
if( ! w ) { |
jens@1 | 37 |
w = [[self alloc] initWith: model]; |
jens@1 | 38 |
[w showWindow: self]; |
jens@1 | 39 |
} |
jens@1 | 40 |
[w.window makeKeyAndOrderFront: self]; |
jens@1 | 41 |
return w; |
jens@1 | 42 |
} |
jens@1 | 43 |
|
jens@1 | 44 |
|
jens@1 | 45 |
- (void) windowWillClose: (NSNotification*)n |
jens@1 | 46 |
{ |
jens@1 | 47 |
[self autorelease]; |
jens@1 | 48 |
} |
jens@1 | 49 |
|
jens@1 | 50 |
|
jens@1 | 51 |
@end |