/* 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 "PerforceSubmittedChange.h" #import "ReadOnlyEditorController.h" #import "PerforceActionDescribe.h" #import "PerforceActionSync.h" #import "MessageDefs.h" #import "AppUtils.h" @interface PerforceSubmittedChange(Private) - (NSComparisonResult) comparegetChangeNumberAscending: (PerforceSubmittedChange*) rhs; - (NSComparisonResult) comparegetChangeNumberDescending: (PerforceSubmittedChange*) rhs; - (NSComparisonResult) comparegetChangeDateAscending: (PerforceSubmittedChange*) rhs; - (NSComparisonResult) comparegetChangeDateDescending: (PerforceSubmittedChange*) rhs; - (NSComparisonResult) comparegetChangeUserAscending: (PerforceSubmittedChange*) rhs; - (NSComparisonResult) comparegetChangeUserDescending: (PerforceSubmittedChange*) rhs; - (NSComparisonResult) comparegetChangeDescriptionAscending: (PerforceSubmittedChange*) rhs; - (NSComparisonResult) comparegetChangeDescriptionDescending: (PerforceSubmittedChange*) rhs; @end @implementation PerforceSubmittedChange + (id) submittedChangeWithString: (NSString *) string // convenience is king... { return [[[PerforceSubmittedChange alloc] initWithString: string] autorelease]; } - (id) initWithString: (NSString *) string { if (self = [super init]) { NSScanner * scanner = [NSScanner scannerWithString: string]; if ([scanner scanString: @"Change " intoString: nil] && [scanner scanInt: &fNumber] && [scanner scanString: @"on " intoString: nil] && [scanner scanUpToString: @" " intoString: &fDate] && [scanner scanString: @"by " intoString: nil] && [scanner scanUpToString: @" " intoString: &fUser] && [scanner scanString: @"'" intoString: nil]) { NSRange range; range.location = [scanner scanLocation]; range.length = [string length] - range.location - 1; fDescription = [string substringWithRange: range]; } [fUser retain]; [fDate retain]; [fDescription retain]; } return self; } - (void) dealloc { [fDate release]; [fUser release]; [fDescription release]; [super dealloc]; } - (NSString *) getChangeNumber { return [NSString stringWithFormat: @"%06d", fNumber]; } - (NSString*) getChangeDate { return fDate; } - (NSString*) getChangeUser { return fUser; } - (NSString*) getChangeDescription { return fDescription; } - (NSComparisonResult) comparegetChangeNumberAscending: (PerforceSubmittedChange*) rhs { if (fNumber < rhs->fNumber) return NSOrderedAscending; else if (fNumber > rhs->fNumber) return NSOrderedDescending; else return NSOrderedSame; } - (NSComparisonResult) comparegetChangeNumberDescending: (PerforceSubmittedChange*) rhs { if (fNumber < rhs->fNumber) return NSOrderedDescending; else if (fNumber > rhs->fNumber) return NSOrderedAscending; else return NSOrderedSame; } - (NSComparisonResult) comparegetChangeDateAscending: (PerforceSubmittedChange*) rhs { return [fDate caseInsensitiveCompare:rhs->fDate]; } - (NSComparisonResult) comparegetChangeDateDescending: (PerforceSubmittedChange*) rhs { return [rhs->fDate caseInsensitiveCompare:fDate]; } - (NSComparisonResult) comparegetChangeUserAscending: (PerforceSubmittedChange*) rhs { return [fUser caseInsensitiveCompare:rhs->fUser]; } - (NSComparisonResult) comparegetChangeUserDescending: (PerforceSubmittedChange*) rhs { return [rhs->fUser caseInsensitiveCompare:fUser]; } - (NSComparisonResult) comparegetChangeDescriptionAscending: (PerforceSubmittedChange*) rhs { return [fDescription caseInsensitiveCompare:rhs->fDescription]; } - (NSComparisonResult) comparegetChangeDescriptionDescending: (PerforceSubmittedChange*) rhs { return [rhs->fDescription caseInsensitiveCompare:fDescription]; } // ///// // // The enablement - (BOOL) canDescribe { return YES; } - (BOOL) canSyncTo { return YES; } - (BOOL) canSyncOnly { return YES; } - (void) resultFromDescribe:(PerforceActionDescribe*)action { if ( [action wasSuccess] ) { NSMutableString* titleString = [NSMutableString stringWithString:@"Description of Changelist "]; [titleString appendString:[action getChangeNum]]; [ReadOnlyEditorController showWindowWith:[action getOutput] title:titleString]; } } // // The actions - (void) doEdit { } - (void) doDescribe { [PerforceActionDescribe defaultRunFor:self selector:@selector(resultFromDescribe:) changeNum: [NSString stringWithFormat: @"%d", fNumber]]; } - (void) doDelete { } - (void) doSubmit { } - (void) doRevert { } - (void) doSyncTo { [PerforceActionSync defaultRun:nil revision: [NSString stringWithFormat: @"@%d", fNumber]]; } - (void) doSyncOnly { [PerforceActionSync defaultRun:nil revision: [NSString stringWithFormat: @"@%d,%d", fNumber, fNumber]]; } @end