#104 ✓resolved
Nick Takayama

CPTextField textDidChange: delegate functionality

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

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

Comments and changes to this ticket

  • Nick Takayama

    Nick Takayama October 12th, 2008 @ 07:30 PM

    updated to use CPNotificationCenter instead of a direct delegate call

  • Nick Takayama
  • Nick Takayama

    Nick Takayama October 14th, 2008 @ 03:09 PM

    • 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)

    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!

  • Ross Boucher
  • Ross Boucher

    Ross Boucher October 19th, 2008 @ 09:58 PM

    • State changed from “new” to “resolved”

    Resolved in f19793f8a3bb3a2de3751e9d4994c6e8e95f86b1.

    Thanks nick.

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Cappuccino Web Framework, including AppKit, Foundation, and Objective-J.

Shared Ticket Bins