|
|
1.1 root 1: #import "drawundo.h"
2:
3: /*
4: * Please refer to external documentation about Draw
5: * with Undo for information about what SimpleGraphicsChange
6: * is and where it fits in.
7: */
8:
9: @interface SimpleGraphicsChange(PrivateMethods)
10:
11: - undoDetails;
12: - redoDetails;
13: - (BOOL)subsumeIdenticalChange:change;
14:
15: @end
16:
17: @implementation SimpleGraphicsChange
18:
19: - saveBeforeChange
20: {
21: [super saveBeforeChange];
22: [changeDetails makeObjectsPerform:@selector(recordDetail)];
23:
24: return self;
25: }
26:
27: - (BOOL)subsumeChange:change
28: /*
29: * ChangeManager will call subsumeChange: when we are the last
30: * completed change and a new change has just begun. We override
31: * the subsumeChange: to offer our subclasses a chance to
32: * consolidate multiple changes into a single change.
33: * First we check to make sure that the new change is of the
34: * same class as the last. If it is then we check to make sure
35: * that it's operating on the same selection. If not we simply
36: * return NO, declining to subsume it. If it does operate on
37: * the same change then we offer our subclass a change to
38: * subsume it by sending [self subsumeIdenticalChange:change].
39: *
40: * For example, if the user presses the up arrow key to move
41: * a graphic up one pixel, that immediately becomes a complete,
42: * undoable change, as it should. If she continues to press
43: * use the arrow keys we don't want to end up making hundreds
44: * of independent move changes that would each have to be
45: * undone seperately. So instead we have the first move
46: * subsume all subsequent MoveGraphicsChanges that operate
47: * on the same selection.
48: */
49: {
50: BOOL identicalChanges = NO;
51: List *selectedGraphics;
52: int count, i;
53:
54: if ([change isKindOf:[self class]]) {
55: if (!graphicsToChange) {
56: identicalChanges = YES;
57: selectedGraphics = [graphicView selectedGraphics];
58: count = [selectedGraphics count];
59: for (i = 0; (i < count) && (identicalChanges); i++) {
60: if ([graphics objectAt:i] != [selectedGraphics objectAt:i])
61: identicalChanges = NO;
62: }
63: }
64: }
65: if (identicalChanges)
66: return [self subsumeIdenticalChange:change];
67: else
68: return NO;
69: }
70:
71: - undoDetails
72: {
73: [changeDetails makeObjectsPerform:@selector(undoDetail)];
74: return self;
75: }
76:
77: - redoDetails
78: {
79: [changeDetails makeObjectsPerform:@selector(redoDetail)];
80: return self;
81: }
82:
83: - (BOOL)subsumeIdenticalChange:change
84: {
85: return NO;
86: }
87:
88: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.