views:

71

answers:

1

Hi everybody, I have an NSTableView that allows inline editing on one of its cells (NSTextFieldCell). This actually works well, but the point is: I want to manipulate the content for the editing session. Imagine having a string with a path (say: "folder/subfolder/myfile.txt") as the content of such a cell. But when the user enters edit mode for this cell (e.g. by double clicking) I want only the string "myfile.txt" to be editable (i.e. to appear in the editor).

Does anyone have a hint for me?

Thanks for reading. Regards, Tobi

+1  A: 

You could create a custom NSFormatter that does this. Override the method stringForObjectValue: to return the full string and editingStringForObjectValue: to return only the part you want to edit. You also need to write a method getObjectValue:forString:errorDescription: to transform the edited string back to the complete string. How to exactly do this depends on the rest of your program. You somehow need to get back the part of the string you removed for editing.

Sven
Thanks for your answer, Sven! I've already tried using an NSFormatter, but with no luck so far. The problem was that when you hook up the NSFormatter to the NSCell, it doesn't influence the editing textField. So the string gets displayed (formatted) nicely when viewed "normally", but as soon as you enter edit mode, the responsible NSTextView / FieldEditor doesn't care about the formatter (for which I haven't found a way to attach to the FieldEditor)...
Tobidobi
Then you must have done something wrong in your formatter. If you attach it to the `NSTextCell` of the table view it gets used for displaying and editing, there is no need to attach it to the field editor. Also it cannot be attached to the field editor because only `NSCells` have formatters.
Sven