/* 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 "ActionListController.h" #import "PerforceAction.h" #import "MessageDefs.h" @implementation ActionListController // // table view data source methods // - (id) init { self = [super init]; fChildren = [[NSMutableArray alloc] init]; fPerforceActions = [[NSMutableArray alloc] init]; return self; } - (void) dealloc { NSNotificationCenter* nCenter = [NSNotificationCenter defaultCenter]; [nCenter removeObserver:self]; [fChildren release]; [fPerforceActions release]; [super dealloc]; } - (void) refreshActionList { [fChildren removeAllObjects]; [fPerforceActions removeAllObjects]; NSArray* actionList = [PerforceAction runningActions]; [fPerforceActions addObjectsFromArray:actionList]; int n = 0; int num = [actionList count]; for ( n = 0; n < num; n++ ) { PerforceAction* action = [actionList objectAtIndex:n]; [fChildren addObject:[action getActionDescription]]; } [fTableView reloadData]; } - (void) handleActionListChanged: (NSNotification*) notification { [self refreshActionList]; } -(void) stopTask:(id)sender { if ( fClickedRow >= 0 && fClickedRow < [fPerforceActions count] ) { PerforceAction* action = [fPerforceActions objectAtIndex:fClickedRow]; [action abort]; } } - (void) awakeFromNib { NSNotificationCenter* nCenter = [NSNotificationCenter defaultCenter]; [nCenter addObserver:self selector:@selector(handleActionListChanged:) name:kActionListChanged object:nil]; NSTableColumn* tableColumn = nil; NSButtonCell* buttonCell = nil; tableColumn = [fTableView tableColumnWithIdentifier:@"0"]; buttonCell = [[[NSButtonCell alloc] init] autorelease]; [buttonCell setButtonType:NSMomentaryPushInButton]; [buttonCell setBezelStyle:NSRoundedBezelStyle]; [buttonCell setTitle:@"Stop"]; NSSize buttonSize = [buttonCell cellSize]; [tableColumn setMaxWidth:buttonSize.width]; [tableColumn setWidth:buttonSize.width]; [buttonCell setTarget:self]; [buttonCell setAction:@selector(stopTask:)]; [tableColumn setDataCell:buttonCell]; [self refreshActionList]; } - (int) numberOfRowsInTableView: (NSTableView*) aTableView { return [fChildren count]; } - (id) tableView: (NSTableView*) aTableView objectValueForTableColumn: (NSTableColumn *) aTableColumn row: (int) rowIdx { if ( [[aTableColumn identifier] isEqualTo:@"1"] ) { return [fChildren objectAtIndex:rowIdx]; } return nil; } // Delegate - (void)tableViewSelectionIsChanging:(NSNotification *)aNotification { fClickedRow = [fTableView selectedRow]; // This stops the selection from happening but still // allows events to be passed on to the button [fTableView deselectAll:self]; } @end