00001 /* 00002 * _CPCibLoading.j 00003 * AppKit 00004 * 00005 * Created by Francisco Tolmasky. 00006 * Copyright 2008, 280 North, Inc. 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 @import <Foundation/CPBundle.j> 00024 @import <Foundation/CPDictionary.j> 00025 @import <Foundation/CPString.j> 00026 00027 00028 var CPCibOwner = @"CPCibOwner"; 00029 00030 var LoadInfoForCib = {}; 00031 00032 @implementation CPObject (CPCibLoading) 00033 00034 - (void)awakeFromCib 00035 { 00036 } 00037 00038 @end 00039 00040 @implementation CPBundle (CPCibLoading) 00041 00042 + (void)loadCibFile:(CPString)anAbsolutePath externalNameTable:(CPDictionary)aNameTable loadDelegate:aDelegate 00043 { 00044 var cib = [[CPCib alloc] initWithContentsOfURL:anAbsolutePath loadDelegate:self]; 00045 00046 LoadInfoForCib[[cib hash]] = { loadDelegate:aDelegate, externalNameTable:aNameTable }; 00047 } 00048 00049 + (void)loadCibNamed:(CPString)aName owner:(id)anOwner loadDelegate:(id)aDelegate 00050 { 00051 // Path is based solely on anOwner: 00052 var bundle = anOwner ? [CPBundle bundleForClass:[anOwner class]] : [CPBundle mainBundle], 00053 path = [bundle pathForResource:aName]; 00054 00055 [self loadCibFile:path externalNameTable:[CPDictionary dictionaryWithObject:anOwner forKey:CPCibOwner] loadDelegate:aDelegate]; 00056 } 00057 00058 - (void)loadCibFile:(CPString)aFileName externalNameTable:(CPDictionary)aNameTable loadDelegate:(id)aDelegate 00059 { 00060 var cib = [[CPCib alloc] initWithCibNamed:aFileName bundle:self loadDelegate:[self class]]; 00061 00062 LoadInfoForCib[[cib hash]] = { loadDelegate:aDelegate, externalNameTable:aNameTable }; 00063 } 00064 00065 + (void)cibDidFinishLoading:(CPCib)aCib 00066 { 00067 var loadInfo = LoadInfoForCib[[aCib hash]]; 00068 00069 delete LoadInfoForCib[[aCib hash]]; 00070 00071 [aCib instantiateCibWithExternalNameTable:loadInfo.externalNameTable]; 00072 00073 [loadInfo.loadDelegate cibDidFinishLoading:aCib]; 00074 } 00075 00076 @end