home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / DEV.Z / EndEditingGraphicsChange.m < prev    next >
Encoding:
Text File  |  1995-11-28  |  1.5 KB  |  67 lines

  1. #import "drawundo.h"
  2.  
  3. /*
  4.  * This change is created when the user finishes editing a text
  5.  * graphic. Undoing this change inserts the re-inserts the text
  6.  * editing cursor in the text. More significantly, undoing this
  7.  * change swaps the contents of the TextGraphic back into the
  8.  * field editor so that it is ready to edit.
  9.  */
  10.  
  11. @interface EndEditingGraphicsChange(PrivateMethods)
  12.  
  13. @end
  14.  
  15. @implementation EndEditingGraphicsChange
  16.  
  17. - initGraphicView:aGraphicView graphic:aGraphic
  18. {
  19.     [super init];
  20.     graphicView = aGraphicView;
  21.     graphic = aGraphic;
  22.  
  23.     return self;
  24. }
  25.  
  26. - (void)dealloc
  27. {
  28.     if ([self hasBeenDone] && [graphic isEmpty])
  29.         [graphic release];
  30.     [super dealloc];
  31. }
  32.  
  33. - (NSString *)changeName
  34. {
  35.     return END_EDITING_OP;
  36. }
  37.  
  38. - (void)undoChange
  39. {
  40.     if ([graphic isEmpty])
  41.     [graphicView insertGraphic:graphic];
  42.     [graphic prepareFieldEditor];    
  43.     [NSApp startEditMode];
  44.     [super undoChange]; 
  45. }
  46.  
  47. - (void)redoChange
  48. {
  49. /* 
  50.  * The order of the next two statements is important.
  51.  * If endEditMode were sent before resignFieldEditor 
  52.  * it would send resetCursor to the document which would
  53.  * make the window the first responder which would end
  54.  * up sending textDidEnd:endChar: to the TextGraphic.
  55.  * Then in the next line we'd send resignFieldEditor to
  56.  * the TextGraphic even though it had already resigned 
  57.  * the field editor.
  58.  */
  59.     [graphic resignFieldEditor];
  60.     [NSApp endEditMode];
  61.     if ([graphic isEmpty])
  62.     [graphicView removeGraphic:graphic];
  63.     [super redoChange]; 
  64. }
  65.  
  66. @end
  67.