Drag and Drop it on my head...
Drag and Drop it on my head...
- Subject: Drag and Drop it on my head...
- From: Jerry LeVan <email@hidden>
- Date: Tue, 19 Nov 2002 20:34:47 -0500
Hi,
I am starting to look at drag and drop. I have a few questions :)
My first example contains a window with a NSTextField and a NSTextView
widget.
I made my "controller" class the window delegate and added the registration
and other drag destination routines into the class.
In my initial try I tried to register the window in the awakeFromNib
routine:
-(void)awakeFromNib // register for the type of pasteboard we are
interested in
{
NSLog(@"In awakeFromNib");
if([NSApp mainWindow]==nil) NSLog(@"Bad Mojo");
NSLog(@"MainWindow: %@",[NSApp mainWindow]);
[theWindow registerForDraggedTypes:
[NSArray arrayWithObject:NSFilenamesPboardType]];
[fileNameOutlet setStringValue:@"Drop a File on Me"];
}
My first surprise was that [NSApp mainWindow] does not return anything!
(I keep getting "Bad Mojo" in the log). So that is why I use theWindow in
the registration.
Question 1: Why does [NSApp mainWindow] return nil?
OK, it is sorta working, if I drag a file onto the window all of the
routines fire as expected and I can recover the pathname of the dragged
file.
However, If I drag the file into the window, then to the textView contained
in the window as soon as I enter the textView my code reports that the
dragging has quit. ( so a "drop" can't be done). It appears to me that the
textView probably has it's own drag and drop set up. This behavior is the
case whether or not the insertion point is visible.
If I drag an icon onto the textField and the cursor is flashing in the
textField (First Responder?) a drop will fail. However if the cursor is
*not* visible I *can* drag into the textField and the drop will succeed.
(ie I don't get the dragging quit message).
One of the goals of the project was to be able to drag a file icon onto a
textField (or a textView) and capture the filename. For a textField I would
place the name of the file into the textField for the textView I want to
display the file in the view.
Here is my *current* theory :)
If I want to able to ensure that I can drag a file icon to a textField, I
need to subclass NSTextField and in the subclass definition include all
of the registration and dragging destination routines.
Question 2: If the above is a true, then what are the "mechanics" of
implementing the subclass? Ie how do I use IB to tie the new class with the
textField dragged onto the main window template, where should the actual
code be placed? How can I communicate the results of the successful drag and
drop back to the main "controller" instance. (or do I even need to talk to
the controller?).
Question 3: How can I tell what behavior of the textField might have
clobbered by the subclass?
Question 4: Can I use the same strategy for textViews?
Whew, that's a mouthful :)
Thanks for any guidance...
--Jerry
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.