/* 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 "PerforceDirectory.h" #import "PerforceActionDirsAndFstat.h" #import "PerforceActionDirs.h" #import "PerforceActionFstat.h" #import "PerforceActionSync.h" #import "PerforceActionEdit.h" #import "PerforceActionRevert.h" #import "PerforceActionDelete.h" #import "IconController.h" #import "IconDefs.h" #import "AppUtils.h" #import "MessageDefs.h" static NSString* kNibExt = @"nib"; static NSString* kPBExt = @"pbproj"; @implementation PerforceDirectory - (void) releaseChildren { [fChildren release]; fChildren = nil; } - (void) resultFromPerforceReleaseChildren: (id) nothing { [self releaseChildren]; SendNotificationWithObject (kDepotControllerChildChanged, self); } - (void) resultFromPerforceDirsAndFstat: (PerforceActionDirsAndFstat*) action { [fChildren release]; fChildren = [[action getDirsAndFiles] retain]; SendNotificationWithObject (kDepotControllerChildChanged, self); } - (void) buildChildren { NSMutableString* dirPath = [NSMutableString stringWithString:fDepotPath]; [dirPath appendString:@"/*"]; fChildren = [[NSMutableArray alloc] init]; [PerforceActionDirsAndFstat defaultRunFor:self selector:@selector(resultFromPerforceDirsAndFstat:) withPath:dirPath]; } - (void) dealloc { [fChildren release]; [fName release]; [fDepotPath release]; [fIcon release]; [super dealloc]; } - (id) initWithDir: (const char*) fullPath { if ( self = [super init] ) { fDepotPath = [[NSString alloc] initWithCString:fullPath]; fName = ExtractLastPathComponent (fDepotPath); [fName retain]; fChildren = nil; IconController* iconController = [IconController defaultIconController]; NSString* dirExtension = [fName pathExtension]; if ( dirExtension ) { if ( [dirExtension isEqualToString:kNibExt] ) { fIcon = [[iconController getIcon:kDirNibIcon] retain]; } else if ( [dirExtension isEqualToString:kPBExt] ) { fIcon = [[iconController getIcon:kDirPBIcon] retain]; } else { fIcon = [[iconController getIcon:kDirIcon] retain]; } } else { fIcon = [[iconController getIcon:kDirIcon] retain]; } } return self; } - (NSString*) getName { return fName; } - (int) getNumberOfChildren { if ( !fChildren ) { [self buildChildren]; } return [fChildren count]; } - (BOOL) hasChildren { // Depots always have children return YES; } - (id) getChildAtIndex: (int) index { if ( !fChildren ) { [self buildChildren]; } return [fChildren objectAtIndex:index]; } - (id) getCellText { return fName; } - (id) getCellImage { return fIcon; } - (NSString*) buildPath: (NSString*) extraPath { NSMutableString* depotPath = [[[NSMutableString alloc] initWithString:fDepotPath] autorelease]; [depotPath appendString:extraPath]; return depotPath; } // // Perforce Protocol // // // data // // // Enablement // - (BOOL) canSyncToHead { return YES; } - (BOOL) canSyncToNone { return YES; } - (BOOL) canEdit { return YES; } - (BOOL) canDelete { return YES; } - (BOOL) canRevert { return YES; } - (BOOL) canDiff { return NO; } - (BOOL) canGetRevisions { return NO; } - (BOOL) canViewInEditor { return NO; } // // Actions // - (void) syncToHead { /* [PerforceActionSync defaultRunFor:self selector:@selector(resultFromPerforceReleaseChildren:) withPath:[self buildPath:@"/..."]]; */ } - (void) syncToNone { /* [PerforceActionSync defaultRunFor:self selector:@selector(resultFromPerforceReleaseChildren:) withPath:[self buildPath:@"/...#none"]]; */ } - (void) syncTo: (NSString*) target { /* NSMutableString* revSpec = [NSMutableString stringWithString:@"/..."]; [revSpec appendString:target]; [PerforceActionSync defaultRunFor:self selector:@selector(resultFromPerforceReleaseChildren:) withPath:[self buildPath:revSpec]]; */ } - (void) showRevisionHistory { } - (void) edit { /* [PerforceActionEdit defaultRunFor:self selector:@selector(resultFromPerforceReleaseChildren:) withPath:[self buildPath:@"/..."]]; */ } - (void) delete { /* [PerforceActionDelete defaultRunFor:self selector:@selector(resultFromPerforceReleaseChildren:) withPath:[self buildPath:@"/..."]]; */ } - (void) revert { /* NSString* pathString = [self buildPath:@"/..."]; [PerforceActionRevert defaultRevertPaths:[NSArray arrayWithObject:pathString]]; */ } - (void) diff { // do nothing } - (void) viewInEditor { // do nothing; } - (NSString*) getPasteboardData { NSMutableString* dragPath = [NSMutableString stringWithString:fDepotPath]; [dragPath appendString:@"/..."]; return dragPath; } - (void) fileChanged:(NSString*)depotPath { if ( !fChildren ) return; int myLen = [fDepotPath length]; int otherLen = [depotPath length]; if ( myLen < otherLen ) { NSComparisonResult compareResult = [depotPath compare:fDepotPath options:0 range:NSMakeRange (0, myLen)]; if ( compareResult == NSOrderedSame ) { int numChildren = [fChildren count]; int n; for ( n = 0; n < numChildren; n++ ) { id child = [fChildren objectAtIndex:n]; [child fileChanged:depotPath]; } } } } - (void) pathChanged:(NSString*)depotPath theFile:(PerforceFile**)theFile { if ( !fChildren ) return; int myLen = [fDepotPath length]; int otherLen = [depotPath length]; if ( myLen < otherLen ) { NSComparisonResult compareResult = [depotPath compare:fDepotPath options:0 range:NSMakeRange (0, myLen)]; if ( compareResult == NSOrderedSame ) { // are the next 4 chars /... ? if ( (otherLen - myLen) == 4 ) { compareResult = [depotPath compare:@"/..." options:0 range:NSMakeRange (myLen, 4)]; if ( compareResult == NSOrderedSame ) { [self releaseChildren]; return; } } int numChildren = [fChildren count]; int n; for ( n = 0; (n < numChildren) && (*theFile == nil); n++ ) { id child = [fChildren objectAtIndex:n]; [child pathChanged:depotPath theFile:theFile]; } } } } - (NSString*) getDepotPath { return fDepotPath; } - (NSString*) getPerforceActionPath { return [self buildPath:@"/..."]; } @end