#import "drawundo.h"

@interface PasteGraphicsChange(PrivateMethods)

- undoDetails;
- redoDetails;

@end

@implementation PasteGraphicsChange

- initGraphicView:aGraphicView graphics:theGraphics
{
int i, count;

[super initGraphicView:aGraphicView];
graphics = [[List alloc] init];
count = [theGraphics count];
for (i = 0; i < count; i++) {
[graphics addObject:[theGraphics objectAt:i]];
}

return self;
}

- free
{
if (![self hasBeenDone])
[graphics freeObjects];
return [super free];
}

- (const char *)changeName
{
return PASTE_OPERATION;
}

- saveBeforeChange
{
return self;
}

- changeDetailClass
{
return nil;
}

- undoDetails
{
int count, i;
id graphic;
List *selectedGraphics;
List *allGraphics;

selectedGraphics = [graphicView selectedGraphics];
allGraphics = [graphicView graphics];
count = [graphics count];
for (i = 0; i < count; i++) {
graphic = [graphics objectAt:i];
[selectedGraphics removeObject:graphic];
[allGraphics removeObject:graphic];
[graphic wasRemovedFrom:graphicView];
}
[graphicView resetGroupInSlist];
return self;
}

- redoDetails
{
int count, i;
id graphic;
List *selectedGraphics;
List *allGraphics;

selectedGraphics = [graphicView selectedGraphics];
allGraphics = [graphicView graphics];
count = [graphics count];
i = count;
while (i--) {
graphic = [graphics objectAt:i];
[selectedGraphics insertObject:graphic at:0];
[allGraphics insertObject:graphic at:0];
[graphic wasAddedTo:graphicView];
if ([graphic isKindOf:[Group class]]) [graphicView setGroupInSlist:YES];
}

return self;
}

@end