UniqueWindowController.m
author Jens Alfke <jens@mooseyard.com>
Thu Mar 20 09:05:58 2008 -0700 (2008-03-20)
changeset 1 e55a17cdabd2
child 2 3d3dcc3116d5
permissions -rw-r--r--
Configurable logging (LogTo).
Added "my_" prefix to category method names.
Added MurmurHash.
Added UniqueWindowController.
Bug fixes.
     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 
    11 
    12 @implementation UniqueWindowController
    13 
    14 
    15 + (UniqueWindowController*) instanceWith: (id)model
    16 {
    17     for( NSWindow *window in [NSApp windows] ) {
    18         id delegate = window.delegate;
    19         if( window.isVisible && [delegate isKindOfClass: [self class]] ) {
    20             UniqueWindowController *c = delegate;
    21             if( c.model == model )
    22                 return c;
    23         }
    24     }
    25     return nil;
    26 }
    27 
    28 
    29 + (UniqueWindowController*) openWith: (id)model
    30 {
    31     UniqueWindowController *w = [self instanceWith: model];
    32     if( ! w ) {
    33         w = [[self alloc] initWith: model];
    34         [w showWindow: self];
    35     }
    36     [w.window makeKeyAndOrderFront: self];
    37     return w;
    38 }
    39 
    40 
    41 - (void) windowWillClose: (NSNotification*)n
    42 {
    43     [self autorelease];
    44 }
    45 
    46 
    47 @end