mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-06 12:39:57 +00:00
Add support to drop files on OS X window (fix #605)
This commit is contained in:
parent
1ce74d3c5a
commit
10be4b4d82
@ -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;
|
||||
|
27
src/she/osx/generate_drop_files.h
Normal file
27
src/she/osx/generate_drop_files.h
Normal file
@ -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
|
@ -50,6 +50,8 @@
|
||||
- (void)createMouseTrackingArea;
|
||||
- (void)destroyMouseTrackingArea;
|
||||
- (void)updateCurrentCursor;
|
||||
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender;
|
||||
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user