Shift-refresh forces no use of cache.
[pithos-macos] / pithos-macos / PithosBrowserController.m
index f8a45af..4ec654a 100644 (file)
@@ -41,6 +41,7 @@
 #import "PithosContainerNode.h"
 #import "PithosSubdirNode.h"
 #import "PithosObjectNode.h"
+#import "PithosSharingAccountsNode.h"
 #import "PithosEmptyNode.h"
 #import "ImageAndTextCell.h"
 #import "FileSystemBrowserCell.h"
@@ -59,6 +60,7 @@
 - (id)init {
     if ((self = [super init])) {
         [self setLineBreakMode:NSLineBreakByTruncatingMiddle];
+        [self setEditable:YES];
     }
     return self;
 }
 
 @interface PithosBrowserController (Private) {}
 - (void)resetContainers:(NSNotification *)notification;
-- (void)getInfo:(NSMenuItem *)sender;
-- (void)downloadObjectFinished:(ASIPithosObjectRequest *)objectRequest;
-- (void)downloadObjectFailed:(ASIPithosObjectRequest *)objectRequest;
-- (void)uploadObjectUsingHashMapFinished:(ASIPithosObjectRequest *)objectRequest;
-- (void)uploadObjectUsingHashMapFailed:(ASIPithosObjectRequest *)objectRequest;
-- (void)uploadMissingBlockFinished:(ASIPithosObjectRequest *)objectRequest;
-- (void)uploadMissingBlockFailed:(ASIPithosObjectRequest *)objectRequest;
 @end
 
 @implementation PithosBrowserController
-@synthesize outlineViewDataSourceArray, splitView, outlineView, browser, draggedNodes, draggedParentNode;
+@synthesize verticalSplitView, horizontalSplitView, leftTopView, leftBottomView, outlineView, browser;
+@synthesize draggedNodes, draggedParentNode;
+@synthesize clipboardNodes, clipboardParentNode, clipboardCopy;
 
 #pragma mark -
 #pragma Object Lifecycle
 
 - (void)dealloc {
     [[NSNotificationCenter defaultCenter] removeObserver:self];
+    [clipboardParentNode release];
+    [clipboardNodes release];
     [draggedParentNode release];
     [draggedNodes release];
     [browserMenu release];
     [sharedPreviewController release];
-    [outlineViewDataSourceArray release];
+    [othersSharedNode release];
+    [mySharedNode release];
+    [sharedNode release];
+    [containersNodeChildren release];
+    [containersNode release];
     [accountNode release];
     [rootNode release];
     [super dealloc];
 - (void)resetContainers:(NSNotification *)notification {
     rootNode = nil;
     [browser loadColumnZero];
-    self.outlineViewDataSourceArray = nil;
-    
-    // Create the outlineView tree
-    // CONTAINERS
-       NSTreeNode *containersTreeNode = [NSTreeNode treeNodeWithRepresentedObject:
-                            [[[PithosEmptyNode alloc] initWithDisplayName:@"CONTAINERS" icon:nil] autorelease]];
-
-    // SHARED
-       NSTreeNode *sharedTreeNode = [NSTreeNode treeNodeWithRepresentedObject:
-                                      [[[PithosEmptyNode alloc] initWithDisplayName:@"SHARED" icon:nil] autorelease]];
-    // SHARED/my shared
-       [[sharedTreeNode mutableChildNodes] addObject:
-     [NSTreeNode treeNodeWithRepresentedObject:
-      [[[PithosEmptyNode alloc] initWithDisplayName:@"my shared" 
-                                               icon:[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kUserIcon)]
-        ] autorelease]]];
-    // SHARED/others shared
-       [[sharedTreeNode mutableChildNodes] addObject:
-     [NSTreeNode treeNodeWithRepresentedObject:
-      [[[PithosEmptyNode alloc] initWithDisplayName:@"others shared"
-                                               icon:[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGroupIcon)]
-        ] autorelease]]];
-    
-    self.outlineViewDataSourceArray = [NSMutableArray arrayWithObjects:containersTreeNode, sharedTreeNode, nil];
-    
+    [containersNodeChildren removeAllObjects];
+    [outlineView reloadData];
        // Expand the folder outline view
     [outlineView expandItem:nil expandChildren:YES];
        [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
     
-    // Create accountNode and trigger a refresh
-    accountNode = [[PithosAccountNode alloc] init];
-    accountNode.children;
+    // Refresh account
+    [accountNode refresh];
+    [mySharedNode refresh];
+    [othersSharedNode refresh];
 }
 
 - (void)windowDidLoad {
     [super windowDidLoad];
     
+    accountNode = [[PithosAccountNode alloc] init];
+    containersNode = [[PithosEmptyNode alloc] initWithDisplayName:@"CONTAINERS" icon:nil];
+    containersNodeChildren = [[NSMutableArray alloc] init];
+    sharedNode = [[PithosEmptyNode alloc] initWithDisplayName:@"SHARED" icon:nil];
+    mySharedNode = [[PithosAccountNode alloc] init];
+    mySharedNode.displayName = @"my shared";
+    mySharedNode.shared = YES;
+    mySharedNode.icon = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kUserIcon)];
+    othersSharedNode = [[PithosSharingAccountsNode alloc] init];
+    othersSharedNode.displayName = @"others shared";
+    othersSharedNode.icon = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGroupIcon)];
+    
     [[[outlineView tableColumns] objectAtIndex:0] setDataCell:[[[PithosOutlineViewCell alloc] init] autorelease]];
     
     // Register for updates
+    // PithosContainerNode updates browser nodes
     [[NSNotificationCenter defaultCenter] addObserver:self 
                                              selector:@selector(pithosNodeChildrenUpdated:) 
                                                  name:@"PithosContainerNodeChildrenUpdated" 
                                                object:nil];
+    // PithosSubdirNode updates browser nodes
     [[NSNotificationCenter defaultCenter] addObserver:self 
                                              selector:@selector(pithosNodeChildrenUpdated:) 
                                                  name:@"PithosSubdirNodeChildrenUpdated" 
                                                object:nil];
+    // PithosAccountNode accountNode updates outlineView container nodes 
     [[NSNotificationCenter defaultCenter] addObserver:self 
                                              selector:@selector(pithosAccountNodeChildrenUpdated:) 
                                                  name:@"PithosAccountNodeChildrenUpdated" 
+                                               object:accountNode];
+    // PithosAccountNode other than accountNode updates nodes 
+    [[NSNotificationCenter defaultCenter] addObserver:self 
+                                             selector:@selector(pithosNodeChildrenUpdated:) 
+                                                 name:@"PithosAccountNodeChildrenUpdated" 
                                                object:nil];
+    // PithosSharingAccountsNode othersSharedNode updates browser nodes 
+    [[NSNotificationCenter defaultCenter] addObserver:self 
+                                             selector:@selector(pithosNodeChildrenUpdated:) 
+                                                 name:@"PithosSharingAccountsNodeChildrenUpdated" 
+                                               object:othersSharedNode];
+    // Updated authentication credentials reset containers in the outline view 
     [[NSNotificationCenter defaultCenter] addObserver:self 
                                              selector:@selector(resetContainers:) 
                                                  name:@"PithosAuthenticationCredentialsUpdated" 
                                                object:nil];
+    // Request for browser refresh 
+    [[NSNotificationCenter defaultCenter] addObserver:self 
+                                             selector:@selector(pithosBrowserRefreshNeeded:) 
+                                                 name:@"PithosBrowserRefreshNeeeded" 
+                                               object:nil];    
 }
 
 #pragma mark -
-#pragma Observers
+#pragma mark Observers
 
 - (void)pithosNodeChildrenUpdated:(NSNotification *)notification {
     PithosNode *node = (PithosNode *)[notification object];
+    if (node == accountNode)
+        return;
     NSLog(@"pithosNodeChildrenUpdated:%@", node.url);
     NSInteger lastColumn = [browser lastColumn];
     for (NSInteger column = lastColumn; column >= 0; column--) {
         if ([[browser parentForItemsInColumn:column] isEqualTo:node]) {
             [browser reloadColumn:column];
-            // The following code is unnecessary since the pithosObject is set in the PithosNode in each refresh
-            // Furthermore it caused problems on delete, because a non-existing parent was asked for
-            //if ((column == lastColumn - 1) && ([[browser parentForItemsInColumn:lastColumn] isLeafItem])) {
-            //    // This reloads the preview column
-            //    [browser setLastColumn:column];
-            //    [browser addColumn];
-            //}
             return;
         }
     }
 - (void)pithosAccountNodeChildrenUpdated:(NSNotification *)notification {
     BOOL containerPithosFound = NO;
     BOOL containerTrashFound = NO;
-    NSMutableArray *containersTreeNodeChildren = [NSMutableArray array];
+    NSMutableIndexSet *removedContainersNodeChildren = [NSMutableIndexSet indexSet];
+    for (NSUInteger i = 0 ; i < [containersNodeChildren count] ; i++) {
+        if (![accountNode.children containsObject:[containersNodeChildren objectAtIndex:i]])
+            [removedContainersNodeChildren addIndex:i];
+    }
+    [containersNodeChildren removeObjectsAtIndexes:removedContainersNodeChildren];
     for (PithosContainerNode *containerNode in accountNode.children) {
         if ([containerNode.pithosContainer.name isEqualToString:@"pithos"]) {
-            containerNode.icon = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kToolbarHomeIcon)];
-            [containersTreeNodeChildren insertObject:[NSTreeNode treeNodeWithRepresentedObject:containerNode] atIndex:0];
+            if (![containersNodeChildren containsObject:containerNode])
+                [containersNodeChildren insertObject:containerNode atIndex:0];
             containerPithosFound = YES;
         } else if ([containerNode.pithosContainer.name isEqualToString:@"trash"]) {
-            containerNode.icon = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kFullTrashIcon)];            
             NSUInteger insertIndex = 1;
             if (!containerPithosFound)
                 insertIndex = 0;
-            [containersTreeNodeChildren insertObject:[NSTreeNode treeNodeWithRepresentedObject:containerNode] atIndex:insertIndex];
+            if (![containersNodeChildren containsObject:containerNode])
+                [containersNodeChildren insertObject:containerNode atIndex:insertIndex];
             containerTrashFound = YES;
-        } else {
-            [containersTreeNodeChildren addObject:[NSTreeNode treeNodeWithRepresentedObject:containerNode]];
+        } else if (![containersNodeChildren containsObject:containerNode]) {
+            [containersNodeChildren addObject:containerNode];
         }
     }
     BOOL refreshAccountNode = NO;
     if (!containerPithosFound) {
-        // create pithos
+        // Create pithos node
         ASIPithosContainerRequest *containerRequest = [ASIPithosContainerRequest createOrUpdateContainerRequestWithContainerName:@"pithos"];
         [containerRequest startSynchronous];
         if ([containerRequest error]) {
         }
     }
     if (!containerTrashFound) {
-        // create trash
+        // Create trash node
         ASIPithosContainerRequest *containerRequest = [ASIPithosContainerRequest createOrUpdateContainerRequestWithContainerName:@"trash"];
         [containerRequest startSynchronous];
         if ([containerRequest error]) {
             refreshAccountNode = YES;
         }
     }
-    if (refreshAccountNode) {
-        [accountNode invalidateChildren];
-        accountNode.children;
-    } else {
-        [[[outlineViewDataSourceArray objectAtIndex:0] mutableChildNodes] setArray:containersTreeNodeChildren];
-        self.outlineViewDataSourceArray = outlineViewDataSourceArray;
-        
-        // Expand the folder outline view
-        [outlineView expandItem:nil expandChildren:YES];
-        [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
-        
-        [self refresh:nil];
+    
+    if (refreshAccountNode)
+        [accountNode refresh];
+    
+    [outlineView reloadData];
+    
+    // Expand the folder outline view
+    [outlineView expandItem:nil expandChildren:YES];
+    
+    if ((rootNode == nil) || (rootNode == containersNode) || (rootNode == sharedNode)) {
+        rootNode = [containersNodeChildren objectAtIndex:0];
+        [browser loadColumnZero];
     }
+    
+    if (notification)
+        [self refresh:nil];
+}
+
+- (void)pithosBrowserRefreshNeeded:(NSNotification *)notification {
+    [self refresh:nil];
 }
 
 #pragma mark -
-#pragma Actions
+#pragma mark Actions
 
 - (IBAction)refresh:(id)sender {
-    for (NSInteger column = [browser lastColumn]; column >= 0; column--) {
-        [(PithosNode *)[browser parentForItemsInColumn:column] invalidateChildren];
+    if ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask) {
+        if (sender)
+            [accountNode forceRefresh];
+        for (NSInteger column = [browser lastColumn]; column >= 0; column--) {
+            PithosNode *node = (PithosNode *)[browser parentForItemsInColumn:column];
+            node.forcedRefresh = YES;
+            [(PithosNode *)[browser parentForItemsInColumn:column] invalidateChildren];                      
+            //[(PithosNode *)[browser parentForItemsInColumn:column] forceRefresh];
+        }        
+    } else {
+        if (sender)
+            [accountNode refresh];
+        for (NSInteger column = [browser lastColumn]; column >= 0; column--) {
+            [(PithosNode *)[browser parentForItemsInColumn:column] invalidateChildren];
+        }
     }
     [browser validateVisibleColumns];
 }
 
 #pragma mark -
-#pragma NSBrowserDelegate
+#pragma mark NSBrowserDelegate
 
 - (id)rootItemForBrowser:(NSBrowser *)browser {
     return rootNode;    
     return NO;
 }
 
+#pragma mark Editing
+
+- (BOOL)browser:(NSBrowser *)browser shouldEditItem:(id)item {
+    PithosNode *node = (PithosNode *)item;
+    if (node.shared || node.sharingAccount || 
+        ([node class] == [PithosContainerNode class]) || ([node class] == [PithosAccountNode class]))
+        return NO;
+    return YES;
+}
+
+- (void)browser:(NSBrowser *)browser setObjectValue:(id)object forItem:(id)item {
+    PithosNode *node = (PithosNode *)item;
+    NSString *newName = (NSString *)object;
+    NSUInteger newNameLength = [newName length];
+    NSRange firstSlashRange = [newName rangeOfString:@"/"];
+    if ((newNameLength == 0) || 
+        ((firstSlashRange.length == 1) && (firstSlashRange.location != (newNameLength - 1))) || 
+        ([newName isEqualToString:node.displayName])) {
+        return;
+    }
+    if (([node class] == [PithosObjectNode class]) || 
+        (([node class] == [PithosSubdirNode class]) && 
+         !node.pithosObject.subdir &&
+         [node.pithosObject.name hasSuffix:@"/"])) {
+        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+        dispatch_async(queue, ^{
+            NSString *destinationObjectName = [[node.pithosObject.name stringByDeletingLastPathComponent] stringByAppendingPathComponent:newName];
+            if ([newName hasSuffix:@"/"])
+                destinationObjectName = [destinationObjectName stringByAppendingString:@"/"];
+            NSError *error = nil;
+            BOOL isDirectory;
+            if ([PithosFileUtilities objectExistsAtContainerName:node.pithosContainer.name 
+                                                      objectName:destinationObjectName 
+                                                           error:&error 
+                                                     isDirectory:&isDirectory 
+                                                  sharingAccount:nil]) {
+                NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+                [alert setMessageText:@"Name Taken"];
+                [alert setInformativeText:[NSString stringWithFormat:@"The name '%@' is already taken. Please choose a different name", newName]];
+                [alert addButtonWithTitle:@"OK"];
+                [alert runModal];
+                return;
+            } else if (error) {
+                return;
+            }
+            ASIPithosObjectRequest *objectRequest = [PithosFileUtilities moveObjectRequestWithContainerName:node.pithosContainer.name 
+                                                                                                 objectName:node.pithosObject.name 
+                                                                                   destinationContainerName:node.pithosContainer.name 
+                                                                                      destinationObjectName:destinationObjectName 
+                                                                                              checkIfExists:NO];
+            if (objectRequest) {
+                objectRequest.delegate = self;
+                objectRequest.didFinishSelector = @selector(moveFinished:);
+                objectRequest.didFailSelector = @selector(moveFailed:);
+                objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+                                          node.parent, @"node", 
+                                          nil];
+                [objectRequest startAsynchronous];
+            }
+        });
+    } else if ([node class] == [PithosSubdirNode class]) {
+        if (firstSlashRange.length == 1)
+            return;
+        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+        dispatch_async(queue, ^{
+            NSString *destinationObjectName = [[node.pithosObject.name stringByDeletingLastPathComponent] stringByAppendingPathComponent:newName];
+            NSError *error = nil;
+            BOOL isDirectory;
+            if ([PithosFileUtilities objectExistsAtContainerName:node.pithosContainer.name 
+                                                      objectName:destinationObjectName 
+                                                           error:&error 
+                                                     isDirectory:&isDirectory 
+                                                  sharingAccount:nil]) {
+                NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+                [alert setMessageText:@"Name Taken"];
+                [alert setInformativeText:[NSString stringWithFormat:@"The name '%@' is already taken. Please choose a different name", newName]];
+                [alert addButtonWithTitle:@"OK"];
+                [alert runModal];
+                return;
+            } else if (error) {
+                return;
+            }
+            if (node.pithosObject.subdir)
+                destinationObjectName = [destinationObjectName stringByAppendingString:@"/"];
+            NSArray *objectRequests = [PithosFileUtilities moveObjectRequestsForSubdirWithContainerName:node.pithosContainer.name 
+                                                                                             objectName:node.pithosObject.name 
+                                                                               destinationContainerName:node.pithosContainer.name 
+                                                                                  destinationObjectName:destinationObjectName 
+                                                                                          checkIfExists:NO];
+            if (objectRequests) {
+                for (ASIPithosObjectRequest *objectRequest in objectRequests) {
+                    objectRequest.delegate = self;
+                    objectRequest.didFinishSelector = @selector(moveFinished:);
+                    objectRequest.didFailSelector = @selector(moveFailed:);
+                    objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+                                              node.parent, @"node", 
+                                              nil];
+                    [objectRequest startAsynchronous];
+                }
+            }
+        });
+    }
+}
+
 #pragma mark Drag and Drop source
 
+- (BOOL)browser:(NSBrowser *)aBrowser canDragRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column 
+      withEvent:(NSEvent *)event {
+    NSIndexPath *baseIndexPath = [browser indexPathForColumn:column];
+    __block BOOL result = YES;
+    [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop){
+        PithosNode *node = [browser itemAtIndexPath:[baseIndexPath indexPathByAddingIndex:idx]];
+        if ([node class] == [PithosContainerNode class]) {
+            result = NO;
+            *stop = YES;
+        }
+    }];
+    return result;
+}
+
 - (BOOL)browser:(NSBrowser *)aBrowser writeRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column 
    toPasteboard:(NSPasteboard *)pasteboard {
     NSMutableArray *propertyList = [NSMutableArray arrayWithCapacity:[rowIndexes count]];
@@ -377,7 +527,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                     NSArray *objectRequests = [PithosFileUtilities objectDataRequestsForSubdirWithContainerName:node.pithosContainer.name 
                                                                                                      objectName:node.pithosObject.name 
                                                                                                     toDirectory:[dropDestination path] 
-                                                                                                  checkIfExists:YES];
+                                                                                                  checkIfExists:YES 
+                                                                                                 sharingAccount:node.sharingAccount];
                     if (objectRequests) {
                         for (ASIPithosObjectRequest *objectRequest in objectRequests) {
                             [names addObject:[objectRequest.userInfo valueForKey:@"fileName"]];
@@ -393,7 +544,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
             ASIPithosObjectRequest *objectRequest = [PithosFileUtilities objectDataRequestWithContainerName:node.pithosContainer.name 
                                                                                                  objectName:node.pithosObject.name 
                                                                                                 toDirectory:[dropDestination path] 
-                                                                                              checkIfExists:YES];
+                                                                                              checkIfExists:YES 
+                                                                                             sharingAccount:node.sharingAccount];
             if (objectRequest) {
                 [names addObject:[objectRequest.userInfo valueForKey:@"fileName"]];
                 objectRequest.delegate = self;
@@ -420,13 +572,23 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
             *row = -1;
         // Only allow dropping in folders
         if (*column != -1) {
+            PithosNode *dropNode;
             if (*row != -1) {
                 // Check if the node is not a folder and if so redirect to the parent item
-                if ([[browser itemAtRow:*row inColumn:*column] class] != [PithosSubdirNode class])
+                dropNode = [browser itemAtRow:*row inColumn:*column];
+                if ([dropNode class] == [PithosObjectNode class])
                     *row = -1;
             }
-            *dropOperation = NSBrowserDropOn;
-            result = NSDragOperationCopy;
+            if (*row == -1)
+                dropNode = [browser parentForItemsInColumn:*column];
+            
+            if (!dropNode.shared && 
+                (!dropNode.sharingAccount || 
+                 ([dropNode class] == [PithosSubdirNode class]) || 
+                 ([dropNode class] == [PithosContainerNode class]))) {
+                *dropOperation = NSBrowserDropOn;
+                result = NSDragOperationCopy;
+            }
         }
     } else if ([[[info draggingPasteboard] types] containsObject:NSFilesPromisePboardType]) {
         // For a drop above, the drop is redirected to the parent item
@@ -438,29 +600,30 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
             if (*row != -1) {
                 // Check if the node is not a folder and if so redirect to the parent item
                 dropNode = [browser itemAtRow:*row inColumn:*column];
-                if ([dropNode class] != [PithosSubdirNode class])
+                if ([dropNode class] == [PithosObjectNode class])
                     *row = -1;
             }
             if (*row == -1)
                 dropNode = [browser parentForItemsInColumn:*column];
             
-            
-            if ([info draggingSourceOperationMask] & NSDragOperationMove) {
-                // NSDragOperationCopy | NSDragOperationMove -> NSDragOperationMove
-                if ((([dropNode class] == [PithosContainerNode class]) || 
-                     dropNode.pithosObject.subdir || 
-                     ![dropNode.pithosObject.name hasSuffix:@"/"]) && 
-                    ![dropNode isEqualTo:draggedParentNode]) { 
-//                    ![dropNode isEqualTo:draggedParentNode] && 
-//                    ![draggedNodes containsObject:dropNode]) {                
-                    result = NSDragOperationMove;
-                }
-            } else if ([info draggingSourceOperationMask] & NSDragOperationCopy) {
-                // NSDragOperationCopy (Option modifier) -> NSDragOperationCopy
-                if (([dropNode class] == [PithosContainerNode class]) || 
-                    dropNode.pithosObject.subdir || 
-                    ![dropNode.pithosObject.name hasSuffix:@"/"]) { 
-                    result = NSDragOperationCopy;
+            if (!dropNode.shared && !dropNode.sharingAccount) {
+                if ([info draggingSourceOperationMask] & NSDragOperationMove) {
+                    // NSDragOperationCopy | NSDragOperationMove -> NSDragOperationMove
+                    if ((([dropNode class] == [PithosContainerNode class]) || 
+                         dropNode.pithosObject.subdir || 
+                         ![dropNode.pithosObject.name hasSuffix:@"/"]) && 
+                        ![dropNode isEqualTo:draggedParentNode]) { 
+    //                    ![dropNode isEqualTo:draggedParentNode] && 
+    //                    ![draggedNodes containsObject:dropNode]) {                
+                        result = NSDragOperationMove;
+                    }
+                } else if ([info draggingSourceOperationMask] & NSDragOperationCopy) {
+                    // NSDragOperationCopy (Option modifier) -> NSDragOperationCopy
+                    if (([dropNode class] == [PithosContainerNode class]) || 
+                        dropNode.pithosObject.subdir || 
+                        ![dropNode.pithosObject.name hasSuffix:@"/"]) { 
+                        result = NSDragOperationCopy;
+                    }
                 }
             }
         }
@@ -518,22 +681,26 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                                                                                                                        blockHash:blockHash 
                                                                                                                          forFile:filePath 
                                                                                                                    checkIfExists:YES 
-                                                                                                                          hashes:&hashes];
+                                                                                                                          hashes:&hashes 
+                                                                                                                  sharingAccount:node.sharingAccount];
                             if (objectRequest) {
                                 objectRequest.delegate = self;
                                 objectRequest.didFinishSelector = @selector(uploadObjectUsingHashMapFinished:);
                                 objectRequest.didFailSelector = @selector(uploadObjectUsingHashMapFailed:);
-                                objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
-                                                          containerName, @"containerName", 
-                                                          objectName, @"objectName", 
-                                                          contentType, @"contentType", 
-                                                          [NSNumber numberWithUnsignedInteger:blockSize], @"blockSize", 
-                                                          blockHash, @"blockHash", 
-                                                          filePath, @"filePath", 
-                                                          hashes, @"hashes", 
-                                                          node, @"node", 
-                                                          [NSNumber numberWithUnsignedInteger:10], @"iteration", 
-                                                          nil];
+                                NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+                                                                 containerName, @"containerName", 
+                                                                 objectName, @"objectName", 
+                                                                 contentType, @"contentType", 
+                                                                 [NSNumber numberWithUnsignedInteger:blockSize], @"blockSize", 
+                                                                 blockHash, @"blockHash", 
+                                                                 filePath, @"filePath", 
+                                                                 hashes, @"hashes", 
+                                                                 node, @"node", 
+                                                                 [NSNumber numberWithUnsignedInteger:10], @"iteration", 
+                                                                 nil];
+                                if (node.sharingAccount)
+                                    [userInfo setObject:node.sharingAccount forKey:@"sharingAccount"];
+                                objectRequest.userInfo = userInfo;
                                 [objectRequest startAsynchronous];
                             }
                         });
@@ -564,7 +731,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                                                                                                            contentTypes:&contentTypes
                                                                                                               filePaths:&filePaths
                                                                                                              hashesArrays:&hashesArrays 
-                                                                                                directoryObjectRequests:&directoryObjectRequests];
+                                                                                                directoryObjectRequests:&directoryObjectRequests 
+                                                                                                         sharingAccount:node.sharingAccount];
                                 for (ASIPithosObjectRequest *objectRequest in directoryObjectRequests) {
                                     objectRequest.delegate = self;
                                     objectRequest.didFinishSelector = @selector(uploadDirectoryObjectFinished:);
@@ -577,16 +745,19 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                                         objectRequest.delegate = self;
                                         objectRequest.didFinishSelector = @selector(uploadObjectUsingHashMapFinished:);
                                         objectRequest.didFailSelector = @selector(uploadObjectUsingHashMapFailed:);
-                                        objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
-                                                                  containerName, @"containerName", 
-                                                                  [objectNames objectAtIndex:i], @"objectName", 
-                                                                  [contentTypes objectAtIndex:i], @"contentType", 
-                                                                  [NSNumber numberWithUnsignedInteger:blockSize], @"blockSize", 
-                                                                  blockHash, @"blockHash", 
-                                                                  [filePaths objectAtIndex:i], @"filePath", 
-                                                                  [hashesArrays objectAtIndex:i], @"hashes", 
-                                                                  [NSNumber numberWithUnsignedInteger:10], @"iteration", 
-                                                                  nil];
+                                        NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+                                                                         containerName, @"containerName", 
+                                                                         [objectNames objectAtIndex:i], @"objectName", 
+                                                                         [contentTypes objectAtIndex:i], @"contentType", 
+                                                                         [NSNumber numberWithUnsignedInteger:blockSize], @"blockSize", 
+                                                                         blockHash, @"blockHash", 
+                                                                         [filePaths objectAtIndex:i], @"filePath", 
+                                                                         [hashesArrays objectAtIndex:i], @"hashes", 
+                                                                         [NSNumber numberWithUnsignedInteger:10], @"iteration", 
+                                                                         nil];
+                                        if (node.sharingAccount)
+                                            [userInfo setObject:node.sharingAccount forKey:@"sharingAccount"];
+                                        objectRequest.userInfo = userInfo;
                                         [objectRequest startAsynchronous];
                                     }
                                 }
@@ -648,7 +819,7 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                         dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                         dispatch_async(queue, ^{
                             NSString *destinationObjectName = [objectNamePrefix stringByAppendingPathComponent:node.displayName];
-                            if ([node.pithosObject.name hasSuffix:@"/"])
+                            if (node.pithosObject.subdir)
                                 destinationObjectName = [destinationObjectName stringByAppendingString:@"/"];
                             NSArray *objectRequests = [PithosFileUtilities moveObjectRequestsForSubdirWithContainerName:node.pithosContainer.name 
                                                                                                              objectName:node.pithosObject.name 
@@ -691,7 +862,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                                                                                                                  objectName:node.pithosObject.name 
                                                                                                    destinationContainerName:containerName 
                                                                                                       destinationObjectName:destinationObjectName 
-                                                                                                              checkIfExists:YES];
+                                                                                                              checkIfExists:YES 
+                                                                                                             sharingAccount:nil];
                             if (objectRequest) {
                                 objectRequest.delegate = self;
                                 objectRequest.didFinishSelector = @selector(copyFinished:);
@@ -708,7 +880,7 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                             NSString *destinationObjectName;
                             if (![dropNode isEqualTo:node.parent]) {
                                 destinationObjectName = [objectNamePrefix stringByAppendingPathComponent:node.displayName];
-                                if ([node.pithosObject.name hasSuffix:@"/"])
+                                if (node.pithosObject.subdir)
                                     destinationObjectName = [destinationObjectName stringByAppendingString:@"/"];
                             } else {
                                 destinationObjectName = [PithosFileUtilities safeSubdirNameForContainerName:containerName 
@@ -718,7 +890,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                                                                                                              objectName:node.pithosObject.name 
                                                                                                destinationContainerName:containerName 
                                                                                                   destinationObjectName:destinationObjectName 
-                                                                                                          checkIfExists:YES];
+                                                                                                          checkIfExists:YES 
+                                                                                                         sharingAccount:nil];
                             if (objectRequests) {
                                 for (ASIPithosObjectRequest *objectRequest in objectRequests) {
                                     objectRequest.delegate = self;
@@ -791,12 +964,10 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
     if (objectRequest.responseStatusCode == 201) {
         NSLog(@"Object created: %@", [objectRequest url]);
         PithosNode *node = [objectRequest.userInfo objectForKey:@"node"];
-        if (node) {
-            [node invalidateChildren];
-            node.children;
-        } else {
+        if (node)
+            [node refresh];
+        else
             [self refresh:nil];
-        }
     } else if (objectRequest.responseStatusCode == 409) {
         NSUInteger iteration = [[objectRequest.userInfo objectForKey:@"iteration"] unsignedIntegerValue] - 1;
         if (iteration == 0) {
@@ -817,7 +988,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                                                                                                       objectName:@".upload" 
                                                                                                        blockSize:[[objectRequest.userInfo objectForKey:@"blockSize"] unsignedIntegerValue]
                                                                                                          forFile:[objectRequest.userInfo objectForKey:@"filePath"] 
-                                                                                               missingBlockIndex:missingBlockIndex];
+                                                                                               missingBlockIndex:missingBlockIndex 
+                                                                                                  sharingAccount:[objectRequest.userInfo objectForKey:@"sharingAccount"]];
         newObjectRequest.delegate = self;
         newObjectRequest.didFinishSelector = @selector(uploadMissingBlockFinished:);
         newObjectRequest.didFailSelector = @selector(uploadMissingBlockFailed:);
@@ -851,7 +1023,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                                                                                                           blockHash:[objectRequest.userInfo objectForKey:@"blockHash"]
                                                                                                             forFile:[objectRequest.userInfo objectForKey:@"filePath"] 
                                                                                                       checkIfExists:NO 
-                                                                                                             hashes:&hashes];
+                                                                                                             hashes:&hashes 
+                                                                                                     sharingAccount:[objectRequest.userInfo objectForKey:@"sharingAccount"]];
             newObjectRequest.delegate = self;
             newObjectRequest.didFinishSelector = @selector(uploadObjectUsingHashMapFinished:);
             newObjectRequest.didFailSelector = @selector(uploadObjectUsingHashMapFailed:);
@@ -864,7 +1037,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                                                                                                           objectName:@".upload" 
                                                                                                            blockSize:[[objectRequest.userInfo objectForKey:@"blockSize"] unsignedIntegerValue]
                                                                                                              forFile:[objectRequest.userInfo objectForKey:@"filePath"] 
-                                                                                                   missingBlockIndex:missingBlockIndex];
+                                                                                                   missingBlockIndex:missingBlockIndex 
+                                                                                                      sharingAccount:[objectRequest.userInfo objectForKey:@"sharingAccount"]];
             newObjectRequest.delegate = self;
             newObjectRequest.didFinishSelector = @selector(uploadMissingBlockFinished:);
             newObjectRequest.didFailSelector = @selector(uploadMissingBlockFailed:);
@@ -887,14 +1061,10 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
     if (objectRequest.responseStatusCode == 201) {
         PithosNode *node = [objectRequest.userInfo objectForKey:@"node"];
         PithosNode *dropNode = [objectRequest.userInfo objectForKey:@"dropNode"];
-        if (node) {
-            [node invalidateChildren];
-            node.children;
-        }
-        if (dropNode) {
-            [dropNode invalidateChildren];
-            dropNode.children;
-        }
+        if (node)
+            [node refresh];
+        if (dropNode)
+            [dropNode refresh];
         if (!node || !dropNode)
             [self refresh:nil];
     } else {
@@ -911,12 +1081,10 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
     NSLog(@"Copy object completed: %@", [objectRequest url]);
     if (objectRequest.responseStatusCode == 201) {
         PithosNode *dropNode = [objectRequest.userInfo objectForKey:@"dropNode"];
-        if (dropNode) {
-            [dropNode invalidateChildren];
-            dropNode.children;
-        } else {
+        if (dropNode)
+            [dropNode refresh];
+        else
             [self refresh:nil];
-        }
     } else {
         [PithosFileUtilities unexpectedResponseStatusAlertWithRequest:objectRequest];
     }
@@ -931,39 +1099,85 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
 #pragma mark NSSplitViewDelegate
 
 - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex {
-    return 120;
+    if (splitView == verticalSplitView)
+        return 120;
+    else
+        return ([horizontalSplitView bounds].size.height - 87);
 }
 
 - (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex {
-    return 220;
+    if (splitView == verticalSplitView)
+        return 220;
+    else
+        return ([horizontalSplitView bounds].size.height - 87);
 }
 
 - (CGFloat)splitView:(NSSplitView *)splitView constrainSplitPosition:(CGFloat)proposedPosition ofSubviewAt:(NSInteger)dividerIndex {
-    if (proposedPosition < 120)
-        return 120;
-    else if (proposedPosition > 220)
-        return 220;
-    else
-        return proposedPosition;
+    if (splitView == verticalSplitView) {
+        if (proposedPosition < 120)
+            return 120;
+        else if (proposedPosition > 220)
+            return 220;
+        else
+            return proposedPosition;
+    } else {
+        return ([horizontalSplitView bounds].size.height - 87);
+    }
+}
+
+#pragma mark -
+#pragma mark NSOutlineViewDataSource
+
+- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
+    if (item == nil)
+        return 2;
+    if (item == containersNode)
+        return containersNodeChildren.count;
+    if (item == sharedNode)
+        return 2;
+    return 0;
+}
+
+- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
+    if (item == nil)
+        return (!index ? containersNode : sharedNode);
+    if (item == sharedNode)
+        return (!index ? mySharedNode : othersSharedNode);
+    return [containersNodeChildren objectAtIndex:index];
+}
+
+- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
+    if ((item == containersNode) || (item == sharedNode))
+        return YES;
+    return NO;
+}
+
+- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
+    PithosNode *node = (PithosNode *)item;
+    return node;    
 }
 
 #pragma mark -
 #pragma mark NSOutlineViewDelegate
 
 - (BOOL)outlineView:outlineView shouldSelectItem:(id)item {
-    return ([[item representedObject] isLeaf]);
+    if ((item == containersNode) || (item == sharedNode))
+        return NO;
+    return YES;
 }
 
 - (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item {
-       return (![[item representedObject] isLeaf]);
+    if ((item == containersNode) || (item == sharedNode))
+        return YES;
+    return NO;
 }
 
 - (void)outlineViewSelectionDidChange:(NSNotification *)notification {
-    PithosNode *node = [[[outlineView itemAtRow:[outlineView selectedRow]] representedObject] representedObject];
+    PithosNode *node = (PithosNode *)[outlineView itemAtRow:[outlineView selectedRow]];
     if (node) {
         rootNode = node;
         [browser loadColumnZero];
-        [self refresh:nil];                                  
+        [self refresh:nil];
     }
 }
 
@@ -975,6 +1189,7 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
     NSInteger row = [browser clickedRow];
     [menu removeAllItems];
     NSMenuItem *menuItem;
+    NSString *menuItemTitle;
     if ((column == -1) || (row == -1)) {
         // General context menu
         NSArray *menuNodesIndexPaths = [browser selectionIndexPaths];
@@ -987,16 +1202,42 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
         } else {
             menuNode = [browser itemAtIndexPath:[menuNodesIndexPaths objectAtIndex:0]];
         }
-        NSArray *menuNodes = [NSArray arrayWithObject:menuNode];
-        // New Folder
-        menuItem = [[[NSMenuItem alloc] initWithTitle:@"New Folder" action:@selector(newFolder:) keyEquivalent:@""] autorelease];
-        [menuItem setRepresentedObject:menuNodes];
-        [menu addItem:menuItem];
-        [menu addItem:[NSMenuItem separatorItem]];
+        if (([menuNode class] == [PithosAccountNode class]) || ([menuNode class] == [PithosSharingAccountsNode class]))
+            return;
+        BOOL shared = menuNode.shared;
+        BOOL sharingAccount = (menuNode.sharingAccount != nil);
+        
+        if (!shared && !sharingAccount) {
+            // New Folder
+            menuItem = [[[NSMenuItem alloc] initWithTitle:@"New Folder" action:@selector(menuNewFolder:) keyEquivalent:@""] autorelease];
+            [menuItem setRepresentedObject:menuNode];
+            [menu addItem:menuItem];
+            [menu addItem:[NSMenuItem separatorItem]];
+        }
+        
         // Get Info
-        menuItem = [[[NSMenuItem alloc] initWithTitle:@"Get Info" action:@selector(getInfo:) keyEquivalent:@""] autorelease];
-        [menuItem setRepresentedObject:menuNodes];
+        menuItem = [[[NSMenuItem alloc] initWithTitle:@"Get Info" action:@selector(menuGetInfo:) keyEquivalent:@""] autorelease];
+        [menuItem setRepresentedObject:[NSArray arrayWithObject:menuNode]];
         [menu addItem:menuItem];
+        
+        if (!shared && !sharingAccount) {
+            // Paste
+            if (clipboardNodes) {
+                NSUInteger clipboardNodesCount = [clipboardNodes count];
+                if (clipboardNodesCount == 0) {
+                    self.clipboardNodes = nil;
+                } else if (clipboardCopy || ![menuNode isEqualTo:clipboardParentNode]) {
+                    if (clipboardNodesCount == 1)
+                        menuItemTitle = [NSString stringWithString:@"Paste Item"];
+                    else
+                        menuItemTitle = [NSString stringWithString:@"Paste Items"];
+                    [menu addItem:[NSMenuItem separatorItem]];
+                    menuItem = [[[NSMenuItem alloc] initWithTitle:menuItemTitle action:@selector(menuPaste:) keyEquivalent:@""] autorelease];
+                    [menuItem setRepresentedObject:menuNode];
+                    [menu addItem:menuItem];
+                }
+            }
+        }
     } else {
         // Node context menu
         NSIndexPath *clickedNodeIndexPath = [[browser indexPathForColumn:column] indexPathByAddingIndex:row];
@@ -1009,92 +1250,152 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
         } else {
             [menuNodes addObject:[browser itemAtIndexPath:clickedNodeIndexPath]];
         }
-        // Move to Trash (pithos container only)
-        // Delete
-        if ([rootNode class] == [PithosContainerNode class]) {
-            if ([rootNode.pithosContainer.name isEqualToString:@"pithos"]) {
-                menuItem = [[[NSMenuItem alloc] initWithTitle:@"Move to Trash" action:@selector(moveToTrash:) keyEquivalent:@""] autorelease];
+        NSUInteger menuNodesCount = [menuNodes count];
+        PithosNode *firstMenuNode = (PithosNode *)[menuNodes objectAtIndex:0];
+        BOOL shared = firstMenuNode.shared;
+        BOOL sharingAccount = (firstMenuNode.sharingAccount != nil);
+        
+        if (!shared && !sharingAccount) {
+            // Move to Trash (pithos container only)
+            // Delete
+            if ([rootNode class] == [PithosContainerNode class]) {
+                if ([rootNode.pithosContainer.name isEqualToString:@"pithos"]) {
+                    menuItem = [[[NSMenuItem alloc] initWithTitle:@"Move to Trash" action:@selector(menuMoveToTrash:) keyEquivalent:@""] autorelease];
+                    [menuItem setRepresentedObject:menuNodes];
+                    [menu addItem:menuItem];
+                }
+                menuItem = [[[NSMenuItem alloc] initWithTitle:@"Delete" action:@selector(menuDelete:) keyEquivalent:@""] autorelease];
                 [menuItem setRepresentedObject:menuNodes];
                 [menu addItem:menuItem];
+                [menu addItem:[NSMenuItem separatorItem]];
             }
-            menuItem = [[[NSMenuItem alloc] initWithTitle:@"Delete" action:@selector(deleteObject:) keyEquivalent:@""] autorelease];
+        }
+        
+        if (!sharingAccount || ([firstMenuNode class] != [PithosAccountNode class])) {
+            // Get Info
+            menuItem = [[[NSMenuItem alloc] initWithTitle:@"Get Info" action:@selector(menuGetInfo:) keyEquivalent:@""] autorelease];
             [menuItem setRepresentedObject:menuNodes];
             [menu addItem:menuItem];
-            [menu addItem:[NSMenuItem separatorItem]];
+            
+            if ((!shared && !sharingAccount) || ([firstMenuNode class] != [PithosContainerNode class]))
+                [menu addItem:[NSMenuItem separatorItem]];
+        }
+        
+        if (!shared && !sharingAccount) {
+            // Cut
+            
+            if (menuNodesCount == 1)
+                menuItemTitle = [NSString stringWithFormat:@"Cut \"%@\"", ((PithosNode *)[menuNodes objectAtIndex:0]).displayName];
+            else 
+                menuItemTitle = [NSString stringWithFormat:@"Cut %lu Items", menuNodesCount];
+            menuItem = [[[NSMenuItem alloc] initWithTitle:menuItemTitle action:@selector(menuCut:) keyEquivalent:@""] autorelease];
+            [menuItem setRepresentedObject:menuNodes];
+            [menu addItem:menuItem];
+        }
+        
+        if ((!shared && !sharingAccount) || 
+            (([firstMenuNode class] != [PithosContainerNode class]) && ([firstMenuNode class] != [PithosAccountNode class]))) {
+            // Copy
+            if (menuNodesCount == 1)
+                menuItemTitle = [NSString stringWithFormat:@"Copy \"%@\"", ((PithosNode *)[menuNodes objectAtIndex:0]).displayName];
+            else 
+                menuItemTitle = [NSString stringWithFormat:@"Copy %lu Items", menuNodesCount];
+            menuItem = [[[NSMenuItem alloc] initWithTitle:menuItemTitle action:@selector(menuCopy:) keyEquivalent:@""] autorelease];
+            [menuItem setRepresentedObject:menuNodes];
+            [menu addItem:menuItem];
+        }
+        
+        if (!shared && !sharingAccount) {
+            // Paste
+            if (menuNodesCount == 1) {
+                PithosNode *menuNode = [menuNodes objectAtIndex:0];
+                if (([menuNode class] == [PithosSubdirNode class]) && 
+                    (menuNode.pithosObject.subdir || ![menuNode.pithosObject.name hasSuffix:@"/"])) {
+                    if (clipboardNodes) {
+                        NSUInteger clipboardNodesCount = [clipboardNodes count];
+                        if (clipboardNodesCount == 0) {
+                            self.clipboardNodes = nil;
+                        } else if (clipboardCopy || ![menuNode isEqualTo:clipboardParentNode]) {
+                            if (clipboardNodesCount == 1)
+                                menuItemTitle = [NSString stringWithString:@"Paste Item"];
+                            else
+                                menuItemTitle = [NSString stringWithString:@"Paste Items"];
+                            menuItem = [[[NSMenuItem alloc] initWithTitle:menuItemTitle action:@selector(menuPaste:) keyEquivalent:@""] autorelease];
+                            [menuItem setRepresentedObject:menuNode];
+                            [menu addItem:menuItem];
+                        }
+                    }
+                }
+            }
         }
-        // Get Info
-        menuItem = [[[NSMenuItem alloc] initWithTitle:@"Get Info" action:@selector(getInfo:) keyEquivalent:@""] autorelease];
-        [menuItem setRepresentedObject:menuNodes];
-        [menu addItem:menuItem];
     }
 }
 
 #pragma mark -
 #pragma mark Menu Actions
 
-- (void)newFolder:(NSMenuItem *)sender {
-    for (PithosNode *node in ((NSArray *)[sender representedObject])) {
-        if ([node class] == [PithosContainerNode class]) {
-            dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
-            dispatch_async(queue, ^{
-                NSString *safeObjectName = [PithosFileUtilities safeSubdirNameForContainerName:node.pithosContainer.name 
-                                                                                    subdirName:@"untitled folder"];
-                ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest writeObjectDataRequestWithContainerName:node.pithosContainer.name 
-                                                                                                             objectName:safeObjectName 
-                                                                                                               eTag:nil 
-                                                                                                        contentType:@"application/directory" 
-                                                                                                    contentEncoding:nil 
-                                                                                                 contentDisposition:nil 
-                                                                                                           manifest:nil 
-                                                                                                            sharing:nil 
-                                                                                                           isPublic:ASIPithosObjectRequestPublicIgnore 
-                                                                                                           metadata:nil 
-                                                                                                               data:[NSData data]];
-                objectRequest.delegate = self;
-                objectRequest.didFinishSelector = @selector(newFolderFinished:);
-                objectRequest.didFailSelector = @selector(newFolderFailed:);
-                objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
-                                          node, @"node", 
-                                          nil];
-                [objectRequest startAsynchronous];
-            });
-        } else if (([node class] == [PithosSubdirNode class]) && 
-                   (node.pithosObject.subdir || 
-                    ![node.pithosObject.name hasSuffix:@"/"])) {
-            dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
-            dispatch_async(queue, ^{
-                NSString *safeObjectName = [PithosFileUtilities safeSubdirNameForContainerName:node.pithosContainer.name 
-                                                                                   subdirName:[node.pithosObject.name stringByAppendingPathComponent:@"untitled folder"]];
-                ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest writeObjectDataRequestWithContainerName:node.pithosContainer.name 
-                                                                                                            objectName:safeObjectName 
-                                                                                                                  eTag:nil 
-                                                                                                           contentType:@"application/directory" 
-                                                                                                       contentEncoding:nil 
-                                                                                                    contentDisposition:nil 
-                                                                                                              manifest:nil 
-                                                                                                               sharing:nil 
-                                                                                                              isPublic:ASIPithosObjectRequestPublicIgnore 
-                                                                                                              metadata:nil 
-                                                                                                                  data:[NSData data]];
-                objectRequest.delegate = self;
-                objectRequest.didFinishSelector = @selector(newFolderFinished:);
-                objectRequest.didFailSelector = @selector(newFolderFailed:);
-                objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
-                                         node, @"node", 
-                                         nil];
-                [objectRequest startAsynchronous];
-            });
-        }
+- (void)menuNewFolder:(NSMenuItem *)sender {
+    PithosNode *node = (PithosNode *)[sender representedObject];
+    if ([node class] == [PithosContainerNode class]) {
+        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+        dispatch_async(queue, ^{
+            NSString *safeObjectName = [PithosFileUtilities safeSubdirNameForContainerName:node.pithosContainer.name 
+                                                                                subdirName:@"untitled folder"];
+            ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest writeObjectDataRequestWithContainerName:node.pithosContainer.name 
+                                                                                                         objectName:safeObjectName 
+                                                                                                           eTag:nil 
+                                                                                                    contentType:@"application/directory" 
+                                                                                                contentEncoding:nil 
+                                                                                             contentDisposition:nil 
+                                                                                                       manifest:nil 
+                                                                                                        sharing:nil 
+                                                                                                       isPublic:ASIPithosObjectRequestPublicIgnore 
+                                                                                                       metadata:nil 
+                                                                                                           data:[NSData data]];
+            objectRequest.delegate = self;
+            objectRequest.didFinishSelector = @selector(newFolderFinished:);
+            objectRequest.didFailSelector = @selector(newFolderFailed:);
+            objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+                                      node, @"node", 
+                                      nil];
+            [objectRequest startAsynchronous];
+        });
+    } else if (([node class] == [PithosSubdirNode class]) && 
+               (node.pithosObject.subdir || 
+                ![node.pithosObject.name hasSuffix:@"/"])) {
+        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+        dispatch_async(queue, ^{
+            NSString *safeObjectName = [PithosFileUtilities safeSubdirNameForContainerName:node.pithosContainer.name 
+                                                                               subdirName:[node.pithosObject.name stringByAppendingPathComponent:@"untitled folder"]];
+            ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest writeObjectDataRequestWithContainerName:node.pithosContainer.name 
+                                                                                                        objectName:safeObjectName 
+                                                                                                              eTag:nil 
+                                                                                                       contentType:@"application/directory" 
+                                                                                                   contentEncoding:nil 
+                                                                                                contentDisposition:nil 
+                                                                                                          manifest:nil 
+                                                                                                           sharing:nil 
+                                                                                                          isPublic:ASIPithosObjectRequestPublicIgnore 
+                                                                                                          metadata:nil 
+                                                                                                              data:[NSData data]];
+            objectRequest.delegate = self;
+            objectRequest.didFinishSelector = @selector(newFolderFinished:);
+            objectRequest.didFailSelector = @selector(newFolderFailed:);
+            objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+                                     node, @"node", 
+                                     nil];
+            [objectRequest startAsynchronous];
+        });
     }
 }
 
-- (void)getInfo:(NSMenuItem *)sender {
+- (void)menuGetInfo:(NSMenuItem *)sender {
     for (PithosNode *node in ((NSArray *)[sender representedObject])) {
         [node showPithosNodeInfo:sender];
     }
 }
 
-- (void)deleteObject:(NSMenuItem *)sender {
+- (void)menuDelete:(NSMenuItem *)sender {
     for (PithosNode *node in ((NSArray *)[sender representedObject])) {
         if (([node class] == [PithosObjectNode class]) || 
             (([node class] == [PithosSubdirNode class]) && 
@@ -1124,7 +1425,7 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
     }
 }
 
-- (void)moveToTrash:(NSMenuItem *)sender {
+- (void)menuMoveToTrash:(NSMenuItem *)sender {
     for (PithosNode *node in ((NSArray *)[sender representedObject])) {
         if (([node class] == [PithosObjectNode class]) || 
             (([node class] == [PithosSubdirNode class]) && 
@@ -1173,6 +1474,153 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
     }
 }
 
+- (void)menuCut:(NSMenuItem *)sender {
+    self.clipboardNodes = (NSArray *)[sender representedObject];
+    self.clipboardParentNode = ((PithosNode *)[clipboardNodes objectAtIndex:0]).parent;
+    self.clipboardCopy = NO;
+}
+
+- (void)menuCopy:(NSMenuItem *)sender {
+    self.clipboardNodes = (NSArray *)[sender representedObject];
+    self.clipboardParentNode = ((PithosNode *)[clipboardNodes objectAtIndex:0]).parent;
+    self.clipboardCopy = YES;
+}
+
+- (void)menuPaste:(NSMenuItem *)sender {
+    if (!clipboardNodes || ![clipboardNodes count])
+        return;
+    PithosNode *dropNode = (PithosNode *)[sender representedObject];
+    if ((([dropNode class] != [PithosSubdirNode class]) && ([dropNode class] != [PithosContainerNode class])) || 
+        (([dropNode class] == [PithosSubdirNode class]) && !dropNode.pithosObject.subdir && [dropNode.pithosObject.name hasSuffix:@"/"])) 
+        return;
+    
+    NSString *containerName = [NSString stringWithString:dropNode.pithosContainer.name];
+    NSString *objectNamePrefix;
+    if ([dropNode class] == [PithosSubdirNode class])
+        objectNamePrefix = [NSString stringWithString:dropNode.pithosObject.name];
+    else
+        objectNamePrefix = [NSString string];
+    
+    NSArray *localClipboardNodes = [NSArray arrayWithArray:clipboardNodes];
+    if (!clipboardCopy && ![dropNode isEqualTo:clipboardParentNode]) {
+        self.clipboardNodes = nil;
+        self.clipboardParentNode = nil;
+        for (PithosNode *node in localClipboardNodes) {
+            if (([node class] == [PithosObjectNode class]) || 
+                (([node class] == [PithosSubdirNode class]) && !node.pithosObject.subdir && [node.pithosObject.name hasSuffix:@"/"])) {
+                dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+                dispatch_async(queue, ^{
+                    NSString *destinationObjectName = [objectNamePrefix stringByAppendingPathComponent:node.displayName];
+                    if ([node.pithosObject.name hasSuffix:@"/"])
+                        destinationObjectName = [destinationObjectName stringByAppendingString:@"/"];
+                    ASIPithosObjectRequest *objectRequest = [PithosFileUtilities moveObjectRequestWithContainerName:node.pithosContainer.name 
+                                                                                                         objectName:node.pithosObject.name 
+                                                                                           destinationContainerName:containerName 
+                                                                                              destinationObjectName:destinationObjectName 
+                                                                                                      checkIfExists:YES];
+                    if (objectRequest) {
+                        objectRequest.delegate = self;
+                        objectRequest.didFinishSelector = @selector(moveFinished:);
+                        objectRequest.didFailSelector = @selector(moveFailed:);
+                        objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+                                                  node.parent, @"node", 
+                                                  dropNode, @"dropNode", 
+                                                  nil];
+                        [objectRequest startAsynchronous];
+                    }
+                });
+            } else if ([node class] == [PithosSubdirNode class]) {
+                dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+                dispatch_async(queue, ^{
+                    NSString *destinationObjectName = [objectNamePrefix stringByAppendingPathComponent:node.displayName];
+                    if (node.pithosObject.subdir)
+                        destinationObjectName = [destinationObjectName stringByAppendingString:@"/"];
+                    NSArray *objectRequests = [PithosFileUtilities moveObjectRequestsForSubdirWithContainerName:node.pithosContainer.name 
+                                                                                                     objectName:node.pithosObject.name 
+                                                                                       destinationContainerName:containerName 
+                                                                                          destinationObjectName:destinationObjectName 
+                                                                                                  checkIfExists:YES];
+                    if (objectRequests) {
+                        for (ASIPithosObjectRequest *objectRequest in objectRequests) {
+                            objectRequest.delegate = self;
+                            objectRequest.didFinishSelector = @selector(moveFinished:);
+                            objectRequest.didFailSelector = @selector(moveFailed:);
+                            objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+                                                      node.parent, @"node", 
+                                                      dropNode, @"dropNode", 
+                                                      nil];
+                            [objectRequest startAsynchronous];
+                        }
+                    }
+                });
+            }
+        }
+    } else {
+        for (PithosNode *node in localClipboardNodes) {
+            if (([node class] == [PithosObjectNode class]) || 
+                (([node class] == [PithosSubdirNode class]) && !node.pithosObject.subdir && [node.pithosObject.name hasSuffix:@"/"])) {
+                dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+                dispatch_async(queue, ^{
+                    NSString *destinationObjectName;
+                    if (![dropNode isEqualTo:node.parent]) {
+                        destinationObjectName = [objectNamePrefix stringByAppendingPathComponent:node.displayName];
+                        if ([node.pithosObject.name hasSuffix:@"/"])
+                            destinationObjectName = [destinationObjectName stringByAppendingString:@"/"];
+                    } else {
+                        destinationObjectName = [PithosFileUtilities safeObjectNameForContainerName:containerName 
+                                                                                         objectName:node.pithosObject.name];
+                    }
+                    ASIPithosObjectRequest *objectRequest = [PithosFileUtilities copyObjectRequestWithContainerName:node.pithosContainer.name 
+                                                                                                         objectName:node.pithosObject.name 
+                                                                                           destinationContainerName:containerName 
+                                                                                              destinationObjectName:destinationObjectName 
+                                                                                                      checkIfExists:YES 
+                                                                                                     sharingAccount:node.sharingAccount];
+                    if (objectRequest) {
+                        objectRequest.delegate = self;
+                        objectRequest.didFinishSelector = @selector(copyFinished:);
+                        objectRequest.didFailSelector = @selector(copyFailed:);
+                        objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+                                                  dropNode, @"dropNode", 
+                                                  nil];
+                        [objectRequest startAsynchronous];
+                    }
+                });
+            } else if ([node class] == [PithosSubdirNode class]) {
+                dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+                dispatch_async(queue, ^{
+                    NSString *destinationObjectName;
+                    if (![dropNode isEqualTo:node.parent]) {
+                        destinationObjectName = [objectNamePrefix stringByAppendingPathComponent:node.displayName];
+                        if (node.pithosObject.subdir)
+                            destinationObjectName = [destinationObjectName stringByAppendingString:@"/"];
+                    } else {
+                        destinationObjectName = [PithosFileUtilities safeSubdirNameForContainerName:containerName 
+                                                                                         subdirName:node.pithosObject.name];
+                    }
+                    NSArray *objectRequests = [PithosFileUtilities copyObjectRequestsForSubdirWithContainerName:node.pithosContainer.name 
+                                                                                                     objectName:node.pithosObject.name 
+                                                                                       destinationContainerName:containerName 
+                                                                                          destinationObjectName:destinationObjectName 
+                                                                                                  checkIfExists:YES 
+                                                                                                 sharingAccount:node.sharingAccount];
+                    if (objectRequests) {
+                        for (ASIPithosObjectRequest *objectRequest in objectRequests) {
+                            objectRequest.delegate = self;
+                            objectRequest.didFinishSelector = @selector(copyFinished:);
+                            objectRequest.didFailSelector = @selector(copyFailed:);
+                            objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+                                                      dropNode, @"dropNode", 
+                                                      nil];
+                            [objectRequest startAsynchronous];
+                        }
+                    }
+                });                
+            }
+        }
+    }
+}
+    
 #pragma mark -
 #pragma mark Menu Actions ASIHTTPRequestDelegate
 
@@ -1180,12 +1628,10 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
     if (objectRequest.responseStatusCode == 201) {
         NSLog(@"New application/directory object created: %@", [objectRequest url]);
         PithosNode *node = [objectRequest.userInfo objectForKey:@"node"];
-        if (node) {
-            [node invalidateChildren];
-            node.children;
-        } else {
+        if (node)
+            [node refresh];
+        else
             [self refresh:nil];
-        }
     } else {
         [PithosFileUtilities unexpectedResponseStatusAlertWithRequest:objectRequest];
     }