PerforceChangeList.m #1

  • //
  • guest/
  • jeff_argast/
  • P4Cocoa/
  • source/
  • Perforce/
  • PerforceChangeList.m
  • View
  • Commits
  • Open Download .zip Download (7 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 "PerforceChangeList.h"
#import "PerforceAction.h"
#import "IconController.h"
#import "IconDefs.h"
#import "AppUtils.h"
#import "PerforceActionChange.h"
#import "PerforceActionDescribe.h"
#import "ReadOnlyEditorController.h"
#import "PerforceActionSubmit.h"
#import "AppController.h"

static NSString* kDefaultChange = @"default";

@implementation PerforceChangeList

- (void) dealloc 
{
    [fChildren release];
    
    [fChangeNumber release];
    [fUserInfo release];
    [fChangeDesc release];
    [fDisplayString release];
        
    [super dealloc];
}

- (void) makeDisplayString: (BOOL) includeUserInfo
{
    NSMutableString* nsString = [[[NSMutableString alloc] init] autorelease];
    
    if ( !fIsDefaultChange )
    {
        [nsString appendString:@"Change "];
    }
    
    [nsString appendString:fChangeNumber];
    
    if ( includeUserInfo )
    {
        if ( [fUserInfo length] > 0 )
        {
            [nsString appendString:@" - "];
        
            [nsString appendString:fUserInfo];
        }
        
        if ( [fChangeDesc length] > 0 )
        {
            [nsString appendString:@" {"];
        
            [nsString appendString:fChangeDesc];
    
            [nsString appendString:@"}"];
        }
    }
    
    // force into an NSString
    fDisplayString = [[NSString alloc] initWithCString:[nsString cString]];
}


- (id) initWithNumber: (NSString*) changeNumber
       withUserInfo: (NSString*) userInfo
       withChangeDesc: (NSString*) changeDesc
       isClient: (BOOL) isClient
{
    self = [super init];
        
    fChangeNumber = [changeNumber copy];
    
	if ( [fChangeNumber isEqualToString:kDefaultChange] )
	{
		fIsDefaultChange = YES;
	}
	else
	{
		fIsDefaultChange = NO;
	}
	
    if ( userInfo && ([userInfo length] > 0) )
    {
        fUserInfo = [userInfo copy];
    }
    else
    {
        fUserInfo = [[NSString alloc] initWithString:@""];
    }
    
    if ( changeDesc )
    {
        fChangeDesc = [changeDesc copy];
    }
    else
    {
        fChangeDesc = [[NSString alloc] initWithString:@""];
    }

    fIsClientChangelist = isClient;
    
    [self makeDisplayString:!fIsClientChangelist];
    
    if ( fIsClientChangelist )
    {
        fIconID = kClientChangeIcon;
    }
    else
    {
        fIconID = kOtherChangeIcon;
    }
    
    return self;

}

- (void) setChildren: (NSArray*) children
{
    [fChildren release];
    
    fChildren = [children copy];
}

- (int)	getNumberOfChildren
{
    if ( fChildren )
    {
        return [fChildren count];
    }
    
    return 0;
}

- (BOOL) hasChildren
{
    if ( fChildren )
    {
        return ([fChildren count] > 0);
    }
    
    return NO;
}

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

- (id) getCellText
{
    return fDisplayString;
}

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

- (NSComparisonResult) compare: (PerforceChangeList*) rhs
{
    if ( fIsDefaultChange )
    {
        if ( rhs->fIsDefaultChange )
        {
            return [fUserInfo caseInsensitiveCompare:rhs->fUserInfo];
        }
        
        return NSOrderedAscending;
    }
    
    if ( rhs->fIsDefaultChange )
    {
        return NSOrderedDescending;
    }
    
    if ( [fUserInfo isEqualTo:rhs->fUserInfo] )
    {
        return [fChangeNumber caseInsensitiveCompare:rhs->fChangeNumber];
    }
    
    return [fUserInfo caseInsensitiveCompare:rhs->fUserInfo];
}

- (BOOL) isClientChangelist
{
    return fIsClientChangelist;
}

- (void) copyFrom:(PerforceChangeList*) rhs
{
	[fChangeNumber release];
	[fUserInfo release];
	[fChangeDesc release];
	[fDisplayString release];
 	[fChildren release];

	
	fChangeNumber 		= [rhs->fChangeNumber retain];
	fUserInfo 			= [rhs->fUserInfo retain];
	fChangeDesc 		= [rhs->fChangeDesc retain];
	fDisplayString 		= [rhs->fDisplayString retain];
 	fChildren 			= [rhs->fChildren retain];
 	fIsClientChangelist	= rhs->fIsClientChangelist;
	fIsDefaultChange 	= rhs->fIsDefaultChange;
	fIconID 			= rhs->fIconID;
}

//
/////
//
// The enablement
- (BOOL) canEdit
{
	return (fIsClientChangelist && !fIsDefaultChange);
}

- (BOOL) canDescribe
{
	return !fIsDefaultChange;
}

- (BOOL) canDelete
{
	return ![self hasChildren];
}

- (BOOL) canSubmit
{
	return [self hasChildren];
}

- (BOOL) canRevert
{
	return NO;//fIsClientChangelist;
}

- (BOOL) canSyncTo
{
	return NO;
}

- (BOOL) canSyncOnly
{
	return NO;
}


- (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
{
	[PerforceActionChangeGet defaultRunFor:[NSApp delegate] selector:@selector(resultFromPerforceChangeOut:) identifier:fChangeNumber];
}

- (void) doDescribe
{
	[PerforceActionDescribe defaultRunFor:self selector:@selector(resultFromDescribe:) changeNum:fChangeNumber];
}

- (void) doDelete
{
	int isOK = NSRunAlertPanel (@"Delete", 
								@"Are you sure you want to delete changelist %s?", 
								@"OK", 
								@"Cancel", 
								nil,
								[fChangeNumber cString]);

	if ( isOK )
	{
		[PerforceActionChangeDelete defaultRunFor:nil selector:nil identifier:fChangeNumber];
	}
}

- (void) doSubmit
{
	if ( fIsDefaultChange )
	{
		[PerforceActionChangeNew defaultRunFor:self selector:@selector(resultFromPerforceChangeNew:)];
	}
	else
	{
		[PerforceActionSubmitChangelist defaultRunFor:nil selector:nil changeNum:fChangeNumber];
	}
}

- (void) doRevert
{
}

- (void) doSyncTo
{
}

- (void) doSyncOnly
{
}

//
//
//
- (void) submitChangeOK: (NSString*) contentString;
{
	[PerforceActionSubmit defaultRunFor:self selector:@selector(resultFromPerforceSubmit:) form:contentString];
}


- (void) resultFromPerforceSubmit: (PerforceActionSubmit*) action
{
	if ( [action wasError] )
	{
		[[NSApp delegate] showEditSheet:self contentData:[action getForm] endSelector:@selector(submitChangeOK:)];
	}
}

- (void) resultFromPerforceChangeNew: (PerforceActionChangeNew*) action
{
	if ( [action wasSuccess] )
	{
		[[NSApp delegate] showEditSheet:self contentData:[action getOutput] endSelector:@selector(submitChangeOK:)];
	}
}

/*
- (void) resultFromPerforceChangeOut: (PerforceActionChangeGet*) action
{
	if ( [action wasSuccess] )
	{
		[[NSApp delegate] showEditSheet:self contentData:[action getOutput] endSelector:@selector(submitChangeOK:)];
	}
}
*/

@end
# Change User Description Committed
#11 4225 Jeff Argast Added resolve support, reveal in finder, drag and drop edit,
show local files, and showing added files.
#10 4208 Jeff Argast Added command line parsing and changed the sorting of user information
in the pending changes view
#9 3149 Jeff Argast Add default changelist to pending list always even if default is empty
#8 3132 Jeff Argast Finally fixed the stupid wrapping problem.
Turns out there
are tabs in the text returned from Perforce.  No problem.
But in NSTextView if a tab occurs beyond the last tab stop
then NSTextView breaks the line.  So no what I want. The fix
is to create a bunch of tab stops out to the etherlands.
#7 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.
#6 3126 Jeff Argast Added drag and drop reordering/reopening of files in the
pending change list view
#5 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.
#4 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).
#3 2803 Jeff Argast Added submit default changelist to the changelist menu
Made the out window selectable
Changed the tabs in a few places
#2 2737 Jeff Argast Added several 0.15 revision functionality
#1 2732 Jeff Argast Initial submission of P4Cocoa