![]() |
API 0.9.5
|
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 00024 00025 var CPCibOwner = @"CPCibOwner"; 00026 00027 @implementation CPObject (CPCibLoading) 00028 00029 - (void)awakeFromCib 00030 { 00031 } 00032 00033 @end 00034 00035 @implementation CPBundle (CPCibLoading) 00036 00037 + (CPCib)loadCibFile:(CPString)anAbsolutePath externalNameTable:(CPDictionary)aNameTable 00038 { 00039 return [[[CPCib alloc] initWithContentsOfURL:anAbsolutePath] instantiateCibWithExternalNameTable:aNameTable]; 00040 } 00041 00042 + (CPCib)loadCibNamed:(CPString)aName owner:(id)anOwner 00043 { 00044 if (![aName hasSuffix:@".cib"]) 00045 aName = [aName stringByAppendingString:@".cib"]; 00046 00047 // Path is based solely on anOwner: 00048 var bundle = anOwner ? [CPBundle bundleForClass:[anOwner class]] : [CPBundle mainBundle], 00049 path = [bundle pathForResource:aName]; 00050 00051 return [self loadCibFile:path externalNameTable:[CPDictionary dictionaryWithObject:anOwner forKey:CPCibOwner]]; 00052 } 00053 00054 - (CPCib)loadCibFile:(CPString)aFileName externalNameTable:(CPDictionary)aNameTable 00055 { 00056 return [[[CPCib alloc] initWithContentsOfURL:aFileName] instantiateCibWithExternalNameTable:aNameTable]; 00057 } 00058 00059 + (CPCib)loadCibFile:(CPString)anAbsolutePath externalNameTable:(CPDictionary)aNameTable loadDelegate:aDelegate 00060 { 00061 return ([[CPCib alloc] 00062 initWithContentsOfURL:anAbsolutePath 00063 loadDelegate:[[_CPCibLoadDelegate alloc] 00064 initWithLoadDelegate:aDelegate 00065 externalNameTable:aNameTable]]); 00066 } 00067 00068 + (CPCib)loadCibNamed:(CPString)aName owner:(id)anOwner loadDelegate:(id)aDelegate 00069 { 00070 if (![aName hasSuffix:@".cib"]) 00071 aName = [aName stringByAppendingString:@".cib"]; 00072 00073 // Path is based solely on anOwner: 00074 var bundle = anOwner ? [CPBundle bundleForClass:[anOwner class]] : [CPBundle mainBundle], 00075 path = [bundle pathForResource:aName]; 00076 00077 return [self loadCibFile:path externalNameTable:[CPDictionary dictionaryWithObject:anOwner forKey:CPCibOwner] loadDelegate:aDelegate]; 00078 } 00079 00080 - (CPCib)loadCibFile:(CPString)aFileName externalNameTable:(CPDictionary)aNameTable loadDelegate:(id)aDelegate 00081 { 00082 return ([[CPCib alloc] 00083 initWithCibNamed:aFileName 00084 bundle:self 00085 loadDelegate:[[_CPCibLoadDelegate alloc] 00086 initWithLoadDelegate:aDelegate 00087 externalNameTable:aNameTable]]); 00088 } 00089 00090 @end 00091 00092 @implementation _CPCibLoadDelegate : CPObject 00093 { 00094 id _loadDelegate; 00095 CPDictionary _externalNameTable; 00096 } 00097 00098 - (id)initWithLoadDelegate:(id)aLoadDelegate externalNameTable:(id)anExternalNameTable 00099 { 00100 self = [self init]; 00101 00102 if (self) 00103 { 00104 _loadDelegate = aLoadDelegate; 00105 _externalNameTable = anExternalNameTable; 00106 } 00107 00108 return self; 00109 } 00110 00111 - (void)cibDidFinishLoading:(CPCib)aCib 00112 { 00113 [aCib instantiateCibWithExternalNameTable:_externalNameTable]; 00114 00115 [_loadDelegate cibDidFinishLoading:aCib]; 00116 } 00117 00118 - (void)cibDidFailToLoad:(CPCib)aCib 00119 { 00120 [_loadDelegate cibDidFailToLoad:aCib]; 00121 } 00122 00123 @end