Changeset 1316

Show
Ignore:
Timestamp:
05/23/04 05:29:02 (5 years ago)
Author:
morris
Message:

add an informal tooltip protocol to NSTableView data sources

also fix a _lot_ of latent bugs in WCFiles & WCSearch listings when dealing with reversed lists

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredClient/trunk/WCChat.h

    r1308 r1316  
    1 /* $Id: WCChat.h,v 1.13 2004/05/22 10:05:18 morris Exp $ */ 
     1/* $Id: WCChat.h,v 1.14 2004/05/23 03:29:02 morris Exp $ */ 
    22 
    33/* 
     
    3131@class WCConnection, WCSplitView, WCTextView, WCTableView; 
    3232 
    33 @protocol WCTableViewMenuValidation, WCTableViewInfoCopying; 
     33@protocol WCTableViewMenuValidation, WCTableViewInfoCopying, WCTableViewToolTipDisplaying; 
     34@protocol WCTableViewTypingAhead; 
    3435 
    3536@protocol WCGetInfoValidation 
     
    4142@end 
    4243 
    43 @interface WCChat : WCWindowController <WCGetInfoValidation, WCTableViewInfoCopying> { 
     44@interface WCChat : WCWindowController <WCGetInfoValidation, WCTableViewInfoCopying, WCTableViewToolTipDisplaying, WCTableViewTypingAhead> { 
    4445        IBOutlet WCSplitView                    *_chatSplitView; 
    4546        IBOutlet NSScrollView                   *_chatOutputScrollView; 
  • WiredClient/trunk/WCChat.m

    r1308 r1316  
    1 /* $Id: WCChat.m,v 1.46 2004/05/22 10:05:18 morris Exp $ */ 
     1/* $Id: WCChat.m,v 1.47 2004/05/23 03:29:02 morris Exp $ */ 
    22 
    33/* 
     
    17461746 
    17471747 
     1748- (NSString *)tableView:(NSTableView *)tableView stringValueForRow:(int)row { 
     1749        NSNumber                *key; 
     1750        WCUser                  *user; 
     1751         
     1752        // --- get user 
     1753        key             = [_sortedUsers objectAtIndex:row]; 
     1754        user    = [_shownUsers objectForKey:key]; 
     1755         
     1756        return [user nick]; 
     1757} 
     1758 
     1759 
     1760 
     1761- (NSString *)tableView:(NSTableView *)tableView toolTipForRow:(int)row { 
     1762        NSNumber                *key; 
     1763        WCUser                  *user; 
     1764         
     1765        // --- get user 
     1766        key             = [_sortedUsers objectAtIndex:row]; 
     1767        user    = [_shownUsers objectForKey:key]; 
     1768         
     1769        return [NSString stringWithFormat:@"%@\n%@", [user nick], [user status]]; 
     1770} 
     1771 
     1772 
     1773 
    17481774- (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard { 
    17491775        NSNumber        *key; 
  • WiredClient/trunk/WCFiles.h

    r1308 r1316  
    1 /* $Id: WCFiles.h,v 1.7 2004/05/22 10:05:18 morris Exp $ */ 
     1/* $Id: WCFiles.h,v 1.8 2004/05/23 03:29:02 morris Exp $ */ 
    22 
    33/* 
     
    3232 
    3333@protocol WCGetInfoValidation, WCTableViewInfoCopying, WCTableViewOptionsSelection; 
    34 @protocol WCTableViewTypingAhead
     34@protocol WCTableViewTypingAhead, WCTableViewToolTipDisplaying
    3535 
    36 @interface WCFiles : WCWindowController <WCGetInfoValidation, WCTableViewInfoCopying, WCTableViewOptionsSelection, WCTableViewTypingAhead> { 
     36@interface WCFiles : WCWindowController <WCGetInfoValidation, WCTableViewInfoCopying, WCTableViewOptionsSelection, WCTableViewTypingAhead, WCTableViewToolTipDisplaying> { 
    3737        IBOutlet WCTableView                    *_filesTableView; 
    3838        IBOutlet NSScrollView                   *_filesScrollView; 
  • WiredClient/trunk/WCFiles.m

    r1308 r1316  
    1 /* $Id: WCFiles.m,v 1.34 2004/05/22 10:05:18 morris Exp $ */ 
     1/* $Id: WCFiles.m,v 1.35 2004/05/23 03:29:02 morris Exp $ */ 
    22 
    33/* 
     
    149149        [_filesTableView setDoubleAction:@selector(open:)]; 
    150150         
    151         // --- type-ahead 
    152         [_filesTableView setTypeAhead:YES]; 
    153          
    154151        // --- get the sort images 
    155152        _sortUpImage    = [[NSImage imageNamed:@"SortUp"] retain]; 
     
    454451        else if([identifier isEqualToString:@"Kind"]) 
    455452                [_shownFiles sortUsingSelector:@selector(kindSort:)]; 
     453        else if([identifier isEqualToString:@"Created"]) 
     454                [_shownFiles sortUsingSelector:@selector(createdSort:)]; 
     455        else if([identifier isEqualToString:@"Modified"]) 
     456                [_shownFiles sortUsingSelector:@selector(modifiedSort:)]; 
    456457        else if([identifier isEqualToString:@"Size"]) 
    457458                [_shownFiles sortUsingSelector:@selector(sizeSort:)]; 
     
    462463        // --- select parent 
    463464        if(_selectPath) { 
    464                 enumerator = [_shownFiles objectEnumerator]; 
     465                enumerator = _sortDescending 
     466                        ? [_shownFiles objectEnumerator] 
     467                        : [_shownFiles objectEnumerator]; 
    465468         
    466469                while((file = [enumerator nextObject])) { 
     
    471474                } 
    472475                 
    473                 [_filesTableView selectRow:row >= 0 ? row : 0 byExtendingSelection:NO]; 
    474                 [_filesTableView scrollRowToVisible:row >= 0 ? row : 0]; 
     476                i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     477                [_filesTableView selectRow:i >= 0 ? i : 0 byExtendingSelection:NO]; 
     478                [_filesTableView scrollRowToVisible:row >= 0 ? i : 0]; 
    475479                 
    476480                [_selectPath release]; 
     
    552556        NSString        *extension; 
    553557        WCFile          *file; 
    554         int                     row; 
     558        int                     i, row; 
    555559                 
    556560        // --- get row number 
     
    564568        } else { 
    565569                // --- get file 
    566                 file = [_shownFiles objectAtIndex:row]; 
     570                i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     571                file = [_shownFiles objectAtIndex:i]; 
    567572                extension = [[[file path] pathExtension] lowercaseString]; 
    568573         
     
    660665        WCFile          *file; 
    661666        BOOL            optionKey, newWindows; 
    662         int                     row; 
     667        int                     i, row; 
    663668                 
    664669        // --- get row number 
     
    669674         
    670675        // --- get file 
    671         file = [_shownFiles objectAtIndex:row]; 
     676        i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     677        file = [_shownFiles objectAtIndex:i]; 
    672678         
    673679        switch([file type]) { 
     
    753759- (IBAction)download:(id)sender { 
    754760        WCFile          *file; 
    755         int                     row; 
     761        int                     i, row; 
    756762                 
    757763        // --- get row number 
     
    762768         
    763769        // --- get file 
    764         file = [_shownFiles objectAtIndex:row]; 
     770        i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     771        file = [_shownFiles objectAtIndex:i]; 
    765772         
    766773        // --- queue a transfer 
     
    795802- (IBAction)info:(id)sender { 
    796803        WCFile          *file; 
    797         int                     row; 
     804        int                     i, row; 
    798805                 
    799806        // --- get row number 
     
    804811         
    805812        // --- get file 
    806         file = [_shownFiles objectAtIndex:row]; 
     813        i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     814        file = [_shownFiles objectAtIndex:i]; 
    807815         
    808816        // --- create an info window 
     
    814822- (IBAction)preview:(id)sender { 
    815823        WCFile          *file; 
    816         int                     row; 
     824        int                     i, row; 
    817825                 
    818826        // --- get row number 
     
    823831         
    824832        // --- get file 
    825         file = [_shownFiles objectAtIndex:row]; 
     833        i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     834        file = [_shownFiles objectAtIndex:i]; 
    826835         
    827836        // --- queue a transfer 
     
    842851 
    843852- (IBAction)reload:(id)sender { 
    844         int             row; 
     853        int             i, row; 
    845854         
    846855        // --- get row number 
     
    848857 
    849858        // --- save selection 
    850         if(row >= 0) 
    851                 _selectPath = [[[_shownFiles objectAtIndex:row] path] retain]; 
     859        if(row >= 0) { 
     860                i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     861                _selectPath = [[[_shownFiles objectAtIndex:i] path] retain]; 
     862        } 
    852863         
    853864        // --- drop cache 
     
    863874        NSString        *title, *description; 
    864875        WCFile          *file; 
    865         int                     row; 
     876        int                     i, row; 
    866877                 
    867878        // --- get row number 
     
    872883         
    873884        // --- get file 
    874         file = [_shownFiles objectAtIndex:row]; 
     885        i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     886        file = [_shownFiles objectAtIndex:i]; 
    875887 
    876888        // --- check if we can delete 
     
    10531065 
    10541066 
     1067- (NSString *)tableView:(NSTableView *)tableView toolTipForRow:(int)row { 
     1068        WCFile          *file; 
     1069        int                     i; 
     1070         
     1071        i               = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     1072        file    = [_shownFiles objectAtIndex:i]; 
     1073         
     1074        return [file name]; 
     1075} 
     1076 
     1077 
     1078 
    10551079- (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard { 
    10561080        WCFile          *file; 
    1057         int                     row; 
     1081        int                     i, row; 
    10581082         
    10591083        // --- get row 
     
    10641088 
    10651089        // --- get file 
    1066         file = [_shownFiles objectAtIndex:row]; 
     1090        i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     1091        file = [_shownFiles objectAtIndex:i]; 
    10671092         
    10681093        // --- put path in pasteboard 
     
    10821107        NSArray                 *types; 
    10831108        WCFile                  *destination; 
     1109        int                             i; 
    10841110         
    10851111        // --- get pasteboard 
     
    10881114                 
    10891115        // --- get destination 
    1090         destination = proposedRow >= 0 && proposedRow < (int) [_shownFiles count] 
    1091                 ? [_shownFiles objectAtIndex:proposedRow] 
     1116        i = _sortDescending 
     1117                ? [_shownFiles count] - (unsigned int) proposedRow - 1 
     1118                : (unsigned int) proposedRow; 
     1119        destination = i >= 0 && i < (int) [_shownFiles count] 
     1120                ? [_shownFiles objectAtIndex:i] 
    10921121                : _path; 
    10931122         
     
    11231152        NSArray                 *types; 
    11241153        WCFile                  *destination; 
     1154        int                             i; 
    11251155 
    11261156        // --- get pasteboard 
     
    11291159                 
    11301160        // --- get destination 
     1161        i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
    11311162        destination = row >= 0 && row < (int) [_shownFiles count] 
    1132                 ? [_shownFiles objectAtIndex:row
     1163                ? [_shownFiles objectAtIndex:i
    11331164                : _path; 
    11341165         
     
    12131244        NSPasteboard    *pasteboard; 
    12141245        WCFile                  *file; 
    1215         int                             row; 
     1246        int                             i, row; 
    12161247         
    12171248        // --- get row number 
     
    12221253         
    12231254        // --- get file 
    1224         file = [_shownFiles objectAtIndex:row]; 
     1255        i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     1256        file = [_shownFiles objectAtIndex:i]; 
    12251257         
    12261258        // --- put it on the pasteboard 
  • WiredClient/trunk/WCSearch.h

    r1313 r1316  
    1 /* $Id: WCSearch.h,v 1.4 2004/05/22 10:15:50 morris Exp $ */ 
     1/* $Id: WCSearch.h,v 1.5 2004/05/23 03:29:02 morris Exp $ */ 
    22 
    33/* 
     
    3232 
    3333@protocol WCGetInfoValidation, WCTableViewInfoCopying, WCTableViewOptionsSelection; 
    34 @protocol WCTableViewTypingAhead
     34@protocol WCTableViewTypingAhead, WCTableViewToolTipDisplaying
    3535 
    36 @interface WCSearch : WCWindowController <WCGetInfoValidation, WCTableViewInfoCopying, WCTableViewOptionsSelection, WCTableViewTypingAhead> { 
     36@interface WCSearch : WCWindowController <WCGetInfoValidation, WCTableViewInfoCopying, WCTableViewOptionsSelection, WCTableViewTypingAhead, WCTableViewToolTipDisplaying> { 
    3737        IBOutlet WCTableView                    *_searchTableView; 
    3838         
  • WiredClient/trunk/WCSearch.m

    r1313 r1316  
    1 /* $Id: WCSearch.m,v 1.23 2004/05/22 10:15:50 morris Exp $ */ 
     1/* $Id: WCSearch.m,v 1.24 2004/05/23 03:29:02 morris Exp $ */ 
    22 
    33/* 
     
    147147        [_searchTableView setDoubleAction:@selector(open:)]; 
    148148         
    149         // --- type-ahead 
    150         [_searchTableView setTypeAhead:YES]; 
    151          
    152149        // --- simulate a click on the name column to sort by name 
    153150        [self tableView:_searchTableView didClickTableColumn: 
     
    364361- (BOOL)validateMenuItem:(id <NSMenuItem>)item { 
    365362        WCFile          *file; 
    366         int                     row; 
     363        int                     i, row; 
    367364         
    368365        // --- get row number 
     
    373370         
    374371        // --- get file 
    375         file = [_shownFiles objectAtIndex:row]; 
     372        i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     373        file = [_shownFiles objectAtIndex:i]; 
    376374         
    377375        if(item == _openMenuItem) 
     
    455453- (IBAction)open:(id)sender { 
    456454        WCFile          *file; 
    457         int                     row; 
     455        int                     i, row; 
    458456                 
    459457        // --- get row number 
     
    464462         
    465463        // --- get file 
    466         file = [_shownFiles objectAtIndex:row]; 
     464        i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     465        file = [_shownFiles objectAtIndex:i]; 
    467466         
    468467        switch([file type]) { 
     
    493492- (IBAction)download:(id)sender { 
    494493        WCFile          *file; 
    495         int                     row; 
     494        int                     i, row; 
    496495         
    497496        // --- get row number 
     
    502501         
    503502        // --- get file 
    504         file = [_shownFiles objectAtIndex:row]; 
     503        i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     504        file = [_shownFiles objectAtIndex:i]; 
    505505         
    506506        // --- queue a transfer 
     
    513513- (IBAction)info:(id)sender { 
    514514        WCFile          *file; 
    515         int                     row; 
     515        int                     i, row; 
    516516         
    517517        // --- get row number 
     
    522522         
    523523        // --- get file 
    524         file = [_shownFiles objectAtIndex:row]; 
     524        i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     525        file = [_shownFiles objectAtIndex:i]; 
    525526         
    526527        // --- create an info window 
     
    532533- (IBAction)revealInFiles:(id)sender { 
    533534        WCFile          *file, *parent; 
    534         int                     row; 
     535        int                     i, row; 
    535536         
    536537        // --- get row number 
     
    541542         
    542543        // --- get file 
    543         file = [_shownFiles objectAtIndex:row]; 
     544        i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     545        file = [_shownFiles objectAtIndex:i]; 
    544546         
    545547        // --- create parent 
     
    682684 
    683685 
     686- (NSString *)tableView:(NSTableView *)tableView stringValueForRow:(int)row { 
     687        WCFile          *file; 
     688        int                     i; 
     689         
     690        i               = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     691        file    = [_shownFiles objectAtIndex:i]; 
     692         
     693        return [file name]; 
     694} 
     695 
     696 
     697 
     698- (NSString *)tableView:(NSTableView *)tableView toolTipForRow:(int)row { 
     699        WCFile          *file; 
     700        int                     i; 
     701         
     702        i               = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     703        file    = [_shownFiles objectAtIndex:i]; 
     704         
     705        return [file name]; 
     706} 
     707 
     708 
     709 
    684710- (void)tableViewShouldCopyInfo:(NSTableView *)tableView { 
    685711        NSPasteboard    *pasteboard; 
    686712        WCFile                  *file; 
    687         int                             row; 
     713        int                             i, row; 
    688714         
    689715        // --- get row number 
     
    694720         
    695721        // --- get file 
    696         file = [_shownFiles objectAtIndex:row]; 
     722        i = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
     723        file = [_shownFiles objectAtIndex:i]; 
    697724         
    698725        // --- put it on the pasteboard 
     
    702729} 
    703730 
    704  
    705  
    706 - (NSString *)tableView:(NSTableView *)tableView stringValueForRow:(int)row { 
    707         WCFile          *file; 
    708         int                     i; 
    709          
    710         i               = _sortDescending ? [_shownFiles count] - (unsigned int) row - 1 : (unsigned int) row; 
    711         file    = [_shownFiles objectAtIndex:i]; 
    712          
    713         return [file name]; 
    714 } 
    715  
    716731@end 
  • WiredClient/trunk/WCTableView.h

    r1308 r1316  
    1 /* $Id: WCTableView.h,v 1.4 2004/05/22 10:05:18 morris Exp $ */ 
     1/* $Id: WCTableView.h,v 1.5 2004/05/23 03:29:02 morris Exp $ */ 
    22 
    33/* 
     
    4040@end 
    4141 
     42@protocol WCTableViewToolTipDisplaying 
     43 
     44- (NSString *)                          tableView:(NSTableView *)tableView toolTipForRow:(int)row; 
     45 
     46@end 
     47 
    4248 
    4349@interface WCTableView : NSTableView { 
     
    4551        NSCharacterSet                  *_typeAheadCharacterSet; 
    4652        BOOL                                    _typeAhead; 
     53         
     54        NSMutableDictionary             *_regions; 
    4755} 
    4856 
    49  
    50 - (void)                                        setTypeAhead:(BOOL)value; 
    51 - (BOOL)                                        typeAhead; 
    52  
    5357@end 
  • WiredClient/trunk/WCTableView.m

    r1312 r1316  
    1 /* $Id: WCTableView.m,v 1.6 2004/05/22 10:11:16 morris Exp $ */ 
     1/* $Id: WCTableView.m,v 1.7 2004/05/23 03:29:02 morris Exp $ */ 
    22 
    33/* 
     
    4848        [characterSet release]; 
    4949         
     50        // --- create dictionary for tooltips 
     51        _regions = [[NSMutableDictionary alloc] init]; 
     52         
    5053        return self; 
    5154} 
     
    6467#pragma mark - 
    6568 
     69- (void)reloadData { 
     70        [_regions removeAllObjects]; 
     71        [self removeAllToolTips]; 
     72         
     73        [super reloadData]; 
     74} 
     75 
     76 
     77 
     78#pragma mark - 
     79 
    6680- (NSMenu *)menuForEvent:(NSEvent *)event { 
    6781        int                     row; 
     
    89103        if(key == NSEnterCharacter || key == NSCarriageReturnCharacter) 
    90104                [super doCommandBySelector:[super doubleAction]]; 
    91         else if(_typeAhead && [_typeAheadCharacterSet characterIsMember:key]) 
     105        else if([[self dataSource] conformsToProtocol:@protocol(WCTableViewTypingAhead)] && 
     106                        [_typeAheadCharacterSet characterIsMember:key]) 
    92107                [self interpretKeyEvents:[NSArray arrayWithObject:event]]; 
    93108        else 
    94109                [super keyDown:event]; 
    95          
    96110} 
    97111 
     
    154168 
    155169 
     170#pragma mark - 
     171 
    156172- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)local { 
    157173        if(local) 
     
    163179 
    164180 
    165 #pragma mark - 
    166  
    167 - (void)setTypeAhead:(BOOL)value { 
    168         if([[self delegate] conformsToProtocol:@protocol(WCTableViewTypingAhead)]) 
    169                 _typeAhead = value; 
    170 
    171  
    172  
    173  
    174 - (BOOL)typeAhead { 
    175         return _typeAhead; 
     181- (NSRect)frameOfCellAtColumn:(int)columnIndex row:(int)rowIndex { 
     182        NSNumber        *tag; 
     183        NSString        *key; 
     184        NSRect          frame; 
     185         
     186        frame = [super frameOfCellAtColumn:columnIndex row:rowIndex]; 
     187        key = [NSString stringWithFormat:@"%d,%d", columnIndex, rowIndex]; 
     188        tag = [_regions objectForKey:key]; 
     189         
     190        if(tag) 
     191                [self removeToolTip:[tag intValue]]; 
     192         
     193        tag = [NSNumber numberWithInt:[self addToolTipRect:frame owner:self userData:NULL]]; 
     194        [_regions setObject:tag forKey:key]; 
     195         
     196        return frame; 
     197
     198 
     199 
     200 
     201- (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag point:(NSPoint)point userData:(void *)data { 
     202        int                     row; 
     203         
     204        row = [self rowAtPoint:point]; 
     205 
     206        if(row >= 0 && [[self dataSource] conformsToProtocol:@protocol(WCTableViewToolTipDisplaying)]) 
     207                return [[self dataSource] tableView:self toolTipForRow:row]; 
     208 
     209        return NULL; 
    176210} 
    177211