jens@1: // jens@1: // UniqueWindowController.m jens@11: // MYUtilities jens@1: // jens@1: // Created by Jens Alfke on 3/14/08. jens@11: // Copyright 2008 Jens Alfke. 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 jens@11: jens@11: jens@11: /* jens@11: Copyright (c) 2008, Jens Alfke . All rights reserved. jens@11: jens@11: Redistribution and use in source and binary forms, with or without modification, are permitted jens@11: provided that the following conditions are met: jens@11: jens@11: * Redistributions of source code must retain the above copyright notice, this list of conditions jens@11: and the following disclaimer. jens@11: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions jens@11: and the following disclaimer in the documentation and/or other materials provided with the jens@11: distribution. jens@11: jens@11: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR jens@11: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND jens@11: FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI- jens@11: BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES jens@11: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR jens@11: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN jens@11: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF jens@11: THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. jens@11: */