Skip to content
Permalink
Browse files

basic file drag handling, displaying the image if it's an image file,…

… or a file icon if not
  • Loading branch information
ejdraper committed May 19, 2015
1 parent 13080b1 commit a0944a6927deee56374f245a92122080f7a50959
Showing with 43 additions and 0 deletions.
  1. +43 −0 app/drag_and_drop_view.rb
  2. BIN resources/file_icon.png
@@ -1,2 +1,45 @@
class DragAndDropView < NSImageView
def draggingEntered(info)
self.highlight!
NSDragOperationCopy
end

def draggingExited(info)
self.unhighlight!
end

def prepareForDragOperation(info)
self.unhighlight!
end

def performDragOperation(info)
if info.draggingSource != self
if NSImage.canInitWithPasteboard(info.draggingPasteboard)
image = NSImage.alloc.initWithPasteboard(info.draggingPasteboard)
else
image = NSImage.imageNamed("file_icon")
end
self.setImage(image)
end
end

def highlight!
@highlight = true
self.needsDisplay = true
end

def unhighlight!
@highlight = false
self.needsDisplay = true
end

def drawRect(frame)
super(frame)

if @highlight
NSColor.grayColor.set
NSBezierPath.setDefaultLineWidth(5)
NSBezierPath.strokeRect(frame)
end
end
end
Binary file not shown.

0 comments on commit a0944a6

Please sign in to comment.
You can’t perform that action at this time.