Skip to content
Permalink
Browse files

implementing a more detailed URL drag event handler that pulls out th…

…e page title also
  • Loading branch information
ejdraper committed May 19, 2015
1 parent aacf671 commit 01adfd330116c2b658ed9fbfcff873891894c439
Showing with 10 additions and 2 deletions.
  1. +5 −0 app/app_delegate.rb
  2. +5 −2 app/drag_and_drop_view.rb
@@ -63,4 +63,9 @@ def drag_received_for_text(text)
def drag_received_for_url(url)
@label.stringValue = "Received: #{url}"
end

def drag_received_for_url_and_title(url, title)
@label.stringValue = "Received: #{url}"
@mainWindow.title = title
end
end
@@ -34,6 +34,9 @@ def performDragOperation(info)
if info.draggingPasteboard.types.include?('NSFilenamesPboardType')
files = info.draggingPasteboard.propertyListForType('NSFilenamesPboardType')
self.send_delegate_event(:drag_received_for_file_paths, files)
elsif info.draggingPasteboard.types.include?('WebURLsWithTitlesPboardType')
url, title = info.draggingPasteboard.propertyListForType('WebURLsWithTitlesPboardType').flatten
self.send_delegate_event(:drag_received_for_url_and_title, url, title)
elsif info.draggingPasteboard.types.include?('public.url')
url = info.draggingPasteboard.propertyListForType('public.url')
self.send_delegate_event(:drag_received_for_url, url) unless url.nil?
@@ -64,10 +67,10 @@ def drawRect(frame)
end
end

def send_delegate_event(name, arg)
def send_delegate_event(name, *args)
return if self.delegate.nil?
return unless self.delegate.respond_to?(name.to_sym)

self.delegate.send(name, arg)
self.delegate.send(name, *args)
end
end

0 comments on commit 01adfd3

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