• 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: NSTableView return key and editing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView return key and editing


  • Subject: Re: NSTableView return key and editing
  • From: Just van Rossum <email@hidden>
  • Date: Fri, 23 May 2003 12:28:59 +0200

[following up to myself once more, for the last time I promise]

> > Inelegant, yes, but the solution just posted by Christopher Corbell

(Jeez, dunno what's wrong with me today, it was posted by Pete Yandell.
Rhymes with Corbell, though...)

> > seems even less elegant.
>
> Sorry, I meant code-wise; it's quite likely that his solution is more
> elegant UI-wise.

I played a bit more with both options, and subclassing NSTableView
really is the way to go. Works like a champ, perfect user experience.
It also gives me the chance the intercept the return key to start editing.

For fun, this is what my subclass looks like in Python:


class MyTableView(NSTableView):

def keyDown_(self, event):
if (event.characters() in "\r\x03" and
self.numberOfSelectedRows() == 1):
# return or enter typed, start editing
self.editColumn_row_withEvent_select_(0, self.selectedRow(),
event, True)
else:
super(MyTableView, self).keyDown_(event)

def textDidEndEditing_(self, notification):
info = notification.userInfo()
if info["NSTextMovement"] == NSReturnTextMovement:
# This is ugly, but just about the only way to do it.
# NSTableView is determined to select and edit something else,
# even the text field that it just finished editing, unless we
# mislead it about what key was pressed to end editing.
info = dict(info) # make a copy
info["NSTextMovement"] = NSIllegalTextMovement
newNotification = NSNotification.notificationWithName_object_userInfo_(
notification.name(),
notification.object(),
info)
super(MyTableView, self).textDidEndEditing_(newNotification)
self.window().makeFirstResponder_(self)
else:
super(MyTableView, self).textDidEndEditing_(notification)


Thanks Pete!

Just
_______________________________________________
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.

  • Prev by Date: Re: Transparent NSTextView makes hole in window ?
  • Next by Date: Re: Cocoa newbie question
  • Previous by thread: Re: NSTableView return key and editing
  • Next by thread: CustomizeToolbar and First Responder
  • Index(es):
    • Date
    • Thread