1 | //
|
---|
2 | // NJRTableView.m
|
---|
3 | // Pester
|
---|
4 | //
|
---|
5 | // Created by Nicholas Riley on Sun Nov 17 2002.
|
---|
6 | // Copyright (c) 2002 Nicholas Riley. All rights reserved.
|
---|
7 | //
|
---|
8 |
|
---|
9 | #import "NJRTableView.h"
|
---|
10 | #import "NSTableView-NJRExtensions.h"
|
---|
11 | #import "NSCharacterSet-NJRExtensions.h"
|
---|
12 |
|
---|
13 | @interface NJRTableView (Private)
|
---|
14 | - (void)_resetTypeSelect;
|
---|
15 | @end
|
---|
16 |
|
---|
17 | @implementation NJRTableView
|
---|
18 |
|
---|
19 | #pragma mark type selection
|
---|
20 |
|
---|
21 | - (id)typeSelectDisplay;
|
---|
22 | {
|
---|
23 | return typeSelectDisplay;
|
---|
24 | }
|
---|
25 |
|
---|
26 | - (void)moveToEndOfDocument:(id)sender {
|
---|
27 | [self scrollRowToVisible: [self numberOfRows] - 1];
|
---|
28 | }
|
---|
29 |
|
---|
30 | - (void)moveToBeginningOfDocument:(id)sender {
|
---|
31 | [self scrollRowToVisible: 0];
|
---|
32 | }
|
---|
33 |
|
---|
34 | - (void)keyDown:(NSEvent *)theEvent;
|
---|
35 | {
|
---|
36 | NSString *characters;
|
---|
37 | unichar firstCharacter;
|
---|
38 | characters = [theEvent characters];
|
---|
39 | firstCharacter = [characters characterAtIndex: 0];
|
---|
40 | switch (firstCharacter) {
|
---|
41 | case 0177: // delete key
|
---|
42 | case NSDeleteFunctionKey:
|
---|
43 | case NSDeleteCharFunctionKey:
|
---|
44 | if ([self selectedRow] >= 0 && [[self dataSource] respondsToSelector: @selector(removeSelectedRowsFromTableView:)]) {
|
---|
45 | [[self dataSource] removeSelectedRowsFromTableView: self];
|
---|
46 | }
|
---|
47 | return;
|
---|
48 | case NSHomeFunctionKey:
|
---|
49 | [self moveToBeginningOfDocument: nil];
|
---|
50 | return;
|
---|
51 | case NSEndFunctionKey:
|
---|
52 | [self moveToEndOfDocument: nil];
|
---|
53 | return;
|
---|
54 | }
|
---|
55 | if ([[NSCharacterSet typeSelectSet] characterIsMember: firstCharacter]) {
|
---|
56 | // invoking -[NSResponder interpretKeyEvents:] will cause insertText: to be invoked, and allows function keys to still work.
|
---|
57 | [self interpretKeyEvents: [NSArray arrayWithObject: theEvent]];
|
---|
58 | } else {
|
---|
59 | [super keyDown: theEvent];
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | - (void)insertText:(id)inString;
|
---|
64 | {
|
---|
65 | // For consistency with List Manager as documented, reset the typeahead buffer after twice the delay until key repeat (in ticks).
|
---|
66 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
---|
67 | int keyRepeatTicks = [defaults integerForKey: @"InitialKeyRepeat"];
|
---|
68 | NSTimeInterval resetDelay;
|
---|
69 |
|
---|
70 | if (keyRepeatTicks == 0) keyRepeatTicks = 35; // default may be missing; if so, set default
|
---|
71 |
|
---|
72 | resetDelay = MIN(2.0 / 60.0 * keyRepeatTicks, 2.0);
|
---|
73 |
|
---|
74 | if (typed == nil) typed = [[NSMutableString alloc] init];
|
---|
75 | [typed appendString: inString];
|
---|
76 |
|
---|
77 | // Cancel any previously queued future invocations of _resetTypeSelect
|
---|
78 | [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(_resetTypeSelect) object: nil];
|
---|
79 |
|
---|
80 | // queue an invocation of clearAccumulatingTypeahead for the near future.
|
---|
81 | [self performSelector: @selector(_resetTypeSelect) withObject: nil afterDelay: resetDelay];
|
---|
82 |
|
---|
83 | // Use stringWithString to make an autoreleased copy, since we may clear out the original string below before it can be used.
|
---|
84 | [[self delegate] tableView: self selectRowMatchingString: [NSString stringWithString: typed]];
|
---|
85 |
|
---|
86 | // Show the current typeahead string in the optional display field, like CodeWarrior does (well, not really, CW is much more elegant because it doesn't select anything until you stop typing)
|
---|
87 | [typeSelectDisplay setObjectValue: typed];
|
---|
88 | }
|
---|
89 |
|
---|
90 | - (void)_resetTypeSelect;
|
---|
91 | {
|
---|
92 | [typed setString: @""];
|
---|
93 | [typeSelectDisplay setObjectValue: nil];
|
---|
94 | }
|
---|
95 |
|
---|
96 | - (void)resetTypeSelect;
|
---|
97 | {
|
---|
98 | [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(_resetTypeSelect) object: nil];
|
---|
99 | [self _resetTypeSelect];
|
---|
100 | }
|
---|
101 |
|
---|
102 | @end
|
---|