Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drop Window for Playground
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
You can’t perform that action at this time.