Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS] Improve drag-drop events #273

Merged
merged 1 commit into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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