Drag and Drop

Hi All,

Making some progress on my app conversion to applescriptOBJ-C but am up against the wall with a simple drag and drop for a text field to receive a file path. Anyone have an example yet? The Cocoa Docs are a bit daunting on this.

Rob D

Dragging text from another location to your text field is built in. Just make sure the
text field is selected before doing the drag. Or in code set the text field as firstResponder.

Thanks Craig,

I just assumed nothing would be built in like that! It does receive files dropped. Is there a way though to make it receive without having to have focus first. There are several text fields and it would be nice to drop files on them sequentially.

Rob

Yes, but you have to implement Drag and Drop. There is a good example in “Cocoa Programming for OS X Third Edition” by Aaron Hillegass. You have to monitor the mouse’s location and when it gets over a text field, that field becomes first responder.

I don’t know how well this will work in AppleScriptObjC. I have been having issues getting more complicated tasks to work correctly.

One thing you could do, which will definitely work, is write an Objective-C class that handles the drag and drop. Its only purpose would be to monitor this task for those fields.

That’s what I thought.

I just ordered Aaron Hillegass’ book last week. This task was always a little dodgy the old way with “on drag entered” etc. so it may be that we have to write some OBJ-C classes this way. I always had to have a few custom classes anyways for things that applescript couldn’t do. Though friends always wrote them for me mostly…

It will be interesting to see just how first class this new citizen will be on OBJ-c environment. More complex stuff seems to be pushing the edges of the new bridge. Overall, I am loving it though so far. We’ll see. I wonder when Sal and friends will give us more examples?

Thanks Craig,

Rob

I’m stuck in much the same situation. I haven’t ordered any more books on objective C and won’t be doing so anytime in the near future. Does Hillegass’s 2nd edition have the same example? It’s only $5 as opposed to $25.

All I’m trying to do is get several text fields to accept dragged files and folders. It took me long enough in the former Applescript Studio to get this working and now it’s a whole new ballgame. Apple decides on some big changes and leaves us hanging in the breeze with no real documentation at all.

The examples and comments in this forum and anywhere else I could find them, are very sparse. The examples provided by Apple are opaque to me. I don’t have a phD in computer science. I have been so far unable to construct an Objective-C class for this. I would rather spend my time on something other than reinventing the wheel.

Does anyone have a complete app that allows more than one Text Fields to accept dragged files or folders? Please help out here.

Rather than drag and drop what if the app selects it when it becomes active, the app is made active by dragging and holding over a window and after a delay it is brought to the front, we’ve all done this before. So use:

on windowDidBecomeKey_(sender)
	myTextField's selectText_(sender)
end windowDidBecomeKey_

You must control drag from the window to the cube and select delegate for this to work.

thank you Richard. This works for one Text Field only. If I use a second field, I must first make it the focus, so this is not enough. Additionally, whatever is in the text field already will have the new text concatenated to it.

Is there a way of making a view become the focus by dragging something into the view?

Mike

New drag-and-drop stuff was introduced in 10.6, after the 3rd edition. Unfortunately the Xcode docs have only been partly updated at this stage, so it’s a bit hard to follow (at least, I find it so).

Can’t find it in NSView, guess you must use drag and drop.

I made a custom class for drag and drop for a text field with Craig’s help. It works great. If anyone is interested I can post it. You need though to make a separate class for each text field, at least with my simple understanding of OBj-C at the moment. You could do multiples with one class probably. I even have used it in my old ASS app since the drag and drop was always dodgy for the text fields.

I tried and tried to get my drag and drop to work for the table and the text fields via applescript class with no luck. That may be impossible. It sure would be great to see a developer example of how to do it via the script if it is. Where are all these (promised?) examples any ways? The tutorials are ok but I would love to see some simple demo apps of various UI implementations. Maybe sometime. Craig and Shane are hopefully getting a reward from apple for pioneering the use of this new ASOC bridge.

Rob