Skip to content

Commit

Permalink
[macOS] Improve drag-drop events (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark committed Jul 6, 2021
1 parent 313e257 commit d85bb9e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
4 changes: 2 additions & 2 deletions macos/QMK Toolbox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/QMK Toolbox",
"\"$(PROJECT_DIR)/QMK Toolbox\"",
"$(PROJECT_DIR)",
);
PRODUCT_BUNDLE_IDENTIFIER = fm.qmk.toolbox;
Expand All @@ -407,7 +407,7 @@
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/QMK Toolbox",
"\"$(PROJECT_DIR)/QMK Toolbox\"",
"$(PROJECT_DIR)",
);
PRODUCT_BUNDLE_IDENTIFIER = fm.qmk.toolbox;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1200"
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -40,9 +40,9 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Release"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
43 changes: 11 additions & 32 deletions macos/QMK Toolbox/QMKWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,29 @@ @implementation QMKWindow

- (void)setup {
[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
// [self registerForDraggedTypes:[NSArray arrayWithObjects:
// NSCreateFileContentsPboardType(@"qmk"),
// NSCreateFileContentsPboardType(@"hex"),
// NSCreateFileContentsPboardType(@"bin"),
// nil]];
};

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)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;
}
}
}

return NSDragOperationNone;
}

- (BOOL)performDragOperation:(id <NSDraggingInfo>)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;
}

Expand Down

0 comments on commit d85bb9e

Please sign in to comment.