1 | /*-------------------------------------------------------------------------------------------------------*\ |
---|
2 | | Adium, Copyright (C) 2001-2005, Adam Iser (adamiser@mac.com | http://www.adiumx.com) | |
---|
3 | \---------------------------------------------------------------------------------------------------------/ |
---|
4 | | This program is free software; you can redistribute it and/or modify it under the terms of the GNU |
---|
5 | | General Public License as published by the Free Software Foundation; either version 2 of the License, |
---|
6 | | or (at your option) any later version. |
---|
7 | | |
---|
8 | | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
---|
9 | | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
10 | | Public License for more details. |
---|
11 | | |
---|
12 | | You should have received a copy of the GNU General Public License along with this program; if not, |
---|
13 | | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
14 | \------------------------------------------------------------------------------------------------------ */ |
---|
15 | |
---|
16 | /*! |
---|
17 | * @class AICompletingTextField |
---|
18 | * @brief A text field that auto-completes known strings |
---|
19 | * |
---|
20 | * A text field that auto-completes known strings. It supports a minimum string length before autocompletion as well as optionally completing any number of comma-separated strings. |
---|
21 | */ |
---|
22 | |
---|
23 | #import <AIUtilities/AITextFieldWithDraggingDelegate.h> |
---|
24 | |
---|
25 | @interface AICompletingTextField : AITextFieldWithDraggingDelegate { |
---|
26 | NSMutableSet *stringSet; |
---|
27 | NSMutableDictionary *impliedCompletionDictionary; |
---|
28 | |
---|
29 | int minLength; |
---|
30 | BOOL completeAfterSeparator; |
---|
31 | int oldUserLength; |
---|
32 | } |
---|
33 | |
---|
34 | /*! |
---|
35 | * @brief Set the minimum string length before autocompletion |
---|
36 | * |
---|
37 | * Set the minimum string length before autocompletion. The text field will not begin to autocomplete until the user has typed at least the specified number of characters. Defaults to 1. |
---|
38 | * @param length The new minimum length before autocompletion |
---|
39 | */ |
---|
40 | - (void)setMinStringLength:(int)length; |
---|
41 | |
---|
42 | /*! |
---|
43 | * @brief Set if the field should expect a comma-delimited series |
---|
44 | * |
---|
45 | * By default, the entire field will be a single autocompleting area; input text is checked in its entirety against specified possible completions. If <b>split</b> is YES, however, the completions will be split at each comma, allowing a series of distinct comma-delimited autocompletions. |
---|
46 | * @param split YES if the list should be treated as a comma-delimited series of autocompletions; NO if the entire field is a single autocompleting area |
---|
47 | */ |
---|
48 | - (void)setCompletesOnlyAfterSeparator:(BOOL)split; |
---|
49 | |
---|
50 | /*! |
---|
51 | * @brief Set all completions for the field. |
---|
52 | * |
---|
53 | * Set all possible completions for the field, overriding all previous completion settings. All completions are treated as literal completions. This does not just call addCompletionString: repeatedly; it is more efficient to use if you already have an array of completions. |
---|
54 | * @param strings An <tt>NSArray</tt> of all completion strings |
---|
55 | */ |
---|
56 | - (void)setCompletingStrings:(NSArray *)strings; |
---|
57 | |
---|
58 | /*! |
---|
59 | * @brief Add a completion for the field. |
---|
60 | * |
---|
61 | * Add a literal completion for the field. |
---|
62 | * @param string The completion to add. |
---|
63 | */ |
---|
64 | - (void)addCompletionString:(NSString *)string; |
---|
65 | |
---|
66 | /*! |
---|
67 | * @brief Add a completion for the field which displays and returns differently. |
---|
68 | * |
---|
69 | * Add a completion for the field. <b>string</b> is the string which will complete for the user (so its beginning is what the user must type, and it is what the user will see in the field). <b>impliedCompletion</b> is what will be returned by <tt>impliedStringValue</tt> when <b>completion</b> is in the text field. |
---|
70 | * @param string The visual completion to add. |
---|
71 | * @param impliedCompletion The actual completion for <b>string</b>, which will be returned by impliedValue and -- if it is an NSString -- by impliedStringValue when string is in the text field. |
---|
72 | */ |
---|
73 | - (void)addCompletionString:(NSString *)string withImpliedCompletion:(id)impliedCompletion; |
---|
74 | |
---|
75 | /*! |
---|
76 | * @brief Return the completed string value of the field |
---|
77 | * |
---|
78 | * Return the string value of the field, taking into account implied completions (see <tt>addCompletionString:withImpliedCompletion:</tt> for information on implied completions). |
---|
79 | * @result An <tt>NSString</tt> of the appropriate string value |
---|
80 | */ |
---|
81 | - (NSString *)impliedStringValue; |
---|
82 | |
---|
83 | /*! |
---|
84 | * @brief Return the implied string value the field has set for a passed string |
---|
85 | * |
---|
86 | * Returns the implied string value which the field has as the implied completion for <b>aString</b>. Useful while parsing multiple strings from the field when making using of multiple, comma-delimited items. |
---|
87 | * @param aString The <tt>NSString</tt> to check for an implied completion |
---|
88 | * @result An <tt>NSString</tt> of the implied string value, or <b>aString</b> if no implied string value is assigned |
---|
89 | */ |
---|
90 | - (NSString *)impliedStringValueForString:(NSString *)aString; |
---|
91 | |
---|
92 | /* |
---|
93 | * @brief Return the implied value of the field |
---|
94 | * |
---|
95 | * This may be the impliedStringValue or some non-NSString which was set as an implied completion |
---|
96 | */ |
---|
97 | - (id)impliedValue; |
---|
98 | @end |
---|