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
|
@implementation MPEntryTableDataSource
|
||||||
|
|
||||||
- (BOOL)tableView:(NSTableView *)tableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard {
|
- (id<NSPasteboardWriting>)tableView:(NSTableView *)tableView pasteboardWriterForRow:(NSInteger)row {
|
||||||
NSMutableArray *entries = [[NSMutableArray alloc] initWithCapacity:rowIndexes.count];
|
id item = self.viewController.entryArrayController.arrangedObjects[row];
|
||||||
[rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
|
if([item isKindOfClass:KPKEntry.class]) {
|
||||||
[entries addObject:self.viewController.entryArrayController.arrangedObjects[idx]];
|
return item;
|
||||||
}];
|
|
||||||
for(KPKEntry *entry in entries) {
|
|
||||||
if(![entry isKindOfClass:[KPKEntry class]]) {
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
[pboard writeObjects:entries];
|
return nil;
|
||||||
return YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -31,22 +31,20 @@
|
|||||||
@property (weak) KPKGroup *localDraggedGroup;
|
@property (weak) KPKGroup *localDraggedGroup;
|
||||||
@property (weak) KPKEntry *localDraggedEntry;
|
@property (weak) KPKEntry *localDraggedEntry;
|
||||||
|
|
||||||
|
@property (strong) NSArray<KPKGroup *> *draggedGroups;
|
||||||
|
@property (strong) NSArray<KPKEntry *> *draggedEntries;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation MPOutlineDataSource
|
@implementation MPOutlineDataSource
|
||||||
|
|
||||||
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard {
|
- (id<NSPasteboardWriting>)outlineView:(NSOutlineView *)outlineView pasteboardWriterForItem:(id)item {
|
||||||
if(items.count != 1) {
|
id representedObject = [item representedObject];
|
||||||
return NO;
|
if([representedObject isKindOfClass:KPKGroup.class]) {
|
||||||
|
KPKGroup *group = representedObject;
|
||||||
|
return group;
|
||||||
}
|
}
|
||||||
self.localDraggedGroup = nil;
|
return nil;
|
||||||
id item = [items.lastObject representedObject];
|
|
||||||
if(![item isKindOfClass:KPKGroup.class]) {
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
KPKGroup *draggedGroup = item;
|
|
||||||
[pasteboard writeObjects:@[draggedGroup]];
|
|
||||||
return (nil != draggedGroup.parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id<NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index {
|
- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id<NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index {
|
||||||
|
|||||||
Reference in New Issue
Block a user