/* 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 "PendingChangesView.h" #import "PerforceAction.h" #import "PendingChangelistProtocol.h" #import "PendingChangesController.h" @implementation PendingChangesView - (NSMenu *)menuForEvent:(NSEvent *)theEvent { [[self window] makeFirstResponder:self]; // Figure out what we hit. If a valid row then make it the selection // unless the item is already in the selection NSPoint clickPoint = [theEvent locationInWindow]; clickPoint = [self convertPoint:clickPoint fromView:nil]; int rowIdx = [self rowAtPoint:clickPoint]; if ( rowIdx >= 0 ) { BOOL inSelection = NO; // Is the hit row in the selection? NSEnumerator* items = [self selectedRowEnumerator]; NSNumber* rowNum; while ( rowNum = [items nextObject] ) { if ( rowIdx == [rowNum intValue] ) { inSelection = YES; } } if ( !inSelection ) { [self selectRow:rowIdx byExtendingSelection:NO]; } } if ( rowIdx >= 0 ) { return [super menuForEvent:theEvent]; } return nil; } - (BOOL) validateMenuItem:(NSMenuItem*)menuItem { id item = [self delegate]; if ( !item ) return NO; BOOL isNoCriticalActionRunning = ![PerforceAction isCriticalActionRunning]; SEL selector = [menuItem action]; if ( selector == @selector(editChangelist:) ) { return [item canEdit]; } if ( selector == @selector(describeChangelist:) ) { return [item canDescribe]; } if ( selector == @selector(deleteChangelist:) ) { return [item canDelete]; } if ( selector == @selector(submitChangelist:) ) { return isNoCriticalActionRunning && [item canSubmit]; } if ( selector == @selector(revert:) ) { return isNoCriticalActionRunning && [item canRevert]; } if ( selector == @selector(revertUnchanged:) ) { return isNoCriticalActionRunning && [item canRevert]; } if ( selector == @selector(diff:) ) { return isNoCriticalActionRunning && [item canDiff]; } if ( selector == @selector(viewInEditor:) ) { return [item canViewInEditor]; } return YES; } - (IBAction) editChangelist:(id)sender { id item = [self delegate]; [item doEdit]; } - (IBAction) describeChangelist:(id)sender { id item = [self delegate]; [item doDescribe]; } - (IBAction) deleteChangelist:(id)sender { id item = [self delegate]; [item doDelete]; } - (IBAction) submitChangelist:(id)sender { id item = [self delegate]; [item doSubmit]; } - (IBAction) revert:(id)sender { id item = [self delegate]; [item doRevert]; } - (IBAction) revertUnchanged:(id)sender { id item = [self delegate]; [item doRevertUnchanged]; } - (IBAction) diff: (id) sender { id item = [self delegate]; [item doDiff]; } - (IBAction) viewInEditor: (id) sender { id item = [self delegate]; [item doViewInEditor]; } @end