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

  1. #import "drawundo.h"
  2.  
  3. @interface CreateGraphicsChange(PrivateMethods)
  4.  
  5. @end
  6.  
  7. @implementation CreateGraphicsChange
  8.  
  9. - initGraphicView:aGraphicView graphic:aGraphic
  10. {
  11.     [super init];
  12.     graphicView = aGraphicView;
  13.     graphic = aGraphic;
  14.     startEditingChange = nil;
  15.  
  16.     return self;
  17. }
  18.  
  19. - free
  20. {
  21.     if (![self hasBeenDone])
  22.         [graphic free];
  23.     if (startEditingChange)
  24.         [startEditingChange free];
  25.     return [super free];
  26. }
  27.  
  28. #define NEW_STRING NXLocalStringFromTable("Operations", "New %s", NULL, "The operation of creating a new graphical entity by dragging the mouse.  The %s is one of Rectangle, Circle, etc.")
  29.  
  30. - (const char *)changeName
  31. {
  32.     char buffer[256];
  33.     sprintf(buffer, NEW_STRING, [graphic title]);
  34.     return NXUniqueString(buffer);
  35. }
  36.  
  37. - undoChange
  38. {
  39.     if (startEditingChange)
  40.         [startEditingChange undoChange];
  41.     [graphicView removeGraphic:graphic];
  42.     [[[NXApp inspectorPanel] delegate] loadGraphic:[graphicView selectedGraphic]]; 
  43.     return [super undoChange];
  44. }
  45.  
  46. - redoChange
  47. {
  48.     [graphicView insertGraphic:graphic];
  49.     [[[NXApp inspectorPanel] delegate] loadGraphic:[graphicView selectedGraphic]];
  50.     if (startEditingChange)
  51.         [startEditingChange redoChange];
  52.     return [super redoChange];
  53. }
  54.  
  55. - (BOOL)incorporateChange:change
  56. /*
  57.  * ChangeManager will call incorporateChange: if another change
  58.  * is started while we are still in progress (after we've 
  59.  * been sent startChange but before we've been sent endChange). 
  60.  * We override incorporateChange: because we want to
  61.  * incorporate a StartEditingGraphicsChange if it happens.
  62.  * Rather than know how to undo and redo the start-editing stuff,
  63.  * we'll simply keep a pointer to the StartEditingGraphicsChange
  64.  * and ask it to undo and redo whenever we undo or redo.
  65.  */
  66. {
  67.     if ([change isKindOf:[StartEditingGraphicsChange class]]) {
  68.         startEditingChange = change;
  69.         return YES;
  70.     } else {
  71.         return NO;
  72.     }
  73. }
  74.  
  75. @end
  76.