PerforceChanges.m #7

  • //
  • guest/
  • jeff_argast/
  • P4Cocoa/
  • source/
  • Perforce/
  • PerforceChanges.m
  • View
  • Commits
  • Open Download .zip Download (10 KB)
/*

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 "PerforceChanges.h"
#import "PerforceChangeList.h"
#import "PerforceAction.h"
#import "IconController.h"
#import "IconDefs.h"
#import "AppUtils.h"
#import "AppDefaults.h"
#import "PerforceChangeFile.h"
#import "PerforceActionChangesPending.h"
#import "PerforceActionOpened.h"
#import "MessageDefs.h"

// local functions
static void FilterOutOtherChanges (NSArray* changesArray, NSMutableArray* resultArray);
static void FilterOutClientChanges (NSMutableArray* resultArray);
static void IntersectWithOpened (NSArray* changeFileArray, NSMutableArray* resultArray);
static void CopyToChildren (NSMutableArray* fromArray, NSMutableArray* toArray);

@implementation PerforceChanges

- (void) resultFromPerforceOpened: (PerforceActionOpened*) action
{
	if ( [action wasSuccess] )
	{
		NSArray* openedArray = [action getOpened];
		
		if ( fClientOnly )
		{
			NSMutableArray* newChildren = [[[NSMutableArray alloc] init] autorelease];
			
			FilterOutOtherChanges (fChangesPendingArray, newChildren);
			
			IntersectWithOpened (openedArray, newChildren);
			
			CopyToChildren (newChildren, fChildren);
			
			// If the default change list is not in the children, add it
			BOOL addDefault = NO;
			
			if ( [fChildren count] > 0 )
			{
				PerforceChangeList* changeList = [fChildren objectAtIndex:0];
				
				if ( ![changeList isDefaultChangelist] )
				{
					addDefault = YES;
				}
			}
			else
			{
				addDefault = YES;
			}
			
			if ( addDefault )
			{
				PerforceChangeList* defaultChangeList = [[[PerforceChangeList alloc] initWithNumber:@"default"
															withUserInfo:GetUserAtClientString()
															withChangeDesc:nil
															isClient:YES] autorelease];
			
				[fChildren insertObject:defaultChangeList atIndex:0];
			}
		}
		else
		{
			[fChildren removeAllObjects];
			
			[fChildren addObjectsFromArray:fChangesPendingArray];
			
			IntersectWithOpened (openedArray, fChildren);
		
			FilterOutClientChanges (fChildren);
		}
	}
	
	[fChangesPendingArray release];
	
	fChangesPendingArray = nil;
	
	SendNotificationWithObject (kPendingChangesChildChanged, self);
}

- (void) resultFromPerforcePendingChanges: (PerforceActionChangesPending*) action
{
	if ( [action wasSuccess] )
	{
		fChangesPendingArray = [[action getChangesPending] retain];
	
		[PerforceActionOpened defaultRunFor:self selector:@selector(resultFromPerforceOpened:) clientOnly:fClientOnly];
	}
}



- (void) buildChildren
{
	if ( !fChildren )
	{
		fChildren = [[NSMutableArray alloc] init];
	}
	
	[PerforceActionChangesPending defaultRunFor:self selector:@selector(resultFromPerforcePendingChanges:)];
    
    fMustGatherChildren = NO;
}

- (void) dealloc 
{
    [fChildren release];
    
    [fChangesName release];
        
    [super dealloc];
}

- (id)	initWithName: (NSString*) changesName
        clientChanges: (BOOL) clientOnly
{    
    if ( self = [super init] )
    {
        fChangesName = [changesName copy];
        
        fClientOnly = clientOnly;
        
        fMustGatherChildren = YES;
        
        if ( fClientOnly )
        {
            fIconID = kClientPendingChangesIcon;
 		}
        else
        {
            fIconID = kOtherPendingChangesIcon;
        }
    }
        
    return self;
}

- (int)	getNumberOfChildren
{
    if ( fMustGatherChildren )
    {
        [self buildChildren];
    }
    
    return [fChildren count];
}

- (BOOL) hasChildren
{
    return YES;
}

- (id) getChildAtIndex: (int) index
{
    if ( fMustGatherChildren )
    {
        [self buildChildren];
    }
    
    return [fChildren objectAtIndex:index];
}

- (id) getCellText
{
    return fChangesName;
}

- (id) getCellImage
{
    return [[IconController defaultIconController] getIcon:fIconID];
}

- (void) refreshClientData
{
    if ( !fClientOnly )
        return;
        
    //[fChildren release];
    
    //fChildren = nil;
    
    fMustGatherChildren = YES;

	SendNotificationWithObject (kPendingChangesChildChanged, self);
}


//
/////
//
// The enablement
- (BOOL) canEdit
{
	return NO;
}

- (BOOL) canDescribe
{
	return NO;
}

- (BOOL) canDelete
{
	return NO;
}

- (BOOL) canSubmit
{
	return NO;
}

- (BOOL) canResolve
{
	return NO;
}

- (BOOL) canRevert
{
	return NO;
}

- (BOOL) canDiff
{
	return NO;
}

- (BOOL) canRevealInFinder
{
	return NO;
}

- (BOOL) canViewInEditor
{
	return NO;
}



// The actions
- (void) doEdit
{
}

- (void) doDescribe
{
}

- (void) doDelete
{
}

- (void) doSubmit
{
}

- (void) doResolve
{
}

- (void) doRevert
{
}

- (void) doRevertUnchanged
{
}

- (void) doDiff
{
}

- (void) doRevealInFinder
{
}

- (void) doViewInEditor
{
}

- (void) appendRevertPath: (NSMutableArray*) revertPathList
{
	// Do Nothing
}


@end

//
//
//
///////////////////////////////////////
//
//
//

void FilterOutOtherChanges (NSArray* changesArray, NSMutableArray* resultArray)
{ 
    int numChanges = [changesArray count];
    int n;
	
    for ( n = 0; n < numChanges; n++ )
    {
        PerforceChangeList* pfcl = [changesArray objectAtIndex:n];
        
        if ( [pfcl isClientChangelist] )
        {
            [resultArray addObject:pfcl];
        }
    }
}

void FilterOutClientChanges (NSMutableArray* resultArray)
{
    int numChanges = [resultArray count];
    int n;
	
    for ( n = numChanges - 1; n >= 0; n-- )
    {
        PerforceChangeList* pfcl = [resultArray objectAtIndex:n];
        
        if ( [pfcl isClientChangelist] )
        {
            [resultArray removeObjectAtIndex:n];
        }
    }
}

void IntersectWithOpened (NSArray* changeFileArray, NSMutableArray* resultArray)
{
    int numItems = [changeFileArray count];

    if ( numItems <= 0 )
        return; // bail

    NSString* changeAndUser = [[changeFileArray objectAtIndex:0] getChangeAndUser];
    
    int n = 0;
    int numChangeLists = [resultArray count];
    
    int currentChange = 0;
    
    NSComparisonResult compareResult = NSOrderedDescending;
    
    PerforceChangeList* newChangeList = nil;

    while ( n < numItems )
    {
        NSRange copyRange;
        NSArray* subArray;
        PerforceChangeFile* changeFile = nil;
        
        int startn = n;
        
        while ( (n < numItems) 
                    && ([changeAndUser compare:[[changeFileArray objectAtIndex:n] getChangeAndUser]] == NSOrderedSame) )
        {
            n++;
        }
        
        changeFile = [changeFileArray objectAtIndex:startn];
                
        newChangeList = [[[PerforceChangeList alloc] initWithNumber:[changeFile getChangeName]
                                                     withUserInfo:[changeFile getUserInfo]
                                                     withChangeDesc:nil
                                                     isClient:[changeFile isClientChange]] autorelease];
                                                                            
        copyRange.location = startn;
        copyRange.length   = n - startn;
        
        subArray = [changeFileArray subarrayWithRange:copyRange];

        while ( (compareResult == NSOrderedDescending) && (currentChange < numChangeLists) )
        {
            compareResult = [newChangeList compare:[resultArray objectAtIndex:currentChange]];
            
            if ( compareResult == NSOrderedDescending )
            {
                currentChange++;
            }
        }
        
        // did we fall off the end of the list? if so just append a new change list
        if ( currentChange >= numChangeLists )
        {
            [newChangeList setChildren:subArray];
            
            [resultArray addObject:newChangeList];            
        }
        else
        {
            if ( compareResult == NSOrderedSame )
            {
                [[resultArray objectAtIndex:currentChange] setChildren:subArray];
            }
            else
            {
                [newChangeList setChildren:subArray];
                
                [resultArray insertObject:newChangeList atIndex:currentChange];
                
                currentChange++;
                
                numChangeLists++;
            }
        }
        
        if ( n < numItems )
        {
            changeAndUser = [[changeFileArray objectAtIndex:n] getChangeAndUser];
        }
        
        compareResult = NSOrderedDescending;
    }
}

void CopyToChildren (NSMutableArray* fromArray, NSMutableArray* toArray)
{
	int numFrom = 0;
	int numTo = [toArray count];
	
	int n, k;
	
	for ( n = (numTo - 1); n >= 0; n-- )
	{
		PerforceChangeList* currentChangeList = [toArray objectAtIndex:n];
		
		BOOL bFound = NO;
		numFrom = [fromArray count];
		
		for ( k = (numFrom - 1); (k >= 0) && !bFound; k-- )
		{
			PerforceChangeList* newChangeList = [fromArray objectAtIndex:k];
			
			if ( [newChangeList compare:currentChangeList] == NSOrderedSame )
			{
				[currentChangeList copyFrom:newChangeList];
				
				[fromArray removeObjectAtIndex:k];
				
				bFound = YES;
			}
		}
	
		if ( !bFound )
		{
			[toArray removeObjectAtIndex:n];
		}
	}
	
	[toArray addObjectsFromArray:fromArray];

	[toArray sortUsingSelector:@selector(compare:)];
}

# Change User Description Committed
#7 4225 Jeff Argast Added resolve support, reveal in finder, drag and drop edit,
show local files, and showing added files.
#6 3149 Jeff Argast Add default changelist to pending list always even if default is empty
#5 3130 Jeff Argast Added double click support to the depot view and pending changelist
view.  Added View File In Editor item on the pending changeist
context menu.
#4 3113 Jeff Argast Reduced the times the depot view completely collapses.
Now it won't collapse on refresh views or submit, but
still collapses when the defaults change.
#3 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).
#2 2737 Jeff Argast Added several 0.15 revision functionality
#1 2732 Jeff Argast Initial submission of P4Cocoa