[aseprite] 38/64: Add support to drop files on OS X window (fix #605)
Tobias Hansen
thansen at moszumanska.debian.org
Tue Jun 21 14:43:03 UTC 2016
This is an automated email from the git hooks/post-receive script.
thansen pushed a commit to branch master
in repository aseprite.
commit 10be4b4d82746bd39c34113052ee9be23f4b29f8
Author: David Capello <davidcapello at gmail.com>
Date: Tue May 17 21:43:29 2016 -0300
Add support to drop files on OS X window (fix #605)
---
src/she/osx/app_delegate.mm | 12 ++----------
src/she/osx/generate_drop_files.h | 27 +++++++++++++++++++++++++++
src/she/osx/view.h | 2 ++
src/she/osx/view.mm | 23 +++++++++++++++++++++++
4 files changed, 54 insertions(+), 10 deletions(-)
diff --git a/src/she/osx/app_delegate.mm b/src/she/osx/app_delegate.mm
index 0c54771..4eefe80 100644
--- a/src/she/osx/app_delegate.mm
+++ b/src/she/osx/app_delegate.mm
@@ -16,6 +16,7 @@
#include "she/event.h"
#include "she/event_queue.h"
#include "she/osx/app.h"
+#include "she/osx/generate_drop_files.h"
#include "she/system.h"
@implementation OSXAppDelegate
@@ -39,16 +40,7 @@
- (BOOL)application:(NSApplication*)app openFiles:(NSArray*)filenames
{
- std::vector<std::string> files;
- for (int i=0; i<[filenames count]; ++i) {
- NSString* fn = [filenames objectAtIndex: i];
- files.push_back(base::normalize_path([fn UTF8String]));
- }
-
- she::Event ev;
- ev.setType(she::Event::DropFiles);
- ev.setFiles(files);
- she::queue_event(ev);
+ generate_drop_files_from_nsarray(filenames);
[app replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
return YES;
diff --git a/src/she/osx/generate_drop_files.h b/src/she/osx/generate_drop_files.h
new file mode 100644
index 0000000..1a7ea3e
--- /dev/null
+++ b/src/she/osx/generate_drop_files.h
@@ -0,0 +1,27 @@
+// SHE library
+// Copyright (C) 2016 David Capello
+//
+// This file is released under the terms of the MIT license.
+// Read LICENSE.txt for more information.
+
+#ifndef SHE_OSX_APP_GENERATE_DROP_FILES_H_INCLUDED
+#define SHE_OSX_APP_GENERATE_DROP_FILES_H_INCLUDED
+#pragma once
+
+#include "base/path.h"
+
+inline void generate_drop_files_from_nsarray(NSArray* filenames)
+{
+ std::vector<std::string> files;
+ for (int i=0; i<[filenames count]; ++i) {
+ NSString* fn = [filenames objectAtIndex: i];
+ files.push_back(base::normalize_path([fn UTF8String]));
+ }
+
+ she::Event ev;
+ ev.setType(she::Event::DropFiles);
+ ev.setFiles(files);
+ she::queue_event(ev);
+}
+
+#endif
diff --git a/src/she/osx/view.h b/src/she/osx/view.h
index 0a3e8c6..f71a2d7 100644
--- a/src/she/osx/view.h
+++ b/src/she/osx/view.h
@@ -50,6 +50,8 @@
- (void)createMouseTrackingArea;
- (void)destroyMouseTrackingArea;
- (void)updateCurrentCursor;
+- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender;
+- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender;
@end
#endif
diff --git a/src/she/osx/view.mm b/src/she/osx/view.mm
index eff8056..42e103e 100644
--- a/src/she/osx/view.mm
+++ b/src/she/osx/view.mm
@@ -14,6 +14,7 @@
#include "she/event.h"
#include "she/event_queue.h"
#include "she/keys.h"
+#include "she/osx/generate_drop_files.h"
#include "she/osx/window.h"
using namespace she;
@@ -97,6 +98,10 @@ bool is_key_pressed(KeyScancode scancode)
self = [super initWithFrame:frameRect];
if (self != nil) {
[self createMouseTrackingArea];
+ [self registerForDraggedTypes:
+ [NSArray arrayWithObjects:
+ NSFilenamesPboardType,
+ nil]];
}
return self;
}
@@ -466,4 +471,22 @@ bool is_key_pressed(KeyScancode scancode)
}
}
+- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender
+{
+ return NSDragOperationCopy;
+}
+
+- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
+{
+ NSPasteboard* pasteboard = [sender draggingPasteboard];
+
+ if ([pasteboard.types containsObject:NSFilenamesPboardType]) {
+ NSArray* filenames = [pasteboard propertyListForType:NSFilenamesPboardType];
+ generate_drop_files_from_nsarray(filenames);
+ return YES;
+ }
+ else
+ return NO;
+}
+
@end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git
More information about the Pkg-games-commits
mailing list