2010-02-07 14:26:50 +00:00
|
|
|
/*
|
2013-04-28 14:35:51 +00:00
|
|
|
Copyright 2013 Hardcoded Software (http://www.hardcoded.net)
|
2010-02-07 14:26:50 +00:00
|
|
|
|
2010-09-30 10:17:41 +00:00
|
|
|
This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2010-02-07 14:26:50 +00:00
|
|
|
which should be included with this package. The terms are also available at
|
2010-09-30 10:17:41 +00:00
|
|
|
http://www.hardcoded.net/licenses/bsd_license
|
2010-02-07 14:26:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#import "DirectoryOutline.h"
|
|
|
|
|
|
|
|
@implementation DirectoryOutline
|
2012-01-13 20:25:34 +00:00
|
|
|
- (id)initWithPyRef:(PyObject *)aPyRef outlineView:(HSOutlineView *)aOutlineView
|
2010-02-07 14:26:50 +00:00
|
|
|
{
|
2012-01-15 23:07:32 +00:00
|
|
|
self = [super initWithPyRef:aPyRef wrapperClass:[PyDirectoryOutline class]
|
|
|
|
callbackClassName:@"DirectoryOutlineView" view:aOutlineView];
|
|
|
|
[[self view] registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
|
2010-02-07 14:26:50 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-01-15 23:07:32 +00:00
|
|
|
- (PyDirectoryOutline *)model
|
2010-02-07 14:26:50 +00:00
|
|
|
{
|
2012-01-15 23:07:32 +00:00
|
|
|
return (PyDirectoryOutline *)model;
|
2010-02-07 14:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delegate */
|
|
|
|
- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id < NSDraggingInfo >)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
|
|
|
|
{
|
|
|
|
NSPasteboard *pboard;
|
|
|
|
NSDragOperation sourceDragMask;
|
|
|
|
sourceDragMask = [info draggingSourceOperationMask];
|
|
|
|
pboard = [info draggingPasteboard];
|
|
|
|
if ([[pboard types] containsObject:NSFilenamesPboardType]) {
|
|
|
|
if (sourceDragMask & NSDragOperationLink)
|
|
|
|
return NSDragOperationLink;
|
|
|
|
}
|
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id < NSDraggingInfo >)info item:(id)item childIndex:(NSInteger)index
|
|
|
|
{
|
|
|
|
NSPasteboard *pboard;
|
|
|
|
NSDragOperation sourceDragMask;
|
|
|
|
sourceDragMask = [info draggingSourceOperationMask];
|
|
|
|
pboard = [info draggingPasteboard];
|
|
|
|
if ([[pboard types] containsObject:NSFilenamesPboardType]) {
|
2011-01-27 09:27:17 +00:00
|
|
|
NSArray *foldernames = [pboard propertyListForType:NSFilenamesPboardType];
|
2010-02-07 14:26:50 +00:00
|
|
|
if (!(sourceDragMask & NSDragOperationLink))
|
|
|
|
return NO;
|
2011-01-27 09:27:17 +00:00
|
|
|
for (NSString *foldername in foldernames) {
|
2012-01-15 23:07:32 +00:00
|
|
|
[[self model] addDirectory:foldername];
|
2010-02-07 14:26:50 +00:00
|
|
|
}
|
2011-01-27 09:27:17 +00:00
|
|
|
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:foldernames forKey:@"foldernames"];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:DGAddedFoldersNotification
|
|
|
|
object:self userInfo:userInfo];
|
2010-02-07 14:26:50 +00:00
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)outlineView:(NSOutlineView *)aOutlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
|
|
|
|
{
|
|
|
|
if ([cell isKindOfClass:[NSTextFieldCell class]]) {
|
|
|
|
NSTextFieldCell *textCell = cell;
|
|
|
|
NSIndexPath *path = item;
|
2012-01-15 23:07:32 +00:00
|
|
|
BOOL selected = [path isEqualTo:[[self view] selectedPath]];
|
2010-02-07 14:26:50 +00:00
|
|
|
if (selected) {
|
|
|
|
[textCell setTextColor:[NSColor blackColor]];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NSInteger state = [self intProperty:@"state" valueAtPath:path];
|
|
|
|
if (state == 1) {
|
|
|
|
[textCell setTextColor:[NSColor blueColor]];
|
|
|
|
}
|
|
|
|
else if (state == 2) {
|
|
|
|
[textCell setTextColor:[NSColor redColor]];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[textCell setTextColor:[NSColor blackColor]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@end
|