• 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: NSOutlineView: New item opened for editing/editing ends with "enter"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOutlineView: New item opened for editing/editing ends with "enter"


  • Subject: Re: NSOutlineView: New item opened for editing/editing ends with "enter"
  • From: Pete Yandell <email@hidden>
  • Date: Sun, 24 Aug 2003 11:27:18 +1000

On Sunday, August 24, 2003, at 03:38 AM, Kevin Smith wrote:

> I have an outline view that uses the ImageAndTextCell from the
> DragNDropOutlineView example. I want it to act like iTunes where
> adding a new item gives it a temporary name and the cell is already
> selected for editing.

Do something like this:

- (IBAction)addItem:(id)sender
{
// Close any open field editors
[[outlineView window] endEditingFor:nil];

// Put your code to add the new item to the data source in here...

// Update the display
[outlineView reloadData];
[outlineView selectItem:newItem byExtendingSelection:NO];
[outlineView editColumn:0 row:[outlineView rowForItem:newItem]
withEvent:nil select:YES];
}


> In addition, once the user hits the "enter" key, the editing should
> end and the same item should still be selected.

You need to subclass NSOutlineView with the following:

- (void)textDidEndEditing:(NSNotification*)notification
{
// This is a hack to make the return key end editing and leave the
selection
// on the current row rather than begin editing the next row. It
works by
// substituting a dodgy key code in place of the return key.

if ([[[notification userInfo] objectForKey:@"NSTextMovement"]
intValue] == NSReturnTextMovement) {
NSMutableDictionary *newUserInfo =
[NSMutableDictionary dictionaryWithDictionary:[notification
userInfo]];
[newUserInfo setObject:[NSNumber
numberWithInt:NSIllegalTextMovement] forKey:@"NSTextMovement"];

NSNotification *newNotification = [NSNotification
notificationWithName:[notification name]
object:[notification object]
userInfo:newUserInfo
];

[super textDidEndEditing:newNotification];

[[self window] makeFirstResponder:self];
}
else
[super textDidEndEditing:notification];
}

This is ripped out of the Omni frameworks which contain a similar hack.

Pete Yandell
http://pete.yandell.com/
_______________________________________________
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.

References: 
 >NSOutlineView: New item opened for editing/editing ends with "enter" (From: Kevin Smith <email@hidden>)

  • Prev by Date: Runtime dylib problem
  • Next by Date: How to convert a path into a 'const UInt8 *path'?
  • Previous by thread: NSOutlineView: New item opened for editing/editing ends with "enter"
  • Next by thread: WWDC DVDs
  • Index(es):
    • Date
    • Thread