1 | // |
---|
2 | // KFTypeSelectTableView.h |
---|
3 | // KFTypeSelectTableView v1.0.4 |
---|
4 | // |
---|
5 | // Keyboard navigation enabled table view. Suitable for |
---|
6 | // class posing as well as normal use. |
---|
7 | // |
---|
8 | // All delegate methods are optional, except you need to implement typeSelectTableView:stringValueForTableColumn:row: |
---|
9 | // if you're using bindings to supply the table view with data. |
---|
10 | // |
---|
11 | // ------------------------------------------------------------------------ |
---|
12 | // Copyright (c) 2005, Ken Ferry All rights reserved. |
---|
13 | // |
---|
14 | // Redistribution and use in source and binary forms, with or without |
---|
15 | // modification, are permitted provided that the following conditions are |
---|
16 | // met: |
---|
17 | // |
---|
18 | // (1) Redistributions of source code must retain the above copyright notice, |
---|
19 | // this list of conditions and the following disclaimer. |
---|
20 | // |
---|
21 | // (2) Redistributions in binary form must reproduce the above copyright |
---|
22 | // notice, this list of conditions and the following disclaimer in the |
---|
23 | // documentation and/or other materials provided with the distribution. |
---|
24 | // |
---|
25 | // (3) Neither Ken Ferry's name nor the names of other contributors |
---|
26 | // may be used to endorse or promote products derived from this software |
---|
27 | // without specific prior written permission. |
---|
28 | // |
---|
29 | // |
---|
30 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
---|
31 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
---|
32 | // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
---|
33 | // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
---|
34 | // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
35 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
36 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
37 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
38 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
39 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
40 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
41 | // |
---|
42 | // ------------------------------------------------------------------------ |
---|
43 | // |
---|
44 | |
---|
45 | |
---|
46 | #pragma mark constants |
---|
47 | |
---|
48 | typedef enum KFTypeSelectMatchAlgorithm { |
---|
49 | KFSubstringMatchAlgorithm = 0, |
---|
50 | KFPrefixMatchAlgorithm = 1 |
---|
51 | } KFTypeSelectMatchAlgorithm; |
---|
52 | |
---|
53 | @interface KFTypeSelectTableView : NSTableView |
---|
54 | |
---|
55 | #pragma mark action methods |
---|
56 | |
---|
57 | // these beep if the operation cannot be performed |
---|
58 | - (void)findNext:(id)sender; |
---|
59 | - (void)findPrevious:(id)sender; |
---|
60 | |
---|
61 | #pragma mark accessors |
---|
62 | // KVO-compliant |
---|
63 | - (NSString *)pattern; |
---|
64 | |
---|
65 | // a tableview with no match algorithm set uses defaultMatchAlgorithm |
---|
66 | // defaultMatchAlgorithm defaults to KFPrefixMatchAlgorithm |
---|
67 | + (KFTypeSelectMatchAlgorithm)defaultMatchAlgorithm; |
---|
68 | + (void)setDefaultMatchAlgorithm:(KFTypeSelectMatchAlgorithm)algorithm; |
---|
69 | |
---|
70 | - (KFTypeSelectMatchAlgorithm)matchAlgorithm; |
---|
71 | - (void)setMatchAlgorithm:(KFTypeSelectMatchAlgorithm)algorithm; |
---|
72 | |
---|
73 | // defaults to NO |
---|
74 | - (BOOL)searchWraps; |
---|
75 | - (void)setSearchWraps:(BOOL)flag; |
---|
76 | |
---|
77 | // supply a set of identifiers to limit columns searched for match. |
---|
78 | // Only columns with identifiers in the provided set are searched. |
---|
79 | // nil identifiers means search all columns. defaults to nil. |
---|
80 | - (NSSet *)searchColumnIdentifiers; |
---|
81 | - (void)setSearchColumnIdentifiers:(NSSet *)identifiers; |
---|
82 | |
---|
83 | @end |
---|
84 | |
---|
85 | @interface NSObject (KFTypeSelectTableViewDelegate) |
---|
86 | |
---|
87 | #pragma mark configuration methods |
---|
88 | |
---|
89 | // Implement this method if the table uses bindings for data. |
---|
90 | // Use something like |
---|
91 | // return [[[arrayController arrangedObjects] objectAtIndex:row] valueForKey:[column identifier]]; |
---|
92 | // Could also use it to supply string representations for non-string data, or to search only part of visible text. |
---|
93 | - (NSString *)typeSelectTableView:(id)tableView stringValueForTableColumn:(NSTableColumn *)column row:(int)row; |
---|
94 | |
---|
95 | // defaults to YES |
---|
96 | - (BOOL)typeSelectTableViewSearchTopToBottom:(id)tableView; |
---|
97 | |
---|
98 | // defaults to first or last row, depending on direction of search |
---|
99 | - (int)typeSelectTableViewInitialSearchRow:(id)tableView; |
---|
100 | |
---|
101 | // A hook for cases (like mail plugin) where there's no good place to configure the table. |
---|
102 | // Will be called before type-select is used with any particular delegate. |
---|
103 | - (void)configureTypeSelectTableView:(id)tableView; |
---|
104 | |
---|
105 | #pragma mark reporting methods |
---|
106 | // pattern of @"" indicates no search, anything else means a search is in progress |
---|
107 | // userInfo dictionary has @"oldPattern" key |
---|
108 | // this notification is sent |
---|
109 | // when a search begins or is modified |
---|
110 | // when a search is cancelled |
---|
111 | // x seconds after a search either succeeds or fails, where x is a timeout period |
---|
112 | - (void)typeSelectTableViewPatternDidChange:(NSNotification *)aNotification; |
---|
113 | - (void)typeSelectTableView:(id)tableView didFindMatch:(NSString *)match range:(NSRange)matchedRange forPattern:(NSString *)pattern; |
---|
114 | - (void)typeSelectTableView:(id)tableView didFailToFindMatchForPattern:(NSString *)pattern; // fallback is a beep if delegate does not implement |
---|
115 | |
---|
116 | @end |
---|
117 | |
---|
118 | #pragma mark notifications |
---|
119 | // delegate automatically receives this notification. See delegate method above. |
---|
120 | extern NSString *KFTypeSelectTableViewPattenDidChangeNotification; |
---|