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