0

I'm trying to enable drag and drop functionality for NSOutlineView in my MacOS app. I want to drag a child from a folder to another folder within the outline view.

I want test asset 1 to be dragged and dropped in Group 2

I have myOutlineView and a controller which is a data source and a delegate of my outline view.

In my outline view controller I have these three methods:

-(BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard

-(NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id < NSDraggingInfo >)info proposedItem:(id)item proposedChildIndex:(NSInteger)index

-(BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id < NSDraggingInfo >)info item:(id)item childIndex:(NSInteger)index

None of them is being called. My nib is setup properly, my outline view is getting filled and all of the functionality is working except the drag and drop feature.

I have also registered the drag type in awake from nib:

[_paraOutlineView registerForDraggedTypes:[NSArray arrayWithObject:@"QStyleSheetModel"]];

I also wrote this:

[_paraOutlineView setDraggingSourceOperationMask:NSDragOperationMove forLocal:YES];

What could be the reason?

5
  • Do you call setDraggingSourceOperationMask:forLocal:?
    – Willeke
    Commented Oct 9, 2023 at 7:24
  • @Willeke yes I did. But it still does not work.
    – Ishi
    Commented Oct 9, 2023 at 7:47
  • Implementing and calling the mentioned methods should do it. Any overrides or custom views in the cells?
    – Willeke
    Commented Oct 9, 2023 at 13:30
  • Yes, I have a custom view that derives from NSOutlineView. But none of the functions in the custom view gets called due to dragging and there are no overrides of these functions.
    – Ishi
    Commented Oct 10, 2023 at 5:32
  • Post a minimal reproducible example please.
    – Willeke
    Commented Oct 10, 2023 at 7:04

1 Answer 1

0

I have successfully resolved the issue! Although I couldn't initially pinpoint the exact problem, it turned out that the overridden function "setDataSource" in my code was making a call to an "init" function, which belonged to a different interface. This unexpected call to the "init" function was preventing the execution of "writeItems:toPasteBoard." The solution was to remove the call to the "init" function, and now everything works as expected.

Not the answer you're looking for? Browse other questions tagged or ask your own question.