1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-30 02:50:05 +00:00

Fixed multiple file drag and drop on OS X

This commit is contained in:
tpoole 2017-02-07 12:54:01 +00:00
parent 7778383ce3
commit dc5e039208
2 changed files with 44 additions and 8 deletions

View file

@ -1865,7 +1865,7 @@ struct JuceNSWindowClass : public ObjCClass<NSWindow>
addIvar<NSViewComponentPeer*> ("owner");
addMethod (@selector (canBecomeKeyWindow), canBecomeKeyWindow, "c@:");
addMethod (@selector (canBecomeMainWindow), canBecomeMainWindow, "c@:");
addMethod (@selector (canBecomeMainWindow), canBecomeMainWindow, "c@:");
addMethod (@selector (becomeKeyWindow), becomeKeyWindow, "v@:");
addMethod (@selector (windowShouldClose:), windowShouldClose, "c@:@");
addMethod (@selector (constrainFrameRect:toScreen:), constrainFrameRect, @encode (NSRect), "@:", @encode (NSRect), "@");

View file

@ -22,6 +22,26 @@
==============================================================================
*/
} // namespace juce
@interface NSDraggingSourceHelper : NSObject <NSDraggingSource>
{
}
@end
@implementation NSDraggingSourceHelper
-(NSDragOperation) draggingSession: (NSDraggingSession *)session sourceOperationMaskForDraggingContext: (NSDraggingContext)context
{
juce::ignoreUnused (session, context);
return NSDragOperationCopy;
}
@end
namespace juce {
//==============================================================================
void LookAndFeel::playAlertSound()
{
NSBeep();
@ -241,14 +261,30 @@ bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& fi
{
if (auto* event = [[view window] currentEvent])
{
auto dragRect = getDragRect (view, event);
auto* dragItems = [[[NSMutableArray alloc] init] autorelease];
for (auto& filename : files)
{
auto* nsFilename = juceStringToNS (filename);
auto* fileURL = [NSURL fileURLWithPath: nsFilename];
auto* dragItem = [[NSDraggingItem alloc] initWithPasteboardWriter: fileURL];
for (int i = 0; i < files.size(); ++i)
if (! [view dragFile: juceStringToNS (files[i])
fromRect: dragRect
slideBack: YES
event: event])
return false;
auto eventPos = [event locationInWindow];
auto dragRect = [view convertRect: NSMakeRect (eventPos.x - 16.0f, eventPos.y - 16.0f, 32.0f, 32.0f)
fromView: nil];
auto *dragImage = [[NSWorkspace sharedWorkspace] iconForFile: nsFilename];
[dragItem setDraggingFrame: dragRect
contents: dragImage];
[dragItems addObject: dragItem];
[dragItem release];
}
auto* helper = [[NSDraggingSourceHelper alloc] autorelease];
if (! [view beginDraggingSessionWithItems: dragItems
event: event
source: helper])
return false;
return true;
}