1 // Copyright (c) 2009 Yanagi Asakura
3 // This software is provided 'as-is', without any express or implied
4 // warranty. In no event will the authors be held liable for any damages
5 // arising from the use of this software.
7 // Permission is granted to anyone to use this software for any purpose,
8 // including commercial applications, and to alter it and redistribute it
9 // freely, subject to the following restrictions:
11 // 1. The origin of this software must not be misrepresented; you must not
12 // claim that you wrote the original software. If you use this software
13 // in a product, an acknowledgment in the product documentation would be
14 // appreciated but is not required.
16 // 2. Altered source versions must be plainly marked as such, and must not be
17 // misrepresented as being the original software.
19 // 3. This notice may not be removed or altered from any source
26 // Created by 柳 on 09/09/24.
27 // Copyright 2009 __MyCompanyName__. All rights reserved.
30 #import "ElisUndoManager.h"
33 @implementation ElisUndoManager
37 undoStack = [[NSMutableArray alloc] init];
41 - (void)pushOperation:(ElisLayer*)layer
43 NSMutableData* data = [[NSMutableData alloc] init];
44 NSKeyedArchiver* encoder = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
46 [layer saveToEncoder:encoder];
47 [encoder finishEncoding];
49 // [undoStack addObject:layer];
50 // [undoStack addObject:data];
51 [undoStack removeObjectsInRange:NSMakeRange(index, [undoStack count] - index)];
54 if([data isEqualToData:[undoStack objectAtIndex:index-1]])
57 [undoStack insertObject:layer atIndex:index];
58 [undoStack insertObject:data atIndex:index+1];
62 - (ElisLayer*)popOperation
64 NSData* data = [undoStack objectAtIndex:index-1];
65 ElisLayer* layer = [undoStack objectAtIndex:index-2];
67 NSKeyedUnarchiver* decoder = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
68 [layer loadFromDecoder:decoder];
69 [decoder finishDecoding];
85 return [undoStack count] != 0;
90 return index+2 < [undoStack count];