Ignore:
Timestamp:
03/02/10 08:04:16 (15 years ago)
Author:
Nicholas Riley
Message:

Date autocomplete: replace a bunch of hacks with easier-to-read, less buggy code now we control the field editor.

Still need to move autocompletion into PSTimeDateEditor and fix one small autocomplete bug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/Pester/Source/PSAlarmSetController.m

    r622 r623  
    627627@end
    628628
    629 
    630629@implementation PSAlarmSetController (NSWindowNotifications)
    631630
     
    664663}
    665664
    666 static BOOL completingTimeDate = NO;
    667 static NSString *lastTimeDateString = nil;
    668 
    669 - (void)controlTextDidBeginEditing:(NSNotification *)notification;
    670 {
    671     NSControl *control = [notification object];
    672    
    673     if (control != timeOfDay)
    674         return;
    675    
    676     [lastTimeDateString release];
    677     lastTimeDateString = [[[[notification userInfo] objectForKey:@"NSFieldEditor"] string] copy];
    678 }
    679 
    680665- (void)controlTextDidChange:(NSNotification *)notification;
    681666{
    682667    // NSLog(@"UPDATING FROM controlTextDidChange: %@", [notification object]);
    683     if ([notification object] == timeDate) {
    684         if (!completingTimeDate) {
    685             NSText *fieldEditor = [[notification userInfo] objectForKey:@"NSFieldEditor"];
    686             NSString *editingString = [fieldEditor string];
    687             if ([editingString length] > [lastTimeDateString length])
    688                 completingTimeDate = YES;
    689             [lastTimeDateString release];
    690             lastTimeDateString = [editingString copy];
    691             if (completingTimeDate) {
    692                 [fieldEditor complete: nil];
    693                 completingTimeDate = NO;
    694             }
    695         }
    696     }
    697668    [self update: [notification object]];
    698 }
    699 
    700 - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector;
    701 {
    702     if (control != timeDate)
    703         return NO;
    704    
    705     if (commandSelector == @selector(moveDown:)) {
    706         completingTimeDate = YES;
    707         [textView complete: nil];
    708         completingTimeDate = NO;
    709         return YES;
    710     }
    711    
    712     return NO;
    713669}
    714670
Note: See TracChangeset for help on using the changeset viewer.