NSOutlineView - edit one item without editing the next item
NSOutlineView - edit one item without editing the next item
- Subject: NSOutlineView - edit one item without editing the next item
- From: Mark Slater <email@hidden>
- Date: Mon, 15 Nov 2004 03:22:16 -0800
I have an NSOutlineView object that controls a large list of objects in another table. Switching from one item to another can be (relatively) time consuming. I'd like the user to be able to edit the name of the item in the outline view just as they would anyplace else... double click on it, edit in place, hit enter or tab when finished. The problem is that, with NSOutlineView (and NSTableView, I think) when the user is done editing one item, the view will automatically select and begin editing the next item. In my program, this would cause the larger list to be reloaded, and since the user generally only wanted to change the name of the list, will be damned annoying. I've tried creating a subclass of NSOutlineView to change this behavior, and it mostly works (the code is below). Please note, I'm pretty sure this code will only work for a one column outline view since I haven't found a way (didn't look hard yet) to determine which NSTableColumn contains the cell being edited.
I override
textShouldBeginEditing: and
textDidEndEditing:. In the former, I call the superclass method; if that method allows editing, I capture the NSText object that will be used. In the latter, I tell the data cell of the outline table column (the only column in this outline view) to stop editing the text, then I update the data source with the new text, and then try to force a redraw of the cell. That last step fails.
After the editing stops, the text editor goes away as it should, but the cell is displayed as a solid gray box. In the code below, you'll see my two attempts at forcing a redraw; neither works. My main question is: does anyone know how to force the cell to redisplay properly at this point?
At a higher level, I should probably also ask if there's a better way to prevent this auto-forwarding of the edit box that I've completely missed... or if there's a better way to set this up all together.
Thanks,
Mark
@interface SingleEditOutlineView : NSOutlineView
{
NSText *currentText;
}
@end
@implementation SingleEditOutlineView
- (BOOL) textShouldBeginEditing: (NSText *) textObject
{
BOOL shouldBegin = [ super textShouldBeginEditing: textObject ];
if( shouldBegin )
{
// Capture the text object that will be used to do the editing.
currentText = textObject;
}
}
- (void) textDidEndEditing: (NSNotification *) aNotification
{
int itemRow = [ self selectedRow ];
[ [ [ self outlineTableColumn ] dataCell ] endEditing: currentText ];
[ [ self dataSource ] outlineView: self
setObjectValue: [ currentText string ]
forTableColumn: nil
byItem: [ self itemAtRow: itemRow ] ];
// The following lines are trying to get the cell redrawn with the new text, but neither
// is able to accomplish that goal.
[ self drawRow: itemRow clipRect: [ self rectOfRow: itemRow ] ];
[ [ [ self outlineTableColumn ] dataCell ]
drawWithFrame: [ self rectOfRow: itemRow ] inView: self ];
}
@end
_______________________________________________
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