jens@1: // jens@1: // UniqueWindowController.m jens@1: // Cloudy jens@1: // jens@1: // Created by Jens Alfke on 3/14/08. jens@1: // Copyright 2008 __MyCompanyName__. All rights reserved. jens@1: // jens@1: jens@1: #import "UniqueWindowController.h" jens@2: #import "GraphicsUtils.h" jens@1: jens@1: jens@1: @implementation UniqueWindowController jens@1: jens@1: jens@3: + (BOOL) isModel: (id)model1 equalToModel: (id)model2 jens@3: { jens@3: return model1==model2; jens@3: } jens@3: jens@3: jens@1: + (UniqueWindowController*) instanceWith: (id)model jens@1: { jens@2: for( NSWindow *window in OpenWindowsWithDelegateClass(self) ) { jens@2: UniqueWindowController *c = window.delegate; jens@3: if( [self isModel: c.model equalToModel: model] ) jens@2: return c; jens@1: } jens@1: return nil; jens@1: } jens@1: jens@1: jens@1: + (UniqueWindowController*) openWith: (id)model jens@1: { jens@1: UniqueWindowController *w = [self instanceWith: model]; jens@1: if( ! w ) { jens@1: w = [[self alloc] initWith: model]; jens@1: [w showWindow: self]; jens@6: } else { jens@6: if( model != w.model ) jens@6: [w reopenWith: model]; jens@1: } jens@1: [w.window makeKeyAndOrderFront: self]; jens@1: return w; jens@1: } jens@1: jens@1: jens@6: - (void) reopenWith: (id)model jens@6: { jens@6: } jens@6: jens@6: jens@1: - (void) windowWillClose: (NSNotification*)n jens@1: { jens@1: [self autorelease]; jens@1: } jens@1: jens@1: jens@1: @end