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.
 
 
 
 

87 lines
3.0 KiB

  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 "DirectoryOutline.h"
  8. @implementation DirectoryOutline
  9. - (id)initWithPyRef:(PyObject *)aPyRef outlineView:(HSOutlineView *)aOutlineView
  10. {
  11. self = [super initWithPyRef:aPyRef wrapperClass:[PyDirectoryOutline class]
  12. callbackClassName:@"DirectoryOutlineView" view:aOutlineView];
  13. [[self view] registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
  14. return self;
  15. }
  16. - (PyDirectoryOutline *)model
  17. {
  18. return (PyDirectoryOutline *)model;
  19. }
  20. /* Public */
  21. - (void)selectAll
  22. {
  23. [[self model] selectAll];
  24. }
  25. /* Delegate */
  26. - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id < NSDraggingInfo >)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
  27. {
  28. NSPasteboard *pboard;
  29. NSDragOperation sourceDragMask;
  30. sourceDragMask = [info draggingSourceOperationMask];
  31. pboard = [info draggingPasteboard];
  32. if ([[pboard types] containsObject:NSFilenamesPboardType]) {
  33. if (sourceDragMask & NSDragOperationLink)
  34. return NSDragOperationLink;
  35. }
  36. return NSDragOperationNone;
  37. }
  38. - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id < NSDraggingInfo >)info item:(id)item childIndex:(NSInteger)index
  39. {
  40. NSPasteboard *pboard;
  41. NSDragOperation sourceDragMask;
  42. sourceDragMask = [info draggingSourceOperationMask];
  43. pboard = [info draggingPasteboard];
  44. if ([[pboard types] containsObject:NSFilenamesPboardType]) {
  45. NSArray *foldernames = [pboard propertyListForType:NSFilenamesPboardType];
  46. if (!(sourceDragMask & NSDragOperationLink))
  47. return NO;
  48. for (NSString *foldername in foldernames) {
  49. [[self model] addDirectory:foldername];
  50. }
  51. NSDictionary *userInfo = [NSDictionary dictionaryWithObject:foldernames forKey:@"foldernames"];
  52. [[NSNotificationCenter defaultCenter] postNotificationName:DGAddedFoldersNotification
  53. object:self userInfo:userInfo];
  54. }
  55. return YES;
  56. }
  57. - (void)outlineView:(NSOutlineView *)aOutlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
  58. {
  59. if ([cell isKindOfClass:[NSTextFieldCell class]]) {
  60. NSTextFieldCell *textCell = cell;
  61. NSIndexPath *path = item;
  62. BOOL selected = [path isEqualTo:[[self view] selectedPath]];
  63. if (selected) {
  64. [textCell setTextColor:[NSColor blackColor]];
  65. return;
  66. }
  67. NSInteger state = [self intProperty:@"state" valueAtPath:path];
  68. if (state == 1) {
  69. [textCell setTextColor:[NSColor blueColor]];
  70. }
  71. else if (state == 2) {
  72. [textCell setTextColor:[NSColor redColor]];
  73. }
  74. else {
  75. [textCell setTextColor:[NSColor blackColor]];
  76. }
  77. }
  78. }
  79. @end