Created
June 4, 2015 23:06
-
-
Save erica/05f9468573bf5ec8d98b to your computer and use it in GitHub Desktop.
Drop Window for Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Cocoa | |
import XCPlayground | |
public let DropNotification = "DropNotification" | |
public class DropWindow : NSWindow { | |
required public init?(coder: NSCoder) { | |
super.init(coder: coder) | |
self.registerForDraggedTypes([NSFilenamesPboardType]) | |
} | |
override public init(contentRect: NSRect, styleMask aStyle: Int, backing bufferingType: NSBackingStoreType, defer flag: Bool) { | |
super.init(contentRect: contentRect, styleMask: aStyle, backing: bufferingType, defer: flag) | |
self.registerForDraggedTypes([NSFilenamesPboardType]) | |
} | |
public convenience init() { | |
let screenFrame : CGRect! = NSScreen.mainScreen()?.frame | |
self.init(contentRect:CGRectMake(screenFrame.size.width - 220, | |
screenFrame.size.height - 80, 120, 80), | |
styleMask: NSTitledWindowMask, backing: .Buffered, defer: false) | |
XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true) | |
NSApplication.sharedApplication().setActivationPolicy(.Regular) | |
self.makeKeyAndOrderFront(nil) | |
self.title = "Drop Files Here" | |
self.backgroundColor = .darkGrayColor() | |
} | |
public func draggingEntered(sender: NSDraggingInfo!) -> NSDragOperation {return NSDragOperation.Copy} | |
public func draggingUpdated(sender: NSDraggingInfo!) -> NSDragOperation {return NSDragOperation.Copy} | |
public func performDragOperation(sender: NSDraggingInfo!) -> Bool { | |
let pboard = sender.draggingPasteboard() | |
let files: [String]! = pboard.propertyListForType(NSFilenamesPboardType) as? [String] | |
NSNotificationCenter.defaultCenter().postNotificationName(DropNotification, object: files) | |
return true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment