I don’t know if this is the best way, but you can end editing by toggling the enabled property of the table. I’m using a data source so this might not work for you.
Unfortunately, that method yields the NSInternalScriptError in my case.
When are you toggling it?
About the returns. They work when I use a data source, but the edit moves to the next row.
That’s right. The standard way to exit the editing mode seems to be to have the user click on a different row. If I could put up with that, then my method of calling editColumn: to begin editing would be fine. I could just name the menu item “go into editing mode” instead of “rename item”, I suppose. But that seems too much like an early-80’s word processor (“Oh, you have to go into editing mode to edit your document. In data entry mode, you can only append.” Those were the days.)
I guess it’s not that bad to have a dialog box pop up when you want to change an entry in the table column. It’s just a shame that something so conceptually simple and natural is something one must jump through hoops for, and even then the result isn’t what users have been led to expect based on Apple’s own software.
About the single click edit you can detect single ‘click’ or ‘double click’ with these handlers, but you would need to know if the user clicked on the selected row. You can do this by using one of the selection changed handlers. I used the ‘should select row’ handler. Then if the user selects a different row, I set a global flag like row_changed and set it to true. Then in the ‘click’ handler, you look at the flag. If it’s true do nothing and false somehow set the selected row to edit. Then reset the flag to false.
That’s exactly what I was thinking of doing. But first I needed to make sure I could go into and out of editing mode smoothly and at will. It seems to have turned out that I can’t. The field editor seems to latch on to first responder status and refuse to give it up, even using Apple’s ‘guaranteed’ methods for making it do so. The only way to make it give up first responder status seems to be to click on a different cell in the table. Every other method seems to result in an error.
I haven’t done the changing to edit part yet.
That’s where I used the call to the editColumn: method. It works great. You go right into editing mode on the selected cell. But then you’re in editing mode on that cell until the user clicks out of the cell. Hitting enter does cause the “on change cell value” handler to be called, but then it just goes right back into editing mode. What I need is some way to take it out of editing mode, preferably one that works during the “on change cell value” handler. But everything I’ve tried there has either had no effect at all, such as setting the main window’s first responder to itself (as Apple recomended as a first try), or raised an error, such as explicitly calling endEditingFor: (as Apple recommends as a final, guaranteed-to-work solution).
I think I’d rather have the user hit a button or something to play the song.
That’s always an option, and it’s how I started out when I was using a browser object. But double-clicking just felt more right, so I switched to the table object. I don’t recall how browser objects handle editing, though.
It seems to me that the iTunes browser uses a browser type view on the double click and play song. While the one click on selection and edit part is for changing names in the playlist section. I don’t see where in iTunes both options are used at the same time.
Hmm. Maybe we’re talking about two different things. In my iTunes, if I single-click in the “Name” column of the list of songs in the current play list, the first time I single-click there the selection changes to that song. The second time I single-click there, if I click on the text of the song name, then it goes into editing mode. If I single-click where the text of the song name is not, then nothing happens. If I double-click anywhere in that cell, the song plays.
Doing that with anything that uses Cocoa seems very difficult. I started out using a browser object, but there’s no double-action for the browser. I switched to table views, and I see no way to make it go into editing mode only if I single-click on the /text/ in a previously selected row.
Am I missing something?
-Joe