Mercurial > projects > dstep
annotate dstep/foundation/NSBundle.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | 7ff919f595d5 |
children | b9de51448c6b |
rev | line source |
---|---|
14 | 1 /** |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Aug 3, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.foundation.NSBundle; | |
8 | |
9 import dstep.foundation.NSArray; | |
10 import dstep.foundation.NSDictionary; | |
11 import dstep.foundation.NSError; | |
12 import dstep.foundation.NSObject; | |
13 import dstep.foundation.NSString; | |
14 import dstep.objc.bridge.Bridge; | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
15 import dstep.objc.objc; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
16 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
17 |
14 | 18 |
19 import bindings = dstep.foundation.NSBundle_bindings; | |
20 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
21 private |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
22 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
23 NSString NSBundleDidLoadNotification_; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
24 NSString NSLoadedClasses_; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
25 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
26 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
27 NSString NSBundleDidLoadNotification () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
28 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
29 if (NSBundleDidLoadNotification_) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
30 return NSBundleDidLoadNotification_; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
31 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
32 return NSBundleDidLoadNotification_ = new NSString(bindings.NSBundleDidLoadNotification); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
33 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
34 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
35 NSString NSLoadedClasses () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
36 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
37 if (NSLoadedClasses_) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
38 return NSLoadedClasses_; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
39 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
40 return NSLoadedClasses_ = new NSString(bindings.NSLoadedClasses); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
41 } |
14 | 42 |
43 enum | |
44 { | |
45 NSBundleExecutableArchitectureI386 = 0x00000007, | |
46 NSBundleExecutableArchitecturePPC = 0x00000012, | |
47 NSBundleExecutableArchitectureX86_64 = 0x01000007, | |
48 NSBundleExecutableArchitecturePPC64 = 0x01000012 | |
49 } | |
50 | |
51 class NSBundle : NSObject | |
52 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
53 mixin (ObjcWrap); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
54 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
55 this () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
56 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
57 super(typeof(this).alloc.init.objcObject); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
58 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
59 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
60 typeof(this) init () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
61 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
62 return invokeObjcSelf!(typeof(this), "init"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
63 } |
14 | 64 |
65 static NSBundle mainBundle () | |
66 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
67 return invokeObjcSuperClass!(NSBundle, "mainBundle"); |
15
7ff919f595d5
Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
68 } |
14 | 69 |
70 static NSBundle bundleWithPath (NSString path) | |
71 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
72 return invokeObjcSuperClass!(NSBundle, "bundleWithPath:", NSString)(path); |
15
7ff919f595d5
Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
73 } |
14 | 74 |
75 Object initWithPath (NSString path) | |
76 { | |
77 return invokeObjcSelf!(Object, "initWithPath:", NSString)(path); | |
78 } | |
79 | |
80 this (NSString path) | |
81 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
82 typeof(this).alloc.initWithPath(path); |
14 | 83 } |
84 | |
85 static NSBundle bundleForClass (Class aClass) | |
86 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
87 return invokeObjcSuperClass!(NSBundle, "bundleForClass:", Class)(aClass); |
15
7ff919f595d5
Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
88 } |
14 | 89 |
90 static NSBundle bundleWithIdentifier (NSString identifier) | |
91 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
92 return invokeObjcSuperClass!(NSBundle, "bundleWithIdentifier:", NSString)(identifier); |
15
7ff919f595d5
Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
93 } |
14 | 94 |
95 static NSArray allBundles () | |
96 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
97 return invokeObjcSuperClass!(NSArray, "allBundles"); |
14 | 98 } |
99 | |
100 static NSArray allFrameworks () | |
101 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
102 return invokeObjcSuperClass!(NSArray, "allFrameworks"); |
14 | 103 } |
104 | |
105 bool load () | |
106 { | |
107 return invokeObjcSelf!(bool, "load"); | |
108 } | |
109 | |
110 bool isLoaded () | |
111 { | |
112 return invokeObjcSelf!(bool, "isLoaded"); | |
113 } | |
114 | |
115 bool unload () | |
116 { | |
117 return invokeObjcSelf!(bool, "unload"); | |
118 } | |
119 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
120 bool preflightAndReturnError (ref NSError error) |
14 | 121 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
122 id err; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
123 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
124 if (error) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
125 err = new objc_object; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
126 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
127 bool result = invokeObjcSelf!(bool, "preflightAndReturnError:", id*)(&err); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
128 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
129 if (err) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
130 error = new NSError(err); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
131 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
132 return result; |
14 | 133 } |
134 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
135 bool loadAndReturnError (ref NSError error) |
14 | 136 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
137 id err; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
138 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
139 if (error) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
140 err = new objc_object; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
141 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
142 bool result = invokeObjcSelf!(bool, "loadAndReturnError:", id*)(&err); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
143 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
144 if (err) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
145 error = new NSError(err); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
146 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
147 return result; |
14 | 148 } |
149 | |
150 NSString bundlePath () | |
151 { | |
152 return invokeObjcSelf!(NSString, "bundlePath"); | |
153 } | |
154 | |
155 NSString resourcePath () | |
156 { | |
157 return invokeObjcSelf!(NSString, "resourcePath"); | |
158 } | |
159 | |
160 NSString executablePath () | |
161 { | |
162 return invokeObjcSelf!(NSString, "executablePath"); | |
163 } | |
164 | |
165 NSString pathForAuxiliaryExecutable (NSString executableName) | |
166 { | |
167 return invokeObjcSelf!(NSString, "pathForAuxiliaryExecutable:", NSString)(executableName); | |
168 } | |
169 | |
170 NSString privateFrameworksPath () | |
171 { | |
172 return invokeObjcSelf!(NSString, "privateFrameworksPath"); | |
173 } | |
174 | |
175 NSString sharedFrameworksPath () | |
176 { | |
177 return invokeObjcSelf!(NSString, "sharedFrameworksPath"); | |
178 } | |
179 | |
180 NSString sharedSupportPath () | |
181 { | |
182 return invokeObjcSelf!(NSString, "sharedSupportPath"); | |
183 } | |
184 | |
185 NSString builtInPlugInsPath () | |
186 { | |
187 return invokeObjcSelf!(NSString, "builtInPlugInsPath"); | |
188 } | |
189 | |
190 NSString bundleIdentifier () | |
191 { | |
192 return invokeObjcSelf!(NSString, "bundleIdentifier"); | |
193 } | |
194 | |
195 Class classNamed (NSString className) | |
196 { | |
197 return invokeObjcSelf!(Class, "classNamed:", NSString)(className); | |
198 } | |
199 | |
200 Class principalClass () | |
201 { | |
202 return invokeObjcSelf!(Class, "principalClass"); | |
203 } | |
204 | |
205 static NSString pathForResource (NSString name, NSString ext, NSString bundlePath) | |
206 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
207 return invokeObjcSuperClass!(NSString, "pathForResource:ofType:inDirectory:", NSString, NSString, NSString)(name, ext, bundlePath); |
14 | 208 } |
209 | |
210 NSString pathForResource (NSString name, NSString ext) | |
211 { | |
212 return invokeObjcSelf!(NSString, "pathForResource:ofType:", NSString, NSString)(name, ext); | |
213 } | |
214 | |
215 NSString pathForResource (NSString name, NSString ext, NSString subpath) | |
216 { | |
217 return invokeObjcSelf!(NSString, "pathForResource:ofType:inDirectory:", NSString, NSString, NSString)(name, ext, subpath); | |
218 } | |
219 | |
220 NSString pathForResource (NSString name, NSString ext, NSString subpath, NSString localizationName) | |
221 { | |
222 return invokeObjcSelf!(NSString, "pathForResource:ofType:inDirectory:forLocalization:", NSString, NSString, NSString, NSString)(name, ext, subpath, localizationName); | |
223 } | |
224 | |
225 static NSArray pathsForResourcesOfType (NSString ext, NSString bundlePath) | |
226 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
227 return invokeObjcSuperClass!(NSArray, "pathsForResourcesOfType:inDirectory:", NSString, NSString)(ext, bundlePath); |
14 | 228 } |
229 | |
230 NSArray pathsForResourcesOfType (NSString ext, NSString subpath) | |
231 { | |
232 return invokeObjcSelf!(NSArray, "pathsForResourcesOfType:inDirectory:", NSString, NSString)(ext, subpath); | |
233 } | |
234 | |
235 NSArray pathsForResourcesOfType (NSString ext, NSString subpath, NSString localizationName) | |
236 { | |
237 return invokeObjcSelf!(NSArray, "pathsForResourcesOfType:inDirectory:forLocalization:", NSString, NSString, NSString)(ext, subpath, localizationName); | |
238 } | |
239 | |
240 NSString localizedStringForKey (NSString key, NSString value, NSString tableName) | |
241 { | |
242 return invokeObjcSelf!(NSString, "localizedStringForKey:value:table:", NSString, NSString, NSString)(key, value, tableName); | |
243 } | |
244 | |
245 NSDictionary infoDictionary () | |
246 { | |
247 return invokeObjcSelf!(NSDictionary, "infoDictionary"); | |
248 } | |
249 | |
250 NSDictionary localizedInfoDictionary () | |
251 { | |
252 return invokeObjcSelf!(NSDictionary, "localizedInfoDictionary"); | |
253 } | |
254 | |
255 Object objectForInfoDictionaryKey (NSString key) | |
256 { | |
257 return invokeObjcSelf!(Object, "objectForInfoDictionaryKey:", NSString)(key); | |
258 } | |
259 | |
260 NSArray localizations () | |
261 { | |
262 return invokeObjcSelf!(NSArray, "localizations"); | |
263 } | |
264 | |
265 NSArray preferredLocalizations () | |
266 { | |
267 return invokeObjcSelf!(NSArray, "preferredLocalizations"); | |
268 } | |
269 | |
270 NSString developmentLocalization () | |
271 { | |
272 return invokeObjcSelf!(NSString, "developmentLocalization"); | |
273 } | |
274 | |
275 static NSArray preferredLocalizationsFromArray (NSArray localizationsArray) | |
276 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
277 return invokeObjcSuperClass!(NSArray, "preferredLocalizationsFromArray:", NSArray)(localizationsArray); |
14 | 278 } |
279 | |
280 static NSArray preferredLocalizationsFromArray (NSArray localizationsArray, NSArray preferencesArray) | |
281 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
282 return invokeObjcSuperClass!(NSArray, "preferredLocalizationsFromArray:forPreferences:", NSArray, NSArray)(localizationsArray, preferencesArray); |
14 | 283 } |
284 | |
285 NSArray executableArchitectures () | |
286 { | |
287 return invokeObjcSelf!(NSArray, "executableArchitectures"); | |
288 } | |
289 } | |
290 |