mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-16 20:59:38 +00:00
Drag and Drop of files to Finder started
This commit is contained in:
@@ -9,6 +9,8 @@
|
|||||||
#import "MPAttachmentTableDataSource.h"
|
#import "MPAttachmentTableDataSource.h"
|
||||||
#import "MPDocument.h"
|
#import "MPDocument.h"
|
||||||
|
|
||||||
|
#import "Kdb3Entry+KVOAdditions.h"
|
||||||
|
#import "Kdb4Entry+KVOAdditions.h"
|
||||||
|
|
||||||
@implementation MPAttachmentTableDataSource
|
@implementation MPAttachmentTableDataSource
|
||||||
|
|
||||||
@@ -56,5 +58,65 @@
|
|||||||
}
|
}
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
- (BOOL)tableView:(NSTableView *)tableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard {
|
||||||
|
NSString *extension;
|
||||||
|
|
||||||
|
if([rowIndexes count] != 1) {
|
||||||
|
return NO; // We only work with one file at a time
|
||||||
|
}
|
||||||
|
MPDocument *document = [[[tableView window] windowController] document];
|
||||||
|
id entry = document.selectedEntry;
|
||||||
|
NSUInteger row = [rowIndexes lastIndex];
|
||||||
|
if([entry isKindOfClass:[Kdb3Entry class]]) {
|
||||||
|
Kdb3Entry *entryV3 = (Kdb3Entry *)entry;
|
||||||
|
extension = [entryV3.binaryDesc pathExtension];
|
||||||
|
}
|
||||||
|
else if([entry isKindOfClass:[Kdb4Entry class]]) {
|
||||||
|
Kdb4Entry *entryV4 = (Kdb4Entry *)entry;
|
||||||
|
BinaryRef *binaryRef = entryV4.binaries[row];
|
||||||
|
extension = [binaryRef.key pathExtension];
|
||||||
|
}
|
||||||
|
NSString *uti = CFBridgingRelease(UTTypeCreatePreferredIdentifierForTag( kUTTagClassFilenameExtension, (__bridge CFStringRef)(extension), NULL ));
|
||||||
|
|
||||||
|
[pboard setPropertyList:@[uti] forType:(NSString *)kPasteboardTypeFilePromiseContent];
|
||||||
|
[pboard setPropertyList:@[uti] forType:(NSString *)kPasteboardTypeFileURLPromise ];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
- (NSArray *)tableView:(NSTableView *)tableView namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination forDraggedRowsWithIndexes:(NSIndexSet *)indexSet {
|
||||||
|
if([indexSet count] != 1) {
|
||||||
|
return nil; // We only work with one file at a time
|
||||||
|
}
|
||||||
|
|
||||||
|
if(![dropDestination isFileURL]) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSUInteger row = [indexSet lastIndex];
|
||||||
|
NSData *fileData;
|
||||||
|
NSString *filename;
|
||||||
|
|
||||||
|
MPDocument *document = [[[tableView window] windowController] document];
|
||||||
|
id entry = document.selectedEntry;
|
||||||
|
|
||||||
|
if([entry isKindOfClass:[Kdb3Entry class]]) {
|
||||||
|
Kdb3Entry *entryV3 = (Kdb3Entry *)entry;
|
||||||
|
filename = entryV3.binaryDesc;
|
||||||
|
fileData = entryV3.binary;
|
||||||
|
}
|
||||||
|
else if([entry isKindOfClass:[Kdb4Entry class]]) {
|
||||||
|
Kdb4Entry *entryV4 = (Kdb4Entry *)entry;
|
||||||
|
BinaryRef *binaryRef = entryV4.binaries[row];
|
||||||
|
filename = binaryRef.key;
|
||||||
|
fileData = [document attachmentDataForItem:binaryRef];
|
||||||
|
}
|
||||||
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
|
||||||
|
NSURL *writeURL = [dropDestination URLByAppendingPathComponent:filename];
|
||||||
|
// Create unique filename if already present
|
||||||
|
[fileData writeToURL:writeURL atomically:YES];
|
||||||
|
});
|
||||||
|
return @[filename];
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -119,12 +119,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)saveAttachmentForItem:(id)item toLocation:(NSURL *)location {
|
- (void)saveAttachmentForItem:(id)item toLocation:(NSURL *)location {
|
||||||
if([item isKindOfClass:[Kdb3Entry class]]) {
|
NSData *fileData = [self attachmentDataForItem:item];
|
||||||
Kdb3Entry *entry = (Kdb3Entry *)item;
|
if(!fileData) {
|
||||||
|
return; // No data to save;
|
||||||
|
}
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
if(! [entry.binary writeToURL:location options:NSDataWritingAtomic error:&error] ) {
|
if( ![fileData writeToURL:location options:NSDataWritingAtomic error:&error] ) {
|
||||||
[NSApp presentError:error];
|
[NSApp presentError:error];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSData *)attachmentDataForItem:(id)item {
|
||||||
|
if([item isKindOfClass:[Kdb3Entry class]]) {
|
||||||
|
Kdb3Entry *entry = (Kdb3Entry *)item;
|
||||||
|
return entry.binary;
|
||||||
}
|
}
|
||||||
else if([item isKindOfClass:[BinaryRef class]]) {
|
else if([item isKindOfClass:[BinaryRef class]]) {
|
||||||
Binary *binary = [self findBinary:item];
|
Binary *binary = [self findBinary:item];
|
||||||
@@ -137,16 +145,21 @@
|
|||||||
else {
|
else {
|
||||||
rawData = [NSMutableData mutableDataWithBase64DecodedData:[binary.data dataUsingEncoding:NSUTF8StringEncoding]];
|
rawData = [NSMutableData mutableDataWithBase64DecodedData:[binary.data dataUsingEncoding:NSUTF8StringEncoding]];
|
||||||
}
|
}
|
||||||
NSError *error = nil;
|
return rawData;
|
||||||
if( ![rawData writeToURL:location options:NSDataWritingAtomic error:&error] ) {
|
|
||||||
[NSApp presentError:error];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)attachmenFileNameForItem:(id)item {
|
||||||
|
if([item isKindOfClass:[Kdb3Entry class]]) {
|
||||||
|
Kdb3Entry *entry = (Kdb3Entry *)item;
|
||||||
|
return entry.binaryDesc;
|
||||||
}
|
}
|
||||||
else {
|
else if([item isKindOfClass:[BinaryRef class]]) {
|
||||||
NSAssert(NO, @"Item is neither BinaryRef nor Kdb3Entry");
|
return ((BinaryRef *)item).key;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSUInteger)nextBinaryId {
|
- (NSUInteger)nextBinaryId {
|
||||||
|
|||||||
@@ -111,6 +111,8 @@ APPKIT_EXTERN NSString *const MPDocumnetDidChangeCurrentEntryNotification;
|
|||||||
item can be either a BinaryRef or an Kdb3Entry.
|
item can be either a BinaryRef or an Kdb3Entry.
|
||||||
*/
|
*/
|
||||||
- (void)saveAttachmentForItem:(id)item toLocation:(NSURL *)location;
|
- (void)saveAttachmentForItem:(id)item toLocation:(NSURL *)location;
|
||||||
|
- (NSData *)attachmentDataForItem:(id)item;
|
||||||
|
- (NSString *)attachmenFileNameForItem:(id)item;
|
||||||
- (void)removeAttachment:(BinaryRef *)reference fromEntry:(KdbEntry *)anEntry;
|
- (void)removeAttachment:(BinaryRef *)reference fromEntry:(KdbEntry *)anEntry;
|
||||||
- (void)removeAttachmentFromEntry:(KdbEntry *)anEntry;
|
- (void)removeAttachmentFromEntry:(KdbEntry *)anEntry;
|
||||||
- (NSUInteger)nextBinaryId;
|
- (NSUInteger)nextBinaryId;
|
||||||
|
|||||||
Reference in New Issue
Block a user