/* 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 "DistributedP4Cocoa.h" #import "PerforceActionWhere.h" #import "PerforceActionEdit.h" #import "PerforceActionRevert.h" #import "PerforceActionSync.h" #import "DepotExpander.h" #import "AppController.h" static DistributedP4Cocoa* gServer = nil; @interface DistributedP4Cocoa (Private) - (void) runWhere: (NSArray*) pathArray withResultSelector: (SEL) resultSelector; - (void) editResult: (PerforceActionWhere*) action; - (void) revertResult: (PerforceActionWhere*) action; - (void) syncResult: (PerforceActionWhere*) action; - (void) revealResult: (PerforceActionWhere*) action; @end @implementation DistributedP4Cocoa + (void) vendP4Cocoa { if ( !gServer ) { gServer = [[DistributedP4Cocoa alloc] init]; NSConnection* defaultConnection = [NSConnection defaultConnection]; [defaultConnection setRootObject:gServer]; [defaultConnection registerName:@"DistributedP4Cocoa"]; } } + (void) unvendP4Cocoa { if ( gServer ) { [gServer release]; } } - (oneway void) perforceEdit: (NSArray*) pathArray { [self runWhere:pathArray withResultSelector:@selector(editResult:)]; } - (oneway void) perforceSync: (NSArray*) pathArray { [self runWhere:pathArray withResultSelector:@selector(syncResult:)]; } - (oneway void) perforceRevert: (NSArray*) pathArray { [self runWhere:pathArray withResultSelector:@selector(revertResult:)]; } - (oneway void) perforceReveal: (NSArray*) pathArray { [self runWhere:pathArray withResultSelector:@selector(revealResult:)]; [NSApp activateIgnoringOtherApps:YES]; } @end @implementation DistributedP4Cocoa (Private) - (void) runWhere: (NSArray*) pathArray withResultSelector: (SEL) resultSelector; { NSEnumerator* enumerator = [pathArray objectEnumerator]; id object; while ( object = [enumerator nextObject] ) { [PerforceActionWhere defaultRunFor:self selector:resultSelector withPath:object]; } } - (void) editResult: (PerforceActionWhere*) action { if ( [action wasSuccess] ) { [PerforceActionEdit defaultRun:[NSArray arrayWithObject:[action getDepotPath]]]; } } - (void) revertResult: (PerforceActionWhere*) action { if ( [action wasSuccess] ) { [PerforceActionRevert defaultRun:[NSArray arrayWithObject:[action getDepotPath]] unchanged:NO]; } } - (void) syncResult: (PerforceActionWhere*) action { if ( [action wasSuccess] ) { [PerforceActionSync defaultRun:[NSArray arrayWithObject:[action getDepotPath]] revision:nil]; } } - (void) revealResult: (PerforceActionWhere*) action { if ( [action wasSuccess] ) { [DepotExpander expandPath:[action getDepotPath] depot:[[NSApp delegate] depotController] usep4Where:NO]; } } @end