You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.0 KiB

4 years ago
  1. /*
  2. Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
  3. This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
  4. which should be included with this package. The terms are also available at
  5. http://www.gnu.org/licenses/gpl-3.0.html
  6. */
  7. #import "PrioritizeList.h"
  8. #import "Utils.h"
  9. #import "Consts.h"
  10. @implementation PrioritizeList
  11. - (id)initWithPyRef:(PyObject *)aPyRef tableView:(NSTableView *)aTableView
  12. {
  13. self = [super initWithPyRef:aPyRef wrapperClass:[PyPrioritizeList class]
  14. callbackClassName:@"PrioritizeListView" view:aTableView];
  15. return self;
  16. }
  17. - (PyPrioritizeList *)model
  18. {
  19. return (PyPrioritizeList *)model;
  20. }
  21. - (void)setView:(NSTableView *)aTableView
  22. {
  23. [super setView:aTableView];
  24. [[self view] registerForDraggedTypes:[NSArray arrayWithObject:DGPrioritizeIndexPasteboardType]];
  25. }
  26. - (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pboard
  27. {
  28. NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
  29. [pboard declareTypes:[NSArray arrayWithObject:DGPrioritizeIndexPasteboardType] owner:self];
  30. [pboard setData:data forType:DGPrioritizeIndexPasteboardType];
  31. return YES;
  32. }
  33. - (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row
  34. proposedDropOperation:(NSTableViewDropOperation)op
  35. {
  36. if (op == NSTableViewDropAbove) {
  37. return NSDragOperationMove;
  38. }
  39. return NSDragOperationNone;
  40. }
  41. - (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
  42. row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
  43. {
  44. NSPasteboard* pboard = [info draggingPasteboard];
  45. NSData* rowData = [pboard dataForType:DGPrioritizeIndexPasteboardType];
  46. NSIndexSet* rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
  47. [[self model] moveIndexes:[Utils indexSet2Array:rowIndexes] toIndex:row];
  48. return YES;
  49. }
  50. @end