• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Undo Names in NSPersistentDocument
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Undo Names in NSPersistentDocument
      • From: Graham Cox <email@hidden>
    • Re: Undo Names in NSPersistentDocument
      • From: Jerry Krinock <email@hidden>
References: 
 >Undo Names in NSPersistentDocument (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Undo Names in NSPersistentDocument (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Outline View CancelEditing
  • Next by Date: NSAlert or what?
  • Previous by thread: Re: Undo Names in NSPersistentDocument
  • Next by thread: Re: Undo Names in NSPersistentDocument
  • Index(es):
    • Date
    • Thread