2011-09-16 15:08:24 +00:00
|
|
|
/*
|
2013-04-28 14:35:51 +00:00
|
|
|
Copyright 2013 Hardcoded Software (http://www.hardcoded.net)
|
2011-09-16 15:08:24 +00:00
|
|
|
|
|
|
|
This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
|
|
|
which should be included with this package. The terms are also available at
|
|
|
|
http://www.hardcoded.net/licenses/bsd_license
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "PrioritizeList.h"
|
|
|
|
#import "Utils.h"
|
|
|
|
#import "Consts.h"
|
|
|
|
|
|
|
|
@implementation PrioritizeList
|
2012-01-12 22:40:23 +00:00
|
|
|
- (id)initWithPyRef:(PyObject *)aPyRef tableView:(NSTableView *)aTableView
|
|
|
|
{
|
2012-01-15 23:07:32 +00:00
|
|
|
self = [super initWithPyRef:aPyRef wrapperClass:[PyPrioritizeList class]
|
|
|
|
callbackClassName:@"PrioritizeListView" view:aTableView];
|
2012-01-12 22:40:23 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-01-13 15:20:46 +00:00
|
|
|
- (PyPrioritizeList *)model
|
2011-09-16 15:08:24 +00:00
|
|
|
{
|
2012-01-13 15:20:46 +00:00
|
|
|
return (PyPrioritizeList *)model;
|
2011-09-16 15:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setView:(NSTableView *)aTableView
|
|
|
|
{
|
|
|
|
[super setView:aTableView];
|
|
|
|
[[self view] registerForDraggedTypes:[NSArray arrayWithObject:DGPrioritizeIndexPasteboardType]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pboard
|
|
|
|
{
|
|
|
|
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
|
|
|
|
[pboard declareTypes:[NSArray arrayWithObject:DGPrioritizeIndexPasteboardType] owner:self];
|
|
|
|
[pboard setData:data forType:DGPrioritizeIndexPasteboardType];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row
|
|
|
|
proposedDropOperation:(NSTableViewDropOperation)op
|
|
|
|
{
|
|
|
|
if (op == NSTableViewDropAbove) {
|
|
|
|
return NSDragOperationMove;
|
|
|
|
}
|
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
|
|
|
|
row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
|
|
|
|
{
|
|
|
|
NSPasteboard* pboard = [info draggingPasteboard];
|
|
|
|
NSData* rowData = [pboard dataForType:DGPrioritizeIndexPasteboardType];
|
|
|
|
NSIndexSet* rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
|
2012-01-13 15:20:46 +00:00
|
|
|
[[self model] moveIndexes:[Utils indexSet2Array:rowIndexes] toIndex:row];
|
2011-09-16 15:08:24 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
@end
|