Re: Undo Names in NSPersistentDocument
Re: Undo Names in NSPersistentDocument
- Subject: Re: Undo Names in NSPersistentDocument
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Sat, 19 Dec 2009 12:34:35 +0700
On 19 Dec 2009, at 11:39, Graham Cox wrote:
>
> On 19/12/2009, at 12:08 PM, Gerriet M. Denkmann wrote:
>
>> How would I do this?
>> Subclass the NSArrayControllers and overrriding add: and remove: to call setActionName:?
>> Or is there a simpler way?
>
>
> My take on this is this: The action name is part of the View layer (because it appears in the menu) but the add/remove are themselves part of the data model. So the action name is best set also by the controller that triggers the add/remove events in the data model.
>
> The typical pattern I use is this:
>
> - (IBAction) someAction:(id) sender
> {
> [myDataModel doSomethingUndoable]; // calls through to data model's -add: method which registers -remove: with the undo manager
> [[self undoManager] setActionName:[sender title]];
> }
>
Following your suggestion I added in MyDocument.m:
- (IBAction)add: sender;
{
[ [ self undoManager ] setActionName: @"Add" ];
[ dictWordArrayController add: sender ];
}
and now got two Undo items:
1. Undo Add (which does nothing)
2. Undo (without name, which undoes the add:)
Same result for subclassing NSArrayController and overriding add:
The documentation says: "Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop"
Setting a breakpoint on registerUndoWithTarget:selector:object: tell me that this is triggered by some internal method in NSArrayController.
Now I don't have any more ideas how to set undo-names.
I had a little more success with my TableViews:
Setting the ActionName in the delegate method -controlTextDidEndEditing: works - somehow.
The problem: this method is called regardless whether some change did occur or not.
So if one double clicks a cell, then clicks somewhere else (or edits the content of the cell from "A" to "B" and back to "A" ) I get an empty "Undo Edit LastName".
Setting a flag in controlTextDidChange: is no real help, because it does not cover the A → B → A case.
Without interfering with setActionName: one never gets empty undos.
Maybe GCUndoManager could implement:
- (void)setActionNameToBeUsedAtTheNextNonEmptyNamelessUndo: (NSString *)actionName;
- or something like that with a slightly shorter name.
Kind regards,
Gerriet.
_______________________________________________
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