/* 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 "PerforceChangeFile.h" #import "IconDefs.h" #import "IconController.h" #import "PerforceAction.h" #import "PerforceActionRevert.h" #import "MessageDefs.h" #import "AppUtils.h" static NSString* kDefaultChange = @"default"; @implementation PerforceChangeFile - (id) initWithName: (NSString*) fileName withRevision: (int) revision withFileType: (NSString*) fileType withChangeName: (NSString*) changeName withChangeType: (NSString*) changeType withUserInfo: (NSString*) userInfo isClient: (BOOL) isClient { NSMutableString* nsString = [NSMutableString stringWithString:changeName]; self = [super init]; fFileName = [fileName copy]; fRevision = revision; fFileType = [fileType copy]; fChangeName = [changeName copy]; fChangeType = [changeType copy]; fFileNameAndRevision = [[NSString stringWithFormat:@"%@#%d", fFileName, fRevision] retain]; fIsClientChange = isClient; if ( userInfo ) { fUserInfo = [userInfo copy]; [nsString appendString:@" - "]; [nsString appendString:userInfo]; } else { fUserInfo = [[NSString alloc] initWithString:@""]; } // force into an NSString fChangeAndUser = [[NSString alloc] initWithCString:[nsString cString]]; if ( isClient ) { if ( [fChangeType isEqualTo:@"edit"] ) { fIconID = kClientEditIcon; } else if ( [fChangeType isEqualTo:@"delete"] ) { fIconID = kClientDeleteIcon; } else { fIconID = kClientAddIcon; } } else { if ( [fChangeType isEqualTo:@"edit"] ) { fIconID = kOtherEditIcon; } else if ( [fChangeType isEqualTo:@"delete"] ) { fIconID = kOtherDeleteIcon; } else { fIconID = kOtherAddIcon; } } return self; } - (void) dealloc { [fFileName release]; [fFileType release]; [fChangeName release]; [fChangeType release]; [fUserInfo release]; [fFileNameAndRevision release]; [super dealloc]; } - (BOOL) isClientChange { return fIsClientChange; } - (int) getNumberOfChildren { return 0; } - (BOOL) hasChildren { return NO; } - (id) getChildAtIndex: (int) index { return nil; } - (id) getCellText { return fFileNameAndRevision; } - (id) getCellImage { return [[IconController defaultIconController] getIcon:fIconID]; } - (NSString*) getChangeAndUser { return fChangeAndUser; } - (NSString*) getChangeName { return fChangeName; } - (NSString*) getUserInfo { return fUserInfo; } - (NSComparisonResult) compare: (PerforceChangeFile*) rhs { if ( [fChangeName isEqualTo:kDefaultChange] ) { if ( [rhs->fChangeName isEqualTo:kDefaultChange] ) { return [fUserInfo caseInsensitiveCompare:rhs->fUserInfo]; } return NSOrderedAscending; } if ( [rhs->fChangeName isEqualTo:kDefaultChange] ) { return NSOrderedDescending; } if ( [fUserInfo isEqualTo:rhs->fUserInfo] ) { return [fChangeName caseInsensitiveCompare:rhs->fChangeName]; } return [fUserInfo caseInsensitiveCompare:rhs->fUserInfo]; } - (NSString*) depotFileName { return fFileName; } /* - (NSString*) clientFileName { return [[PerforceAction defaultAction] where:[self depotFileName]]; } */ // ///// // // The enablement - (BOOL) canEdit { return NO; } - (BOOL) canDescribe { return NO; } - (BOOL) canDelete { return NO; } - (BOOL) canSubmit { return NO; } - (BOOL) canRevert { return YES; } - (BOOL) canSyncTo { return NO; } - (BOOL) canSyncOnly { return NO; } // The actions - (void) doEdit { } - (void) doDescribe { } - (void) doDelete { } - (void) doSubmit { } - (void) doRevert { [PerforceActionRevert defaultRunFor:self selector:@selector(resultFromRevert:) withPath:fFileName]; } - (void) doSyncTo { } - (void) doSyncOnly { } - (void) resultFromRevert: (PerforceActionRevert*) action { if ( [action wasSuccess] ) { SendNotificationWithObject (kDepotFileChanged, fFileName); } } @end