2013-09-01 83 views
1

如何實現NSOutlineViewDataSource拖拽Finder時拖拽文件系統中不存在的目錄?我已經搜索和搜索並閱讀了大量的文檔,但很難找到有用的任何有價值的東西。我使用管理類文件系統樹的自定義數據源,並且所有項目都是跟蹤其路徑的類的實例。我想能夠將文件和目錄拖出大綱視圖到Finder中。NSOutlineView拖拽目錄

我:

- (BOOL)outlineView:(NSOutlineView *)outlineView 
     writeItems:(NSArray *)items 
     toPasteboard:(NSPasteboard *)pasteboard 
{ 
    NSMutableArray *types = [NSMutableArray array]; 
    for (JOItemInfo *itemInfo in items) { 
     NSString *extension = itemInfo.name.pathExtension; 
     if (extension.length > 0) [types addObject:extension]; 
    } 

    [pasteboard declareTypes:@[(__bridge_transfer NSString *)kPasteboardTypeFileURLPromise] 
         owner:self]; 
    [pasteboard setPropertyList:types 
         forType:(__bridge_transfer NSString *)kPasteboardTypeFileURLPromise]; 
    DDLogInfo(@"Wrote types %@ to pasteboard %@ for key %@", 
       types, 
       pasteboard, 
       (__bridge_transfer NSString *)kPasteboardTypeFileURLPromise); 
    return YES; 
} 

,並寫入給定的通道里面的物品的-outlineView:namesOfPromisedFilesDroppedAtDestination:forDraggedItems:的實現。這樣做的作用在於我可以將項目拖出到Finder,但是當我放開時沒有其他任何事情發生,並且-...namesOfPromisedFilesDropped...方法甚至沒有被調用。此外,

[self.outlineView setDraggingDestinationFeedbackStyle:NSTableViewDraggingDestinationFeedbackStyleRegular]; 
[self.outlineView setDraggingSourceOperationMask:NSDragOperationNone forLocal:YES]; 
[self.outlineView setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO]; 

是在我的-awakeFromNibif (extension.length > 0) ...是基於我在某處找到的一個示例,但是它的日期和文檔說要返回一個擴展名,所以我認爲這是適當的。就我個人而言,我發現這個整個地區的文件非常缺乏,特別是關於NSOutlineView。謝謝!

回答

2

我將(__bridge_transfer NSString *)kPasteboardTypeFileURLPromise更改爲NSFilesPromisePboardType,我現在可以拖動文件(至少有擴展名),並且可以在Finder中成功刪除它們。 (我已經使用了前者的文件,後者建議這樣做,但它們並不具有相同的效果。)

此外,我嘗試刪除條件並允許它爲空擴展添加空字符串,它像一個魅力一樣工作。我現在可以拖出大綱視圖到Finder中。