Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSTextView autocompletion delegate method not called from popup window

I programmatically call complete: to call NSTextView autocompletion delegate method:

- (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index

I have 2 tables, one is in the main sheet, and the other one in the popup window. The popup window is modally opened from the sheet.

Both tables have the column with the same subclass of NSTextView. Both tables have as delegate the same file owner, however the delegate method is called only for the table in the main sheet.

The strange thing is that all other delegate methods are correctly called from the table in the popup window:

- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
- (BOOL)control:(NSControl *)control isValidObject:(id)object
- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex

UPDATE:

About the NSTableView structure:

The tables are cell-based NSTableView. The column is made by NSTextFieldCell that I've subclassed. The code below is from the subclassed NSTextFieldCell.

The method returns another subclass, named CBAutocompleteTextField, this time inheriting from NSTextView, which is the text editor inside the cell.

- (NSTextView *)fieldEditorForView:(NSView *)aControlView
{
    return [[[CBAutocompleteTextField alloc] init] autorelease];
} 

So in the end, the class invoking complete: is a subclass of NSTextView.

like image 892
aneuryzm Avatar asked Nov 10 '22 21:11

aneuryzm


1 Answers

Try this if it helps, for perform auto completion you will need to call complete: in the text fields field editor by using below delegate method:-

- (void)controlTextDidChange:(NSNotification *)notification {
    if( autoComplete ){
        return;
    } else {
        autoComplete = YES;
        [[[notification userInfo] objectForKey:@"NSFieldEditor"] complete:nil];
    }
}
like image 195
Hussain Shabbir Avatar answered Nov 15 '22 06:11

Hussain Shabbir