UniqueWindowController.m
author Jens Alfke <jens@mooseyard.com>
Sun May 10 18:57:43 2009 -0700 (2009-05-10)
changeset 29 8874aff14cc9
parent 6 2d492d8c2053
permissions -rw-r--r--
* Added kv*Set utility functions for handling KV grunge when mutating an NSSet property.
* Change CFMakeCollectable to NSMakeCollectable.
jens@1
     1
//
jens@1
     2
//  UniqueWindowController.m
jens@11
     3
//  MYUtilities
jens@1
     4
//
jens@1
     5
//  Created by Jens Alfke on 3/14/08.
jens@11
     6
//  Copyright 2008 Jens Alfke. All rights reserved.
jens@1
     7
//
jens@1
     8
jens@1
     9
#import "UniqueWindowController.h"
jens@2
    10
#import "GraphicsUtils.h"
jens@1
    11
jens@1
    12
jens@1
    13
@implementation UniqueWindowController
jens@1
    14
jens@1
    15
jens@3
    16
+ (BOOL) isModel: (id)model1 equalToModel: (id)model2
jens@3
    17
{
jens@3
    18
    return model1==model2;
jens@3
    19
}
jens@3
    20
jens@3
    21
jens@1
    22
+ (UniqueWindowController*) instanceWith: (id)model
jens@1
    23
{
jens@2
    24
    for( NSWindow *window in OpenWindowsWithDelegateClass(self) ) {
jens@2
    25
        UniqueWindowController *c = window.delegate;
jens@3
    26
        if( [self isModel: c.model equalToModel: model] )
jens@2
    27
            return c;
jens@1
    28
    }
jens@1
    29
    return nil;
jens@1
    30
}
jens@1
    31
jens@1
    32
jens@1
    33
+ (UniqueWindowController*) openWith: (id)model
jens@1
    34
{
jens@1
    35
    UniqueWindowController *w = [self instanceWith: model];
jens@1
    36
    if( ! w ) {
jens@1
    37
        w = [[self alloc] initWith: model];
jens@1
    38
        [w showWindow: self];
jens@6
    39
    } else {
jens@6
    40
        if( model != w.model )
jens@6
    41
            [w reopenWith: model];
jens@1
    42
    }
jens@1
    43
    [w.window makeKeyAndOrderFront: self];
jens@1
    44
    return w;
jens@1
    45
}
jens@1
    46
jens@1
    47
jens@6
    48
- (void) reopenWith: (id)model
jens@6
    49
{
jens@6
    50
}
jens@6
    51
jens@6
    52
jens@1
    53
- (void) windowWillClose: (NSNotification*)n
jens@1
    54
{
jens@1
    55
    [self autorelease];
jens@1
    56
}
jens@1
    57
jens@1
    58
jens@1
    59
@end
jens@11
    60
jens@11
    61
jens@11
    62
/*
jens@11
    63
 Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
jens@11
    64
 
jens@11
    65
 Redistribution and use in source and binary forms, with or without modification, are permitted
jens@11
    66
 provided that the following conditions are met:
jens@11
    67
 
jens@11
    68
 * Redistributions of source code must retain the above copyright notice, this list of conditions
jens@11
    69
 and the following disclaimer.
jens@11
    70
 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
jens@11
    71
 and the following disclaimer in the documentation and/or other materials provided with the
jens@11
    72
 distribution.
jens@11
    73
 
jens@11
    74
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
jens@11
    75
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
jens@11
    76
 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
jens@11
    77
 BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
jens@11
    78
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
jens@11
    79
  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
jens@11
    80
 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
jens@11
    81
 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
jens@11
    82
 */