comparison dstep/appkit/NSWorkspace.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
children b9de51448c6b
comparison
equal deleted inserted replaced
15:7ff919f595d5 16:19885b43130e
1 /**
2 * Copyright: Copyright (c) 2009 Jacob Carlborg.
3 * Authors: Jacob Carlborg
4 * Version: Initial created: Sep 24, 2009
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6 */
7 module dstep.appkit.NSWorkspace;
8
9 import dstep.appkit.AppKitDefines;
10 import dstep.foundation.NSArray;
11 import dstep.appkit.NSImage;
12 import dstep.appkit.NSView;
13 import dstep.foundation.NSAppleEventDescriptor;
14 import dstep.foundation.NSDictionary;
15 import dstep.foundation.NSError;
16 import dstep.foundation.NSGeometry;
17 import dstep.foundation.NSNotification;
18 import dstep.foundation.NSObjCRuntime;
19 import dstep.foundation.NSObject;
20 import dstep.foundation.NSString;
21 import dstep.foundation.NSURL;
22 import dstep.foundation.NSValue;
23 import dstep.objc.bridge.Bridge;
24 import dstep.objc.objc;
25
26 import bindings = dstep.appkit.NSWorkspace_bindings;
27
28 typedef NSUInteger NSWorkspaceLaunchOptions;
29 typedef NSUInteger NSWorkspaceIconCreationOptions;
30
31 private
32 {
33 NSString NSWorkspaceDidLaunchApplicationNotification_;
34 NSString NSWorkspaceDidMountNotification_;
35 NSString NSWorkspaceDidPerformFileOperationNotification_;
36 NSString NSWorkspaceDidTerminateApplicationNotification_;
37 NSString NSWorkspaceDidUnmountNotification_;
38 NSString NSWorkspaceWillLaunchApplicationNotification_;
39 NSString NSWorkspaceWillPowerOffNotification_;
40 NSString NSWorkspaceWillUnmountNotification_;
41 NSString NSWorkspaceWillSleepNotification_;
42 NSString NSWorkspaceDidWakeNotification_;
43 NSString NSWorkspaceSessionDidBecomeActiveNotification_;
44 NSString NSWorkspaceSessionDidResignActiveNotification_;
45 NSString NSPlainFileType_;
46 NSString NSDirectoryFileType_;
47 NSString NSApplicationFileType_;
48 NSString NSFilesystemFileType_;
49 NSString NSShellCommandFileType_;
50 NSString NSWorkspaceMoveOperation_;
51 NSString NSWorkspaceCopyOperation_;
52 NSString NSWorkspaceLinkOperation_;
53 NSString NSWorkspaceCompressOperation_;
54 NSString NSWorkspaceDecompressOperation_;
55 NSString NSWorkspaceEncryptOperation_;
56 NSString NSWorkspaceDecryptOperation_;
57 NSString NSWorkspaceDestroyOperation_;
58 NSString NSWorkspaceRecycleOperation_;
59 NSString NSWorkspaceDuplicateOperation_;
60 }
61
62 NSString NSWorkspaceDidLaunchApplicationNotification ()
63 {
64 if (NSWorkspaceDidLaunchApplicationNotification_)
65 return NSWorkspaceDidLaunchApplicationNotification_;
66
67 return NSWorkspaceDidLaunchApplicationNotification_ = new NSString(bindings.NSWorkspaceDidLaunchApplicationNotification);
68 }
69
70 NSString NSWorkspaceDidMountNotification ()
71 {
72 if (NSWorkspaceDidMountNotification_)
73 return NSWorkspaceDidMountNotification_;
74
75 return NSWorkspaceDidMountNotification_ = new NSString(bindings.NSWorkspaceDidMountNotification);
76 }
77
78 NSString NSWorkspaceDidPerformFileOperationNotification ()
79 {
80 if (NSWorkspaceDidPerformFileOperationNotification_)
81 return NSWorkspaceDidPerformFileOperationNotification_;
82
83 return NSWorkspaceDidPerformFileOperationNotification_ = new NSString(bindings.NSWorkspaceDidPerformFileOperationNotification);
84 }
85
86 NSString NSWorkspaceDidTerminateApplicationNotification ()
87 {
88 if (NSWorkspaceDidTerminateApplicationNotification_)
89 return NSWorkspaceDidTerminateApplicationNotification_;
90
91 return NSWorkspaceDidTerminateApplicationNotification_ = new NSString(bindings.NSWorkspaceDidTerminateApplicationNotification);
92 }
93
94 NSString NSWorkspaceDidUnmountNotification ()
95 {
96 if (NSWorkspaceDidUnmountNotification_)
97 return NSWorkspaceDidUnmountNotification_;
98
99 return NSWorkspaceDidUnmountNotification_ = new NSString(bindings.NSWorkspaceDidUnmountNotification);
100 }
101
102 NSString NSWorkspaceWillLaunchApplicationNotification ()
103 {
104 if (NSWorkspaceWillLaunchApplicationNotification_)
105 return NSWorkspaceWillLaunchApplicationNotification_;
106
107 return NSWorkspaceWillLaunchApplicationNotification_ = new NSString(bindings.NSWorkspaceWillLaunchApplicationNotification);
108 }
109
110 NSString NSWorkspaceWillPowerOffNotification ()
111 {
112 if (NSWorkspaceWillPowerOffNotification_)
113 return NSWorkspaceWillPowerOffNotification_;
114
115 return NSWorkspaceWillPowerOffNotification_ = new NSString(bindings.NSWorkspaceWillPowerOffNotification);
116 }
117
118 NSString NSWorkspaceWillUnmountNotification ()
119 {
120 if (NSWorkspaceWillUnmountNotification_)
121 return NSWorkspaceWillUnmountNotification_;
122
123 return NSWorkspaceWillUnmountNotification_ = new NSString(bindings.NSWorkspaceWillUnmountNotification);
124 }
125
126 NSString NSWorkspaceWillSleepNotification ()
127 {
128 if (NSWorkspaceWillSleepNotification_)
129 return NSWorkspaceWillSleepNotification_;
130
131 return NSWorkspaceWillSleepNotification_ = new NSString(bindings.NSWorkspaceWillSleepNotification);
132 }
133
134 NSString NSWorkspaceDidWakeNotification ()
135 {
136 if (NSWorkspaceDidWakeNotification_)
137 return NSWorkspaceDidWakeNotification_;
138
139 return NSWorkspaceDidWakeNotification_ = new NSString(bindings.NSWorkspaceDidWakeNotification);
140 }
141
142 NSString NSWorkspaceSessionDidBecomeActiveNotification ()
143 {
144 if (NSWorkspaceSessionDidBecomeActiveNotification_)
145 return NSWorkspaceSessionDidBecomeActiveNotification_;
146
147 return NSWorkspaceSessionDidBecomeActiveNotification_ = new NSString(bindings.NSWorkspaceSessionDidBecomeActiveNotification);
148 }
149
150 NSString NSWorkspaceSessionDidResignActiveNotification ()
151 {
152 if (NSWorkspaceSessionDidResignActiveNotification_)
153 return NSWorkspaceSessionDidResignActiveNotification_;
154
155 return NSWorkspaceSessionDidResignActiveNotification_ = new NSString(bindings.NSWorkspaceSessionDidResignActiveNotification);
156 }
157
158 NSString NSPlainFileType ()
159 {
160 if (NSPlainFileType_)
161 return NSPlainFileType_;
162
163 return NSPlainFileType_ = new NSString(bindings.NSPlainFileType);
164 }
165
166 NSString NSDirectoryFileType ()
167 {
168 if (NSDirectoryFileType_)
169 return NSDirectoryFileType_;
170
171 return NSDirectoryFileType_ = new NSString(bindings.NSDirectoryFileType);
172 }
173
174 NSString NSApplicationFileType ()
175 {
176 if (NSApplicationFileType_)
177 return NSApplicationFileType_;
178
179 return NSApplicationFileType_ = new NSString(bindings.NSApplicationFileType);
180 }
181
182 NSString NSFilesystemFileType ()
183 {
184 if (NSFilesystemFileType_)
185 return NSFilesystemFileType_;
186
187 return NSFilesystemFileType_ = new NSString(bindings.NSFilesystemFileType);
188 }
189
190 NSString NSShellCommandFileType ()
191 {
192 if (NSShellCommandFileType_)
193 return NSShellCommandFileType_;
194
195 return NSShellCommandFileType_ = new NSString(bindings.NSShellCommandFileType);
196 }
197
198 NSString NSWorkspaceMoveOperation ()
199 {
200 if (NSWorkspaceMoveOperation_)
201 return NSWorkspaceMoveOperation_;
202
203 return NSWorkspaceMoveOperation_ = new NSString(bindings.NSWorkspaceMoveOperation);
204 }
205
206 NSString NSWorkspaceCopyOperation ()
207 {
208 if (NSWorkspaceCopyOperation_)
209 return NSWorkspaceCopyOperation_;
210
211 return NSWorkspaceCopyOperation_ = new NSString(bindings.NSWorkspaceCopyOperation);
212 }
213
214 NSString NSWorkspaceLinkOperation ()
215 {
216 if (NSWorkspaceLinkOperation_)
217 return NSWorkspaceLinkOperation_;
218
219 return NSWorkspaceLinkOperation_ = new NSString(bindings.NSWorkspaceLinkOperation);
220 }
221
222 NSString NSWorkspaceCompressOperation ()
223 {
224 if (NSWorkspaceCompressOperation_)
225 return NSWorkspaceCompressOperation_;
226
227 return NSWorkspaceCompressOperation_ = new NSString(bindings.NSWorkspaceCompressOperation);
228 }
229
230 NSString NSWorkspaceDecompressOperation ()
231 {
232 if (NSWorkspaceDecompressOperation_)
233 return NSWorkspaceDecompressOperation_;
234
235 return NSWorkspaceDecompressOperation_ = new NSString(bindings.NSWorkspaceDecompressOperation);
236 }
237
238 NSString NSWorkspaceEncryptOperation ()
239 {
240 if (NSWorkspaceEncryptOperation_)
241 return NSWorkspaceEncryptOperation_;
242
243 return NSWorkspaceEncryptOperation_ = new NSString(bindings.NSWorkspaceEncryptOperation);
244 }
245
246 NSString NSWorkspaceDecryptOperation ()
247 {
248 if (NSWorkspaceDecryptOperation_)
249 return NSWorkspaceDecryptOperation_;
250
251 return NSWorkspaceDecryptOperation_ = new NSString(bindings.NSWorkspaceDecryptOperation);
252 }
253
254 NSString NSWorkspaceDestroyOperation ()
255 {
256 if (NSWorkspaceDestroyOperation_)
257 return NSWorkspaceDestroyOperation_;
258
259 return NSWorkspaceDestroyOperation_ = new NSString(bindings.NSWorkspaceDestroyOperation);
260 }
261
262 NSString NSWorkspaceRecycleOperation ()
263 {
264 if (NSWorkspaceRecycleOperation_)
265 return NSWorkspaceRecycleOperation_;
266
267 return NSWorkspaceRecycleOperation_ = new NSString(bindings.NSWorkspaceRecycleOperation);
268 }
269
270 NSString NSWorkspaceDuplicateOperation ()
271 {
272 if (NSWorkspaceDuplicateOperation_)
273 return NSWorkspaceDuplicateOperation_;
274
275 return NSWorkspaceDuplicateOperation_ = new NSString(bindings.NSWorkspaceDuplicateOperation);
276 }
277
278 enum
279 {
280 NSWorkspaceLaunchAndPrint = 0x00000002,
281 NSWorkspaceLaunchInhibitingBackgroundOnly = 0x00000080,
282 NSWorkspaceLaunchWithoutAddingToRecents = 0x00000100,
283 NSWorkspaceLaunchWithoutActivation = 0x00000200,
284 NSWorkspaceLaunchAsync = 0x00010000,
285 NSWorkspaceLaunchAllowingClassicStartup = 0x00020000,
286 NSWorkspaceLaunchPreferringClassic = 0x00040000,
287 NSWorkspaceLaunchNewInstance = 0x00080000,
288 NSWorkspaceLaunchAndHide = 0x00100000,
289 NSWorkspaceLaunchAndHideOthers = 0x00200000,
290 NSWorkspaceLaunchDefault = NSWorkspaceLaunchAsync |
291 NSWorkspaceLaunchAllowingClassicStartup
292 }
293
294 enum
295 {
296 NSExcludeQuickDrawElementsIconCreationOption = 1 << 1,
297 NSExclude10_4ElementsIconCreationOption = 1 << 2
298 }
299
300 class NSWorkspace : NSObject
301 {
302 mixin (ObjcWrap);
303
304 static NSWorkspace sharedWorkspace ()
305 {
306 return invokeObjcSelfClass!(NSWorkspace, "sharedWorkspace");
307 }
308
309 NSNotificationCenter notificationCenter ()
310 {
311 return invokeObjcSelf!(NSNotificationCenter, "notificationCenter");
312 }
313
314 bool openFile (NSString fullPath)
315 {
316 return invokeObjcSelf!(bool, "openFile:", NSString)(fullPath);
317 }
318
319 bool openFile (NSString fullPath, NSString appName)
320 {
321 return invokeObjcSelf!(bool, "openFile:withApplication:", NSString, NSString)(fullPath, appName);
322 }
323
324 bool openFile (NSString fullPath, NSString appName, bool flag)
325 {
326 return invokeObjcSelf!(bool, "openFile:withApplication:andDeactivate:", NSString, NSString, bool)(fullPath, appName, flag);
327 }
328
329 bool openTempFile (NSString fullPath)
330 {
331 return invokeObjcSelf!(bool, "openTempFile:", NSString)(fullPath);
332 }
333
334 bool openFile (NSString fullPath, NSImage anImage, NSPoint point, NSView aView)
335 {
336 return invokeObjcSelf!(bool, "openFile:fromImage:at:inView:", NSString, NSImage, NSPoint, NSView)(fullPath, anImage, point, aView);
337 }
338
339 bool openURL (NSURL url)
340 {
341 return invokeObjcSelf!(bool, "openURL:", NSURL)(url);
342 }
343
344 bool launchApplication (NSString appName)
345 {
346 return invokeObjcSelf!(bool, "launchApplication:", NSString)(appName);
347 }
348
349 bool launchApplication (NSString appName, bool showIcon, bool autolaunch)
350 {
351 return invokeObjcSelf!(bool, "launchApplication:showIcon:autolaunch:", NSString, bool, bool)(appName, showIcon, autolaunch);
352 }
353
354 NSString fullPathForApplication (NSString appName)
355 {
356 return invokeObjcSelf!(NSString, "fullPathForApplication:", NSString)(appName);
357 }
358
359 bool selectFile (NSString fullPath, NSString rootFullpath)
360 {
361 return invokeObjcSelf!(bool, "selectFile:inFileViewerRootedAtPath:", NSString, NSString)(fullPath, rootFullpath);
362 }
363
364 void findApplications ()
365 {
366 return invokeObjcSelf!(void, "findApplications");
367 }
368
369 void noteFileSystemChanged ()
370 {
371 return invokeObjcSelf!(void, "noteFileSystemChanged");
372 }
373
374 void noteFileSystemChanged (NSString path)
375 {
376 return invokeObjcSelf!(void, "noteFileSystemChanged:", NSString)(path);
377 }
378
379 bool fileSystemChanged ()
380 {
381 return invokeObjcSelf!(bool, "fileSystemChanged");
382 }
383
384 void noteUserDefaultsChanged ()
385 {
386 return invokeObjcSelf!(void, "noteUserDefaultsChanged");
387 }
388
389 bool userDefaultsChanged ()
390 {
391 return invokeObjcSelf!(bool, "userDefaultsChanged");
392 }
393
394 bool getInfoForFile (NSString fullPath, out NSString appName, ref NSString type)
395 {
396 id app;
397 id t;
398
399 if (type)
400 t = type.objcObject;
401
402 bool result = invokeObjcSelf!(bool, "getInfoForFile:application:type:", NSString, id*, id*)(fullPath, &app, &t);
403
404 if (app)
405 appName = new NSString(app);
406
407 if (t)
408 type = new NSString(t);
409
410 return result;
411 }
412
413 bool isFilePackageAtPath (NSString fullPath)
414 {
415 return invokeObjcSelf!(bool, "isFilePackageAtPath:", NSString)(fullPath);
416 }
417
418 NSImage iconForFile (NSString fullPath)
419 {
420 return invokeObjcSelf!(NSImage, "iconForFile:", NSString)(fullPath);
421 }
422
423 NSImage iconForFiles (NSArray fullPaths)
424 {
425 return invokeObjcSelf!(NSImage, "iconForFiles:", NSArray)(fullPaths);
426 }
427
428 NSImage iconForFileType (NSString fileType)
429 {
430 return invokeObjcSelf!(NSImage, "iconForFileType:", NSString)(fileType);
431 }
432
433 bool setIcon (NSImage image, NSString fullPath, uint options)
434 {
435 return invokeObjcSelf!(bool, "setIcon:forFile:options:", NSImage, NSString, uint)(image, fullPath, options);
436 }
437
438 bool getFileSystemInfoForPath (NSString fullPath, bool* removableFlag, bool* writableFlag, bool* unmountableFlag, ref NSString description, ref NSString fileSystemType)
439 {
440 id desc;
441 id fileSysType;
442
443 if (description)
444 desc = description.objcObject;
445
446 if (fileSysType)
447 fileSysType = fileSystemType.objcObject;
448
449 bool result = invokeObjcSelf!(bool, "getFileSystemInfoForPath:isRemovable:isWritable:isUnmountable:description:type:", NSString, bool*, bool*, bool*, id*, id*)(fullPath, removableFlag, writableFlag, unmountableFlag, &desc, &fileSysType);
450
451 if (desc)
452 description = new NSString(desc);
453
454 if (fileSysType)
455 fileSystemType = new NSString(fileSysType);
456
457 return result;
458 }
459
460 bool performFileOperation (NSString operation, NSString source, NSString destination, NSArray files, NSInteger* tag)
461 {
462 return invokeObjcSelf!(bool, "performFileOperation:source:destination:files:tag:", NSString, NSString, NSString, NSArray, NSInteger*)(operation, source, destination, files, tag);
463 }
464
465 bool unmountAndEjectDeviceAtPath (NSString path)
466 {
467 return invokeObjcSelf!(bool, "unmountAndEjectDeviceAtPath:", NSString)(path);
468 }
469
470 NSInteger extendPowerOffBy (NSInteger requested)
471 {
472 return invokeObjcSelf!(NSInteger, "extendPowerOffBy:", NSInteger)(requested);
473 }
474
475 void slideImage (NSImage image, NSPoint fromPoint, NSPoint toPoint)
476 {
477 return invokeObjcSelf!(void, "slideImage:from:to:", NSImage, NSPoint, NSPoint)(image, fromPoint, toPoint);
478 }
479
480 void hideOtherApplications ()
481 {
482 return invokeObjcSelf!(void, "hideOtherApplications");
483 }
484
485 NSArray mountedLocalVolumePaths ()
486 {
487 return invokeObjcSelf!(NSArray, "mountedLocalVolumePaths");
488 }
489
490 NSArray mountedRemovableMedia ()
491 {
492 return invokeObjcSelf!(NSArray, "mountedRemovableMedia");
493 }
494
495 NSArray mountNewRemovableMedia ()
496 {
497 return invokeObjcSelf!(NSArray, "mountNewRemovableMedia");
498 }
499
500 void checkForRemovableMedia ()
501 {
502 return invokeObjcSelf!(void, "checkForRemovableMedia");
503 }
504
505 NSString absolutePathForAppBundleWithIdentifier (NSString bundleIdentifier)
506 {
507 return invokeObjcSelf!(NSString, "absolutePathForAppBundleWithIdentifier:", NSString)(bundleIdentifier);
508 }
509
510 bool launchAppWithBundleIdentifier (NSString bundleIdentifier, uint options, NSAppleEventDescriptor descriptor, ref NSNumber identifier)
511 {
512 id ident;
513
514 if (identifier)
515 ident = identifier.objcObject;
516
517 bool result = invokeObjcSelf!(bool, "launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier:", NSString, uint, NSAppleEventDescriptor, id*)(bundleIdentifier, options, descriptor, &ident);
518
519 if (ident)
520 identifier = new NSNumber(ident);
521
522 return result;
523 }
524
525 bool openURLs (NSArray urls, NSString bundleIdentifier, uint options, NSAppleEventDescriptor descriptor, ref NSArray identifiers)
526 {
527 id ident;
528
529 if (identifiers)
530 ident = identifiers.objcObject;
531
532 bool result = invokeObjcSelf!(bool, "openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers:", NSArray, NSString, uint, NSAppleEventDescriptor, id*)(urls, bundleIdentifier, options, descriptor, &ident);
533
534 if (ident)
535 identifiers = new NSArray(ident);
536
537 return result;
538 }
539
540 NSArray launchedApplications ()
541 {
542 return invokeObjcSelf!(NSArray, "launchedApplications");
543 }
544
545 NSDictionary activeApplication ()
546 {
547 return invokeObjcSelf!(NSDictionary, "activeApplication");
548 }
549
550 NSString typeOfFile (NSString absoluteFilePath, out NSError outError)
551 {
552 id error;
553
554 NSString result = invokeObjcSelf!(NSString, "typeOfFile:error:", NSString, id*)(absoluteFilePath, &error);
555
556 if (error)
557 outError = new NSError(error);
558
559 return result;
560 }
561
562 NSString localizedDescriptionForType (NSString typeName)
563 {
564 return invokeObjcSelf!(NSString, "localizedDescriptionForType:", NSString)(typeName);
565 }
566
567 NSString preferredFilenameExtensionForType (NSString typeName)
568 {
569 return invokeObjcSelf!(NSString, "preferredFilenameExtensionForType:", NSString)(typeName);
570 }
571
572 bool filenameExtension (NSString filenameExtension, NSString typeName)
573 {
574 return invokeObjcSelf!(bool, "filenameExtension:isValidForType:", NSString, NSString)(filenameExtension, typeName);
575 }
576
577 bool type (NSString firstTypeName, NSString secondTypeName)
578 {
579 return invokeObjcSelf!(bool, "type:conformsToType:", NSString, NSString)(firstTypeName, secondTypeName);
580 }
581 }
582