File:  [NeXTSTEP 3.3 examples] / Examples / AppKit / Draw / graphicsUndo.subproj / CreateGraphicsChange.m
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:48:39 2018 UTC (8 years, 1 month ago) by root
Branches: NeXT, MAIN
CVS tags: NeXTSTEP33, HEAD
Sample Programs from NeXSTEP 3.3

#import "drawundo.h"

@interface CreateGraphicsChange(PrivateMethods)

@end

@implementation CreateGraphicsChange

- initGraphicView:aGraphicView graphic:aGraphic
{
    [super init];
    graphicView = aGraphicView;
    graphic = aGraphic;
    startEditingChange = nil;

    return self;
}

- free
{
    if (![self hasBeenDone])
        [graphic free];
    if (startEditingChange)
        [startEditingChange free];
    return [super free];
}

#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.")

- (const char *)changeName
{
    char buffer[256];
    sprintf(buffer, NEW_STRING, [graphic title]);
    return NXUniqueString(buffer);
}

- undoChange
{
    if (startEditingChange)
        [startEditingChange undoChange];
    [graphicView removeGraphic:graphic];
    [[[NXApp inspectorPanel] delegate] loadGraphic:[graphicView selectedGraphic]]; 
    return [super undoChange];
}

- redoChange
{
    [graphicView insertGraphic:graphic];
    [[[NXApp inspectorPanel] delegate] loadGraphic:[graphicView selectedGraphic]];
    if (startEditingChange)
        [startEditingChange redoChange];
    return [super redoChange];
}

- (BOOL)incorporateChange:change
/*
 * ChangeManager will call incorporateChange: if another change
 * is started while we are still in progress (after we've 
 * been sent startChange but before we've been sent endChange). 
 * We override incorporateChange: because we want to
 * incorporate a StartEditingGraphicsChange if it happens.
 * Rather than know how to undo and redo the start-editing stuff,
 * we'll simply keep a pointer to the StartEditingGraphicsChange
 * and ask it to undo and redo whenever we undo or redo.
 */
{
    if ([change isKindOf:[StartEditingGraphicsChange class]]) {
        startEditingChange = change;
        return YES;
    } else {
        return NO;
    }
}

@end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.