NSOutlineView将项目拖放为文件

时间:2016-01-22 08:25:55

标签: objective-c cocoa drag-and-drop nsdocument

我最近正致力于一个旨在从rar档案中提取文件的项目。我使用NSOutlineView来呈现内容。其中每个文件和目录都列为类Entry项。我想将用户拖动的文件解压缩到Finder中的目标文件夹。但我无法做到正确,这里是条目中的相关代码:

- (NSArray<NSString *> *)writableTypesForPasteboard:(NSPasteboard *)pasteboard {
    NSLog(@"%s", __func__);
    // I don't known how to put an file representation on the pasteboard, and I don't want to extract it yet until the user drops in an Finder view. So I returned an URL, but seems not working.
    NSArray *ourTypes = @[(NSString *)kUTTypeURL];
    return ourTypes;
}

- (NSPasteboardWritingOptions)writingOptionsForType:(NSString *)_type pasteboard:(NSPasteboard *)pasteboard {
    NSLog(@"%s", __func__);

    if ([_type isEqualToString:NSPasteboardTypeString]) {
        return NSPasteboardWritingPromised;
    }
    return 0;
}

- (id)pasteboardPropertyListForType:(NSString *)_type {
    NSLog(@"%s", __func__);
    if ([_type isEqualToString:(NSString *)kUTTypeURL]) {
        NSURL *url = [NSURL fileURLWithPath:path];
        return [url pasteboardPropertyListForType:(NSString *)kUTTypeURL];
    }
    if ([_type isEqualToString:NSPasteboardTypeString]) {
        return self.name;
    } else {
        return nil;
    }
}

提前感谢任何信息或反馈。

0 个答案:

没有答案