Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
I am implementing drag and drop for a NSOutlineview.

In the "validateDrop" method, I return either NSDragOperationCopy or NSDragOperationMove.

In the "acceptDrop" method, I ask "NSDraggingInfo" for which type of drag it is (see code below).
When the dragoperation is NSDragOperationCopy it behaves as it should.
But when the user does a move operaton, I always get NSDragOperationEvery (= -1), instead of NSDragOperationMove.

Is this normal behaviour, or is there something wrong? Why isn't NSDragOperationMove returned?

Code:
- (NSDragOperation)outlineView:(id)outlineView 
				  validateDrop:(id <NSDraggingInfo>)info 
				  proposedItem:(id)item //item is the proposed parent of the dragged items, item == nil is rootnode
			proposedChildIndex:(int)index {//index is the child location of the dragged items in item, index = -1: (replace item or) drop inside this item
	int myDragOperation = NSDragOperationNone;
	if(item) {
		//each item needs a parent !=nil
		id actualItem = [item representedObject]; 
		if ([actualItem isFolder]) {
			//each parent needs to be a folder
			id dtsrc = [[info draggingSource] dataSource];
			if (dtsrc == self) {
				if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
					myDragOperation = NSDragOperationCopy;	//option key is pressed
				else
					myDragOperation = NSDragOperationMove;
				
				//avoid drag of item on itself or in its children
				for (int i=0; i < [dataToDrag count]; i++) {
					id draggedItem = [[dataToDrag objectAtIndex:i] representedObject];
					if ((actualItem == draggedItem) || ([actualItem isChildOf:draggedItem]))
						myDragOperation = NSDragOperationNone;
				}
			} else {
				//copy from a different document
				myDragOperation = NSDragOperationCopy;
			}
		}
	}
	return myDragOperation;
}

- (BOOL)outlineView:(id)outlineView 
		 acceptDrop:(id <NSDraggingInfo>)info 
			   item:(id)item		//parent for the dragitems
		 childIndex:(int)index { //-1, add as a child to item, else add at this position to item
	//determine type of data
	NSArray *supportedTypes = [NSArray arrayWithObjects:@"myDropType",NSFilesPromisePboardType,nil]; //in order of preference
	NSString *bestType = [[info draggingPasteboard] availableTypeFromArray:supportedTypes];
	
	//process dragdata
	BOOL succes = NO;
	if ([bestType isEqualToString:@"myDropType"]){
		//my own type, use dataToDrag
		//drag tye
		NSDragOperation dragtype = [info draggingSourceOperationMask];
		if (dragtype == NSDragOperationCopy){
			printf("copy\n");
		}
		if (dragtype == NSDragOperationMove){
			printf("move\n");
		}
		if (dragtype == NSDragOperationEvery){
			printf("every\n");
		}
		NSLog(@"%i",dragtype);
		//origin data, this document, or another
		id src = [[info draggingSource] dataSource]; 
		
		
		succes = YES;
	} else if ([bestType isEqualToString:NSFilesPromisePboardType]){
		succes = YES;		
	}
	return succes;
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.