/* 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 "DepotViewSelection.h" #import "PerforceActionRevert.h" #import "PerforceActionEdit.h" #import "PerforceActionSync.h" #import "PerforceActionDelete.h" #import "PerforceFile.h" @implementation DepotViewSelection - (id) initWithItems: (NSArray*) selectedItems { self = [super init]; fSelectedItems = [selectedItems retain]; return self; } - (void) dealloc { [fSelectedItems release]; } - (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; } - (BOOL) canSyncToHead { return [self canDoSelector:@selector(canSyncToHead)]; } - (BOOL) canSyncToNone { return [self canDoSelector:@selector(canSyncToNone)]; } - (BOOL) canEdit { return [self canDoSelector:@selector(canEdit)]; } - (BOOL) canDelete { return [self canDoSelector:@selector(canDelete)]; } - (BOOL) canRevert { return [self canDoSelector:@selector(canRevert)]; } - (BOOL) canDiff { return [self canDoSelector:@selector(canDiff)]; } - (BOOL) canGetRevisions { return [self canDoSelector:@selector(canGetRevisions)]; } - (BOOL) canViewInEditor { return [self canDoSelector:@selector(canViewInEditor)]; } // // Actions // - (NSArray*) selectedDepotPaths { NSMutableArray* depotArray = [NSMutableArray array]; int numItems = [fSelectedItems count]; int n; for ( n = 0; n < numItems; n++ ) { id item = [fSelectedItems objectAtIndex:n]; [depotArray addObject:[item getPerforceActionPath]]; } return depotArray; } - (void) doSelector: (SEL) selector { int numItems = [fSelectedItems count]; int n; for ( n = 0; n < numItems; n++ ) { id item = [fSelectedItems objectAtIndex:n]; [item performSelector:selector]; } } - (void) syncToHead { [PerforceActionSync defaultRun:[self selectedDepotPaths] revision:nil]; } - (void) syncToNone { [PerforceActionSync defaultRun:[self selectedDepotPaths] revision:@"#none"]; } - (void) syncTo: (NSString*) target { [PerforceActionSync defaultRun:[self selectedDepotPaths] revision:target]; } - (void) showRevisionHistory { [self doSelector:@selector(showRevisionHistory)]; } - (void) edit { [PerforceActionEdit defaultRun:[self selectedDepotPaths]]; } - (void) delete { [PerforceActionDelete defaultRun:[self selectedDepotPaths]]; } - (void) revert { [PerforceActionRevert defaultRun:[self selectedDepotPaths] unchanged:NO]; } - (void) revertUnchanged { [PerforceActionRevert defaultRun:[self selectedDepotPaths] unchanged:YES]; } - (void) diff { [self doSelector:@selector(diff)]; } - (void) viewInEditor { [self doSelector:@selector(viewInEditor)]; } @end