/* 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 "PendingViewSelection.h" #import "AppUtils.h" #import "DepotViewProtocol.h" #import "PerforceChangeFile.h" #import "PerforceChangeList.h" static NSString* kPendingChangesDragType = @"PendingChangesDragType"; @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(handleChangeChanged:) name:kActionSyncCommandComplete object:nil]; [nCenter addObserver:self selector:@selector(handleChangeChanged:) name:kActionEditCommandComplete object:nil]; [nCenter addObserver:self selector:@selector(handleChangeChanged:) name:kActionDeleteCommandComplete object:nil]; [nCenter addObserver:self selector:@selector(handleChangeChanged:) name:kActionRevertCommandComplete object:nil]; [nCenter addObserver:self selector:@selector(handleChangeChanged:) name:kActionAddCommandComplete object:nil]; [nCenter addObserver:self selector:@selector(handleChangeChanged:) name:kActionSubmitCommandComplete object:nil]; [nCenter addObserver:self selector:@selector(handleChildChanged:) name:kPendingChangesChildChanged object:nil]; } [fPendingChangesView setTarget:self]; [fPendingChangesView setDoubleAction:@selector(doubleAction:)]; [fPendingChangesView setVerticalMotionCanBeginDrag:NO]; [fPendingChangesView registerForDraggedTypes:[NSArray arrayWithObject:kPendingChangesDragType]]; } - (void) doubleAction: (id) sender { NSWindow* window = [fPendingChangesView window]; NSPoint clickPoint = [NSEvent mouseLocation]; clickPoint = [window convertScreenToBase:clickPoint]; clickPoint = [fPendingChangesView convertPoint:clickPoint fromView:nil]; int rowIndex = [fPendingChangesView rowAtPoint:clickPoint]; if ( rowIndex >= 0 ) { id<PendingChangelistProtocol> item = [fPendingChangesView itemAtRow:rowIndex]; if ( [item canViewInEditor] ) { [item doViewInEditor]; } } } - (NSArray*) getSelectedItems { // 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]]; } return objects; } - (void) setSelectedItems:(NSArray*)objects { // now select the items that were selected before the expansion [fPendingChangesView deselectAll:self]; int numItems = [objects count]; int n; for ( n = 0; n < numItems; n++ ) { int rowIndex = [fPendingChangesView rowForItem:[objects objectAtIndex:n]]; if ( rowIndex >= 0 ) { [fPendingChangesView selectRow:rowIndex byExtendingSelection:YES]; } } } - (void) handleChangeChanged: (NSNotification*) notification { // This sucks, but at the moment all the children are // destroyed and recreated leaving the existing selection // referencing rows to invalid objects [fPendingChangesView deselectAll:self]; [self refreshClientData]; } - (void) handleChildChanged: (NSNotification*) notification { // This ultimately doesn't work because of the stale // data. It works in the depot view though, so we // should be able to get it to work here. //NSArray* selectedItems = [self getSelectedItems]; [fPendingChangesView reloadData]; //[self setSelectedItems:selectedItems]; } - (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]]; } } - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item { // WEIRD: Must implement this delegate function and return NO in order for // double click to work return NO; } // // 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]; } - (BOOL) canViewInEditor { id <PendingChangelistProtocol> selection = [self getSelection]; return [selection canViewInEditor]; } // 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) doRevertUnchanged { id <PendingChangelistProtocol> selection = [self getSelection]; [selection doRevertUnchanged]; } - (void) doDiff { id <PendingChangelistProtocol> selection = [self getSelection]; [selection doDiff]; } - (void) doViewInEditor { id <PendingChangelistProtocol> selection = [self getSelection]; [selection doViewInEditor]; } - (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 { // only drag items that are client change files BOOL canDrag = YES; int numItems = [items count]; int n; for ( n = 0; (n < numItems) && (canDrag == YES); n++ ) { id anItem = [items objectAtIndex:n]; if ( [anItem isKindOfClass:[PerforceChangeFile class]] ) { PerforceChangeList* parentList = [anItem parentChangelist]; if ( ![parentList isClientChangelist] ) { canDrag = NO; } } else // we can't drag anything other than files { canDrag = NO; } } if ( canDrag ) { // Put our own custom type into the pasteboard, which is the pointer to the array of items unsigned int arrayPtrVal = (unsigned int)items; NSData* arrayData = [NSData dataWithBytes:&arrayPtrVal length:sizeof(unsigned int)]; [pb declareTypes:[NSArray arrayWithObject:kPendingChangesDragType] owner:nil]; [pb setData:arrayData forType:kPendingChangesDragType]; } return canDrag; } // Destination, i.e. target of drag - (NSDragOperation)outlineView:(NSOutlineView*)olv validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index { // drop on change lists only, not children and only client change lists if ( [item isKindOfClass:[PerforceChangeFile class]] ) { PerforceChangeList* parentList = [item parentChangelist]; if ( [parentList isClientChangelist] ) { [olv setDropItem:parentList dropChildIndex:NSOutlineViewDropOnItemIndex]; return NSDragOperationCopy; } } else if ( [item isKindOfClass:[PerforceChangeList class]] ) { if ( [item isClientChangelist] ) { [olv setDropItem:item dropChildIndex:NSOutlineViewDropOnItemIndex]; return NSDragOperationCopy; } } [olv setDropItem:nil dropChildIndex:NSOutlineViewDropOnItemIndex]; return NSDragOperationNone; } // Destination, i.e. target of drag - (BOOL)outlineView:(NSOutlineView*)olv acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index { NSPasteboard* pb = [info draggingPasteboard]; NSData* arrayData = nil; NSString* type; type = [pb availableTypeFromArray: [NSArray arrayWithObject:kPendingChangesDragType]]; if ( type ) { arrayData = [pb dataForType:kPendingChangesDragType]; if ( arrayData ) { NSArray* draggingArray = nil; [arrayData getBytes:&draggingArray]; //NSLog([draggingArray description]); // Get the selection NSArray* selectedItems = [self getSelectedItems]; [item reopen:draggingArray]; [fPendingChangesView reloadData]; [self setSelectedItems:selectedItems]; return YES; } } return NO; } // // // @end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 3176 | paolo_resmini | initial branch for Paolo Resmini | ||
//guest/jeff_argast/P4Cocoa/source/Controllers/PendingChangesController.m | |||||
#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 |