/* 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 "PerforceClient.h" #import "PerforceActionClient.h" #import "AppController.h" #import "ReadOnlyEditorController.h" #import "AppDefaults.h" @interface PerforceClient(Sorting) - (NSComparisonResult) comparegetClientNameAscending: (PerforceClient *) rhs; - (NSComparisonResult) comparegetClientNameDescending: (PerforceClient *) rhs; - (NSComparisonResult) comparegetClientDateAscending: (PerforceClient *) rhs; - (NSComparisonResult) comparegetClientDateDescending: (PerforceClient *) rhs; - (NSComparisonResult) comparegetClientRootAscending: (PerforceClient *) rhs; - (NSComparisonResult) comparegetClientRootDescending: (PerforceClient *) rhs; - (NSComparisonResult) comparegetClientDescriptionAscending: (PerforceClient *) rhs; - (NSComparisonResult) comparegetClientDescriptionDescending: (PerforceClient *) rhs; @end @implementation PerforceClient + (id) clientWithString: (NSString *) string // convenience is king... { return [[[PerforceClient alloc] initWithString: string] autorelease]; } - (id) initWithString: (NSString *) string { if (self = [super init]) { NSScanner * scanner = [NSScanner scannerWithString: string]; if ([scanner scanString: @"Client " intoString: nil] && [scanner scanUpToString: @" " intoString: &fName] && [scanner scanUpToString: @" " intoString: &fDate] && [scanner scanString: @"root " intoString: nil] && [scanner scanUpToString: @"'" intoString: &fRoot]) { fRoot = [fRoot substringToIndex: [fRoot length] - 1]; [scanner scanString: @"'" intoString: nil]; NSRange range; range.location = [scanner scanLocation]; range.length = [string length] - range.location - 1; fDescription = [string substringWithRange: range]; } [fName retain]; [fDate retain]; [fRoot retain]; [fDescription retain]; } return self; } - (void) dealloc { [fName release]; [fDate release]; [fRoot release]; [fDescription release]; [super dealloc]; } - (NSString*) getClientName { return fName; } - (NSString*) getClientDate { return fDate; } - (NSString*) getClientRoot { return fRoot; } - (NSString*) getClientDescription { return fDescription; } - (NSComparisonResult) comparegetClientNameAscending: (PerforceClient*) rhs { return [fName caseInsensitiveCompare: rhs->fName]; } - (NSComparisonResult) comparegetClientNameDescending: (PerforceClient*) rhs { return [rhs->fName caseInsensitiveCompare: fName]; } - (NSComparisonResult) comparegetClientDateAscending: (PerforceClient*) rhs { return [fDate compare:rhs->fDate]; } - (NSComparisonResult) comparegetClientDateDescending: (PerforceClient*) rhs { return [rhs->fDate compare:fDate]; } // Since many roots are the same except for capitalization, this groups them nicely. - (NSComparisonResult) comparegetClientRootAscending: (PerforceClient*) rhs { NSComparisonResult result = [fRoot caseInsensitiveCompare: rhs->fRoot]; if (result == NSOrderedSame) result = [fRoot compare: rhs->fRoot]; return result; } - (NSComparisonResult) comparegetClientRootDescending: (PerforceClient*) rhs { NSComparisonResult result = [rhs->fRoot caseInsensitiveCompare: fRoot]; if (result == NSOrderedSame) result = [rhs->fRoot compare: fRoot]; return result; } - (NSComparisonResult) comparegetClientDescriptionAscending: (PerforceClient*) rhs { return [fDescription caseInsensitiveCompare: rhs->fDescription]; } - (NSComparisonResult) comparegetClientDescriptionDescending: (PerforceClient*) rhs { return [rhs->fDescription caseInsensitiveCompare: fDescription]; } // The enablement - (BOOL) canEdit:(NSString**)clientName { *clientName = fName; return YES; } - (BOOL) canDescribe { return YES; } - (BOOL) canDelete { AppDefaults* appDef = [AppDefaults defaultAppDefaults]; return [fName isEqualToString:[appDef getPerforceClient]]; } - (BOOL) canSwitchTo { AppDefaults* appDef = [AppDefaults defaultAppDefaults]; return ![fName isEqualToString:[appDef getPerforceClient]]; } // The actions - (void) doEdit { [PerforceActionClientGet defaultRunFor:[NSApp delegate] selector:@selector(resultFromPerforceClientOut:) identifier:fName]; } - (void) doDescribe { [PerforceActionClientGet defaultRunFor:self selector:@selector(resultFromDescribe:) identifier:fName]; } - (void) doDelete { int isOK = NSRunAlertPanel (@"Delete", @"Are you sure you want to delete client %s?", @"OK", @"Cancel", nil, [fName cString]); if ( isOK ) { [PerforceActionClientDelete defaultRunFor:nil selector:nil identifier:fName]; } } - (void) doSwitchTo { AppDefaults* appDef = [AppDefaults defaultAppDefaults]; [appDef setPerforceClient:fName]; } - (void) resultFromDescribe:(PerforceActionClientGet*)action { if ( [action wasSuccess] ) { NSMutableString* titleString = [NSMutableString stringWithString:@"Description of Client "]; [titleString appendString:[action getIdentifier]]; [ReadOnlyEditorController showWindowWith:[action getOutput] title:titleString]; } } @end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 3391 | Paul Ferguson | More memory leak fixes, other code cleanup | ||
#1 | 3210 | Paul Ferguson | Initial branch | ||
//guest/jeff_argast/P4Cocoa/source/Perforce/PerforceClient.m | |||||
#2 | 3196 | Jeff Argast |
Submitted Paul's changes to fix a hanging bug when a client root has a non-ASCII character. His changes also clean up the parsing of clients tremendously. |
||
#1 | 2732 | Jeff Argast | Initial submission of P4Cocoa |