home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Examples / AppKit / Draw / graphicsUndo.subproj / SimpleGraphicsChange.m < prev    next >
Text File  |  1992-02-09  |  2KB  |  87 lines

  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 8ange isKindOf:[self class]]) {
  55.         identicalChanges = YES;
  56.     selectedGraphics = [graphicView selectedGraphics];
  57.     count = [selectedGraphics count];
  58.     for (i = 0; (i < count) && (identicalChanges); i++) {
  59.         if ([graphics objectAt:i] != [selectedGraphics objectAt:i])
  60.             identicalChanges = NO;
  61.         }
  62.     } 
  63.     if (identicalChanges)
  64.         return [self subsumeIdenticalChange:change];
  65.     else
  66.         return NO;
  67. }
  68.  
  69. - undoDetails
  70. {
  71.     [changeDetails makeObjectsPerform:@selector(undoDetail)];
  72.     return self;
  73. }
  74.  
  75. - redoDetails
  76. {
  77.     [changeDetails makeObjectsPerform:@selector(redoDetail)];
  78.     return self;
  79. }
  80.  
  81. - (BOOL)subsumeIdenticalChange:change
  82. {
  83.     return NO;
  84. }
  85.  
  86. @end
  87.