Close node info windows when changing accounts in the browser
[pithos-macos] / pithos-macos / PithosBrowserController.m
index d753e9f..e8f0743 100644 (file)
 
 @implementation PithosBrowserController
 @synthesize pithos;
-@synthesize accountNode;
-@synthesize verticalSplitView, horizontalSplitView, leftTopView, leftBottomView, outlineView, browser, outlineViewMenu, browserMenu;
+@synthesize pithosAccountManager, accountNode;
 @synthesize draggedNodes, draggedParentNode;
 @synthesize clipboardNodes, clipboardParentNode, clipboardCopy;
-@synthesize activityTextField, activityProgressIndicator;
 
 #pragma mark -
 #pragma Object Lifecycle
     [activityProgressIndicator setMaxValue:1.0];
     activityFacility = [PithosActivityFacility defaultPithosActivityFacility];
     
-    self.accountNode = [[PithosAccountNode alloc] initWithPithos:pithos];
+    self.accountNode = [[PithosAccountNode alloc] initWithPithosAccountManager:pithosAccountManager andPithos:pithos];
     containersNode = [[PithosEmptyNode alloc] initWithDisplayName:@"CONTAINERS" icon:nil];
     containersNodeChildren = [[NSMutableArray alloc] init];
     sharedNode = [[PithosEmptyNode alloc] initWithDisplayName:@"SHARED" icon:nil];
-    mySharedNode = [[PithosAccountNode alloc] initWithPithos:pithos];
+    mySharedNode = [[PithosAccountNode alloc] initWithPithosAccountManager:pithosAccountManager andPithos:pithos];
     mySharedNode.displayName = @"shared by me";
     mySharedNode.shared = YES;
     mySharedNode.icon = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kUserIcon)];
-    othersSharedNode = [[PithosSharingAccountsNode alloc] initWithPithos:pithos];
+    othersSharedNode = [[PithosSharingAccountsNode alloc] initWithPithosAccountManager:pithosAccountManager andPithos:pithos];
     othersSharedNode.displayName = @"shared with me";
     othersSharedNode.icon = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGroupIcon)];
     
     // Request for browser refresh 
     [[NSNotificationCenter defaultCenter] addObserver:self 
                                              selector:@selector(pithosBrowserRefreshNeeded:) 
-                                                 name:@"PithosBrowserRefreshNeeeded" 
+                                                 name:@"PithosBrowserRefreshNeeded" 
                                                object:nil];
 }
 
     [downloadCallbackQueue cancelAllOperations];
     [downloadCallbackQueue setSuspended:YES];
 
+    [accountNode pithosNodeWillBeRemoved];
+    [mySharedNode pithosNodeWillBeRemoved];
+    [othersSharedNode pithosNodeWillBeRemoved];
+    
     rootNode = nil;
     [browser loadColumnZero];
     [containersNodeChildren removeAllObjects];
     [downloadCallbackQueue setSuspended:NO];
 
     accountNode.pithos = pithos;
+    accountNode.pithosAccountManager = pithosAccountManager;
     [accountNode forceRefresh];
     mySharedNode.pithos = pithos;
+    mySharedNode.pithosAccountManager = pithosAccountManager;
     [mySharedNode forceRefresh];
     othersSharedNode.pithos = pithos;
+    othersSharedNode.pithosAccountManager = pithosAccountManager;
     [othersSharedNode forceRefresh];
             
 //    [activityFacility reset];
 #pragma mark Observers
 
 - (void)pithosNodeChildrenUpdated:(NSNotification *)notification {
+    if (![NSThread isMainThread]) {
+        [self performSelectorOnMainThread:@selector(pithosNodeChildrenUpdated:) withObject:notification waitUntilDone:NO];
+        return;
+    }
     PithosNode *node = (PithosNode *)[notification object];
     if ((node == accountNode) || ![node.pithos isEqualTo:pithos])
         return;
 }
 
 - (void)pithosAccountNodeChildrenUpdated:(NSNotification *)notification {
+    if (![NSThread isMainThread]) {
+        [self performSelectorOnMainThread:@selector(pithosAccountNodeChildrenUpdated:) withObject:notification waitUntilDone:NO];
+        return;
+    }
     BOOL containerPithosFound = NO;
     BOOL containerTrashFound = NO;
     NSMutableIndexSet *removedContainersNodeChildren = [NSMutableIndexSet indexSet];
 #pragma mark Actions
 
 - (IBAction)forceRefresh:(id)sender {
+    if (![NSThread isMainThread]) {
+        [self performSelectorOnMainThread:@selector(forceRefresh:) withObject:sender waitUntilDone:NO];
+        return;
+    }
     if (editingItem)
         return;
     if (sender)
 }
 
 - (IBAction)refresh:(id)sender {
+    if (![NSThread isMainThread]) {
+        [self performSelectorOnMainThread:@selector(refresh:) withObject:sender waitUntilDone:NO];
+        return;
+    }
     if (editingItem)
         return;
     if ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask) {
@@ -1940,9 +1961,9 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
 
 - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex {
     if (splitView == verticalSplitView)
-        return 120;
+        return 140;
     else
-        return ([horizontalSplitView bounds].size.height - 108);
+        return ([horizontalSplitView bounds].size.height - 142);
 }
 
 - (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex {
@@ -1952,17 +1973,12 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
         return ([horizontalSplitView bounds].size.height - 108);
 }
 
-- (CGFloat)splitView:(NSSplitView *)splitView constrainSplitPosition:(CGFloat)proposedPosition ofSubviewAt:(NSInteger)dividerIndex {
-    if (splitView == verticalSplitView) {
-        if (proposedPosition < 120)
-            return 120;
-        else if (proposedPosition > 220)
-            return 220;
-        else
-            return proposedPosition;
-    } else {
-        return ([horizontalSplitView bounds].size.height - 108);
+- (BOOL)splitView:(NSSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)view {
+    if (((splitView == verticalSplitView) && (view == leftView)) ||
+        ((splitView == horizontalSplitView) && (view == leftBottomView))) {
+        return NO;
     }
+    return YES;
 }
 
 #pragma mark -