Text Views, Text Fields and dragging
Text Views, Text Fields and dragging
- Subject: Text Views, Text Fields and dragging
- From: Harilaos Skiadas <email@hidden>
- Date: Sun, 12 Sep 2004 13:32:23 -0700 (PDT)
I'll give it another try and send my question again,
in hope for some response. It seems like a simple
question, but I can't figure out what goes wrong.
The situation is as follows. I have two windows,
window 1 and window 2. Window 1 has a text view, and
so does Window 2. They have not been subclassed.
Window 1 is the document window for a document based
application. Window 2 is in the same application,
different NIB file. Window 2 also has a text field. I
have subclassed the text field and added the six
operations supposed to allow drag and drop (code
follows) and have implemented my own way to deal with
the dropped data. When I drag to the text field from
the text view of window 2 (i.e. same window), no
problem, my code works fine.
But when I drag and drop from the text view in window
1 to the text field, it doesn't. To be more precise,
draggingEntered: and draggingExited: get called from
the text field, which I see with an NSLog, but neither
prepareForDragOperation: nor performDragOperation: get
called.
The drop is performed though, in the sense that my
text field contains as a value now whatever was
dragged. It just hasn't been processed.
I am afraid I can't explain this behavior, and it
really is bothersome. Hopefully I have just overlooked
something. Any ideas?
Here's the code:
- (unsigned int)draggingEntered:(id
<NSDraggingInfo>)sender
{
NSLog(@"draggingEntered");
if ([sender draggingSource] != self) {
NSPasteboard *pb = [sender draggingPasteboard];
NSString *type = [pb availableTypeFromArray:
[NSArray arrayWithObject:NSStringPboardType]];
if (type != nil) {
return NSDragOperationCopy;
}
}
return NSDragOperationNone;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender
{
NSLog(@"draggingExited");
}
- (BOOL)prepareForDragOperation:(id
<NSDraggingInfo>)sender
{
return YES;
}
- (BOOL)performDragOperation:(id
<NSDraggingInfo>)sender
{
NSLog(@"Performing Drag Operation");
NSPasteboard *pb = [sender draggingPasteboard];
if (![self readStringFromPasteboard:pb]) {
NSLog(@"Error: Could not read from dragging
pasteboard");
return NO;
}
return YES;
}
- (void)concludeDragOperation:(id
<NSDraggingInfo>)sender
{
NSLog(@"concludeDragOperation:");
}
- (BOOL)readStringFromPasteboard:(NSPasteboard *)pb
{
NSString *value;
NSString *type;
type = [pb availableTypeFromArray:[NSArray
arrayWithObject:NSStringPboardType]];
if (type) {
value = [pb stringForType:NSStringPboardType];
[[self delegate] sendCommandsToInput:[value
componentsSeparatedByString:@"\n"]];
return YES;
}
return NO;
}
TIA,
Haris
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden