Changeset 1086

Show
Ignore:
Timestamp:
03/27/04 22:37:46 (5 years ago)
Author:
morris
Message:

add type column to accounts and prepare it for dynamic columns

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredClient/trunk/English.lproj/Accounts.nib/info.nib

    r944 r1086  
    44<dict> 
    55        <key>IBDocumentLocation</key> 
    6         <string>248 95 400 354 0 0 1280 1002 </string> 
     6        <string>297 136 400 354 0 0 1280 1002 </string> 
    77        <key>IBFramework Version</key> 
    88        <string>349.0</string> 
    99        <key>IBSystem Version</key> 
    10         <string>7D24</string> 
     10        <string>7F44</string> 
    1111</dict> 
    1212</plist> 
  • WiredClient/trunk/WCAccount.h

    r944 r1086  
    1 /* $Id: WCAccount.h,v 1.1 2004/03/08 19:23:42 morris Exp $ */ 
     1/* $Id: WCAccount.h,v 1.2 2004/03/27 21:36:15 morris Exp $ */ 
    22 
    33/* 
     
    6969 
    7070- (NSComparisonResult)          nameSort:(WCAccount *)other; 
     71- (NSComparisonResult)          typeSort:(WCAccount *)other; 
    7172 
    7273@end 
  • WiredClient/trunk/WCAccount.m

    r944 r1086  
    1 /* $Id: WCAccount.m,v 1.1 2004/03/08 19:23:42 morris Exp $ */ 
     1/* $Id: WCAccount.m,v 1.2 2004/03/27 21:36:15 morris Exp $ */ 
    22 
    33/* 
     
    240240} 
    241241 
     242 
     243 
     244- (NSComparisonResult)typeSort:(WCAccount *)other { 
     245        NSComparisonResult              result; 
     246         
     247        // --- then sort by size 
     248        if(_type == WCAccountTypeUser && [other type] == WCAccountTypeGroup) 
     249                return NSOrderedAscending; 
     250        else if(_type == WCAccountTypeGroup && [other type] == WCAccountTypeUser) 
     251                return NSOrderedDescending; 
     252        else 
     253                result = [self nameSort:other]; 
     254         
     255        return result; 
     256} 
     257 
    242258@end 
  • WiredClient/trunk/WCAccounts.h

    r944 r1086  
    1 /* $Id: WCAccounts.h,v 1.1 2004/03/08 19:23:42 morris Exp $ */ 
     1/* $Id: WCAccounts.h,v 1.2 2004/03/27 21:36:15 morris Exp $ */ 
    22 
    33/* 
     
    3434        IBOutlet NSTableView                    *_accountsTableView; 
    3535 
    36         IBOutlet NSTableColumn                  *_iconTableColumn; 
    3736        IBOutlet NSTableColumn                  *_nameTableColumn; 
    3837 
     
    4948        NSImage                                                 *_userImage, *_groupImage; 
    5049        int                                                             _users, _groups; 
     50 
     51        NSImage                                                 *_sortUpImage, *_sortDownImage; 
     52        NSTableColumn                                   *_lastTableColumn; 
     53        BOOL                                                    _sortDescending; 
    5154} 
    5255 
  • WiredClient/trunk/WCAccounts.m

    r1037 r1086  
    1 /* $Id: WCAccounts.m,v 1.3 2004/03/18 18:14:37 morris Exp $ */ 
     1/* $Id: WCAccounts.m,v 1.4 2004/03/27 21:36:15 morris Exp $ */ 
    22 
    33/* 
     
    3333#import "WCConnection.h" 
    3434#import "WCError.h" 
     35#import "WCIconCell.h" 
    3536#import "WCMain.h" 
    3637#import "WCPreferences.h" 
     
    105106 
    106107- (void)windowDidLoad { 
    107         NSImageCell            *imageCell; 
    108  
    109         // --- set up the icon column for images 
    110         imageCell = [[NSImageCell alloc] init]; 
    111         [_iconTableColumn setDataCell:imageCell]; 
    112         [imageCell release]; 
     108        WCIconCell             *iconCell; 
     109 
     110        // --- set up our custom cell type 
     111        iconCell = [[WCIconCell alloc] initWithImageWidth:16 whitespace:NO]; 
     112        [[_accountsTableView tableColumnWithIdentifier:@"Name"] setDataCell:iconCell]; 
     113        [iconCell release]; 
    113114 
    114115        // --- double-click 
    115116        [_accountsTableView setDoubleAction:@selector(edit:)]; 
     117         
     118        // --- get the sort images 
     119        _sortUpImage    = [[NSImage imageNamed:@"SortUp"] retain]; 
     120        _sortDownImage  = [[NSImage imageNamed:@"SortDown"] retain]; 
    116121         
    117122        // --- window position 
    118123        [self setShouldCascadeWindows:NO]; 
    119124        [self setWindowFrameAutosaveName:@"Accounts"]; 
     125         
     126        // --- simulate a click on the name column to sort by name 
     127        [self tableView:_accountsTableView didClickTableColumn: 
     128                [_accountsTableView tableColumnWithIdentifier:@"Name"]]; 
    120129         
    121130        // --- start off in the table view 
     
    276285 
    277286- (void)accountsShouldCompleteGroups:(NSNotification *)notification { 
    278         NSString                        *argument
     287        NSString                        *argument, *identifier
    279288        WCConnection            *connection; 
    280289         
     
    301310        [_shownAccounts addObjectsFromArray:_allAccounts]; 
    302311 
     312        // --- get identifier 
     313        identifier = [_lastTableColumn identifier]; 
     314 
    303315        // --- sort the list 
    304         [_shownAccounts sortUsingSelector:@selector(nameSort:)]; 
    305  
     316        if([identifier isEqualToString:@"Name"]) 
     317                [_shownAccounts sortUsingSelector:@selector(nameSort:)]; 
     318        else if([identifier isEqualToString:@"Type"]) 
     319                [_shownAccounts sortUsingSelector:@selector(typeSort:)]; 
     320         
    306321        // --- we're done 
    307322        [_progressIndicator stopAnimation:self]; 
     
    525540 
    526541 
    527 - (id)tableView:(NSTableView *)sender objectValueForTableColumn:(NSTableColumn *)column row:(int)row { 
     542- (void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn { 
     543        NSImage         *sortImage; 
     544        NSString        *identifier; 
     545         
     546        if(_lastTableColumn == tableColumn) { 
     547                // --- invert sorting 
     548                _sortDescending = !_sortDescending; 
     549        } else { 
     550                _sortDescending = NO; 
     551                 
     552                if(_lastTableColumn) 
     553                        [tableView setIndicatorImage:NULL inTableColumn:_lastTableColumn]; 
     554                 
     555                // --- set the new sorting selector 
     556                _lastTableColumn = tableColumn; 
     557                 
     558                // --- get identifier 
     559                identifier = [tableColumn identifier]; 
     560                 
     561                if([identifier isEqualToString:@"Name"]) 
     562                        [_shownAccounts sortUsingSelector:@selector(nameSort:)]; 
     563                else if([identifier isEqualToString:@"Type"]) 
     564                        [_shownAccounts sortUsingSelector:@selector(typeSort:)]; 
     565                 
     566                [tableView setHighlightedTableColumn:tableColumn]; 
     567        } 
     568         
     569        // --- set the image for the new column header 
     570        sortImage = _sortDescending ? _sortDownImage : _sortUpImage; 
     571        [tableView setIndicatorImage:sortImage inTableColumn:tableColumn]; 
     572        [tableView reloadData]; 
     573
     574 
     575 
     576 
     577- (id)tableView:(NSTableView *)sender objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row { 
    528578        WCAccount       *account; 
     579        NSString        *identifier; 
     580        int                     i; 
    529581 
    530582        // --- get account 
    531         account = [_shownAccounts objectAtIndex:row]; 
     583        i                       = _sortDescending ? [_shownAccounts count] - (unsigned int) row - 1 : (unsigned int) row; 
     584        account         = [_shownAccounts objectAtIndex:i]; 
     585        identifier  = [tableColumn identifier]; 
    532586         
    533587        // --- populate columns 
    534         if(column == _iconTableColumn) { 
     588        if([identifier isEqualToString:@"Name"]) { 
     589                NSImage         *icon; 
     590                 
    535591                switch([account type]) { 
    536592                        case WCAccountTypeUser: 
    537                                 return _userImage; 
     593                                icon = _userImage; 
    538594                                break; 
    539                          
     595                                
    540596                        case WCAccountTypeGroup: 
    541                                 return _groupImage; 
     597                                icon = _groupImage; 
    542598                                break; 
    543599                } 
    544                  
    545                 return NULL
     600 
     601                return [NSArray arrayWithObjects:[account name], icon, NULL]
    546602        } 
    547         else if(column == _nameTableColumn) { 
    548                 return [account name]; 
     603        else if([identifier isEqualToString:@"Type"]) { 
     604                switch([account type]) { 
     605                        case WCAccountTypeUser: 
     606                                return NSLocalizedString(@"User", @"Account type"); 
     607                                break; 
     608                                 
     609                        case WCAccountTypeGroup: 
     610                                return NSLocalizedString(@"Group", @"Account type"); 
     611                                break; 
     612                } 
    549613        } 
    550614