home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Examples / AppKit / Draw / graphicsUndo.subproj / SimpleGraphicsChange.m < prev    next >
Text File  |  1995-08-03  |  2KB  |  85 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. - (void)undoDetails;
  12. - (void)redoDetails;
  13. - (BOOL)subsumeIdenticalChange:change;
  14.  
  15. @end
  16.  
  17. @implementation SimpleGraphicsChange
  18.  
  19. - (void)saveBeforeChange
  20. {
  21.     [super saveBeforeChange];
  22.     [changeDetails makeObjectsPerform:@selector(recordDetail)]; 
  23. }
  24.  
  25. - (BOOL)subsumeChange:change
  26. /*
  27.  * ChangeManager will call subsumeChange: when we are the last 
  28.  * completed change and a new change has just begun. We override
  29.  * the subsumeChange: to offer our subclasses a chance to
  30.  * consolidate multiple changes into a single change.
  31.  * First we check to make sure that the new change is of the
  32.  * same class as the last. If it is then we check to make sure
  33.  * that it's operating on the same selection. If not we simply
  34.  * return NO, declining to subsume it. If it does operate on
  35.  * the same change then we offer our subclass a change to 
  36.  * subsume it by sending [self subsumeIdenticalChange:change].
  37.  *
  38.  * For example, if the user presses the up arrow key to move
  39.  * a graphic up one pixel, that immediately becomes a complete,
  40.  * undoable change, as it should. If she continues to press
  41.  * use the arrow keys we don't want to end up making hundreds
  42.  * of independent move changes that would each have to be
  43.  * undone seperately. So instead we have the first move
  44.  * subsume all subsequent MoveGraphicsChanges that operate
  45.  * on the same selection.
  46.  */
  47. {
  48.     BOOL        identicalChanges = NO;
  49.     NSMutableArray        *selectedGraphics;
  50.     int            count, i;
  51.  
  52.     if ([change isKindOfClass:[self class]]) {
  53.     if (!graphicsToChange) {
  54.         identicalChanges = YES;
  55.         selectedGraphics = [graphicView selectedGraphics];
  56.         count = [selectedGraphics count];
  57.         for (i = 0; (i < count) && (identicalChanges); i++) {
  58.         if ([graphics objectAtIndex:i] != [selectedGraphics objectAtIndex:i])
  59.             identicalChanges = NO;
  60.         }
  61.     }
  62.     } 
  63.     if (identicalChanges)
  64.         return [self subsumeIdenticalChange:change];
  65.     else
  66.         return NO;
  67. }
  68.  
  69. - (void)undoDetails
  70. {
  71.     [changeDetails makeObjectsPerform:@selector(undoDetail)]; 
  72. }
  73.  
  74. - (void)redoDetails
  75. {
  76.     [changeDetails makeObjectsPerform:@selector(redoDetail)]; 
  77. }
  78.  
  79. - (BOOL)subsumeIdenticalChange:change
  80. {
  81.     return NO;
  82. }
  83.  
  84. @end
  85.