Je rencontre des problèmes avec l'opération d'annulation. Le code suivant n'annulera pas une opération removeObjectForKey:
mais l'opération de rétablissement setObject:ForKey:
fonctionne.NSUndoManager n'annulera pas l'édition d'un NSMutableDictionary
- (void) insertIntoDictionary:(NSBezierPath *)thePath
{
[[[window undoManager] prepareWithInvocationTarget:self] removeFromDictionary:thePath];
if(![[window undoManager] isUndoing])
[[window undoManager] setActionName:@"Save Path"];
NSLog(@"Object id is: %d and Key id is: %d", [currentPath objectAtIndex:0], thePath);
[colorsForPaths setObject:[currentPath objectAtIndex:0] forKey:thePath];
}
- (void) removeFromDictionary:(NSBezierPath *)thePath
{
[[[window undoManager] prepareWithInvocationTarget:self] insertIntoDictionary:thePath];
if(![[window undoManager] isUndoing])
[[window undoManager] setActionName:@"Delete Path"];
NSLog(@"Object id is: %d and Key id is: %d", [colorsForPaths objectForKey:thePath], thePath);
[colorsForPaths removeObjectForKey:thePath];
}
La sortie sur la console ressemble à:
// Before setObject:ForKey:
Object id is: 1183296 and Key id is: 1423872
// Before removeObjectForKey:
UNDO
Object id is: 0 and Key id is: 1423872
Je ne comprends pas pourquoi l'ID d'objet est différent, bien que l'ID de clé reste le même. Y a-t-il un traitement spécial annuler/rétablir des objets NSMutableDictionary
?
thx xonic
Ah sacrément, désolé à ce sujet ... avait un extrait de gauche de jouer avec le code. Je suis fatigué, je suppose :) J'ai maintenant corrigé le code, mais le résultat ne fonctionne toujours pas. Thx – xon1c