Changeset 3545

Show
Ignore:
Timestamp:
01/20/06 20:04:58 (3 years ago)
Author:
morris
Message:

Make dock work again

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredClient/trunk/WCApplicationController.m

    r3542 r3545  
    276276        if(selector == @selector(hideConnection:)) 
    277277                return ([self _shownConnection] != NULL); 
    278         else if(selector == @selector(nextConnection:)) 
    279                 return ([self _shownConnection] != NULL); 
    280         else if(selector == @selector(previousConnection:)) 
    281                 return ([self _shownConnection] != NULL); 
     278        else if(selector == @selector(nextConnection:) || selector == @selector(previousConnection:)) 
     279                return [[WCDock dock] validateMenuItem:item]; 
    282280 
    283281        return YES; 
  • WiredClient/trunk/WCChat.h

    r3540 r3545  
    7979- (id)initChatWithConnection:(WCServerConnection *)connection windowNibName:(NSString *)windowNibName name:(NSString *)name; 
    8080 
     81- (void)serverConnectionLoggedIn:(NSNotification *)notification; 
     82 
    8183- (void)validate; 
    8284 
  • WiredClient/trunk/WCChat.m

    r3540 r3545  
    599599 
    600600 
    601 - (void)serverConnectionWillReconnect:(NSNotification *)notification { 
     601- (void)serverConnectionLoggedIn:(NSNotification *)notification { 
    602602        [_users removeAllObjects]; 
    603603        [_shownUsers removeAllObjects]; 
  • WiredClient/trunk/WCConnectionController.m

    r3540 r3545  
    126126 
    127127- (void)serverConnectionShouldHide:(NSNotification *)notification { 
    128 //      _hidden = ![[self window] isVisible]; 
    129 //      [[self window] orderOut:self]; 
     128        _hidden = ![[self window] isVisible]; 
     129 
     130        [[self window] orderOut:self]; 
    130131} 
    131132 
     
    133134 
    134135- (void)serverConnectionShouldUnhide:(NSNotification *)notification { 
    135 //    if(!_hidden) 
    136 //            [[self window] orderFront:self]; 
     136      if(!_hidden) 
     137              [[self window] orderFront:self]; 
    137138} 
    138139 
  • WiredClient/trunk/WCDock.m

    r3542 r3545  
    3434@interface WCDock(Private) 
    3535 
    36 - (void)validate; 
    37 - (void)updateStatus; 
    38  
    39 - (WCServerConnection *)selectedConnection; 
    40 - (WCServerConnection *)connectionAtIndex:(int)index; 
    41 - (void)openConnection:(WCServerConnection *)connection; 
     36- (void)_validate; 
     37- (void)_updateStatus; 
     38 
     39- (WCServerConnection *)_selectedConnection; 
     40- (WCServerConnection *)_connectionAtIndex:(unsigned int)index; 
     41 
     42- (void)_openConnection:(WCServerConnection *)connection; 
     43 
     44@end 
     45 
     46 
     47@implementation WCDock(Private) 
     48 
     49- (void)_validate { 
     50        int             row; 
     51         
     52        row = [_dockTableView selectedRow]; 
     53 
     54        [_openButton setEnabled:(row >= 0)]; 
     55        [_hideButton setEnabled:(row >= 0)]; 
     56        [_hideButton setTitle:[[self _selectedConnection] isHidden] 
     57                ? NSLS(@"Show", "Show/hide button title") 
     58                : NSLS(@"Hide", "Show/hide button title")]; 
     59
     60 
     61 
     62 
     63- (void)_updateStatus { 
     64        [_statusTextField setStringValue:[NSSWF: 
     65                NSLS(@"%u %@", @"Dock status (connections, 'connection(s)')"), 
     66                [_shownConnections count], 
     67                [_shownConnections count] == 1 
     68                        ? NSLS(@"connection", @"Connection singular") 
     69                        : NSLS(@"connections", @"Connection plural")]]; 
     70
     71 
     72 
     73 
     74#pragma mark - 
     75 
     76- (WCServerConnection *)_selectedConnection { 
     77        int             row; 
     78         
     79        row = [_dockTableView selectedRow]; 
     80         
     81        if(row < 0) 
     82                return NULL; 
     83         
     84        return [self _connectionAtIndex:row]; 
     85
     86 
     87 
     88 
     89- (WCServerConnection *)_connectionAtIndex:(unsigned int)index { 
     90        if(index < [_shownConnections count]) 
     91                return [_shownConnections objectAtIndex:index]; 
     92         
     93        return NULL; 
     94
     95 
     96 
     97 
     98#pragma mark - 
     99 
     100- (void)_openConnection:(WCServerConnection *)connection { 
     101        NSEnumerator            *enumerator; 
     102        WCServerConnection      *eachConnection; 
     103         
     104        if(!connection) 
     105                return; 
     106 
     107        if([WCSettings boolForKey:WCAutoHideOnSwitch]) { 
     108                enumerator = [_shownConnections objectEnumerator]; 
     109                 
     110                while((eachConnection = [enumerator nextObject])) { 
     111                        if(eachConnection != connection && ![eachConnection isHidden]) 
     112                                [eachConnection hide]; 
     113                } 
     114                 
     115                [_dockTableView reloadData]; 
     116        } 
     117                 
     118        if([connection isHidden]) 
     119                [connection unhide]; 
     120                 
     121        [[connection chat] showWindow:self]; 
     122 
     123        [self _validate]; 
     124
    42125 
    43126@end 
     
    68151 
    69152        [self window]; 
    70          
     153 
     154        [[NSNotificationCenter defaultCenter] 
     155                addObserver:self 
     156                   selector:@selector(connectionDidClose:) 
     157                           name:WCConnectionDidClose]; 
     158 
     159        [[NSNotificationCenter defaultCenter] 
     160                addObserver:self 
     161                   selector:@selector(connectionShouldTerminate:) 
     162                           name:WCConnectionShouldTerminate]; 
     163 
     164        [[NSNotificationCenter defaultCenter] 
     165                addObserver:self 
     166                   selector:@selector(serverConnectionLoggedIn:) 
     167                           name:WCServerConnectionLoggedIn]; 
     168 
     169        [[NSNotificationCenter defaultCenter] 
     170                addObserver:self 
     171                   selector:@selector(chatUsersDidChange:) 
     172                           name:WCChatUsersDidChange]; 
     173 
    71174        [[NSNotificationCenter defaultCenter] 
    72175                addObserver:self 
     
    105208        WIMultiImageCell        *imageCell; 
    106209         
    107         // --- set up our custom cell types 
    108210        iconCell = [[WIIconCell alloc] init]; 
    109211        [iconCell setImageWidth:14.0]; 
     
    115217        [imageCell release]; 
    116218 
    117         // --- window position 
    118219        [self setShouldCascadeWindows:NO]; 
    119220        [self setWindowFrameAutosaveName:@"Dock"]; 
    120221         
    121         // --- set up table view 
    122222        [_dockTableView setDoubleAction:@selector(open:)]; 
    123223        [_dockTableView setDrawsStripes:YES]; 
    124224        [_dockTableView registerForDraggedTypes:[NSArray arrayWithObject:WCServerConnectionPboardType]]; 
    125225 
    126         // --- update buttons 
    127         [self validate]; 
    128         [self updateStatus]; 
    129 
    130  
    131  
    132  
    133 - (void)connectionHasAttached:(NSNotification *)notification { 
    134 /*      NSEnumerator            *enumerator; 
    135         WCServerConnection      *connection, *each; 
    136          
    137         // --- add connection 
     226        [self _validate]; 
     227        [self _updateStatus]; 
     228
     229 
     230 
     231 
     232- (void)connectionDidClose:(NSNotification *)notification { 
     233        [_dockTableView reloadData]; 
     234
     235 
     236 
     237 
     238- (void)connectionShouldTerminate:(NSNotification *)notification { 
     239        WCServerConnection      *connection; 
     240 
     241        connection = [notification object]; 
     242        [_shownConnections removeObject:connection]; 
     243        [_dockTableView reloadData]; 
     244         
     245        [self _updateStatus]; 
     246
     247 
     248 
     249 
     250- (void)serverConnectionLoggedIn:(NSNotification *)notification { 
     251        NSEnumerator            *enumerator; 
     252        WCServerConnection      *connection, *eachConnection; 
     253         
    138254        connection = [notification object]; 
    139255        [_shownConnections addObject:connection]; 
    140         [_dockTableView reloadData]; 
    141  
    142         // --- hide all previously unhidden 
     256 
    143257        if([WCSettings boolForKey:WCAutoHideOnSwitch]) { 
    144258                enumerator = [_shownConnections objectEnumerator]; 
    145259                 
    146                 while((each = [enumerator nextObject])) { 
    147                         if(each != connection && ![connection isHidden]) 
    148                                 [each postNotificationName:WCConnectionShouldHide object:each]; 
     260                while((eachConnection = [enumerator nextObject])) { 
     261                        if(eachConnection != connection && ![connection isHidden]) 
     262                                [eachConnection hide]; 
    149263                } 
    150264        } 
    151265 
    152266        [_dockTableView reloadData]; 
    153         [self updateStatus];*/ 
    154 
    155  
    156  
    157  
    158 - (void)connectionHasClosed:(NSNotification *)notification { 
    159         [_dockTableView reloadData]; 
    160 
    161  
    162  
    163  
    164 - (void)connectionShouldTerminate:(NSNotification *)notification { 
     267        [self _updateStatus]; 
     268
     269 
     270 
     271 
     272- (void)chatUsersDidChange:(NSNotification *)notification { 
     273        [_dockTableView reloadData]; 
     274
     275 
     276 
     277 
     278- (void)messagesDidAddMessage:(NSNotification *)notification { 
     279        [_dockTableView reloadData]; 
     280
     281 
     282 
     283 
     284- (void)messagesDidReadMessage:(NSNotification *)notification { 
     285        [_dockTableView reloadData]; 
     286
     287 
     288 
     289 
     290- (void)newsDidAddPost:(NSNotification *)notification { 
     291        [_dockTableView reloadData]; 
     292
     293 
     294 
     295 
     296- (void)newsDidReadPost:(NSNotification *)notification { 
     297        [_dockTableView reloadData]; 
     298
     299 
     300 
     301 
     302#pragma mark - 
     303 
     304- (BOOL)validateMenuItem:(NSMenuItem *)item { 
     305        SEL             selector; 
     306 
     307        selector = [item action]; 
     308         
     309        if(selector == @selector(nextConnection:) || selector == @selector(previousConnection:)) 
     310                return ([_shownConnections count] > 0); 
     311 
     312        return YES; 
     313
     314 
     315 
     316 
     317#pragma mark - 
     318 
     319- (IBAction)open:(id)sender { 
     320        [self _openConnection:[self _selectedConnection]]; 
     321
     322 
     323 
     324 
     325- (IBAction)hide:(id)sender { 
    165326        WCServerConnection      *connection; 
    166  
    167         connection = [notification object]; 
    168         [_shownConnections removeObject:connection]; 
    169         [_dockTableView reloadData]; 
    170         [self updateStatus]; 
    171 
    172  
    173  
    174  
    175 - (void)chatUsersDidChange:(NSNotification *)notification { 
    176         [_dockTableView reloadData]; 
    177 
    178  
    179  
    180  
    181 - (void)messagesDidAddMessage:(NSNotification *)notification { 
    182         [_dockTableView reloadData]; 
    183 
    184  
    185  
    186  
    187 - (void)messagesDidReadMessage:(NSNotification *)notification { 
    188         [_dockTableView reloadData]; 
    189 
    190  
    191  
    192  
    193 - (void)newsDidAddPost:(NSNotification *)notification { 
    194         [_dockTableView reloadData]; 
    195 
    196  
    197  
    198  
    199 - (void)newsDidReadPost:(NSNotification *)notification { 
    200         [_dockTableView reloadData]; 
    201 
    202  
    203  
    204  
    205 #pragma mark - 
    206  
    207 - (void)validate { 
    208         int             row; 
    209          
    210         row = [_dockTableView selectedRow]; 
    211  
    212         [_openButton setEnabled:(row >= 0)]; 
    213         [_hideButton setEnabled:(row >= 0)]; 
    214         [_hideButton setTitle:[[self selectedConnection] isHidden] 
    215                 ? NSLS(@"Show", "Show/hide button title") 
    216                 : NSLS(@"Hide", "Show/hide button title")]; 
    217 
    218  
    219  
    220  
    221 - (BOOL)validateMenuItem:(NSMenuItem *)item { 
    222         NSLog(@"%@", item); 
    223         return YES; 
    224 
    225  
    226  
    227  
    228 - (void)updateStatus { 
    229         [_statusTextField setStringValue:[NSSWF: 
    230                 NSLS(@"%u %@", @"Dock status (connections, 'connection(s)')"), 
    231                 [_shownConnections count], 
    232                 [_shownConnections count] == 1 
    233                         ? NSLS(@"connection", @"Connection singular") 
    234                         : NSLS(@"connections", @"Connection plural")]]; 
    235 
    236  
    237  
    238  
    239 - (WCServerConnection *)selectedConnection { 
    240         int             row; 
    241          
    242         row = [_dockTableView selectedRow]; 
    243          
    244         if(row < 0) 
    245                 return NULL; 
    246          
    247         return [self connectionAtIndex:row]; 
    248 
    249  
    250  
    251  
    252 - (WCServerConnection *)connectionAtIndex:(int)index { 
    253         return [_shownConnections objectAtIndex:index]; 
    254 
    255  
    256  
    257  
    258 - (void)openConnection:(WCServerConnection *)connection { 
    259 /*      NSEnumerator            *enumerator; 
    260         WCServerConnection      *each; 
    261  
    262         if(connection) { 
    263                 // --- hide all previously unhidden 
    264                 if([WCSettings boolForKey:WCAutoHideOnSwitch]) { 
    265                         enumerator = [_shownConnections objectEnumerator]; 
    266                          
    267                         while((each = [enumerator nextObject])) { 
    268                                 if(each != connection && ![each isHidden]) 
    269                                         [each postNotificationName:WCConnectionShouldHide object:each]; 
    270                         } 
    271                 } 
    272                  
    273                 [_dockTableView reloadData]; 
    274                  
    275                 // --- unhide first 
    276                 if([connection isHidden]) 
    277                         [connection postNotificationName:WCConnectionShouldUnhide object:connection]; 
    278                  
    279                 // --- show connection 
    280                 [[connection chat] showWindow:self]; 
    281                 [self validate]; 
    282         }*/ 
    283 
    284  
    285  
    286  
    287 #pragma mark - 
    288  
    289 - (IBAction)open:(id)sender { 
    290         [self openConnection:[self selectedConnection]]; 
    291 
    292  
    293  
    294  
    295 - (IBAction)hide:(id)sender { 
    296 /*      WCServerConnection      *connection; 
    297          
    298         connection = [self selectedConnection]; 
     327         
     328        connection = [self _selectedConnection]; 
    299329         
    300330        if([connection isHidden]) 
    301                 [connection postNotificationName:WCConnectionShouldUnhide object:connection]; 
     331                [connection unhide]; 
    302332        else 
    303                 [connection postNotificationName:WCConnectionShouldHide object:connection]; 
    304  
    305         [self validate]; 
    306         [_dockTableView setNeedsDisplay:YES];*/ 
     333                [connection hide]; 
     334 
     335        [self _validate]; 
     336        [_dockTableView setNeedsDisplay:YES]; 
    307337} 
    308338 
     
    310340 
    311341- (IBAction)hideConnection:(id)sender { 
    312 /*    WCServerConnection      *connection; 
     342      WCServerConnection      *connection; 
    313343         
    314344        connection = [(WCConnectionController *) [[NSApp keyWindow] windowController] connection]; 
    315         [connection postNotificationName:WCConnectionShouldHide object:connection]; 
    316          
    317         [self validate]; 
    318         [_dockTableView setNeedsDisplay:YES];*/ 
     345        [connection hide]; 
     346         
     347        [self _validate]; 
     348        [_dockTableView setNeedsDisplay:YES]; 
    319349} 
    320350 
     
    325355        int                                     i; 
    326356         
    327         connection = [(WCConnectionController *) [[NSApp keyWindow] windowController] connection]; 
     357        if([[[NSApp keyWindow] windowController] isKindOfClass:[WCConnectionController class]]) 
     358                connection = [(WCConnectionController *) [[NSApp keyWindow] windowController] connection]; 
     359        else 
     360                connection = [_shownConnections lastObject]; 
     361         
     362        if(!connection) 
     363                return; 
     364         
    328365        i = [_shownConnections indexOfObject:connection] + 1; 
    329366         
    330367        if((unsigned int) i >= [_shownConnections count]) 
    331368                i = 0; 
    332          
    333         nextConnection = [_shownConnections objectAtIndex:i]; 
    334          
     369                
     370        nextConnection = [self _connectionAtIndex:i]; 
     371                
    335372        if(connection != nextConnection) 
    336                 [self openConnection:nextConnection]; 
     373                [self _openConnection:nextConnection]; 
    337374} 
    338375 
     
    343380        int                                     i; 
    344381         
    345         connection = [(WCConnectionController *) [[NSApp keyWindow] windowController] connection]; 
     382        if([[[NSApp keyWindow] windowController] isKindOfClass:[WCConnectionController class]]) 
     383                connection = [(WCConnectionController *) [[NSApp keyWindow] windowController] connection]; 
     384        else 
     385                connection = [self _connectionAtIndex:0]; 
     386         
     387        if(!connection) 
     388                return; 
     389 
    346390        i = [_shownConnections indexOfObject:connection] - 1; 
    347391         
     
    349393                i = [_shownConnections count] - 1; 
    350394 
    351         previousConnection = [_shownConnections objectAtIndex:i]; 
     395        previousConnection = [self _connectionAtIndex:i]; 
    352396 
    353397        if(connection != previousConnection) 
    354                 [self openConnection:previousConnection]; 
     398                [self _openConnection:previousConnection]; 
    355399} 
    356400 
     
    370414        NSMutableArray          *images; 
    371415         
    372         connection = [self connectionAtIndex:row]; 
     416        connection = [self _connectionAtIndex:row]; 
    373417         
    374418        if(tableColumn == _nameTableColumn) { 
     
    399443 
    400444                // --- has unread posts? 
    401                 if([[connection messages] numberOfUnreadMessages] > 0) { 
     445                if([[connection news] numberOfUnreadPosts] > 0) { 
    402446                        [images addObject:[connection isHidden] 
    403447                                ? [_postsImage tintedImageWithColor:[NSColor colorWithDeviceWhite:1.0 alpha:0.5]] 
     
    422466- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(int)row { 
    423467        if([cell respondsToSelector:@selector(setTextColor:)]) { 
    424                 // --- gray out hidden connections 
    425                 [cell setTextColor:[[self connectionAtIndex:row] isHidden] 
     468                [cell setTextColor:[[self _connectionAtIndex:row] isHidden] 
    426469                        ? [NSColor grayColor] 
    427470                        : [NSColor blackColor]]; 
     
    432475 
    433476- (void)tableViewSelectionDidChange:(NSNotification *)notification { 
    434         [self validate]; 
    435         [self updateStatus]; 
     477        [self _validate]; 
     478        [self _updateStatus]; 
    436479} 
    437480 
     
    452495 
    453496- (NSDragOperation)tableView:(NSTableView*)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)operation { 
    454         // --- only accept drops in between rows 
    455497        if(operation != NSTableViewDropAbove) 
    456498                return NSDragOperationNone; 
  • WiredClient/trunk/WCMessagesWindow.m

    r3427 r3545  
    5151                        } 
    5252                         
    53                         if([[event characters] isComposedOfCharactersFromSet:characterSet]) { 
     53                        if([[event characters] isComposedOfCharactersFromSet:characterSet] && 
     54                           [event character] != '\t') { 
    5455                                [[self delegate] showPrivateMessageReplyWithString:[event characters]]; 
    5556                                 
  • WiredClient/trunk/WCPublicChat.m

    r3542 r3545  
    283283- (void)serverConnectionLoggedIn:(NSNotification *)notification { 
    284284        [self showWindow:self]; 
     285         
     286        [super serverConnectionLoggedIn:notification]; 
    285287} 
    286288 
  • WiredClient/trunk/WCServerConnection.h

    r3540 r3545  
    132132 
    133133- (void)reconnect; 
     134- (void)hide; 
     135- (void)unhide; 
    134136 
    135137- (BOOL)isReconnecting; 
  • WiredClient/trunk/WCServerConnection.m

    r3542 r3545  
    6868        _notificationCenter = [[NSNotificationCenter alloc] init]; 
    6969         
     70        [self window]; 
     71 
    7072        [self addObserver:self 
    7173                         selector:@selector(connectionDidConnect:) 
     
    116118                                 name:WCServerConnectionReceivedPrivileges]; 
    117119 
    118         [self window]; 
     120        [self addObserver:self 
     121                         selector:@selector(serverConnectionShouldHide:) 
     122                                 name:WCServerConnectionShouldHide]; 
     123 
     124        [self addObserver:self 
     125                         selector:@selector(serverConnectionShouldUnhide:) 
     126                                 name:WCServerConnectionShouldUnhide]; 
    119127 
    120128        return self; 
     
    416424 
    417425 
     426- (void)serverConnectionShouldHide:(NSNotification *)notification { 
     427        _hidden = YES; 
     428} 
     429 
     430 
     431 
     432- (void)serverConnectionShouldUnhide:(NSNotification *)notification { 
     433        _hidden = NO; 
     434} 
     435 
     436 
     437 
    418438#pragma mark - 
    419439 
     
    734754 
    735755 
     756- (void)terminate { 
     757        [self postNotificationName:WCConnectionShouldTerminate object:self]; 
     758} 
     759 
     760 
     761 
    736762- (void)reconnect { 
    737763        [self postNotificationName:WCServerConnectionWillReconnect object:self]; 
     
    744770 
    745771 
    746 - (void)terminate { 
    747         [self postNotificationName:WCConnectionShouldTerminate object:self]; 
     772- (void)hide { 
     773        [self postNotificationName:WCServerConnectionShouldHide object:self]; 
     774
     775 
     776 
     777 
     778- (void)unhide { 
     779        [self postNotificationName:WCServerConnectionShouldUnhide object:self]; 
    748780} 
    749781