author | Jens Alfke <jens@mooseyard.com> |
Tue May 20 17:40:28 2008 -0700 (2008-05-20) | |
changeset 10 | 82a37ccf6b8c |
parent 3 | 8fad19466c59 |
child 11 | e5976864dfe9 |
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@6 | 39 |
} else { |
jens@6 | 40 |
if( model != w.model ) |
jens@6 | 41 |
[w reopenWith: model]; |
jens@1 | 42 |
} |
jens@1 | 43 |
[w.window makeKeyAndOrderFront: self]; |
jens@1 | 44 |
return w; |
jens@1 | 45 |
} |
jens@1 | 46 |
|
jens@1 | 47 |
|
jens@6 | 48 |
- (void) reopenWith: (id)model |
jens@6 | 49 |
{ |
jens@6 | 50 |
} |
jens@6 | 51 |
|
jens@6 | 52 |
|
jens@1 | 53 |
- (void) windowWillClose: (NSNotification*)n |
jens@1 | 54 |
{ |
jens@1 | 55 |
[self autorelease]; |
jens@1 | 56 |
} |
jens@1 | 57 |
|
jens@1 | 58 |
|
jens@1 | 59 |
@end |