Mercurial > projects > dstep
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dstep/appkit/NSWorkspace.d Sun Jan 03 22:06:11 2010 +0100 @@ -0,0 +1,582 @@ +/** + * Copyright: Copyright (c) 2009 Jacob Carlborg. + * Authors: Jacob Carlborg + * Version: Initial created: Sep 24, 2009 + * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) + */ +module dstep.appkit.NSWorkspace; + +import dstep.appkit.AppKitDefines; +import dstep.foundation.NSArray; +import dstep.appkit.NSImage; +import dstep.appkit.NSView; +import dstep.foundation.NSAppleEventDescriptor; +import dstep.foundation.NSDictionary; +import dstep.foundation.NSError; +import dstep.foundation.NSGeometry; +import dstep.foundation.NSNotification; +import dstep.foundation.NSObjCRuntime; +import dstep.foundation.NSObject; +import dstep.foundation.NSString; +import dstep.foundation.NSURL; +import dstep.foundation.NSValue; +import dstep.objc.bridge.Bridge; +import dstep.objc.objc; + +import bindings = dstep.appkit.NSWorkspace_bindings; + +typedef NSUInteger NSWorkspaceLaunchOptions; +typedef NSUInteger NSWorkspaceIconCreationOptions; + +private +{ + NSString NSWorkspaceDidLaunchApplicationNotification_; + NSString NSWorkspaceDidMountNotification_; + NSString NSWorkspaceDidPerformFileOperationNotification_; + NSString NSWorkspaceDidTerminateApplicationNotification_; + NSString NSWorkspaceDidUnmountNotification_; + NSString NSWorkspaceWillLaunchApplicationNotification_; + NSString NSWorkspaceWillPowerOffNotification_; + NSString NSWorkspaceWillUnmountNotification_; + NSString NSWorkspaceWillSleepNotification_; + NSString NSWorkspaceDidWakeNotification_; + NSString NSWorkspaceSessionDidBecomeActiveNotification_; + NSString NSWorkspaceSessionDidResignActiveNotification_; + NSString NSPlainFileType_; + NSString NSDirectoryFileType_; + NSString NSApplicationFileType_; + NSString NSFilesystemFileType_; + NSString NSShellCommandFileType_; + NSString NSWorkspaceMoveOperation_; + NSString NSWorkspaceCopyOperation_; + NSString NSWorkspaceLinkOperation_; + NSString NSWorkspaceCompressOperation_; + NSString NSWorkspaceDecompressOperation_; + NSString NSWorkspaceEncryptOperation_; + NSString NSWorkspaceDecryptOperation_; + NSString NSWorkspaceDestroyOperation_; + NSString NSWorkspaceRecycleOperation_; + NSString NSWorkspaceDuplicateOperation_; +} + +NSString NSWorkspaceDidLaunchApplicationNotification () +{ + if (NSWorkspaceDidLaunchApplicationNotification_) + return NSWorkspaceDidLaunchApplicationNotification_; + + return NSWorkspaceDidLaunchApplicationNotification_ = new NSString(bindings.NSWorkspaceDidLaunchApplicationNotification); +} + +NSString NSWorkspaceDidMountNotification () +{ + if (NSWorkspaceDidMountNotification_) + return NSWorkspaceDidMountNotification_; + + return NSWorkspaceDidMountNotification_ = new NSString(bindings.NSWorkspaceDidMountNotification); +} + +NSString NSWorkspaceDidPerformFileOperationNotification () +{ + if (NSWorkspaceDidPerformFileOperationNotification_) + return NSWorkspaceDidPerformFileOperationNotification_; + + return NSWorkspaceDidPerformFileOperationNotification_ = new NSString(bindings.NSWorkspaceDidPerformFileOperationNotification); +} + +NSString NSWorkspaceDidTerminateApplicationNotification () +{ + if (NSWorkspaceDidTerminateApplicationNotification_) + return NSWorkspaceDidTerminateApplicationNotification_; + + return NSWorkspaceDidTerminateApplicationNotification_ = new NSString(bindings.NSWorkspaceDidTerminateApplicationNotification); +} + +NSString NSWorkspaceDidUnmountNotification () +{ + if (NSWorkspaceDidUnmountNotification_) + return NSWorkspaceDidUnmountNotification_; + + return NSWorkspaceDidUnmountNotification_ = new NSString(bindings.NSWorkspaceDidUnmountNotification); +} + +NSString NSWorkspaceWillLaunchApplicationNotification () +{ + if (NSWorkspaceWillLaunchApplicationNotification_) + return NSWorkspaceWillLaunchApplicationNotification_; + + return NSWorkspaceWillLaunchApplicationNotification_ = new NSString(bindings.NSWorkspaceWillLaunchApplicationNotification); +} + +NSString NSWorkspaceWillPowerOffNotification () +{ + if (NSWorkspaceWillPowerOffNotification_) + return NSWorkspaceWillPowerOffNotification_; + + return NSWorkspaceWillPowerOffNotification_ = new NSString(bindings.NSWorkspaceWillPowerOffNotification); +} + +NSString NSWorkspaceWillUnmountNotification () +{ + if (NSWorkspaceWillUnmountNotification_) + return NSWorkspaceWillUnmountNotification_; + + return NSWorkspaceWillUnmountNotification_ = new NSString(bindings.NSWorkspaceWillUnmountNotification); +} + +NSString NSWorkspaceWillSleepNotification () +{ + if (NSWorkspaceWillSleepNotification_) + return NSWorkspaceWillSleepNotification_; + + return NSWorkspaceWillSleepNotification_ = new NSString(bindings.NSWorkspaceWillSleepNotification); +} + +NSString NSWorkspaceDidWakeNotification () +{ + if (NSWorkspaceDidWakeNotification_) + return NSWorkspaceDidWakeNotification_; + + return NSWorkspaceDidWakeNotification_ = new NSString(bindings.NSWorkspaceDidWakeNotification); +} + +NSString NSWorkspaceSessionDidBecomeActiveNotification () +{ + if (NSWorkspaceSessionDidBecomeActiveNotification_) + return NSWorkspaceSessionDidBecomeActiveNotification_; + + return NSWorkspaceSessionDidBecomeActiveNotification_ = new NSString(bindings.NSWorkspaceSessionDidBecomeActiveNotification); +} + +NSString NSWorkspaceSessionDidResignActiveNotification () +{ + if (NSWorkspaceSessionDidResignActiveNotification_) + return NSWorkspaceSessionDidResignActiveNotification_; + + return NSWorkspaceSessionDidResignActiveNotification_ = new NSString(bindings.NSWorkspaceSessionDidResignActiveNotification); +} + +NSString NSPlainFileType () +{ + if (NSPlainFileType_) + return NSPlainFileType_; + + return NSPlainFileType_ = new NSString(bindings.NSPlainFileType); +} + +NSString NSDirectoryFileType () +{ + if (NSDirectoryFileType_) + return NSDirectoryFileType_; + + return NSDirectoryFileType_ = new NSString(bindings.NSDirectoryFileType); +} + +NSString NSApplicationFileType () +{ + if (NSApplicationFileType_) + return NSApplicationFileType_; + + return NSApplicationFileType_ = new NSString(bindings.NSApplicationFileType); +} + +NSString NSFilesystemFileType () +{ + if (NSFilesystemFileType_) + return NSFilesystemFileType_; + + return NSFilesystemFileType_ = new NSString(bindings.NSFilesystemFileType); +} + +NSString NSShellCommandFileType () +{ + if (NSShellCommandFileType_) + return NSShellCommandFileType_; + + return NSShellCommandFileType_ = new NSString(bindings.NSShellCommandFileType); +} + +NSString NSWorkspaceMoveOperation () +{ + if (NSWorkspaceMoveOperation_) + return NSWorkspaceMoveOperation_; + + return NSWorkspaceMoveOperation_ = new NSString(bindings.NSWorkspaceMoveOperation); +} + +NSString NSWorkspaceCopyOperation () +{ + if (NSWorkspaceCopyOperation_) + return NSWorkspaceCopyOperation_; + + return NSWorkspaceCopyOperation_ = new NSString(bindings.NSWorkspaceCopyOperation); +} + +NSString NSWorkspaceLinkOperation () +{ + if (NSWorkspaceLinkOperation_) + return NSWorkspaceLinkOperation_; + + return NSWorkspaceLinkOperation_ = new NSString(bindings.NSWorkspaceLinkOperation); +} + +NSString NSWorkspaceCompressOperation () +{ + if (NSWorkspaceCompressOperation_) + return NSWorkspaceCompressOperation_; + + return NSWorkspaceCompressOperation_ = new NSString(bindings.NSWorkspaceCompressOperation); +} + +NSString NSWorkspaceDecompressOperation () +{ + if (NSWorkspaceDecompressOperation_) + return NSWorkspaceDecompressOperation_; + + return NSWorkspaceDecompressOperation_ = new NSString(bindings.NSWorkspaceDecompressOperation); +} + +NSString NSWorkspaceEncryptOperation () +{ + if (NSWorkspaceEncryptOperation_) + return NSWorkspaceEncryptOperation_; + + return NSWorkspaceEncryptOperation_ = new NSString(bindings.NSWorkspaceEncryptOperation); +} + +NSString NSWorkspaceDecryptOperation () +{ + if (NSWorkspaceDecryptOperation_) + return NSWorkspaceDecryptOperation_; + + return NSWorkspaceDecryptOperation_ = new NSString(bindings.NSWorkspaceDecryptOperation); +} + +NSString NSWorkspaceDestroyOperation () +{ + if (NSWorkspaceDestroyOperation_) + return NSWorkspaceDestroyOperation_; + + return NSWorkspaceDestroyOperation_ = new NSString(bindings.NSWorkspaceDestroyOperation); +} + +NSString NSWorkspaceRecycleOperation () +{ + if (NSWorkspaceRecycleOperation_) + return NSWorkspaceRecycleOperation_; + + return NSWorkspaceRecycleOperation_ = new NSString(bindings.NSWorkspaceRecycleOperation); +} + +NSString NSWorkspaceDuplicateOperation () +{ + if (NSWorkspaceDuplicateOperation_) + return NSWorkspaceDuplicateOperation_; + + return NSWorkspaceDuplicateOperation_ = new NSString(bindings.NSWorkspaceDuplicateOperation); +} + +enum +{ + NSWorkspaceLaunchAndPrint = 0x00000002, + NSWorkspaceLaunchInhibitingBackgroundOnly = 0x00000080, + NSWorkspaceLaunchWithoutAddingToRecents = 0x00000100, + NSWorkspaceLaunchWithoutActivation = 0x00000200, + NSWorkspaceLaunchAsync = 0x00010000, + NSWorkspaceLaunchAllowingClassicStartup = 0x00020000, + NSWorkspaceLaunchPreferringClassic = 0x00040000, + NSWorkspaceLaunchNewInstance = 0x00080000, + NSWorkspaceLaunchAndHide = 0x00100000, + NSWorkspaceLaunchAndHideOthers = 0x00200000, + NSWorkspaceLaunchDefault = NSWorkspaceLaunchAsync | +NSWorkspaceLaunchAllowingClassicStartup +} + +enum +{ + NSExcludeQuickDrawElementsIconCreationOption = 1 << 1, + NSExclude10_4ElementsIconCreationOption = 1 << 2 +} + +class NSWorkspace : NSObject +{ + mixin (ObjcWrap); + + static NSWorkspace sharedWorkspace () + { + return invokeObjcSelfClass!(NSWorkspace, "sharedWorkspace"); + } + + NSNotificationCenter notificationCenter () + { + return invokeObjcSelf!(NSNotificationCenter, "notificationCenter"); + } + + bool openFile (NSString fullPath) + { + return invokeObjcSelf!(bool, "openFile:", NSString)(fullPath); + } + + bool openFile (NSString fullPath, NSString appName) + { + return invokeObjcSelf!(bool, "openFile:withApplication:", NSString, NSString)(fullPath, appName); + } + + bool openFile (NSString fullPath, NSString appName, bool flag) + { + return invokeObjcSelf!(bool, "openFile:withApplication:andDeactivate:", NSString, NSString, bool)(fullPath, appName, flag); + } + + bool openTempFile (NSString fullPath) + { + return invokeObjcSelf!(bool, "openTempFile:", NSString)(fullPath); + } + + bool openFile (NSString fullPath, NSImage anImage, NSPoint point, NSView aView) + { + return invokeObjcSelf!(bool, "openFile:fromImage:at:inView:", NSString, NSImage, NSPoint, NSView)(fullPath, anImage, point, aView); + } + + bool openURL (NSURL url) + { + return invokeObjcSelf!(bool, "openURL:", NSURL)(url); + } + + bool launchApplication (NSString appName) + { + return invokeObjcSelf!(bool, "launchApplication:", NSString)(appName); + } + + bool launchApplication (NSString appName, bool showIcon, bool autolaunch) + { + return invokeObjcSelf!(bool, "launchApplication:showIcon:autolaunch:", NSString, bool, bool)(appName, showIcon, autolaunch); + } + + NSString fullPathForApplication (NSString appName) + { + return invokeObjcSelf!(NSString, "fullPathForApplication:", NSString)(appName); + } + + bool selectFile (NSString fullPath, NSString rootFullpath) + { + return invokeObjcSelf!(bool, "selectFile:inFileViewerRootedAtPath:", NSString, NSString)(fullPath, rootFullpath); + } + + void findApplications () + { + return invokeObjcSelf!(void, "findApplications"); + } + + void noteFileSystemChanged () + { + return invokeObjcSelf!(void, "noteFileSystemChanged"); + } + + void noteFileSystemChanged (NSString path) + { + return invokeObjcSelf!(void, "noteFileSystemChanged:", NSString)(path); + } + + bool fileSystemChanged () + { + return invokeObjcSelf!(bool, "fileSystemChanged"); + } + + void noteUserDefaultsChanged () + { + return invokeObjcSelf!(void, "noteUserDefaultsChanged"); + } + + bool userDefaultsChanged () + { + return invokeObjcSelf!(bool, "userDefaultsChanged"); + } + + bool getInfoForFile (NSString fullPath, out NSString appName, ref NSString type) + { + id app; + id t; + + if (type) + t = type.objcObject; + + bool result = invokeObjcSelf!(bool, "getInfoForFile:application:type:", NSString, id*, id*)(fullPath, &app, &t); + + if (app) + appName = new NSString(app); + + if (t) + type = new NSString(t); + + return result; + } + + bool isFilePackageAtPath (NSString fullPath) + { + return invokeObjcSelf!(bool, "isFilePackageAtPath:", NSString)(fullPath); + } + + NSImage iconForFile (NSString fullPath) + { + return invokeObjcSelf!(NSImage, "iconForFile:", NSString)(fullPath); + } + + NSImage iconForFiles (NSArray fullPaths) + { + return invokeObjcSelf!(NSImage, "iconForFiles:", NSArray)(fullPaths); + } + + NSImage iconForFileType (NSString fileType) + { + return invokeObjcSelf!(NSImage, "iconForFileType:", NSString)(fileType); + } + + bool setIcon (NSImage image, NSString fullPath, uint options) + { + return invokeObjcSelf!(bool, "setIcon:forFile:options:", NSImage, NSString, uint)(image, fullPath, options); + } + + bool getFileSystemInfoForPath (NSString fullPath, bool* removableFlag, bool* writableFlag, bool* unmountableFlag, ref NSString description, ref NSString fileSystemType) + { + id desc; + id fileSysType; + + if (description) + desc = description.objcObject; + + if (fileSysType) + fileSysType = fileSystemType.objcObject; + + bool result = invokeObjcSelf!(bool, "getFileSystemInfoForPath:isRemovable:isWritable:isUnmountable:description:type:", NSString, bool*, bool*, bool*, id*, id*)(fullPath, removableFlag, writableFlag, unmountableFlag, &desc, &fileSysType); + + if (desc) + description = new NSString(desc); + + if (fileSysType) + fileSystemType = new NSString(fileSysType); + + return result; + } + + bool performFileOperation (NSString operation, NSString source, NSString destination, NSArray files, NSInteger* tag) + { + return invokeObjcSelf!(bool, "performFileOperation:source:destination:files:tag:", NSString, NSString, NSString, NSArray, NSInteger*)(operation, source, destination, files, tag); + } + + bool unmountAndEjectDeviceAtPath (NSString path) + { + return invokeObjcSelf!(bool, "unmountAndEjectDeviceAtPath:", NSString)(path); + } + + NSInteger extendPowerOffBy (NSInteger requested) + { + return invokeObjcSelf!(NSInteger, "extendPowerOffBy:", NSInteger)(requested); + } + + void slideImage (NSImage image, NSPoint fromPoint, NSPoint toPoint) + { + return invokeObjcSelf!(void, "slideImage:from:to:", NSImage, NSPoint, NSPoint)(image, fromPoint, toPoint); + } + + void hideOtherApplications () + { + return invokeObjcSelf!(void, "hideOtherApplications"); + } + + NSArray mountedLocalVolumePaths () + { + return invokeObjcSelf!(NSArray, "mountedLocalVolumePaths"); + } + + NSArray mountedRemovableMedia () + { + return invokeObjcSelf!(NSArray, "mountedRemovableMedia"); + } + + NSArray mountNewRemovableMedia () + { + return invokeObjcSelf!(NSArray, "mountNewRemovableMedia"); + } + + void checkForRemovableMedia () + { + return invokeObjcSelf!(void, "checkForRemovableMedia"); + } + + NSString absolutePathForAppBundleWithIdentifier (NSString bundleIdentifier) + { + return invokeObjcSelf!(NSString, "absolutePathForAppBundleWithIdentifier:", NSString)(bundleIdentifier); + } + + bool launchAppWithBundleIdentifier (NSString bundleIdentifier, uint options, NSAppleEventDescriptor descriptor, ref NSNumber identifier) + { + id ident; + + if (identifier) + ident = identifier.objcObject; + + bool result = invokeObjcSelf!(bool, "launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier:", NSString, uint, NSAppleEventDescriptor, id*)(bundleIdentifier, options, descriptor, &ident); + + if (ident) + identifier = new NSNumber(ident); + + return result; + } + + bool openURLs (NSArray urls, NSString bundleIdentifier, uint options, NSAppleEventDescriptor descriptor, ref NSArray identifiers) + { + id ident; + + if (identifiers) + ident = identifiers.objcObject; + + bool result = invokeObjcSelf!(bool, "openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers:", NSArray, NSString, uint, NSAppleEventDescriptor, id*)(urls, bundleIdentifier, options, descriptor, &ident); + + if (ident) + identifiers = new NSArray(ident); + + return result; + } + + NSArray launchedApplications () + { + return invokeObjcSelf!(NSArray, "launchedApplications"); + } + + NSDictionary activeApplication () + { + return invokeObjcSelf!(NSDictionary, "activeApplication"); + } + + NSString typeOfFile (NSString absoluteFilePath, out NSError outError) + { + id error; + + NSString result = invokeObjcSelf!(NSString, "typeOfFile:error:", NSString, id*)(absoluteFilePath, &error); + + if (error) + outError = new NSError(error); + + return result; + } + + NSString localizedDescriptionForType (NSString typeName) + { + return invokeObjcSelf!(NSString, "localizedDescriptionForType:", NSString)(typeName); + } + + NSString preferredFilenameExtensionForType (NSString typeName) + { + return invokeObjcSelf!(NSString, "preferredFilenameExtensionForType:", NSString)(typeName); + } + + bool filenameExtension (NSString filenameExtension, NSString typeName) + { + return invokeObjcSelf!(bool, "filenameExtension:isValidForType:", NSString, NSString)(filenameExtension, typeName); + } + + bool type (NSString firstTypeName, NSString secondTypeName) + { + return invokeObjcSelf!(bool, "type:conformsToType:", NSString, NSString)(firstTypeName, secondTypeName); + } +} +