• 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: Sending a message to super's super (tab keyDown in NSTextView)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sending a message to super's super (tab keyDown in NSTextView)


  • Subject: Re: Sending a message to super's super (tab keyDown in NSTextView)
  • From: Jon Hess <email@hidden>
  • Date: Thu, 21 Aug 2008 02:07:46 -0700

Hey Jerry -

A couple of comments.

If you want to call super's super method, one way to do that is to put a category on you super class with a method name that is unique that invokes the selector you want on super. If that sounds evil, that's because it is :). Calling super super is usually a hint that some refactoring would be a better choice. In this case you don't have a choice though since NSTextView isn't your class. NSTextView has you covered though.

You may not know this, but when you edit an NSTextField, you're actually typing into an NSTextView. So NSTextView already has all of the logic to "act like a text field". I believe the property that controlls this is 'isFieldEditor'. I don't have access to the reference docs right now to double check though.

Yet another possibility would be to ovveride insertTab: and insertBackTab: instead of keyDown:, however, I think toggling isFieldEditor is your best bet.

From my phone -
Jon Hess

On Aug 21, 2008, at 1:22 AM, Jerry Krinock <email@hidden> wrote:

When the 'tab' or 'backTab' key is pressed, NSTextView accepts it as a character to be typewritten. But sometimes I want NSTextView to behave like an NSTextField, with 'tab' or 'backTab' selecting the next or previous key view. So, in my NSTextView subclass, I over- ride -keyDown: and re-implement the next/previous view selection.

It works, but, besides being redundant code, this re-implementation seems like an evil assumption of some other class' behavior by my subclass. What I really want to say is: "Behave like your 'grandfather' class, NSView". But there is no supersuper keyword.

Is there any way to improve this?.....

- (void)keyDown:(NSEvent*)event {
   NSString *s = [event charactersIgnoringModifiers] ;
   unichar keyChar = 0 ;
   if ([s length] == 1) {
       keyChar = [s characterAtIndex:0] ;

// Our superclass NSTextView accepts tabs and backtabs as text.
// If we want _tabToNextKeyView, we re-implement the NSView behavior
// of selecting the next or previous key view
if ((keyChar == NSTabCharacter)&& _tabToNextKeyView) {
[[self window] selectNextKeyView:self] ;
}
else if ((keyChar == NSBackTabCharacter) && _tabToNextKeyView) {
[[self window] selectPreviousKeyView:self] ;
}
else {
// Handle using super's (i.e. NSTextView) - interpretKeyEvents:,
// which will typewrite the key-downed character
NSArray* events = [NSArray arrayWithObject:event] ;
[self interpretKeyEvents:events] ;
}
}
}



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Sending a message to super's super (tab keyDown in NSTextView)
      • From: Jerry Krinock <email@hidden>
References: 
 >Sending a message to super's super (tab keyDown in NSTextView) (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: !foo vs foo == nil
  • Next by Date: Re: Parse form values from HTTP POST
  • Previous by thread: Sending a message to super's super (tab keyDown in NSTextView)
  • Next by thread: Re: Sending a message to super's super (tab keyDown in NSTextView)
  • Index(es):
    • Date
    • Thread