Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

CPTextField textDidChange: delegate functionality

#104

CPTextField doesn't currently support delegates or any of the delegate methods used by NSTextField. I've implemented delegate:, setDelegate: and added the appropriate bits of code in order to get CPTextField firing controlTextDidChange: events to its delegate.

Have implemented using CPNotificationCenter, and now provide textDidBeginEditing and textDidEndEditing delegate methods

Reported by Nick Takayama · October 12th, 2008 @ 03:40 PM

State: resolved
Milestone: none
Assigned to: Francisco Tolmasky Francisco Tolmasky

Activity

  1. Nick Takayama
    Nick Takayama

    updated to use CPNotificationCenter instead of a direct delegate call

    October 12th, 2008 @ 07:30 PM

  2. Nick Takayama
  3. Nick Takayama
    Nick Takayama
    • Assigned user set to Francisco Tolmasky

    new patch to fix style issues that boucher pointed out.

    boucher had some questions about the delegate methods in CPControl. For the most part I based my code on that found on cocotron, and there were a couple of aspects to the delegate methods (eg textDidChange:) that had no obvious purpose:

    //this looks to prevent false propagation of notifications for other objects
    if([note object] != self)
        return;
    
    

    this block, as in my comment, is possibly to prevent this method from being used to fire textDidChange for other objects... I have no idea why this would occur. I left it in just in case.

    [[CPNotificationCenter defaultCenter] postNotificationName:CPControlTextDidChangeNotification object:self userInfo:[CPDictionary dictionaryWithObject:[note object] forKey:@"CPFieldEditor"]];
    
    

    the question was 'why are we rebundling the notification?'. This is a fair question, and my best guess is that it is to ensure that all textDidChange, textDidBeginEditing and textDidEndEditing notifications are formatted properly without any additional information. This might be to allow some kind of lazy re-use of other notification objects.

    For example, a control subclass might have the following code: var note = [CPNotification notificationWithName:MyCustomNotificationName object:self userInfo:nil]; [self textDidBeginEditing:note]; //now I can trigger my own notification using the same object [[CPNotificationCenter defaultCenter] postNotification:note];

    Sorry for the long explanation. That's the best I can do to explain the code as it is. Quite happy to rewrite if necessary!

    October 14th, 2008 @ 03:09 PM

  4. Ross Boucher
  5. Ross Boucher
    Ross Boucher
    • State changed from new to resolved

    Resolved in f19793f8a3bb3a2de3751e9d4994c6e8e95f86b1.

    Thanks nick.

    October 19th, 2008 @ 09:58 PM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.