FROM : Neil Clayton
DATE : Sat Jun 24 13:51:48 2006
Hi,
I'd like to be able to nicely undo a cut operation, for a managed
coredata object.
My initial idea was something like this (where Preset is the managed
object):
- (void) addPresetBack:(Preset*)preset {
[presetsController insert:preset];
}
- (IBAction) cut:(id)sender {
Preset *preset = [presetsController selectedObject];
[self copy:self]; // store some interesting data in pasteboard
NSUndoManager *undo = [self undoManager];
[[undo prepareWithInvocationTarget:self] addPresetBack:preset];
if(![undo isUndoing]) {
[undo setActionName:NSLocalizedString(@"Cut", @"Cut")];
}
[presetsController removeObject:preset];
}
But I'm finding (probably quite sensible) that the preset is dead/
empty once I get back to addPresetBack. This makes sense, since
removing it from the NSArrayController probably causes the object to
be deleted from the current DB. Thus, when Undo is called, I end up
inserting a blank object.
What's the recommended way to handle cut/undo style operations with
CoreData?
---
Neil Clayton
DATE : Sat Jun 24 13:51:48 2006
Hi,
I'd like to be able to nicely undo a cut operation, for a managed
coredata object.
My initial idea was something like this (where Preset is the managed
object):
- (void) addPresetBack:(Preset*)preset {
[presetsController insert:preset];
}
- (IBAction) cut:(id)sender {
Preset *preset = [presetsController selectedObject];
[self copy:self]; // store some interesting data in pasteboard
NSUndoManager *undo = [self undoManager];
[[undo prepareWithInvocationTarget:self] addPresetBack:preset];
if(![undo isUndoing]) {
[undo setActionName:NSLocalizedString(@"Cut", @"Cut")];
}
[presetsController removeObject:preset];
}
But I'm finding (probably quite sensible) that the preset is dead/
empty once I get back to addPresetBack. This makes sense, since
removing it from the NSArrayController probably causes the object to
be deleted from the current DB. Thus, when Undo is called, I end up
inserting a blank object.
What's the recommended way to handle cut/undo style operations with
CoreData?
---
Neil Clayton
| Related mails | Author | Date |
|---|---|---|
| Neil Clayton | Jun 24, 13:51 | |
| Jim Correia | Jun 26, 17:42 |






Cocoa mail archive

