Revision 133b1f2d pithos-macos/PithosBrowserController.m

b/pithos-macos/PithosBrowserController.m
339 339
- (BOOL)browser:(NSBrowser *)aBrowser writeRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column 
340 340
   toPasteboard:(NSPasteboard *)pasteboard {
341 341
    NSMutableArray *propertyList = [NSMutableArray arrayWithCapacity:[rowIndexes count]];
342
    NSIndexPath *baseIndexPath = [browser indexPathForColumn:column]; 
343
    for (NSUInteger i = [rowIndexes firstIndex]; i <= [rowIndexes lastIndex]; i = [rowIndexes indexGreaterThanIndex:i]) {
344
        PithosNode *node = [browser itemAtIndexPath:[baseIndexPath indexPathByAddingIndex:i]];
342
    NSIndexPath *baseIndexPath = [browser indexPathForColumn:column];
343
    [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop){
344
        PithosNode *node = [browser itemAtIndexPath:[baseIndexPath indexPathByAddingIndex:idx]];
345 345
        [propertyList addObject:[node.pithosObject.name pathExtension]];
346
    }
346
    }];
347 347

  
348 348
    [pasteboard declareTypes:[NSArray arrayWithObject:NSFilesPromisePboardType] owner:self];
349 349
    [pasteboard setPropertyList:propertyList forType:NSFilesPromisePboardType];
......
354 354
- (NSArray *)browser:(NSBrowser *)aBrowser namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination 
355 355
forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
356 356
    NSMutableArray *names = [NSMutableArray arrayWithCapacity:[rowIndexes count]];
357
    NSIndexPath *baseIndexPath = [browser indexPathForColumn:column]; 
358
    for (NSUInteger i = [rowIndexes firstIndex]; i <= [rowIndexes lastIndex]; i = [rowIndexes indexGreaterThanIndex:i]) {
359
        PithosNode *node = [browser itemAtIndexPath:[baseIndexPath indexPathByAddingIndex:i]];
357
    NSIndexPath *baseIndexPath = [browser indexPathForColumn:column];
358
    [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop){
359
        PithosNode *node = [browser itemAtIndexPath:[baseIndexPath indexPathByAddingIndex:idx]];
360 360
        
361 361
        // If the node is a subdir ask if the whole tree should be downloaded
362 362
        if ([node class] == [PithosSubdirNode class]) {
......
394 394
                [objectRequest startAsynchronous];
395 395
            }
396 396
        }
397
    }
397
    }];
398 398
    return names;
399 399
}
400 400

  
......
712 712
    return 220;
713 713
}
714 714

  
715
- (CGFloat)splitView:(NSSplitView *)splitView constrainSplitPosition:(CGFloat)proposedPosition ofSubviewAt:(NSInteger)dividerIndex {
716
    if (proposedPosition < 120)
717
        return 120;
718
    else if (proposedPosition > 220)
719
        return 220;
720
    else
721
        return proposedPosition;
722
}
723

  
715 724
#pragma mark -
716 725
#pragma mark NSOutlineViewDelegate
717 726

  
......
743 752
    if ((column == -1) || (row == -1)) {
744 753
        // General context menu
745 754
    } else {
755
        NSIndexPath *clickedNodeIndexPath = [[browser indexPathForColumn:column] indexPathByAddingIndex:row];
756
        NSArray *menuNodesIndexPaths = [browser selectionIndexPaths];
757
        if (![menuNodesIndexPaths containsObject:clickedNodeIndexPath])
758
            menuNodesIndexPaths = [NSArray arrayWithObject:clickedNodeIndexPath];
759
        
746 760
        // Move to Trash (pithos container only)
747 761
        // Delete
748 762
        if ([rootNode class] == [PithosContainerNode class]) {
749 763
            if ([rootNode.pithosContainer.name isEqualToString:@"pithos"]) {
750 764
                menuItem = [[[NSMenuItem alloc] initWithTitle:@"Move to Trash" action:@selector(moveToTrash:) keyEquivalent:@""] autorelease];
751
                [menuItem setRepresentedObject:[browser itemAtRow:row inColumn:column]];
765
                [menuItem setRepresentedObject:menuNodesIndexPaths];
752 766
                [menu addItem:menuItem];
753 767
            }
754 768
            menuItem = [[[NSMenuItem alloc] initWithTitle:@"Delete" action:@selector(deleteObject:) keyEquivalent:@""] autorelease];
755
            [menuItem setRepresentedObject:[browser itemAtRow:row inColumn:column]];
769
            [menuItem setRepresentedObject:menuNodesIndexPaths];
756 770
            [menu addItem:menuItem];
757 771
            [menu addItem:[NSMenuItem separatorItem]];
758 772
        }
759 773
        // Get Info
760 774
        menuItem = [[[NSMenuItem alloc] initWithTitle:@"Get Info" action:@selector(getInfo:) keyEquivalent:@""] autorelease];
761
        [menuItem setRepresentedObject:[browser itemAtRow:row inColumn:column]];
775
        [menuItem setRepresentedObject:menuNodesIndexPaths];
762 776
        [menu addItem:menuItem];
763 777
    }
764 778
}
......
767 781
#pragma mark Menu Actions
768 782

  
769 783
- (void)getInfo:(NSMenuItem *)sender {
770
    [(PithosNode *)[sender representedObject] showPithosNodeInfo:sender];
784
    for (NSIndexPath *nodeIndexPath in ((NSArray *)[sender representedObject])) {
785
        PithosNode *node = [browser itemAtIndexPath:nodeIndexPath];
786
        [node showPithosNodeInfo:sender];
787
    }
771 788
}
772 789

  
773 790
- (void)deleteObject:(NSMenuItem *)sender {
774
    PithosNode *node = (PithosNode *)[sender representedObject];
775
    if (([node class] == [PithosObjectNode class]) || 
776
        (([node class] == [PithosSubdirNode class]) && 
777
         !node.pithosObject.subdir &&
778
         [node.pithosObject.name hasSuffix:@"/"])) {
779
        ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest deleteObjectRequestWithContainerName:node.pithosContainer.name 
780
                                                                                                  objectName:node.pithosObject.name];
781
        objectRequest.delegate = self;
782
        objectRequest.didFinishSelector = @selector(deleteObjectFinished:);
783
        objectRequest.didFailSelector = @selector(deleteObjectFailed:);
784
        [objectRequest startAsynchronous];
785
    } else if ([node class] == [PithosSubdirNode class]) {
786
        NSArray *objectRequests = [PithosFileUtilities deleteObjectRequestsForSubdirWithContainerName:node.pithosContainer.name 
787
                                                                                           objectName:node.pithosObject.name];
788
        if (objectRequests) {
789
            for (ASIPithosObjectRequest *objectRequest in objectRequests) {
790
                objectRequest.delegate = self;
791
                objectRequest.didFinishSelector = @selector(deleteObjectFinished:);
792
                objectRequest.didFailSelector = @selector(deleteObjectFailed:);
793
                [objectRequest startAsynchronous];
794
            }
795
        }
796
        
797
    }    
798
}
799

  
800
- (void)moveToTrash:(NSMenuItem *)sender {
801
    PithosNode *node = (PithosNode *)[sender representedObject];
802
    if (([node class] == [PithosObjectNode class]) || 
803
        (([node class] == [PithosSubdirNode class]) && 
804
         !node.pithosObject.subdir &&
805
         [node.pithosObject.name hasSuffix:@"/"])) {
806
        NSString *safeObjectName = [PithosFileUtilities safeObjectNameForContainerName:@"trash" 
807
                                                                            objectName:node.pithosObject.name];
808
        if (safeObjectName) {
809
            ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest moveObjectDataRequestWithContainerName:node.pithosContainer.name 
810
                                                                                                        objectName:node.pithosObject.name 
811
                                                                                                       contentType:nil 
812
                                                                                                   contentEncoding:nil 
813
                                                                                                contentDisposition:nil 
814
                                                                                                          manifest:nil 
815
                                                                                                           sharing:nil 
816
                                                                                                          isPublic:ASIPithosObjectRequestPublicIgnore 
817
                                                                                                          metadata:nil 
818
                                                                                          destinationContainerName:@"trash" 
819
                                                                                             destinationObjectName:safeObjectName];
791
    for (NSIndexPath *nodeIndexPath in ((NSArray *)[sender representedObject])) {
792
        PithosNode *node = [browser itemAtIndexPath:nodeIndexPath];
793
        if (([node class] == [PithosObjectNode class]) || 
794
            (([node class] == [PithosSubdirNode class]) && 
795
             !node.pithosObject.subdir &&
796
             [node.pithosObject.name hasSuffix:@"/"])) {
797
            ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest deleteObjectRequestWithContainerName:node.pithosContainer.name 
798
                                                                                                      objectName:node.pithosObject.name];
820 799
            objectRequest.delegate = self;
821
            objectRequest.didFinishSelector = @selector(moveToTrashFinished:);
822
            objectRequest.didFailSelector = @selector(moveToTrashFailed:);
800
            objectRequest.didFinishSelector = @selector(deleteObjectFinished:);
801
            objectRequest.didFailSelector = @selector(deleteObjectFailed:);
823 802
            [objectRequest startAsynchronous];
824
        }
825
    } else if ([node class] == [PithosSubdirNode class]) {
826
        NSString *safeObjectName = [PithosFileUtilities safeSubdirNameForContainerName:@"trash" 
827
                                                                            subdirName:node.pithosObject.name];
828
        if (safeObjectName) {
829
            NSArray *objectRequests = [PithosFileUtilities moveObjectRequestsForSubdirWithContainerName:node.pithosContainer.name 
830
                                                                                             objectName:node.pithosObject.name 
831
                                                                               destinationContainerName:@"trash" 
832
                                                                                  destinationObjectName:safeObjectName];
803
        } else if ([node class] == [PithosSubdirNode class]) {
804
            NSArray *objectRequests = [PithosFileUtilities deleteObjectRequestsForSubdirWithContainerName:node.pithosContainer.name 
805
                                                                                               objectName:node.pithosObject.name];
833 806
            if (objectRequests) {
834 807
                for (ASIPithosObjectRequest *objectRequest in objectRequests) {
835 808
                    objectRequest.delegate = self;
836
                    objectRequest.didFinishSelector = @selector(moveToTrashFinished:);
837
                    objectRequest.didFailSelector = @selector(moveToTrashFailed:);
809
                    objectRequest.didFinishSelector = @selector(deleteObjectFinished:);
810
                    objectRequest.didFailSelector = @selector(deleteObjectFailed:);
838 811
                    [objectRequest startAsynchronous];
839 812
                }
840 813
            }
841
        }        
814
            
815
        }
816
    }
817
}
818

  
819
- (void)moveToTrash:(NSMenuItem *)sender {
820
    for (NSIndexPath *nodeIndexPath in ((NSArray *)[sender representedObject])) {
821
        PithosNode *node = [browser itemAtIndexPath:nodeIndexPath];
822
        if (([node class] == [PithosObjectNode class]) || 
823
            (([node class] == [PithosSubdirNode class]) && 
824
             !node.pithosObject.subdir &&
825
             [node.pithosObject.name hasSuffix:@"/"])) {
826
            NSString *safeObjectName = [PithosFileUtilities safeObjectNameForContainerName:@"trash" 
827
                                                                                objectName:node.pithosObject.name];
828
            if (safeObjectName) {
829
                ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest moveObjectDataRequestWithContainerName:node.pithosContainer.name 
830
                                                                                                            objectName:node.pithosObject.name 
831
                                                                                                           contentType:nil 
832
                                                                                                       contentEncoding:nil 
833
                                                                                                    contentDisposition:nil 
834
                                                                                                              manifest:nil 
835
                                                                                                               sharing:nil 
836
                                                                                                              isPublic:ASIPithosObjectRequestPublicIgnore 
837
                                                                                                              metadata:nil 
838
                                                                                              destinationContainerName:@"trash" 
839
                                                                                                 destinationObjectName:safeObjectName];
840
                objectRequest.delegate = self;
841
                objectRequest.didFinishSelector = @selector(moveToTrashFinished:);
842
                objectRequest.didFailSelector = @selector(moveToTrashFailed:);
843
                [objectRequest startAsynchronous];
844
            }
845
        } else if ([node class] == [PithosSubdirNode class]) {
846
            NSString *safeObjectName = [PithosFileUtilities safeSubdirNameForContainerName:@"trash" 
847
                                                                                subdirName:node.pithosObject.name];
848
            if (safeObjectName) {
849
                NSArray *objectRequests = [PithosFileUtilities moveObjectRequestsForSubdirWithContainerName:node.pithosContainer.name 
850
                                                                                                 objectName:node.pithosObject.name 
851
                                                                                   destinationContainerName:@"trash" 
852
                                                                                      destinationObjectName:safeObjectName];
853
                if (objectRequests) {
854
                    for (ASIPithosObjectRequest *objectRequest in objectRequests) {
855
                        objectRequest.delegate = self;
856
                        objectRequest.didFinishSelector = @selector(moveToTrashFinished:);
857
                        objectRequest.didFailSelector = @selector(moveToTrashFailed:);
858
                        [objectRequest startAsynchronous];
859
                    }
860
                }
861
            }        
862
        }
842 863
    }
843 864
}
844 865

  

Also available in: Unified diff