Re: Field editor undo vs document dirty
Re: Field editor undo vs document dirty
- Subject: Re: Field editor undo vs document dirty
- From: "Adam R. Maxwell" <email@hidden>
- Date: Tue, 07 Apr 2009 08:06:54 -0700
On Apr 6, 2009, at 11:52 PM, Quincey Morris wrote:
I can't work out if this simple and I'm just missing it, or if this
is hard ...
In a NSDocument-based application, I have some text fields in the
document window. Typing in one of these text fields (that is, typing
characters but not pressing Tab or Return to end editing) is of
course undoable by default (Undo Typing), but typing does not cause
the document to be marked dirty.
The first thing I don't understand is whether that's a bug. Although
the document isn't really changed (because the typing hasn't been
committed yet), but the presence of undoable typing perhaps ought to
prevent the document window from closing without first asking
whether to save the changes.
I think this happens as you expect if you use bindings and
NSObjectController; if not, you have to find a way to do it manually.
Using the document's undo manager for the field editor would
potentially give you multiple undo steps for a single edit action,
which isn't what you want in general.
The second thing I don't understand is how to make that happen.
Committing the change in windowWillClose: doesn't help because by
the time that's called the decision whether to save has already been
taken. Perhaps its as simple as overriding the close:, saveDocument:
and saveDocumentAs: actions to first commit pending edits in
suitable text fields, but it's not clear how easy it is to detect
and cover all the necessary cases.
Can anyone explain the simple answer to me, or suggest a strategy if
the answer isn't so simple?
Have your controller object implement the NSEditor protocol. Send the
document objectDidBeginEditing:/objectDidEndEditing: at the
appropriate times (maybe using text delegate notifications), and it
will send you commitEditing/discardEditing et al. as needed.
NSDocument says it handles this in the header, even though it doesn't
explicitly conform to NSEditorRegistration, so I believe this will
keep working.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden