home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Examples / AppKit / Draw / graphicsUndo.subproj / UngroupGraphicsChange.m < prev    next >
Text File  |  1995-11-28  |  3KB  |  139 lines

  1. #import "drawundo.h"
  2.  
  3. @interface UngroupGraphicsChange(PrivateMethods)
  4.  
  5. @end
  6.  
  7. @implementation UngroupGraphicsChange
  8.  
  9. - initGraphicView:aGraphicView
  10. {
  11.     [super init];
  12.     graphicView = aGraphicView;
  13.     changeDetails = nil;
  14.     groups = nil;
  15.  
  16.     return self;
  17. }
  18.  
  19. - (void)dealloc
  20. {
  21.     int i, count;
  22.     id group;
  23.  
  24.     if ([self hasBeenDone]) {
  25.     count = [groups count];
  26.     for (i = 0; i < count; i++) {
  27.         group = [groups objectAtIndex:i];
  28.         [[group subGraphics] removeAllObjects];
  29.         [group release];
  30.     }
  31.     }
  32.     [groups release];
  33.     if (changeDetails != nil) {
  34.     [changeDetails removeAllObjects];
  35.     [changeDetails release];
  36.     }
  37.     [super dealloc];
  38. }
  39.  
  40. - (NSString *)changeName
  41. {
  42.     return UNGROUP_OP;
  43. }
  44.  
  45. - (void)saveBeforeChange
  46. {
  47.     NSMutableArray *selectedGraphics;
  48.     int i, count;
  49.     id g;
  50.     id changeDetailClass;
  51.  
  52.     groups = [[NSMutableArray alloc] init];
  53.     changeDetailClass = [self changeDetailClass];
  54.     changeDetails = [[NSMutableArray alloc] init];
  55.  
  56.     selectedGraphics = [graphicView selectedGraphics];
  57.     count = [selectedGraphics count];
  58.     for (i = 0; i < count; i++) {
  59.     g = [selectedGraphics objectAtIndex:i];
  60.     if ([g isKindOfClass:[Group class]]) {
  61.         [groups addObject:g];
  62.         [changeDetails addObject:[[changeDetailClass alloc] initGraphic:g change:self]];
  63.     }
  64.     }
  65.     [changeDetails makeObjectsPerform:@selector(recordGraphicPositionIn:) withObject:[graphicView graphics]];
  66.  
  67.     count = [groups count];
  68.     if (count == 0)
  69.         [self disable]; 
  70. }
  71.  
  72. - (void)undoChange
  73. {
  74.     NSMutableArray *allGraphics, *graphics;
  75.     int i, j, count, graphicCount;
  76.     NSRect affectedBounds;
  77.     id group, graphic, detail;
  78.  
  79.     allGraphics = [graphicView graphics];
  80.     count = [changeDetails count];
  81.     for (i = 0; i < count; i++) {
  82.         detail = [changeDetails objectAtIndex:i];
  83.     group = [detail graphic];
  84.     graphics = [group subGraphics];
  85.     graphicCount = [graphics count];
  86.     for (j = 0; j < graphicCount; j++) {
  87.         graphic = [graphics objectAtIndex:j];
  88.         [graphic setCacheable:NO];
  89.         [allGraphics removeObject:graphic];
  90.     }
  91.     [allGraphics insertObject:group atIndex:[detail graphicPosition]];
  92.     }
  93.     
  94.     [graphicView getSelection];
  95.     [graphicView setGroupInSlist:YES];
  96.     affectedBounds = [graphicView getBBoxOfArray:groups];
  97.     [graphicView cache:affectedBounds];
  98.     [[graphicView window] flushWindow];
  99.     [[[NSApp inspectorPanel] delegate] loadGraphic:[graphicView selectedGraphic]]; 
  100.  
  101.     [super undoChange]; 
  102. }
  103.  
  104. - (void)redoChange
  105. {
  106.     NSMutableArray *allGraphics;
  107.     int k;
  108.     int i, count;
  109.     NSRect affectedBounds;
  110.     id group;
  111.  
  112.     affectedBounds = [graphicView getBBoxOfArray:groups];
  113.  
  114.     allGraphics = [graphicView graphics];
  115.     count = [groups count];
  116.     for (i = 0; i < count; i++) {
  117.         group = [groups objectAtIndex:i];
  118.     k = [allGraphics indexOfObject:group];
  119.     [allGraphics removeObjectAtIndex:k];
  120.     [group transferSubGraphicsTo:allGraphics at:k];
  121.     }
  122.  
  123.     [graphicView getSelection];
  124.     [graphicView resetGroupInSlist];
  125.     [graphicView cache:affectedBounds];
  126.     [[graphicView window] flushWindow];
  127.     [[[NSApp inspectorPanel] delegate] loadGraphic:[graphicView selectedGraphic]]; 
  128.  
  129.  
  130.     [super redoChange]; 
  131. }
  132.  
  133. - (Class)changeDetailClass
  134. {
  135.     return [OrderChangeDetail class];
  136. }
  137.  
  138. @end
  139.