/* 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 "RevisionsController.h" #import "PerforceFileRevision.h" #import "PerforceAction.h" #import "AppUtils.h" #import "AppDefaults.h" #import "PerforceActionPrint.h" #import "PerforceActionSync.h" #import "PerforceActionDescribe.h" #import "PerforceActionDiff2.h" #import "ReadOnlyEditorController.h" #import "NonCascadingWindow.h" #import "MessageDefs.h" //static int kMaxFileNameLength = 26; @implementation RevisionsController + (void) showWithRevisions:(NSArray*)revisions { RevisionsController* revisionsController = [[[RevisionsController alloc] init] autorelease]; [revisionsController setRevisions:revisions]; [revisionsController showWindow:self]; //[[revisionsController window] makeKeyWindow]; } - (id) init { self = [super initWithWindowNibName:@"Revisions"]; // This may seem odd, but we retain ourself here and then autorelease when the // window is closed [self retain]; return self; } - (void) windowDidLoad { NonCascadingWindow* window = (NonCascadingWindow*) [self window]; // For some reason this didn't take in IB so we have to // do it manually [window makeFirstResponder:fRevisionsView]; [fRevisionsView setDoubleAction:@selector(describeRevision:)]; [fRevisionsView setTarget:self]; [fRevisionsView setAutosaveName:@"RevisionsTableInfo"]; [fRevisionsView setAutosaveTableColumns:YES]; PerforceFileRevision* firstRevision = [fRevisions objectAtIndex:0]; NSMutableString* titleString = [NSMutableString stringWithString:@"Revision History for "]; [titleString appendString:[firstRevision getShortFilename]]; [window setTitle:titleString]; [window setDefaultsFrameName:@"RevisionsFrameSize"]; } - (void) setRevisions: (NSArray*) revisions { fRevisions = [revisions retain]; [fDiffRevButton setEnabled:NO]; [fRevisionsView reloadData]; [fRevisionsView selectRow:0 byExtendingSelection:NO]; } - (void) dealloc { [fRevisions release]; [super dealloc]; } - (void)windowWillClose:(NSNotification *)aNotification { [self autorelease]; } - (void) makeSystemCall { DiffFiles (fTempPathOne, fTempPathTwo); [fTempPathOne release]; [fTempPathTwo release]; fTempPathOne = nil; fTempPathTwo = nil; } - (void) resultFromPerforcePrintOne: (id) nothing { [fPerforceActionPrintOne release]; fPerforceActionPrintOne = nil; if ( fPerforceActionPrintTwo == nil ) { [self makeSystemCall]; } } - (void) resultFromPerforcePrintTwo: (id) nothing { [fPerforceActionPrintTwo release]; fPerforceActionPrintTwo = nil; if ( fPerforceActionPrintOne == nil ) { [self makeSystemCall]; } } - (IBAction) diffRevisionsDoesInvokeP4DIFF: (id) sender { if ( [fRevisionsView numberOfSelectedRows] == 2 ) { NSEnumerator* rowEnum = [fRevisionsView selectedRowEnumerator]; NSNumber* firstItem = (NSNumber*) [rowEnum nextObject]; NSNumber* secondItem = (NSNumber*) [rowEnum nextObject]; int firstIdx = [firstItem longValue]; int secondIdx = [secondItem longValue]; PerforceFileRevision* firstRevision = [fRevisions objectAtIndex:firstIdx]; PerforceFileRevision* secondRevision = [fRevisions objectAtIndex:secondIdx]; [PerforceActionDiff2 depotPath1:[firstRevision getFilename] revision1:[firstRevision getRevision] depotPath2:[secondRevision getFilename] revision2:[secondRevision getRevision]]; } } - (IBAction) diffRevisions: (id) sender { if ( [fRevisionsView numberOfSelectedRows] == 2 ) { NSEnumerator* rowEnum = [fRevisionsView selectedRowEnumerator]; // reverse first and second item so that the earlier revision // is first NSNumber* secondItem = (NSNumber*) [rowEnum nextObject]; NSNumber* firstItem = (NSNumber*) [rowEnum nextObject]; int firstIdx = [firstItem longValue]; int secondIdx = [secondItem longValue]; PerforceFileRevision* firstRevision = [fRevisions objectAtIndex:firstIdx]; PerforceFileRevision* secondRevision = [fRevisions objectAtIndex:secondIdx]; NSMutableString* firstPath = [NSMutableString stringWithString:[firstRevision getFilename]]; NSMutableString* secondPath = [NSMutableString stringWithString:[secondRevision getFilename]]; NSMutableString* tempPathOne = [NSMutableString stringWithString:GetAppTempPath()]; NSMutableString* tempPathTwo = [NSMutableString stringWithString:GetAppTempPath()]; NSMutableString* tempNameOne = [NSMutableString stringWithString:ExtractLastPathComponent ([firstRevision getFilename])]; NSMutableString* tempNameTwo = [NSMutableString stringWithString:ExtractLastPathComponent ([secondRevision getFilename])]; /* NO LONGER NEEDED? This was a problem when I was using the -o option for p4 print but now that I am using the filemanager to create the file I think it all works // HACK: MAC only supports 32 character file names. // This shouldn't be a problem on OS X but it is -- I think // it may be the calls the p4api lib is using. // kMaxFileNameLength leaves space for the rev number we append int sLength = [tempNameOne cStringLength]; if ( sLength > kMaxFileNameLength ) { NSRange delRange; delRange.location = kMaxFileNameLength; delRange.length = sLength - kMaxFileNameLength; [tempNameOne deleteCharactersInRange:delRange]; } sLength = [tempNameTwo cStringLength]; if ( sLength > kMaxFileNameLength ) { NSRange delRange; delRange.location = kMaxFileNameLength; delRange.length = sLength - kMaxFileNameLength; [tempNameTwo deleteCharactersInRange:delRange]; } */ [tempPathOne appendString:tempNameOne]; [tempPathOne appendString:@"#"]; [tempPathOne appendString: [firstRevision getRevision]]; [tempPathTwo appendString:tempNameTwo]; [tempPathTwo appendString:@"#"]; [tempPathTwo appendString: [secondRevision getRevision]]; [firstPath appendString:@"#"]; [firstPath appendString:[firstRevision getRevision]]; [secondPath appendString:@"#"]; [secondPath appendString:[secondRevision getRevision]]; ////////////////// fPerforceActionPrintOne = [[PerforceActionPrint alloc] init]; [fPerforceActionPrintOne runFor:self selector:@selector(resultFromPerforcePrintOne:) withPath:firstPath outputPath:tempPathOne]; fPerforceActionPrintTwo = [[PerforceActionPrint alloc] init]; [fPerforceActionPrintTwo runFor:self selector:@selector(resultFromPerforcePrintTwo:) withPath:secondPath outputPath:tempPathTwo]; fTempPathOne = [tempPathOne retain]; fTempPathTwo = [tempPathTwo retain]; ////////////////// } } // // - (void) resultFromDescribe:(PerforceActionDescribe*)action { if ( [action wasSuccess] ) { NSMutableString* titleString = [NSMutableString stringWithString:@"Description of Changelist "]; [titleString appendString:[action getChangeNum]]; [ReadOnlyEditorController showWindowWith:[action getOutput] title:titleString]; } } - (IBAction) describeRevision: (id) sender { int itemIdx = [fRevisionsView selectedRow]; PerforceFileRevision* fileRevision = [fRevisions objectAtIndex:itemIdx]; [PerforceActionDescribe defaultRunFor:self selector:@selector(resultFromDescribe:) changeNum:[fileRevision getChangelist]]; } - (IBAction) viewFileRevision:(id)sender { int itemIdx = [fRevisionsView selectedRow]; PerforceFileRevision* fileRevision = [fRevisions objectAtIndex:itemIdx]; NSString* fileName = GetTempFileName ([fileRevision getFilename], [fileRevision getRevision]); NSMutableString* revPath = [NSMutableString stringWithString:[fileRevision getFilename]]; [revPath appendString:@"#"]; [revPath appendString:[fileRevision getRevision]]; [PerforceActionPrint defaultRunFor:self selector:@selector(viewAfterPrint:) withPath:revPath outputPath:fileName]; } - (IBAction) syncToFileRevision:(id)sender { int itemIdx = [fRevisionsView selectedRow]; PerforceFileRevision* fileRevision = [fRevisions objectAtIndex:itemIdx]; NSMutableString* revPath = [NSMutableString stringWithString:@"#"]; [revPath appendString:[fileRevision getRevision]]; [PerforceActionSync defaultRun:[NSArray arrayWithObject:[fileRevision getFilename]] revision:revPath]; } - (void) viewAfterPrint:(PerforceActionPrint*) action { if ( [action wasSuccess] ) { ViewFileInEditor ([action getOutputPath]); } } // // // // table view data source methods // - (int) numberOfRowsInTableView: (NSTableView*) aTableView { return [fRevisions count]; } - (id) tableView: (NSTableView*) aTableView objectValueForTableColumn: (NSTableColumn *) aTableColumn row: (int) rowIdx { NSString* identifier = [aTableColumn identifier]; PerforceFileRevision* fileRevision = [fRevisions objectAtIndex:rowIdx]; return [fileRevision valueForKey:identifier]; } // // table view data delegate methods // - (void) tableViewSelectionDidChange: (NSNotification *) aNotification { int numSel = [fRevisionsView numberOfSelectedRows]; if ( numSel == 2 ) { [fDiffRevButton setEnabled:YES]; } else { [fDiffRevButton setEnabled:NO]; } if ( numSel == 1 ) { [fDescribeButton setEnabled:YES]; [fViewButton setEnabled:YES]; [fSyncButton setEnabled:YES]; } else { [fDescribeButton setEnabled:NO]; [fViewButton setEnabled:NO]; [fSyncButton setEnabled:NO]; } } // // // @end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 3176 | paolo_resmini | initial branch for Paolo Resmini | ||
//guest/jeff_argast/P4Cocoa/source/Controllers/RevisionsController.m | |||||
#2 | 3111 | Jeff Argast |
Made multiple selection smarter by operating on the entire selection as an atomic operation with the server. Also partially fixed the read only window to not wrap at the window boundary. I did the same for the editable window, but now the problem appears to be that p4 change -o is breaking its output at some character location before the string gets into the editor (at least I think that is the problem). |
||
#1 | 2732 | Jeff Argast | Initial submission of P4Cocoa |