PendingChangesController.m #4

  • //
  • guest/
  • jeff_argast/
  • P4Cocoa/
  • source/
  • Controllers/
  • PendingChangesController.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 "PendingChangesController.h"
#import "OutlineItem.h"
#import "AppDefaults.h"
#import "MessageDefs.h"
#import "PerforceChanges.h"
#import "DepotViewProtocol.h"
#import "PendingViewSelection.h"
#import "AppUtils.h"

@implementation PendingChangesController

- (void) comeForward
{
    fForward = YES;
    
    [fPendingChangesView reloadData];
}

- (void) stepBack
{
    fForward = NO;
}

- (void) dealloc
{
    NSNotificationCenter* nCenter = [NSNotificationCenter defaultCenter];

    [nCenter removeObserver:self];

    [fChildren release];
    
	[fCachedSelection release];
	
    [super dealloc];
}

- (void) buildChildren
{
    NSMutableArray* childArray = [[NSMutableArray alloc] initWithCapacity:2];
    
    NSMutableString* nsString = [NSMutableString stringWithString:@"Pending Changelists (client '"];
    
    AppDefaults* appDefaults = [AppDefaults defaultAppDefaults];
        
    [nsString appendString:[appDefaults getPerforceClient]];
    
    [nsString appendString:@"')"];
    
    [childArray addObject:[[[PerforceChanges alloc] 
                                initWithName:nsString clientChanges:YES] 
                                    autorelease]];
    
    [childArray addObject:[[[PerforceChanges alloc] 
                                initWithName:@"Pending Changelists (other clients)" clientChanges:NO] 
                                    autorelease]];
    
    fChildren = childArray;
    
}

- (void) awakeFromNib
{
    NSTableColumn *tableColumn = nil;
    NSBrowserCell *browserCell = nil;

    tableColumn = [fPendingChangesView tableColumnWithIdentifier:@"1"];
    
    browserCell = [[[NSBrowserCell alloc] init] autorelease];
    
    [browserCell setEditable:NO];
    
    [browserCell setLeaf:YES];
    
    [tableColumn setDataCell:browserCell];


    {
        NSNotificationCenter* nCenter = [NSNotificationCenter defaultCenter];
    
        [nCenter addObserver:self selector:@selector(handleDefaultsChanged:) name:kDefaultsUserChanged object:nil];
        [nCenter addObserver:self selector:@selector(handleDefaultsChanged:) name:kDefaultsClientChanged object:nil];
        [nCenter addObserver:self selector:@selector(handleDefaultsChanged:) name:kDefaultsPortChanged object:nil];
        [nCenter addObserver:self selector:@selector(handleDefaultsChanged:) name:kGlobalSyncComplete object:nil];
        [nCenter addObserver:self selector:@selector(handleDefaultsChanged:) name:kDefaultsConfigurationsChanged object:nil];
        [nCenter addObserver:self selector:@selector(handleDefaultsChanged:) name:kRefreshAllViews object:nil];
		[nCenter addObserver:self selector:@selector(handleChangeChanged:) name:kChangeChanged object:nil];

        [nCenter addObserver:self selector:@selector(handleChildChanged:) name:kPendingChangesChildChanged object:nil];
	}

	[fPendingChangesView setVerticalMotionCanBeginDrag:NO];
}

- (void) handleChangeChanged: (NSNotification*) notification
{
	[self refreshClientData];
}

- (void) handleChildChanged: (NSNotification*) notification
{
	[fPendingChangesView reloadData];
}



- (void) handleDefaultsChanged: (NSNotification*) notification
{
	[self refreshData];
}


/*
** The outline view datasource protocol
*/

// outlineView:child:ofItem:
- (id) outlineView: (NSOutlineView *) outlineView 
       child: 		(int) index 
       ofItem:		(id) item
{
    if ( item )
    {
        return [item getChildAtIndex: index];
    }
    
    if ( !fForward )
    {
		/*
		skip entirely.  It works ok this way and has the advantage
		of not hitting the server when the panel is not forward
        if ( fChildren )
        {
            return [fChildren objectAtIndex: index];
        }
        */
        return nil;
    }

    if ( !fChildren )
    {
        [self buildChildren];
    }
    
    return [fChildren objectAtIndex: index];
}

// outlineView:isItemExpandable:
- (BOOL) outlineView: 		(NSOutlineView *) outlineView 
         isItemExpandable: 	(id) item
{
    if ( item )
    {
        return [item hasChildren];
    }
    
    return YES;
}

// outlineView:numberOfChildrenOfItem:
- (int) outlineView: 			(NSOutlineView*) outlineView 
        numberOfChildrenOfItem: (id) item
{
    if ( item )
    {
        return [item getNumberOfChildren];
    }

    if ( !fForward )
    {
        /*
		skip entirely.  It works ok this way and has the advantage
		of not hitting the server when the panel is not forward
		if ( fChildren )
        {
            return [fChildren count];
        }
        */
		
        return 0;
    }
    
    if ( !fChildren )
    {
        [self buildChildren];
    }

    return [fChildren count];
}

// outlineView:objectValueForTableColumn:byItem:
- (id) outlineView: 				(NSOutlineView *) outlineView 
       objectValueForTableColumn: 	(NSTableColumn *) tableColumn
       byItem: 						(id) item
{
    return [item getCellText];
}
    

/*
** outline view delegate methods
*/

- (void) 	outlineView: 		(NSOutlineView *) olv 
            willDisplayCell:	(NSCell *) cell 
            forTableColumn:		(NSTableColumn *) tableColumn 
            item:				(id) item 
{  
    if ( [[tableColumn identifier] isEqualToString:@"1"] ) 
    {
        [(NSBrowserCell*)cell setImage:[item getCellImage]];
    }
}


//
// getSelection
//
- (id<PendingChangelistProtocol>) getSelection
{
	if ( !fCachedSelection )
	{
		// plus one because the num items selected may be 0
		NSMutableArray* objects = [NSMutableArray arrayWithCapacity:([fPendingChangesView numberOfSelectedRows] + 1)];
		
		NSEnumerator* items = [fPendingChangesView selectedRowEnumerator];
		NSNumber*     rowNum;
		
		while ( rowNum = [items nextObject] )
		{
			int rowIdx = [rowNum intValue];
			
			[objects addObject:[fPendingChangesView itemAtRow:rowIdx]];
		}
		
		fCachedSelection = [[PendingViewSelection alloc] initWithItems:objects];
	}
	
	return fCachedSelection;
}

- (void)outlineViewSelectionDidChange:(NSNotification *)notification
{
	[fCachedSelection release];
	
	fCachedSelection = nil;
}


//
//
//

// The enablement
- (BOOL) canEdit
{
	id <PendingChangelistProtocol> selection = [self getSelection];
	
	return [selection canEdit];
}

- (BOOL) canDescribe
{
	id <PendingChangelistProtocol> selection = [self getSelection];
	
	return [selection canDescribe];
}

- (BOOL) canDelete
{
	id <PendingChangelistProtocol> selection = [self getSelection];
	
	return [selection canDelete];
}

- (BOOL) canSubmit
{
	id <PendingChangelistProtocol> selection = [self getSelection];
	
	return [selection canSubmit];
}

- (BOOL) canRevert
{
	id <PendingChangelistProtocol> selection = [self getSelection];
	
	return [selection canRevert];
}

- (BOOL) canDiff
{
	id <PendingChangelistProtocol> selection = [self getSelection];
	
	return [selection canDiff];
}


// The actions
- (void) doEdit
{
	id <PendingChangelistProtocol> selection = [self getSelection];
	
	[selection doEdit];
}

- (void) doDescribe
{
	id <PendingChangelistProtocol> selection = [self getSelection];
	
	[selection doDescribe];
}

- (void) doDelete
{
	id <PendingChangelistProtocol> selection = [self getSelection];
	
	[selection doDelete];
}

- (void) doSubmit
{
	id <PendingChangelistProtocol> selection = [self getSelection];
	
	[selection doSubmit];
}

- (void) doRevert
{
	id <PendingChangelistProtocol> selection = [self getSelection];
	
	[selection doRevert];
}

- (void) doDiff
{
	id <PendingChangelistProtocol> selection = [self getSelection];
	
	[selection doDiff];
}

- (void) appendRevertPath: (NSMutableArray*) revertPathList
{
	// the controller does nothing.  TODO: This means the protocol definition is too broad
	// and needs to be broken into more granular protocols. 
}

//
//
//

- (void) refreshData
{
    if ( fChildren )
    {
        [fChildren release];
    
        fChildren = nil;
    
        [fPendingChangesView reloadData];
    }
}

- (void) refreshClientData
{
    if ( fChildren && ( [fChildren count] > 0 ) )
    {
        PerforceChanges* clientChanges = [fChildren objectAtIndex:0];
        
        [clientChanges refreshClientData];
    
        [fPendingChangesView reloadData];
    }
}

//
// Drag and drop
//

// Source, i.e. starting a drag
- (BOOL)outlineView:(NSOutlineView *)olv writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pb 
{
	if ( [items count] > 1 )
		return NO;
	
	id item = [items objectAtIndex:0];
	
	WriteStringToPasteboard ([item getPasteboardData], pb);
	
    return YES;
}

// Destination, i.e. target of drag
- (NSDragOperation)outlineView:(NSOutlineView*)olv 
				   validateDrop:(id <NSDraggingInfo>)info 
				   proposedItem:(id)item 
				   proposedChildIndex:(int)index
{
	[olv setDropItem:nil dropChildIndex:NSOutlineViewDropOnItemIndex];
	
	return NSDragOperationCopy;
}

// Destination, i.e. target of drag
- (BOOL)outlineView:(NSOutlineView*)olv acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
{
	NSPasteboard* pb = [info draggingPasteboard];
	
	NSArray* value = nil;
	NSString* type;
	
	type = [pb availableTypeFromArray: [NSArray arrayWithObject:NSFilenamesPboardType]];
	
	if ( type )
	{
		value = [pb propertyListForType:NSFilenamesPboardType];

		if ( value )
		{
		}
	}

	return NO;
}

//
//
//

@end
# Change User Description Committed
#10 4225 Jeff Argast Added resolve support, reveal in finder, drag and drop edit,
show local files, and showing added files.
#9 3134 Jeff Argast Added copy/paste support in the depot view
Added expand path to depot view
Added bookmarks
#8 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.
#7 3126 Jeff Argast Added drag and drop reordering/reopening of files in the
pending change list view
#6 3114 Jeff Argast Fixed retaining the correct selection after a perforce action
completed executing and updated the outline 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