Skip to content

Commit

Permalink
basic file drag handling, displaying the image if it's an image file,…
Browse files Browse the repository at this point in the history
… or a file icon if not
  • Loading branch information
ejdraper committed May 19, 2015
1 parent 13080b1 commit a0944a6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions app/drag_and_drop_view.rb
@@ -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 added resources/file_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a0944a6

Please sign in to comment.