• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: shouldChangeTextInRanges and undo
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: shouldChangeTextInRanges and undo


  • Subject: Re: shouldChangeTextInRanges and undo
  • From: Douglas Davidson <email@hidden>
  • Date: Thu, 10 Nov 2005 17:56:18 -0800


On Nov 10, 2005, at 5:39 PM, Ken Victor wrote:

to see this, i created an almost codeless cocoa doc based app. in the doc window nib, i replaced the NSTextField with an undoable NSTextView and gave it a custom class. the custom class consists of only one method as follows:

- (BOOL) shouldChangeTextInRanges: (NSArray*) affectedRanges replacementStrings: (NSArray*) replacementStrings {
static NSMutableCharacterSet* cSet = nil;
BOOL result = [super shouldChangeTextInRanges: affectedRanges replacementStrings: replacementStrings];



It's easier to do this in a delegate method, but if you are going to override shouldChange... then you have to do thing s in a different order. You should do your check first, and if you are going to prohibit the change, just return NO without calling the super method. If you are going to allow the change, return the return value of the super method. I've roughly rearranged your implementation below.


Douglas Davidson


- (BOOL) shouldChangeTextInRanges: (NSArray*) affectedRanges replacementStrings: (NSArray*) replacementStrings {
static NSMutableCharacterSet* cSet = nil;
if (!cSet) {
cSet = [NSMutableCharacterSet controlCharacterSet];
[cSet removeCharactersInString: @"\t"];
[cSet retain];
}
NSEnumerator* en = [replacementStrings objectEnumerator];
while (NSString* aRepStr = [en nextObject]) {
NSRange foundRange = [aRepStr rangeOfCharacterFromSet: cSet];
if (foundRange.location != NSNotFound) {
NSBeep();
return NO;
}
}


return [super shouldChangeTextInRanges: affectedRanges replacementStrings: replacementStrings];
}



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: shouldChangeTextInRanges and undo
      • From: Ken Victor <email@hidden>
References: 
 >shouldChangeTextInRanges and undo (From: Ken Victor <email@hidden>)

  • Prev by Date: Re: Speeding up creation of NSDictionary from XML? (iTunes related)
  • Next by Date: Re: shouldChangeTextInRanges and undo
  • Previous by thread: shouldChangeTextInRanges and undo
  • Next by thread: Re: shouldChangeTextInRanges and undo
  • Index(es):
    • Date
    • Thread