 |
 |
Drag and Drop Cursor
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
Hey guys,
Im using a standard drag and drop procedure on my NSTextView. When I drop a file onto the TextView, their is a small blue border inside it (as normal) but there is no green + cursor like nearly every other app. Do I have to custom do this? I couldn't find anything on mamasam relating.
Thanks
Oliver
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Aug 2002
Location: Oxford, England
Status:
Offline
|
|
Read through this page and make sure you are returning NSDragOperationGeneric from the draggingEntered; method.
This page on cocoadev might help if you haven't already read it.
If you can't figure it out, post the code your using.
|
|
Luke
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
Hey,
I had a look in my draggingEntered: method and it seems quite custom. I'm a bit confused as to what I should change/add, here is my dragging and dropping code in my TextView subclass:
Code:
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
if (![self dragIsFile:sender])
{
return [super draggingEntered:sender];
}
[self lockFocus];
[[NSColor selectedControlColor] set];
NSFrameRectWithWidth([self visibleRect], 2.5);
[self unlockFocus];
[[self window] flushWindow];
return NSDragOperationGeneric;
}
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
{
NSRect currentRect;
if (![self dragIsFile:sender])
{
return [super draggingUpdated:sender];
}
currentRect = [self visibleRect];
if (!NSEqualRects(currentRect, previousRect))
{
previousRect = currentRect;
[self setNeedsDisplay:YES];
}
else
{
[self lockFocus];
[[NSColor selectedControlColor] set];
NSFrameRectWithWidth(currentRect, 2);
[self unlockFocus];
[[self window] flushWindow];
}
return NSDragOperationGeneric;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
if (![self dragIsFile:sender])
{
return [super prepareForDragOperation:sender];
}
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSString *filename;
BOOL result;
if (![self dragIsFile:sender])
{
return [super performDragOperation:sender];
}
filename = [self getFileForDrag:sender];
result = [[self delegate] handleDroppedFile:filename forTextView:self];
if (result == NO)
{
[self setNeedsDisplay:YES];
}
return result;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
if (![self dragIsFile:sender])
{
[super concludeDragOperation:sender];
return;
}
[self setNeedsDisplay:YES];
}
- (void)draggingExited:(id <NSDraggingInfo>)sender
{
if (![self dragIsFile:sender])
{
[super draggingExited:sender];
return;
}
[self setNeedsDisplay:YES];
}
- (BOOL)dragIsFile:(id <NSDraggingInfo>)sender
{
BOOL isDirectory;
BOOL fileExists;
NSString *dragFilename = [self getFileForDrag:sender];
if (dragFilename == nil)
{
return NO;
}
fileExists = [[NSFileManager defaultManager] fileExistsAtPath:dragFilename isDirectory:&isDirectory];
return (fileExists && (!isDirectory));
}
- (NSString *)getFileForDrag:(id <NSDraggingInfo>)sender
{
NSPasteboard *pb = [sender draggingPasteboard];
NSString *availableType = [pb availableTypeFromArray:[NSArray arrayWithObjects:NSFilenamesPboardType, NSPDFPboardType, nil]];
NSString *availableTypeString = [pb availableTypeFromArray:[NSArray arrayWithObjects:NSStringPboardType, nil]];
NSString *dragFilename;
NSArray *props;
if (availableType == nil)
{
return nil;
}
if (availableTypeString != nil)
{
return nil;
}
props = [pb propertyListForType:availableType];
dragFilename = [props objectAtIndex:0];
return dragFilename;
}
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2004
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |