NSTextView in NSPersistentDocument does not update the dirty flag until it loses the first responder

I have an NSTextView in an NSPersistentDocument window. I associate the contents of the text box with the Master Data field of the Data Core, but when I enter the text in the text view, the title bar of the document does not say β€œEdited” until the text view loses focus. Thus, if I leave after editing, the new data will not be saved.

If you pass the NSContinuouslyUpdatesValueBindingOption flag to a text view anchor, β€œEdited” appears immediately, but the performance does suffer from long documents.

How do I tell Core Data about unsaved changes without actually assigning all the text data with each change?

(This question is similar to β€œ Binded NSTextField does not update an object until it loses focus ” except that I cannot use NSContinuouslyUpdatesValueBindingOption because it edits operations very slow.)

+4
source share
2 answers

I think this is impossible, as I understand it. When you assign changes to a property of an NSManagnedObject, CoreData can control the diry status (and undo) for you. If you just try to change diry without data, the potential save operation will not work.

Take a look at " Document Architecture Provides Free Cancellation Support " for how dirty state and cancellation support are implemented.

If you have really large text documents, I suggest not storing them in the CoreData property. As you can read in β€œ Incremental data reads and writes ” I suggest storing the text in a separate file and using NSFileWrapper. At least I use this solution for my application.

This is the way. what CoreData offers here is "... However, it is better if you can store BLOBs as resources in the file system and support (for example, URLs or paths) to these resources. Then you can download BLOBs and if necessary"

I do not know what text you have in NSTextView, but you accept "long documents".

+1
source

If you subclass your " NSTextView ", you can catch the " insertText: " method, and then, as soon as you type, set the "document Edited" flag of the document without the heavy use (and intensive processor) that you make.

0
source

All Articles