Re: NSUndoManager in non-NSDocument Cocoa Applications: unable to change 'Undo' menu item name.
Re: NSUndoManager in non-NSDocument Cocoa Applications: unable to change 'Undo' menu item name.
- Subject: Re: NSUndoManager in non-NSDocument Cocoa Applications: unable to change 'Undo' menu item name.
- From: "Frederick C. Lee" <email@hidden>
- Date: Thu, 17 Jun 2004 16:39:42 -0700
Greetings & Thanks for the speedy reply.
I've been studying codes and your critiques and am closer to
understanding this beast.
1) Controller level: I've correctly got the undoManager working for/in
the controller. All it does is reset the entire selection from a
pop-up list to default (hence I don't need the object (nil)). I had to
use a placebo parameter for the called reset method (resetData) to
avoid 'selector' errors at run time. So the user can simply reset the
pop-up list to default after selecting an item. {The redo is displayed
correctly, but doesn't do anything. I'll worry about that later.}
2) Model level: I tried to set up another undoManager 'entry' for
individual fields of the model. This test case is for currency of the
model 'countryModel'. I'm using the SAME undoManager as the
controller, having passed the undoManager instance value to the model's
Init method (initWithUndoModel). It seems logical to me, based on
others' code.
So within an Accessor method of the model (setCurrencyName), I tried to
setActionName of the received undoManager. *** IT FAILED ***.
What I got was a dimmed 'Undo Country Selection' from the controller.
--------
I'm thinking here...
Nick Zitzmann said:
"...if the object is the
first responder, then you'll see the changes in the Edit menu."
So I believe the cause of the problem is the 'scope' of the undoManager
being passed to the model.
Hmmm. How do I select the CORRECT firstResponder?
So I replaced:
// countryModel = [[CountryModel alloc] initWithUndoManager:[self
undoManager]];
with:
countryModel = [[CountryModel alloc]
initWithUndoManager:[currencyName_Field undoManager]]; //...received
field of new currency name.
...in the controller to see the effect: I got the default 'undo' back
in the menu. But still, I don't have any action from the
model-accessor's undoManger's setActionName.
Note: the model doesn't have any direct link to any GUI object (fields,
etc.), so is dependent on values passed through the initialization
process.
--------
Question #1: Do I need to RESET this same undoManager (associated with
the window), between controller's use & model's use? I notice that
after the model's accessors, the menu Undo/Redo's go gray.
Question #2: Is it normal routine to reset the undoManager after a
'session' to the default value? I'm left with the grayed "Undo Country
Selection".
Thanks for your time & input! I'm still studying sample codes. Thanks
Nick for your code!
Regards,
Ric.
=============================
Scenario...
Controller:
- (void) LookUp: (NSString *)inCountry {
[self setUndoManager:[[[countries_PopUp window] firstResponder]
undoManager]];
[[self undoManager] setActionName:@"Country Selection"]; // <--
This works.
[[self undoManager] registerUndoWithTarget:self
selector:@selector(resetData:) object:nil]; // <-- This works.
// Note: 'countryModel is an instance variable.
countryModel = [[CountryModel alloc] initWithUndoManager:[self
undoManager]]; // <-- passing undoManager to Model.
...
...
...
} // end LookUp().
Model:
// Called from CountryController:
- (id)initWithUndoManager:(NSUndoManager *)newUndoManager
{
self = [self init];
NSLog(@"{countryModel} initWithUndoManager.");
[self setUndoManager:newUndoManager];
return self;
}
...
...
- (void) setCurrencyName: (NSString *)theName {
if (currencyName) {
[theName retain];
NSLog(@"***** {CountryModel} setCurrencyName.*****");
[[self undoManager] setActionName:@"Currency Name"]; // <---
This does NOT work.
[[self undoManager] registerUndoWithTarget:self
selector:@selector(setCurrencyName:)
object:currencyName];
}
[currencyName release];
currencyName = theName;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.