Skip to content

Instantly share code, notes, and snippets.

@drnic
Created December 31, 2008 03:08
Show Gist options
  • Save drnic/41854 to your computer and use it in GitHub Desktop.
Save drnic/41854 to your computer and use it in GitHub Desktop.
# Image well
def addImage(sender)
return unless recipe = recipeArrayController.selectedObjects.lastObject
p recipe # => #<NSManagedObject_Recipe_:0x800525ee0>
openPanel = NSOpenPanel.openPanel
openPanel.canChooseDirectories = false
openPanel.canCreateDirectories = false
openPanel.allowsMultipleSelection = false
selector = :"addImageSheetDidEnd:returnCode:contextInfo:"
openPanel.beginSheetForDirectory(nil, file: nil, modalForWindow: window, modalDelegate: self, didEndSelector: selector, contextInfo: recipe)
end
def addImageSheetDidEnd(openPanel, returnCode: returnCode, contextInfo: recipe)
return if returnCode == NSCancelButton
guid = NSProcessInfo.processInfo.globallyUniqueString
destPath = applicationSupportFolder.stringByAppendingPathComponent(guid)
NSFileManager.defaultManager.copyPath(openPanel.filename, toPath: destPath, handler: nil)
# recipe.imagePath = destPath # doesn't work?
p recipe # => #<Pointer:0x80065c1e0>
recipe.setValue(destPath, forKey:"imagePath")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment