Added menu for outlineView items.
authorMiltiadis Vasilakis <mvasilak@gmail.com>
Fri, 30 Sep 2011 14:06:57 +0000 (17:06 +0300)
committerMiltiadis Vasilakis <mvasilak@gmail.com>
Fri, 30 Sep 2011 14:06:57 +0000 (17:06 +0300)
pithos-macos/PithosBrowserController.h
pithos-macos/PithosBrowserController.m

index d94f433..f0b1150 100644 (file)
@@ -53,6 +53,7 @@
     NSViewController *sharedPreviewController;
     
     NSMenu *browserMenu;
+    NSMenu *outlineViewMenu;
     
     NSSplitView *verticalSplitView;
     NSSplitView *horizontalSplitView;
index 4103f61..58979fd 100644 (file)
     [clipboardNodes release];
     [draggedParentNode release];
     [draggedNodes release];
+    [outlineViewMenu release];
     [browserMenu release];
     [sharedPreviewController release];
     [othersSharedNode release];
     browserMenu = [[NSMenu alloc] init];
     [browserMenu setDelegate:self];
     [browser setMenu:browserMenu];
+
+    outlineViewMenu = [[NSMenu alloc] init];
+    [outlineViewMenu setDelegate:self];
+    [outlineView setMenu:outlineViewMenu];
 }
 
 - (void)resetContainers:(NSNotification *)notification {
@@ -1180,43 +1185,70 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
 #pragma mark NSMenuDelegate
 
 - (void)menuNeedsUpdate:(NSMenu *)menu {
-    NSInteger column = [browser clickedColumn];
-    NSInteger row = [browser clickedRow];
     [menu removeAllItems];
     NSMenuItem *menuItem;
     NSString *menuItemTitle;
-    if ((column == -1) || (row == -1)) {
-        // General context menu
-        NSArray *menuNodesIndexPaths = [browser selectionIndexPaths];
-        PithosNode *menuNode;
-        if ([menuNodesIndexPaths count] == 0) {
-            menuNode = [browser parentForItemsInColumn:0];
-        } else if (([menuNodesIndexPaths count] != 1) || 
-            ([[browser itemAtIndexPath:[menuNodesIndexPaths objectAtIndex:0]] class] == [PithosObjectNode class])) {
-            menuNode = [browser parentForItemsInColumn:([[menuNodesIndexPaths objectAtIndex:0] length] - 1)];
+    BOOL nodeContextMenu = NO;
+    PithosNode *menuNode;
+    NSMutableArray *menuNodes;
+    if (menu == browserMenu) {
+        NSInteger column = [browser clickedColumn];
+        NSInteger row = [browser clickedRow];
+        if ((column == -1) || (row == -1)) {
+            // General context menu
+            NSArray *menuNodesIndexPaths = [browser selectionIndexPaths];
+            if ([menuNodesIndexPaths count] == 0) {
+                menuNode = [browser parentForItemsInColumn:0];
+            } else if (([menuNodesIndexPaths count] != 1) || 
+                       ([[browser itemAtIndexPath:[menuNodesIndexPaths objectAtIndex:0]] class] == [PithosObjectNode class])) {
+                menuNode = [browser parentForItemsInColumn:([[menuNodesIndexPaths objectAtIndex:0] length] - 1)];
+            } else {
+                menuNode = [browser itemAtIndexPath:[menuNodesIndexPaths objectAtIndex:0]];
+            }
         } else {
-            menuNode = [browser itemAtIndexPath:[menuNodesIndexPaths objectAtIndex:0]];
+            // Node context menu
+            NSIndexPath *clickedNodeIndexPath = [[browser indexPathForColumn:column] indexPathByAddingIndex:row];
+            NSArray *menuNodesIndexPaths = [browser selectionIndexPaths];
+            menuNodes = [NSMutableArray arrayWithCapacity:[menuNodesIndexPaths count]];
+            if ([menuNodesIndexPaths containsObject:clickedNodeIndexPath]) {
+                for (NSIndexPath *nodeIndexPath in menuNodesIndexPaths) {
+                    [menuNodes addObject:[browser itemAtIndexPath:nodeIndexPath]];
+                }
+            } else {
+                [menuNodes addObject:[browser itemAtIndexPath:clickedNodeIndexPath]];
+            }
+            nodeContextMenu = YES;
         }
-        if (([menuNode class] == [PithosAccountNode class]) || ([menuNode class] == [PithosSharingAccountsNode class]))
+    } else if (menu == outlineViewMenu) {
+        NSInteger row = [outlineView clickedRow];
+        if (row == -1)
+            row = [outlineView selectedRow];
+        if (row == -1)
+            return;
+        menuNode = [outlineView itemAtRow:row];
+    }
+
+    if (!nodeContextMenu) {
+        // General context menu
+        if (([menuNode class] == [PithosAccountNode class]) || 
+            ([menuNode class] == [PithosSharingAccountsNode class]) ||
+            ([menuNode class] == [PithosEmptyNode class]))
             return;
         BOOL shared = menuNode.shared;
         BOOL sharingAccount = (menuNode.sharingAccount != nil);
-        
+        // New Folder
         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(menuGetInfo:) keyEquivalent:@""] autorelease];
         [menuItem setRepresentedObject:[NSArray arrayWithObject:menuNode]];
         [menu addItem:menuItem];
-        
+        // Paste
         if (!shared && !sharingAccount) {
-            // Paste
             if (clipboardNodes) {
                 NSUInteger clipboardNodesCount = [clipboardNodes count];
                 if (clipboardNodesCount == 0) {
@@ -1235,24 +1267,13 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
         }
     } else {
         // Node context menu
-        NSIndexPath *clickedNodeIndexPath = [[browser indexPathForColumn:column] indexPathByAddingIndex:row];
-        NSArray *menuNodesIndexPaths = [browser selectionIndexPaths];
-        NSMutableArray *menuNodes = [NSMutableArray arrayWithCapacity:[menuNodesIndexPaths count]];
-        if ([menuNodesIndexPaths containsObject:clickedNodeIndexPath]) {
-            for (NSIndexPath *nodeIndexPath in menuNodesIndexPaths) {
-                [menuNodes addObject:[browser itemAtIndexPath:nodeIndexPath]];
-            }
-        } else {
-            [menuNodes addObject:[browser itemAtIndexPath:clickedNodeIndexPath]];
-        }
         NSUInteger menuNodesCount = [menuNodes count];
         PithosNode *firstMenuNode = (PithosNode *)[menuNodes objectAtIndex:0];
         BOOL shared = firstMenuNode.shared;
         BOOL sharingAccount = (firstMenuNode.sharingAccount != nil);
-        
+        // Move to Trash (pithos container only)
+        // Delete
         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];
@@ -1265,9 +1286,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                 [menu addItem:[NSMenuItem separatorItem]];
             }
         }
-        
+        // Get Info
         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];
@@ -1275,10 +1295,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
             if ((!shared && !sharingAccount) || ([firstMenuNode class] != [PithosContainerNode class]))
                 [menu addItem:[NSMenuItem separatorItem]];
         }
-        
+        // Cut
         if (!shared && !sharingAccount) {
-            // Cut
-            
             if (menuNodesCount == 1)
                 menuItemTitle = [NSString stringWithFormat:@"Cut \"%@\"", ((PithosNode *)[menuNodes objectAtIndex:0]).displayName];
             else 
@@ -1287,10 +1305,9 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
             [menuItem setRepresentedObject:menuNodes];
             [menu addItem:menuItem];
         }
-        
+        // Copy
         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 
@@ -1299,9 +1316,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
             [menuItem setRepresentedObject:menuNodes];
             [menu addItem:menuItem];
         }
-        
+        // Paste
         if (!shared && !sharingAccount) {
-            // Paste
             if (menuNodesCount == 1) {
                 PithosNode *menuNode = [menuNodes objectAtIndex:0];
                 if (([menuNode class] == [PithosSubdirNode class]) &&