Re: Detecting A Changed Cell When Editing Ends
Re: Detecting A Changed Cell When Editing Ends
- Subject: Re: Detecting A Changed Cell When Editing Ends
- From: James DiPalma <email@hidden>
- Date: Mon, 23 Dec 2002 01:28:16 -0500
From: Jonathan Jackel <email@hidden>
I want to know when a text field cell ends editing AND has been
changed.
Just another option. I used to fix this problem by posing as
NSTextField, but now I just subclass and set each text field's class in
IB to a QuietTextField.
From: Mike Ferris <email@hidden>
You always get the DidEndEditing whether any changes happened or not.
Which can be prevented:
@interface JimQuietTextField : NSTextField
{
BOOL didBeginEditing;
}
- (void) textDidBeginEditing:(NSNotification*)note;
- (void) textDidEndEditing:(NSNotification*)note;
@end
-----
@implementation QuietTextField
- (id) initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (nil != self) {
didBeginEditing = NO;
}
return self;
}
- (void) textDidBeginEditing:(NSNotification*)note
{
didBeginEditing = YES;
[super textDidBeginEditing:note];
}
- (void) textDidEndEditing:(NSNotification*)note;
{
BOOL sendsActionOnEndEditing;
// get the current state of sendsActionOnEndEditing
sendsActionOnEndEditing = [[self cell] sendsActionOnEndEditing];
// prevent action methods from being sent if text did not begin
editing
if (!didBeginEditing) {
[[self cell] setSendsActionOnEndEditing:NO];
}
// call super
[super textDidEndEditing:note];
// reset the sendActionOnEndEditing flag in our cell
if (!didBeginEditing) {
[[self cell]
setSendsActionOnEndEditing:sendsActionOnEndEditing];
}
// after the end of editing, begin editing is set to NO
didBeginEditing = NO;
}
@end
You can either compare the value at that time with the original value
to see if it changed, or you can also catch DidChange and make a note
of it.
If a field is actually edited by a user, I want an action to be sent
even if this new field's text is equal to its old text (which might not
mean that its object value is equal -- unlikely). A TextField's target
can then chose to do nothing if this user change would not do anything.
I would prefer that AppKit did not send didEndEditing when no user
action didBeginEditing; it just makes sense to me. However, Apple
decided about 5 years ago that some then existing developers might get
bitten by a fix to this behavior.
-jim
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.