QueryFieldEditor
by Adam Hertz, Manager, Information Architecture Group

This example is a field editor that does escape completion against any IXBTree cursor.  It is used in Webster and Librarian.  You attach it to a TextField, and when the user types Esc, it completes the prefix using a IXBTree's key space as the set of possible completions.

It behaves like (and was inspired by) the escape completion in Edit: it cycles through all possible completions for a given prefix.  You attach it to a TextField by implementing the Window delegate's - windowWillReturnFieldEditor:toObject:hook.  You arm it with an IXBTree cursor, and away you go.

The following code snippet shows how the Window delegate manages the QueryFieldEditor:

#import <indexing/IXRecordManager.h>
#import <indexing/FileFinder.h>
#import <btree/IXBTreeCursor.h>

/* This method sets the proper IXBTree cursor for the field editor */

- setCursorForFieldEditor
{
    /* The idea here is to set the field editor to a cursor of any IXBTree
     * with strings as keys
     */
    [fieldEditor setCursor:cursor];
    return cursor;
}

/* You must implement this window delegate method to set the proper field editor for
 * the textfield named "fieldEditor"
 */
- windowWillReturnFieldEditor:sender toObject:client
{	
    if (client != queryField) return nil;
    if (fieldEditor == nil) {
	fieldEditor = [[QueryFieldEditor alloc] init];
	[self setCursorForFieldEditor];
    }
    return fieldEditor;
}