/* Copyright (C) 2002-2003, Jeffrey D. Argast. The authors make NO WARRANTY or representation, either express or implied, with respect to this software, its quality, accuracy, merchantability, or fitness for a particular purpose. This software is provided "AS IS", and you, its user, assume the entire risk as to its quality and accuracy. Permission is hereby granted to use, copy, modify, and distribute this software or portions thereof for any purpose, without fee, subject to these conditions: (1) If any part of the source code is distributed, then this statement must be included, with this copyright and no-warranty notice unaltered. (2) Permission for use of this software is granted only if the user accepts full responsibility for any undesirable consequences; the authors accept NO LIABILITY for damages of any kind. */ #import "PendingViewSelection.h" #import "PerforceActionRevert.h" #import "PerforceActionResolve.h" @implementation PendingViewSelection - (id) initWithItems: (NSArray*) selectedItems { self = [super init]; fSelectedItems = [selectedItems retain]; return self; } - (void) dealloc { [fSelectedItems release]; [super dealloc]; } - (BOOL) canDoSelector: (SEL) selector { int numItems = [fSelectedItems count]; int n; BOOL canDo = YES; for ( n = 0; (n < numItems) && canDo; n++ ) { id item = [fSelectedItems objectAtIndex:n]; if ( ![item performSelector:selector] ) { canDo = NO; } } return canDo; } - (void) doSelector: (SEL) selector { int numItems = [fSelectedItems count]; int n; for ( n = 0; n < numItems; n++ ) { id item = [fSelectedItems objectAtIndex:n]; [item performSelector:selector]; } } // The enablement - (BOOL) canEdit { return [self canDoSelector:@selector(canEdit)]; } - (BOOL) canDescribe { return [self canDoSelector:@selector(canDescribe)]; } - (BOOL) canDelete { return [self canDoSelector:@selector(canDelete)]; } - (BOOL) canSubmit { return [self canDoSelector:@selector(canSubmit)]; } - (BOOL) canResolve { return [self canDoSelector:@selector(canResolve)]; } - (BOOL) canRevert { return [self canDoSelector:@selector(canRevert)]; } - (BOOL) canDiff { return [self canDoSelector:@selector(canDiff)]; } - (BOOL) canRevealInFinder { return [self canDoSelector:@selector(canRevealInFinder)];; } - (BOOL) canViewInEditor { return [self canDoSelector:@selector(canViewInEditor)];; } // The actions - (NSArray*) selectedPathList { int numItems = [fSelectedItems count]; int n; NSMutableArray* selectedPathList = [NSMutableArray arrayWithCapacity:numItems]; for ( n = 0; n < numItems; n++ ) { id item = [fSelectedItems objectAtIndex:n]; [item appendRevertPath:selectedPathList]; } return selectedPathList; } - (void) doEdit { [self doSelector:@selector(doEdit)]; } - (void) doDescribe { [self doSelector:@selector(doDescribe)]; } - (void) doDelete { [self doSelector:@selector(doDelete)]; } - (void) doSubmit { [self doSelector:@selector(doSubmit)]; } - (void) doResolve { [PerforceActionResolve defaultRun:[self selectedPathList]]; } - (void) doRevert { [PerforceActionRevert defaultRun:[self selectedPathList] unchanged:NO]; } - (void) doRevertUnchanged { [PerforceActionRevert defaultRun:[self selectedPathList] unchanged:YES]; } - (void) doDiff { [self doSelector:@selector(doDiff)]; } - (void) doRevealInFinder { [self doSelector:@selector(doRevealInFinder)]; } - (void) doViewInEditor { [self doSelector:@selector(doViewInEditor)]; } - (void) appendRevertPath: (NSMutableArray*) revertPathList { // Do nothing. TODO: This means the protocol is too broad and should be broken into more // granular protocols. } @end