From f3df13e7a137562b9d1db5279892571449eeb24c Mon Sep 17 00:00:00 2001 From: fauxpark Date: Mon, 5 Jul 2021 23:35:23 +1000 Subject: [PATCH] [macOS] Improve drag-drop events --- .gitignore | 2 +- macos/QMK Toolbox.xcodeproj/project.pbxproj | 4 +- .../xcschemes/QMK Toolbox.xcscheme | 8 ++-- macos/QMK Toolbox/QMKWindow.m | 43 +++++-------------- 4 files changed, 18 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index a5c77dd573..6f343ca87d 100644 --- a/.gitignore +++ b/.gitignore @@ -280,7 +280,7 @@ xcuserdata # you should judge for yourself, the pros and cons are mentioned at: # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control # -# Pods/ +Pods/ # Carthage # diff --git a/macos/QMK Toolbox.xcodeproj/project.pbxproj b/macos/QMK Toolbox.xcodeproj/project.pbxproj index 4d4bd2c530..a0e5b873ff 100644 --- a/macos/QMK Toolbox.xcodeproj/project.pbxproj +++ b/macos/QMK Toolbox.xcodeproj/project.pbxproj @@ -386,7 +386,7 @@ ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/QMK Toolbox", + "\"$(PROJECT_DIR)/QMK Toolbox\"", "$(PROJECT_DIR)", ); PRODUCT_BUNDLE_IDENTIFIER = fm.qmk.toolbox; @@ -407,7 +407,7 @@ ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/QMK Toolbox", + "\"$(PROJECT_DIR)/QMK Toolbox\"", "$(PROJECT_DIR)", ); PRODUCT_BUNDLE_IDENTIFIER = fm.qmk.toolbox; diff --git a/macos/QMK Toolbox.xcodeproj/xcshareddata/xcschemes/QMK Toolbox.xcscheme b/macos/QMK Toolbox.xcodeproj/xcshareddata/xcschemes/QMK Toolbox.xcscheme index df5c3bef65..dffce75c80 100644 --- a/macos/QMK Toolbox.xcodeproj/xcshareddata/xcschemes/QMK Toolbox.xcscheme +++ b/macos/QMK Toolbox.xcodeproj/xcshareddata/xcschemes/QMK Toolbox.xcscheme @@ -1,6 +1,6 @@ )sender { - NSPasteboard *pboard; - NSDragOperation sourceDragMask; + NSPasteboard *pboard = [sender draggingPasteboard]; - sourceDragMask = [sender draggingSourceOperationMask]; - pboard = [sender draggingPasteboard]; + if ([[pboard types] containsObject:NSFilenamesPboardType]) { + if ([[pboard pasteboardItems] count] == 1) { + NSString *file = [pboard propertyListForType:NSFilenamesPboardType][0]; + NSString * fileExtension = [[file pathExtension] lowercaseString]; - if ( [[pboard types] containsObject:NSFilenamesPboardType] ) { - if (sourceDragMask & NSDragOperationLink) { - return NSDragOperationLink; + if ([fileExtension isEqualToString:@"qmk"] || [fileExtension isEqualToString:@"hex"] || [fileExtension isEqualToString:@"bin"]) { + return NSDragOperationCopy; + } } } @@ -36,26 +32,9 @@ - (NSDragOperation)draggingEntered:(id )sender { } - (BOOL)performDragOperation:(id )sender { - NSPasteboard *pboard; - NSDragOperation sourceDragMask; - - sourceDragMask = [sender draggingSourceOperationMask]; - pboard = [sender draggingPasteboard]; - - NSArray *files = [pboard propertyListForType:NSFilenamesPboardType]; - for (NSString * file in files) { - if ([[[file pathExtension] lowercaseString] isEqualToString:@"qmk"] || - [[[file pathExtension] lowercaseString] isEqualToString:@"hex"] || - [[[file pathExtension] lowercaseString] isEqualToString:@"bin"]) { - [(AppDelegate *)[[NSApplication sharedApplication] delegate] setFilePath:[NSURL URLWithString:file]]; - } else { - NSAlert *alert = [[NSAlert alloc] init]; - - [alert setMessageText:@"This file format isn't supported"]; - [alert addButtonWithTitle:@"Sorry"]; - [alert runModal]; - } - } + NSPasteboard *pboard = [sender draggingPasteboard]; + NSString *file = [pboard propertyListForType:NSFilenamesPboardType][0]; + [(AppDelegate *)[[NSApplication sharedApplication] delegate] setFilePath:[NSURL fileURLWithPath:file]]; return YES; }