//
//  UniqueWindowController.m
//  Cloudy
//
//  Created by Jens Alfke on 3/14/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "UniqueWindowController.h"
#import "GraphicsUtils.h"


@implementation UniqueWindowController


+ (BOOL) isModel: (id)model1 equalToModel: (id)model2
{
    return model1==model2;
}


+ (UniqueWindowController*) instanceWith: (id)model
{
    for( NSWindow *window in OpenWindowsWithDelegateClass(self) ) {
        UniqueWindowController *c = window.delegate;
        if( [self isModel: c.model equalToModel: model] )
            return c;
    }
    return nil;
}


+ (UniqueWindowController*) openWith: (id)model
{
    UniqueWindowController *w = [self instanceWith: model];
    if( ! w ) {
        w = [[self alloc] initWith: model];
        [w showWindow: self];
    } else {
        if( model != w.model )
            [w reopenWith: model];
    }
    [w.window makeKeyAndOrderFront: self];
    return w;
}


- (void) reopenWith: (id)model
{
}


- (void) windowWillClose: (NSNotification*)n
{
    [self autorelease];
}


@end
