I am triying to implement a nspathcontrol and want to handle the drag and drop operation within the code, but i am having problems. The draggingEntered and performDragOperation are not reacting.
What am I doing wrong?
[code] property templatePathControl : missing value – connected to pathcontrol in UI
on applicationWillFinishLaunching_(aNotification)
templatePathControl's registerForDraggedTypes_({"public.file-url"})
end applicationWillFinishLaunching_
on draggingEntered_(sender)
log "draggingEntered_"
set pb to sender's draggingPasteboard()
set theOptions to {NSPasteboardURLReadingFileURLsOnlyKey:1}
set theresult to pb's canReadObjectForClasses_options_({current application's |NSURL|}, theOptions)
return theresult
end draggingEntered_
on performDragOperation_(sender)
-- Get the file path
tell me to log "performDragOperation_"
set pb to sender's draggingPasteboard()
set theOptions to {NSPasteboardURLReadingFileURLsOnlyKey:1}
set imageURLs to pb's readObjectsForClasses_options_({current application's |NSURL|}, theOptions)
set draggedURL to item 1 of (imageURLs as list)
set filePath to draggedURL's |path|()
return true -- otherwise it doesn't happen
end performDragOperation_[/code]
Maybe this is related, not sure, but you do need this for drag and drop of files onto the app’s icon. Did you declare the document types you wish to be “seen” by your drag operation? In the Info panel of your Target, under the Properties Tab…
Also, I see you only register the public.file-url in the registerForDraggesTypes method, in the Docs it says:
Maybe this is the reason why it doesn’t work. Plus, maybe someone else can confirm, but based on what is said in the Docs, the dragging of a URL onto a Path control seems to be a fairly automatic process…
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)
Dropping a file on the app icon is not a problem and is working.
The problem is more the dragging en dropping of files on the pathcontrol widget in the UI.
The automatic handling of the drag and drop is no problem and works too.
I want to catch the the drop to take actions and accept or reject the dropped files.
[code]on pathControl_validateDrop_(sender, draginfo)
– return the type of operation you want
return current application’s NSDragOperationCopy
end pathControl_validateDrop_
on pathControl_acceptDrop_(sender, draginfo)
– your code here
– true to accept , false to deny the drop
return true or false
end pathControl_acceptDrop_[/code]