File:  [NeXTSTEP 3.3 examples] / Examples / AppKit / Draw / graphicsUndo.subproj / GridChange.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 GridChange(PrivateMethods)

@end

@implementation GridChange

- initGraphicView:aGraphicView
{
    [super init];
    graphicView = aGraphicView;

    return self;
}

- (const char *)changeName
{
    return NXLocalStringFromTable("Operations", "Grid Change", NULL, "The operation of changing the spacing or color of the grid.");
}

- saveBeforeChange
{
    oldSpacing = [graphicView gridSpacing];
    oldGray = [graphicView gridGray];
    oldVisible = [graphicView gridIsVisible];
    oldEnabled = [graphicView gridIsEnabled];
    return self;
}

- undoChange
{
    newSpacing = [graphicView gridSpacing];
    newGray = [graphicView gridGray];
    newVisible = [graphicView gridIsVisible];
    newEnabled = [graphicView gridIsEnabled];

    [[self changeManager] disableChanges:self];
	[graphicView setGridSpacing:oldSpacing andGray:oldGray];
	[graphicView setGridVisible:oldVisible];
	[graphicView setGridEnabled:oldEnabled];
    [[self changeManager] enableChanges:self];
    return [super undoChange];
}

- redoChange
{
    [[self changeManager] disableChanges:self];
	[graphicView setGridSpacing:newSpacing andGray:newGray];
	[graphicView setGridVisible:newVisible];
	[graphicView setGridEnabled:newEnabled];
    [[self changeManager] enableChanges:self];
    return [super redoChange];
}

- (BOOL)subsumeChange:change
/*
 * ChangeManager will call subsumeChange: when we are the last 
 * completed change and a new change has just begun. We override
 * the subsumeChange: because we want to consolidate multiple
 * grid changes into a single change. For example, if the user
 * selects the menu item "Show Grid" and then selects the menu
 * item "Turn Grid On", we'll only leave a single GridChange in
 * the ChangeManager's list of changes.Both changes can then be
 * be undone and redone in one action.
 */
{
    if ([change isKindOf:[GridChange class]]) {
        [self saveBeforeChange];
        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.