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

  1. #import "drawundo.h"
  2.  
  3. /*
  4.  * Please refer to external documentation about Draw
  5.  * with Undo for information about what GraphicsChange 
  6.  * is and where it fits in.
  7.  */
  8.  
  9. @interface GraphicsChange(PrivateMethods)
  10.  
  11. - (void)undoDetails;
  12. - (void)redoDetails;
  13.  
  14. @end
  15.  
  16. @implementation GraphicsChange
  17.  
  18. - initGraphicView:aGraphicView
  19. {
  20.     [super init];
  21.     graphicView = aGraphicView;
  22.     graphics = nil;
  23.     changeDetails = nil;
  24.  
  25.     return self;
  26. }
  27.  
  28. - initGraphicView:aGraphicView forChangeToGraphic:aGraphic
  29. {
  30.     [self initGraphicView:aGraphicView];
  31.     graphicsToChange = [[NSMutableArray alloc] init];
  32.     [graphicsToChange addObject:aGraphic];
  33.     return self;
  34. }
  35.  
  36. - (void)dealloc
  37. {
  38.    [graphics release];
  39.    [graphicsToChange release];
  40.     if (changeDetails != nil) {
  41.     [changeDetails removeAllObjects];
  42.     [changeDetails release];
  43.     }
  44.  
  45.     [super dealloc];
  46. }
  47.  
  48. - (void)saveBeforeChange
  49. {
  50.     NSMutableArray *selectedGraphics;
  51.     int i, count;
  52.     Class changeDetailClass;
  53.     id changeDetail;
  54.     BOOL changeExpected = NO;
  55.  
  56.     if (!graphicsToChange) {
  57.     selectedGraphics = [graphicView selectedGraphics];
  58.     } else {
  59.     selectedGraphics = graphicsToChange;
  60.     }
  61.     count = [selectedGraphics count];
  62.     if (count == 0) {
  63.         [self disable];
  64.     } else {
  65.     changeDetailClass = [self changeDetailClass];
  66.     if (changeDetailClass != nil)
  67.         changeDetails = [[NSMutableArray alloc] init];
  68.     else
  69.         changeExpected = YES;
  70.     graphics = [[NSMutableArray alloc] init];
  71.     for (i = 0; i < count; i++) {
  72.         [graphics addObject:[selectedGraphics objectAtIndex:i]];
  73.         if (changeDetailClass != nil) {
  74.         changeDetail = [[changeDetailClass alloc] initGraphic:[selectedGraphics objectAtIndex:i] change:self];
  75.         changeExpected = changeExpected || [changeDetail changeExpected];
  76.         [changeDetails addObject:changeDetail];
  77.         }
  78.     }
  79.     }
  80.     
  81.     if (!changeExpected)
  82.         [self disable]; 
  83. }
  84.  
  85. - (void)undoChange
  86. {
  87.     [graphicView redrawGraphics:graphics afterChangeAgent:self performs:@selector(undoDetails)];
  88.     [[graphicView window] flushWindow];
  89.     [[[NSApp inspectorPanel] delegate] loadGraphic:[graphicView selectedGraphic]]; 
  90.  
  91.     [super undoChange]; 
  92. }
  93.  
  94. - (void)redoChange
  95. {
  96.     [graphicView redrawGraphics:graphics afterChangeAgent:self performs:@selector(redoDetails)];
  97.     [[graphicView window] flushWindow];
  98.     [[[NSApp inspectorPanel] delegate] loadGraphic:[graphicView selectedGraphic]]; 
  99.  
  100.     [super redoChange]; 
  101. }
  102.  
  103. - (Class)changeDetailClass
  104. /*
  105.  * To be overridden 
  106.  */
  107. {
  108.     return [ChangeDetail class];
  109. }
  110.  
  111. - (void)undoDetails
  112. /*
  113.  * To be overridden 
  114.  */
  115. {
  116.      
  117. }
  118.  
  119. - (void)redoDetails
  120. /*
  121.  * To be overridden 
  122.  */
  123. {
  124.      
  125. }
  126.  
  127. @end
  128.