mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 21:42:32 +00:00
Converting to modern API for drag and drop
This commit is contained in:
@@ -31,18 +31,12 @@
|
||||
|
||||
@implementation MPEntryTableDataSource
|
||||
|
||||
- (BOOL)tableView:(NSTableView *)tableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard {
|
||||
NSMutableArray *entries = [[NSMutableArray alloc] initWithCapacity:rowIndexes.count];
|
||||
[rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
[entries addObject:self.viewController.entryArrayController.arrangedObjects[idx]];
|
||||
}];
|
||||
for(KPKEntry *entry in entries) {
|
||||
if(![entry isKindOfClass:[KPKEntry class]]) {
|
||||
return NO;
|
||||
- (id<NSPasteboardWriting>)tableView:(NSTableView *)tableView pasteboardWriterForRow:(NSInteger)row {
|
||||
id item = self.viewController.entryArrayController.arrangedObjects[row];
|
||||
if([item isKindOfClass:KPKEntry.class]) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
[pboard writeObjects:entries];
|
||||
return YES;
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -31,22 +31,20 @@
|
||||
@property (weak) KPKGroup *localDraggedGroup;
|
||||
@property (weak) KPKEntry *localDraggedEntry;
|
||||
|
||||
@property (strong) NSArray<KPKGroup *> *draggedGroups;
|
||||
@property (strong) NSArray<KPKEntry *> *draggedEntries;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPOutlineDataSource
|
||||
|
||||
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard {
|
||||
if(items.count != 1) {
|
||||
return NO;
|
||||
- (id<NSPasteboardWriting>)outlineView:(NSOutlineView *)outlineView pasteboardWriterForItem:(id)item {
|
||||
id representedObject = [item representedObject];
|
||||
if([representedObject isKindOfClass:KPKGroup.class]) {
|
||||
KPKGroup *group = representedObject;
|
||||
return group;
|
||||
}
|
||||
self.localDraggedGroup = nil;
|
||||
id item = [items.lastObject representedObject];
|
||||
if(![item isKindOfClass:KPKGroup.class]) {
|
||||
return NO;
|
||||
}
|
||||
KPKGroup *draggedGroup = item;
|
||||
[pasteboard writeObjects:@[draggedGroup]];
|
||||
return (nil != draggedGroup.parent);
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id<NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index {
|
||||
|
||||
Reference in New Issue
Block a user