UniqueWindowController.m
author Jens Alfke <jens@mooseyard.com>
Wed Sep 02 08:41:25 2009 -0700 (2009-09-02)
changeset 35 5cab3034d3a1
parent 6 2d492d8c2053
permissions -rw-r--r--
10.6 compatibility: Fix some new compiler warnings, and work around apparent regressions in NSTask and -stringByStandardizingPath.
     1 //
     2 //  UniqueWindowController.m
     3 //  MYUtilities
     4 //
     5 //  Created by Jens Alfke on 3/14/08.
     6 //  Copyright 2008 Jens Alfke. 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
    60 
    61 
    62 /*
    63  Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
    64  
    65  Redistribution and use in source and binary forms, with or without modification, are permitted
    66  provided that the following conditions are met:
    67  
    68  * Redistributions of source code must retain the above copyright notice, this list of conditions
    69  and the following disclaimer.
    70  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
    71  and the following disclaimer in the documentation and/or other materials provided with the
    72  distribution.
    73  
    74  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
    75  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
    76  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
    77  BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    78  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
    79   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
    80  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
    81  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    82  */