| 79 | | if(key == NSEnterCharacter || key == NSCarriageReturnCharacter) |
|---|
| 80 | | [super doCommandBySelector:[super doubleAction]]; |
|---|
| | 112 | if(key == NSEnterCharacter || key == NSCarriageReturnCharacter) { |
|---|
| | 113 | if([self doubleAction]) |
|---|
| | 114 | [self doCommandBySelector:[self doubleAction]]; |
|---|
| | 115 | } |
|---|
| | 116 | // --- delete |
|---|
| | 117 | else if(key == NSDeleteFunctionKey) { |
|---|
| | 118 | if([self deleteAction]) |
|---|
| | 119 | [self doCommandBySelector:[self deleteAction]]; |
|---|
| | 120 | } |
|---|
| | 121 | // --- enter type-ahead find |
|---|
| | 122 | else if([[self dataSource] respondsToSelector:@selector(outlineView:stringValueForRow:)] && |
|---|
| | 123 | [_typeAheadCharacterSet characterIsMember:key]) { |
|---|
| | 124 | [self interpretKeyEvents:[NSArray arrayWithObject:event]]; |
|---|
| | 125 | } |
|---|
| | 126 | // --- pass down |
|---|
| | 127 | else { |
|---|
| | 128 | [super keyDown:event]; |
|---|
| | 129 | } |
|---|
| | 130 | } |
|---|
| | 131 | |
|---|
| | 132 | |
|---|
| | 133 | |
|---|
| | 134 | - (void)insertText:(NSString *)string { |
|---|
| | 135 | static NSDate *lastDate; |
|---|
| | 136 | NSString *value; |
|---|
| | 137 | NSDate *date; |
|---|
| | 138 | int i, rows; |
|---|
| | 139 | |
|---|
| | 140 | // --- get values |
|---|
| | 141 | rows = [self numberOfRows]; |
|---|
| | 142 | date = [NSDate date]; |
|---|
| | 143 | |
|---|
| | 144 | // --- compare with previous time |
|---|
| | 145 | if([date timeIntervalSinceDate:lastDate] < 0.5) |
|---|
| | 146 | [_typeAheadString appendString:string]; |
|---|
| 82 | | [super keyDown:event]; |
|---|
| | 148 | [_typeAheadString setString:string]; |
|---|
| | 149 | |
|---|
| | 150 | // --- save this time |
|---|
| | 151 | [lastDate release]; |
|---|
| | 152 | lastDate = [date retain]; |
|---|
| | 153 | |
|---|
| | 154 | // --- find the first row that matches |
|---|
| | 155 | for(i = 0; i < rows; i++) { |
|---|
| | 156 | value = [[self dataSource] tableView:self stringValueForRow:i]; |
|---|
| | 157 | |
|---|
| | 158 | if([value compare:_typeAheadString options:NSCaseInsensitiveSearch] > NSOrderedAscending) { |
|---|
| | 159 | [self selectRow:i byExtendingSelection:NO]; |
|---|
| | 160 | [self scrollRowToVisible:i]; |
|---|
| | 161 | |
|---|
| | 162 | break; |
|---|
| | 163 | } |
|---|
| | 164 | } |
|---|
| | 165 | } |
|---|
| | 166 | |
|---|
| | 167 | |
|---|
| | 168 | |
|---|
| | 169 | - (void)moveLeft:(id)sender { |
|---|
| | 170 | if([[self delegate] respondsToSelector:@selector(back:)]) |
|---|
| | 171 | [[self delegate] back:sender]; |
|---|
| | 172 | } |
|---|
| | 173 | |
|---|
| | 174 | |
|---|
| | 175 | |
|---|
| | 176 | - (void)moveRight:(id)sender { |
|---|
| | 177 | if([[self delegate] respondsToSelector:@selector(forward:)]) |
|---|
| | 178 | [[self delegate] forward:sender]; |
|---|
| 88 | | if([[self delegate] respondsToSelector:@selector(outlineViewShouldCopyInfo:)]) |
|---|
| 89 | | [[self delegate] outlineViewShouldCopyInfo:self]; |
|---|
| 90 | | } |
|---|
| 91 | | |
|---|
| 92 | | |
|---|
| 93 | | |
|---|
| 94 | | - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)local { |
|---|
| 95 | | if(local) |
|---|
| 96 | | return NSDragOperationEvery; |
|---|
| 97 | | |
|---|
| 98 | | return NSDragOperationGeneric; |
|---|
| 99 | | } |
|---|
| 100 | | |
|---|
| 101 | | |
|---|
| 102 | | |
|---|
| 103 | | #pragma mark - |
|---|
| | 184 | if([[self delegate] respondsToSelector:@selector(tableViewShouldCopyInfo:)]) |
|---|
| | 185 | [[self delegate] tableViewShouldCopyInfo:self]; |
|---|
| | 186 | } |
|---|
| | 187 | |
|---|
| | 188 | |
|---|
| | 189 | |
|---|
| | 190 | - (void)flagsChanged:(id)sender { |
|---|
| | 191 | if([[self delegate] respondsToSelector:@selector(tableViewShouldCopyInfo:)]) |
|---|
| | 192 | [[self delegate] tableViewShouldCopyInfo:self]; |
|---|
| | 193 | } |
|---|
| | 194 | |
|---|
| | 195 | |
|---|
| | 196 | |
|---|
| | 197 | - (void)cancelOperation:(id)sender { |
|---|
| | 198 | if([self escapeAction]) |
|---|
| | 199 | [self doCommandBySelector:[self escapeAction]]; |
|---|
| | 200 | } |
|---|
| | 201 | |
|---|
| | 202 | |
|---|
| | 203 | |
|---|
| | 204 | #pragma mark - |
|---|
| | 205 | |
|---|
| | 206 | - (void)setHighlightedTableColumn:(NSTableColumn *)tableColumn { |
|---|
| | 207 | NSString *key; |
|---|
| | 208 | |
|---|
| | 209 | if([self highlightedTableColumn]) { |
|---|
| | 210 | if([self highlightedTableColumn] == tableColumn) { |
|---|
| | 211 | _sortDescending = !_sortDescending; |
|---|
| | 212 | } else { |
|---|
| | 213 | _sortDescending = NO; |
|---|
| | 214 | [self setIndicatorImage:NULL inTableColumn:[self highlightedTableColumn]]; |
|---|
| | 215 | } |
|---|
| | 216 | } |
|---|
| | 217 | |
|---|
| | 218 | key = [NSString stringWithFormat:@"WCTableView %@ Selected Column", [self autosaveName]]; |
|---|
| | 219 | [[NSUserDefaults standardUserDefaults] setObject:[tableColumn identifier] forKey:key]; |
|---|
| | 220 | |
|---|
| | 221 | key = [NSString stringWithFormat:@"WCTableView %@ Sort Descending", [self autosaveName]]; |
|---|
| | 222 | [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:_sortDescending] forKey:key]; |
|---|
| | 223 | |
|---|
| | 224 | [self setIndicatorImage:_sortDescending ? _sortDownImage : _sortUpImage |
|---|
| | 225 | inTableColumn:tableColumn]; |
|---|
| | 226 | [super setHighlightedTableColumn:tableColumn]; |
|---|
| | 227 | } |
|---|
| | 228 | |
|---|
| | 229 | |
|---|
| | 230 | |
|---|
| | 231 | - (BOOL)sortDescending { |
|---|
| | 232 | return _sortDescending; |
|---|
| | 233 | } |
|---|
| | 234 | |
|---|
| | 235 | |
|---|
| 111 | | if([[self delegate] conformsToProtocol:@protocol(WCTableViewSelectOptions)]) { |
|---|
| 112 | | key = [NSString stringWithFormat:@"WCTableViewOptions %@ Columns", [self autosaveName]]; |
|---|
| 113 | | columns = [[NSUserDefaults standardUserDefaults] arrayForKey:key]; |
|---|
| 114 | | enumerator = [[self tableColumns] objectEnumerator]; |
|---|
| 115 | | |
|---|
| 116 | | while((tableColumn = [enumerator nextObject])) { |
|---|
| 117 | | if(![columns containsObject:[tableColumn identifier]]) |
|---|
| 118 | | [self removeTableColumn:tableColumn]; |
|---|
| 119 | | } |
|---|
| 120 | | |
|---|
| 121 | | [self sizeLastColumnToFit]; |
|---|
| | 243 | if(value) { |
|---|
| | 244 | if([[self delegate] conformsToProtocol:@protocol(WCTableViewSelectOptions)]) { |
|---|
| | 245 | key = [NSString stringWithFormat:@"WCTableViewOptions %@ Columns", [self autosaveName]]; |
|---|
| | 246 | columns = [[NSUserDefaults standardUserDefaults] arrayForKey:key]; |
|---|
| | 247 | enumerator = [[self tableColumns] objectEnumerator]; |
|---|
| | 248 | |
|---|
| | 249 | while((tableColumn = [enumerator nextObject])) { |
|---|
| | 250 | if(![columns containsObject:[tableColumn identifier]]) |
|---|
| | 251 | [self removeTableColumn:tableColumn]; |
|---|
| | 252 | } |
|---|
| | 253 | |
|---|
| | 254 | if([self autoresizesAllColumnsToFit]) |
|---|
| | 255 | [self sizeToFit]; |
|---|
| | 256 | else |
|---|
| | 257 | [self sizeLastColumnToFit]; |
|---|
| | 258 | } |
|---|
| | 259 | |
|---|
| | 260 | key = [NSString stringWithFormat:@"WCTableView %@ Selected Column", [self autosaveName]]; |
|---|
| | 261 | identifier = [[NSUserDefaults standardUserDefaults] stringForKey:key]; |
|---|
| | 262 | |
|---|
| | 263 | if(identifier) |
|---|
| | 264 | tableColumn = [self tableColumnWithIdentifier:identifier]; |
|---|
| | 265 | else |
|---|
| | 266 | tableColumn = [[self tableColumns] objectAtIndex:0]; |
|---|
| | 267 | |
|---|
| | 268 | key = [NSString stringWithFormat:@"WCTableView %@ Sort Descending", [self autosaveName]]; |
|---|
| | 269 | _sortDescending = [[NSUserDefaults standardUserDefaults] boolForKey:key]; |
|---|
| | 270 | |
|---|
| | 271 | if(tableColumn) { |
|---|
| | 272 | if([[self delegate] respondsToSelector:@selector(outlineView:shouldSelectTableColumn:)]) |
|---|
| | 273 | [[self delegate] outlineView:self shouldSelectTableColumn:tableColumn]; |
|---|
| | 274 | } |
|---|
| | 362 | |
|---|
| | 363 | |
|---|
| | 364 | #pragma mark - |
|---|
| | 365 | |
|---|
| | 366 | - (BOOL)clickedHeaderView { |
|---|
| | 367 | NSPoint point; |
|---|
| | 368 | |
|---|
| | 369 | point = [[self headerView] convertPoint:[[NSApp currentEvent] locationInWindow] |
|---|
| | 370 | fromView:NULL]; |
|---|
| | 371 | |
|---|
| | 372 | return ([[self headerView] hitTest:point] != NULL); |
|---|
| | 373 | } |
|---|
| | 374 | |
|---|
| | 375 | |
|---|
| | 376 | |
|---|
| | 377 | #pragma mark - |
|---|
| | 378 | |
|---|
| | 379 | - (void)setEscapeAction:(SEL)action { |
|---|
| | 380 | _escapeAction = action; |
|---|
| | 381 | } |
|---|
| | 382 | |
|---|
| | 383 | |
|---|
| | 384 | |
|---|
| | 385 | - (SEL)escapeAction { |
|---|
| | 386 | return _escapeAction; |
|---|
| | 387 | } |
|---|
| | 388 | |
|---|
| | 389 | |
|---|
| | 390 | |
|---|
| | 391 | #pragma mark - |
|---|
| | 392 | |
|---|
| | 393 | - (void)setDeleteAction:(SEL)action { |
|---|
| | 394 | _deleteAction = action; |
|---|
| | 395 | } |
|---|
| | 396 | |
|---|
| | 397 | |
|---|
| | 398 | |
|---|
| | 399 | - (SEL)deleteAction { |
|---|
| | 400 | return _deleteAction; |
|---|
| | 401 | } |
|---|
| | 402 | |
|---|
| | 403 | |
|---|
| | 404 | |
|---|
| | 405 | #pragma mark - |
|---|
| | 406 | |
|---|
| | 407 | - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)local { |
|---|
| | 408 | if(local) |
|---|
| | 409 | return NSDragOperationEvery; |
|---|
| | 410 | |
|---|
| | 411 | return NSDragOperationGeneric; |
|---|
| | 412 | } |
|---|
| | 413 | |
|---|
| | 414 | |
|---|
| | 415 | |
|---|
| | 416 | - (NSRect)frameOfCellAtColumn:(int)columnIndex row:(int)rowIndex { |
|---|
| | 417 | NSNumber *tag; |
|---|
| | 418 | NSString *key; |
|---|
| | 419 | NSRect frame; |
|---|
| | 420 | |
|---|
| | 421 | frame = [super frameOfCellAtColumn:columnIndex row:rowIndex]; |
|---|
| | 422 | key = [NSString stringWithFormat:@"%d,%d", columnIndex, rowIndex]; |
|---|
| | 423 | tag = [_regions objectForKey:key]; |
|---|
| | 424 | |
|---|
| | 425 | if(tag) |
|---|
| | 426 | [self removeToolTip:[tag intValue]]; |
|---|
| | 427 | |
|---|
| | 428 | tag = [NSNumber numberWithInt:[self addToolTipRect:frame owner:self userData:NULL]]; |
|---|
| | 429 | [_regions setObject:tag forKey:key]; |
|---|
| | 430 | |
|---|
| | 431 | return frame; |
|---|
| | 432 | } |
|---|
| | 433 | |
|---|
| | 434 | |
|---|
| | 435 | |
|---|
| | 436 | - (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag point:(NSPoint)point userData:(void *)data { |
|---|
| | 437 | int row; |
|---|
| | 438 | |
|---|
| | 439 | row = [self rowAtPoint:point]; |
|---|
| | 440 | |
|---|
| | 441 | if(row >= 0 && [[self dataSource] respondsToSelector:@selector(tableView:toolTipForRow:)]) |
|---|
| | 442 | return [[self dataSource] tableView:self toolTipForRow:row]; |
|---|
| | 443 | |
|---|
| | 444 | return NULL; |
|---|
| | 445 | } |
|---|
| | 446 | |
|---|