Detecting whether the mouse is being dragged in AppKit

154 Views Asked by At

I have a view with a tracking area which changes the mouse cursor based on where the mouse is in the view. This same view is also a dragging destination for a certain type of file.

When I drag a file (e.g. from Finder) into this view, the green plus icon shows up next to the cursor briefly but then disappears once the tracking area updates the cursor. Is there any way for me to tell that the mouse is being dragged and not update the cursor if it is?

1

There are 1 best solutions below

0
DanielGibbs On

Not quite as direct as I'd hoped for, but one solution I came up with was to set a flag during the NSDraggingDestination methods, and then check that flag in the code that sets the cursor. This seems to work well enough.

- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
    self.dragIsBeingPerformed = YES;
    // Rest of method.
}

- (void)draggingExited:(id<NSDraggingInfo>)sender {
    self.dragIsBeingPerformed = NO;
    // Rest of method.
}

- (void)concludeDragOperation:(id<NSDraggingInfo>)sender {
    self.dragIsBeingPerformed = NO;
    // Rest of method.
}